master
chentaisen 2024-09-05 15:06:48 +08:00
parent 7859e79739
commit d4d2741e39
2 changed files with 39 additions and 22 deletions

View File

@ -69,7 +69,7 @@ public class RuleEditionController {
//java OSS //java OSS
UploadOss.uploadFiles(ruleEdition.getRuleEngine(), ruleEdition.getRuleKind()); UploadOss.uploadFiles(ruleEdition.getRuleEngine(), ruleEdition.getRuleKind());
OSSFileDownload.streamingDownload(ruleEdition.getRuleKind()); OSSFileDownload.compile(ruleEdition.getRuleKind());
//对路径里的.java文件进行编译 //对路径里的.java文件进行编译
SourceCodeCompiler.javaCompilerPath("/home"); SourceCodeCompiler.javaCompilerPath("/home");

View File

@ -5,6 +5,8 @@ import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.ObjectMetadata;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import java.io.File; import java.io.File;
public class OSSFileDownload { public class OSSFileDownload {
@ -21,28 +23,43 @@ public class OSSFileDownload {
private static final String filePath = "oss/"; private static final String filePath = "oss/";
public static Result<Object> streamingDownload(String fileName) { // public static Result<Object> streamingDownload(String fileName) {
//
// String source = null;
// // 创建 OSSClient 实例
// OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
// // 判断 bucket 是否存在
// Boolean flag_bucket = ossClient.doesBucketExist(bucketName);
// if (!flag_bucket) {
// System.out.println("bucket不存在");
// return Result.error("bucket不存在");
// }
// String objectName = fileName + ".java";
// Boolean flag_file = ossClient.doesObjectExist(bucketName, filePath + objectName);
// if (!flag_file) {
// System.out.println("预下载文件不存在");
// return Result.error("预下载文件不存在");
// }
// // 本地文件下载路径
// String localPath = "home/" + objectName;
// ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + objectName), new File(localPath));
// System.out.println(object);
// ossClient.shutdown();
// return Result.success(source);
// }
String source = null; public static Result<Object> compile(String fileName) {
// 创建 OSSClient 实例 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); String[] strings = {"-classpath", "/home/lib", "-verbose", "-d", "/home/lib", fileName};
// 判断 bucket 是否存在 //编译任务
Boolean flag_bucket = ossClient.doesBucketExist(bucketName); int result = compiler.run(null, null, null, strings);
if (!flag_bucket) { //检查编译结果
System.out.println("bucket不存在"); if (result == 0) {
return Result.error("bucket不存在"); System.out.println("编译成功,生成的.class文件位于源代码同目录");
} else {
System.out.println("编译失败");
} }
String objectName = fileName + ".java"; String externalClassFilePath = "/home";
Boolean flag_file = ossClient.doesObjectExist(bucketName, filePath + objectName); return Result.success();
if (!flag_file) {
System.out.println("预下载文件不存在");
return Result.error("预下载文件不存在");
}
// 本地文件下载路径
String localPath = "home/" + objectName;
ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, filePath + objectName), new File(localPath));
System.out.println(object);
ossClient.shutdown();
return Result.success(source);
} }
} }