Compare commits
48 Commits
ed6e6805e2
...
1a1dd5a446
Author | SHA1 | Date |
---|---|---|
|
1a1dd5a446 | |
|
73d586561c | |
|
ee235e9f68 | |
|
7df2263bb2 | |
|
2952c5a2f5 | |
|
a4a81e0813 | |
|
9a09e09ba7 | |
|
7ea00fa1ce | |
|
b60abb6ce1 | |
|
e2aaabba6f | |
|
90809ec693 | |
|
4190277076 | |
|
769faff8eb | |
|
a71a996367 | |
|
955d634621 | |
|
3b9c9d0f6b | |
|
cfb1982f75 | |
|
4823fb68e3 | |
|
051671a23c | |
|
5427bc562f | |
|
87118e5521 | |
|
4ec95e574c | |
|
688aff0d00 | |
|
52dd3adb53 | |
|
a9fec774b5 | |
|
a5b7eccec0 | |
|
6391f07cb6 | |
|
f8f5b3129a | |
|
8dc14d8bce | |
|
7db0831ada | |
|
e965382c3b | |
|
8cc215d549 | |
|
6fe767e404 | |
|
3e97c2fb02 | |
|
e1840fc74b | |
|
92136dba5a | |
|
ceb61b1e37 | |
|
c4019ee777 | |
|
0afe9411f9 | |
|
38ebdfe04a | |
|
23d2802083 | |
|
5720b4c59a | |
|
d477fc9662 | |
|
35576979c4 | |
|
8f726025cc | |
|
ae63ab2c0e | |
|
b62c181969 | |
|
d6dd2f1d0d |
|
@ -17,6 +17,8 @@ VOLUME ["/home/logs/cloud-rule","/home/uploadPath"]
|
|||
|
||||
#拷贝执行jar包文件
|
||||
COPY ./cloud-rule-server/target/cloud-rule.jar /home/app.jar
|
||||
COPY ./cloud-rule-common/target/classes/com/muyu/common /home/lib/com/muyu/common
|
||||
COPY ./cloud-rule-engine/target/classes/com/muyu /home/lib/com/muyu
|
||||
|
||||
#构建启动命令
|
||||
ENTRYPOINT ["java","-Dfile.encoding=utf-8","-jar"]
|
||||
|
|
|
@ -81,4 +81,11 @@ public class RuleVersion extends BaseEntity {
|
|||
.build();
|
||||
}
|
||||
|
||||
public static RuleVersion updBuild(RuleVersionUpdReq ruleVersionUpdReq, Supplier<Long> idSupplier) {
|
||||
return RuleVersion.builder()
|
||||
.ruleId(idSupplier.get())
|
||||
.ruleVersionText(ruleVersionUpdReq.getRuleVersionActivate())
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu
|
||||
* @Project:cloud-rule
|
||||
* @name:OSSUpload
|
||||
* @Date:2024/9/3 下午3:34
|
||||
*/
|
||||
public class OSSUpload {
|
||||
|
||||
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写
|
||||
private static final String endpoint = "oss-cn-shanghai.aliyuncs.com" ;
|
||||
// AccessKeyID
|
||||
private static final String accessKeyId = "LTAI5tHKdDATVKeBjFH8mb8D" ;
|
||||
// AccessKeySecret
|
||||
private static final String accessKeySecret = "5ejb4qdgukfD1FdM181kdeAkSuURo7" ;
|
||||
// Bucket名称
|
||||
private static final String bucketName = "java-web-generating-class" ;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传到OSS后文件保存的目录,例如:folder/subfolder/,最后以斜杠结尾
|
||||
String objectName = "build/version/rule/DataEngineRecordActuator.class";
|
||||
|
||||
try {
|
||||
InputStream inputStream = new FileInputStream("C:\\Users\\13636\\Desktop\\test\\DataEngineRecordActuator.class");
|
||||
//
|
||||
// // 将内容转换为字节数组输入流
|
||||
// ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 构造上传请求
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
||||
|
||||
// 执行上传操作
|
||||
ossClient.putObject(putObjectRequest);
|
||||
|
||||
System.out.println("文件"+"DataEngineRecordActuator.class"+"存储成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("文件"+"DataEngineRecordActuator.class"+"存储成功");
|
||||
} finally {
|
||||
// 关闭OSSClient
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.compile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ExternalClassLoader extends URLClassLoader {
|
||||
|
||||
public ExternalClassLoader(URL[] urls) {
|
||||
super(urls, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
public Class<?> defineClassFromBytes(byte[] classBytes, String className) throws IOException {
|
||||
return super.defineClass(className, classBytes, 0, classBytes.length);
|
||||
}
|
||||
|
||||
public Class<?> loadClassFromPath(Path classFilePath, String className) throws IOException {
|
||||
byte[] classData = Files.readAllBytes(classFilePath);
|
||||
return defineClassFromBytes(classData, className);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.muyu.compile;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.DataValue;
|
||||
import com.muyu.constant.MethodSuffix;
|
||||
import com.muyu.engine.basic.BasicEngine;
|
||||
import com.muyu.upload.ALiYunUpload;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.tools.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.compile
|
||||
* @Project:cloud-rule
|
||||
* @name:OSSFileCompile
|
||||
* @Date:2024/8/31 下午7:08
|
||||
*/
|
||||
public class FilesCompilerLoad {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FilesCompilerLoad.class);
|
||||
|
||||
static Map<String , BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static Result<Object> javaCompiler(String fileName){
|
||||
|
||||
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
String[] strings = {"-classpath","/home/lib","-verbose","-d", "/home/lib","home/"+fileName + MethodSuffix.JAVASUFFIX };
|
||||
// 执行编译任务
|
||||
int result = compiler.run(null, null, null, strings);
|
||||
// 检查编译结果
|
||||
if (result == 0) {
|
||||
System.out.println("编译成功,生成的.class文件位于源代码同目录");
|
||||
} else {
|
||||
System.out.println("编译失败");
|
||||
}
|
||||
|
||||
ALiYunUpload.uploadClassFiles(fileName,"/home/lib/com/muyu/generate/"+fileName+ MethodSuffix.CLASSSUFFIX);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public static Result<Object> classLoad(String fileName){
|
||||
|
||||
Class<?> clazz ;
|
||||
|
||||
try {
|
||||
// class文件路径
|
||||
String externalClassFilePath = "/home/lib/com/muyu/generate/"+fileName + MethodSuffix.CLASSSUFFIX;
|
||||
log.info("class文件路径:[{}]",externalClassFilePath);
|
||||
Path path = Paths.get(externalClassFilePath);
|
||||
|
||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||
|
||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||
|
||||
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||
log.info("开始创建加载器...");
|
||||
// 加载类
|
||||
// 注意类名必须是完全限定名(包括包名)
|
||||
clazz = externalClassLoader.loadClassFromPath(path, "com.muyu.generate."+fileName);
|
||||
log.info("加载成功:[{}]",clazz.getName());
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
engineMap.put(fileName, (BasicEngine<DataValue>) instance);
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
DataValue dataValue = DataValue.builder()
|
||||
.type("String")
|
||||
.label("姓名")
|
||||
.key("name")
|
||||
.value("张三")
|
||||
.build();
|
||||
|
||||
BasicEngine<DataValue> engine = engineMap.get(fileName);
|
||||
engine.set(dataValue);
|
||||
engine.execution();
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package com.muyu.compile;
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.apache.catalina.startup.EngineConfig;
|
||||
|
||||
import javax.tools.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.compile
|
||||
* @Project:cloud-rule
|
||||
* @name:OSSFileCompile
|
||||
* @Date:2024/8/31 下午7:08
|
||||
*/
|
||||
public class OSSFileCompile{
|
||||
|
||||
// public static Map<String, byte[]> compile(String fileName, String source,String extLib) throws IOException {
|
||||
// System.out.println("-------");
|
||||
// JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
// StandardJavaFileManager stdManager = compiler.getStandardFileManager(null, null, null);
|
||||
// try (MemoryJavaFileManager manager = new MemoryJavaFileManager(stdManager)) {
|
||||
// JavaFileObject javaFileObject = manager.makeStringSource(fileName, source);
|
||||
// // 传入诊断监听器 size和传入的javaObject相同
|
||||
// DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
|
||||
// List<String> optionList = Arrays.asList("-extdirs",extLib);
|
||||
// JavaCompiler.CompilationTask task = compiler.getTask(null, manager,diagnosticCollector, optionList, null, Arrays.asList(javaFileObject));
|
||||
// Boolean result = task.call();
|
||||
// if (result == null || !result.booleanValue()) {
|
||||
// throw new RuntimeException("Compilation failed.");
|
||||
// }
|
||||
// return manager.getClassBytes();
|
||||
// }
|
||||
// }
|
||||
|
||||
public static Result<Object> compile(String source,String extLib){
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
|
||||
// 执行编译任务
|
||||
int result = compiler.run(null, null, null, source);
|
||||
|
||||
// 检查编译结果
|
||||
if (result == 0) {
|
||||
System.out.println("编译成功,生成的.class文件位于源代码同目录");
|
||||
return Result.success("编译成功,生成的.class文件位于源代码同目录");
|
||||
} else {
|
||||
System.out.println("编译失败");
|
||||
return Result.error("编译失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.muyu.constant;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
* @Package:com.muyu.constant
|
||||
* @Project:cloud-rule
|
||||
* @name:MethodSuffix
|
||||
* @Date:2024/9/5 下午2:44
|
||||
*/
|
||||
public class MethodSuffix {
|
||||
public static final String JAVASUFFIX = ".java";
|
||||
public static final String CLASSSUFFIX = ".class";
|
||||
}
|
|
@ -1,15 +1,13 @@
|
|||
package com.muyu.load;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.compile.OSSFileCompile;
|
||||
import com.muyu.util.SourceCodeCompiler;
|
||||
import com.muyu.compile.FilesCompilerLoad;
|
||||
import com.muyu.constant.MethodSuffix;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:蓬叁
|
||||
|
@ -29,8 +27,12 @@ public class OSSFileLoad {
|
|||
// bucket
|
||||
private static final String bucketName = "java-web-generating-class";
|
||||
// OSS文件路径
|
||||
private static final String filePath = "build/version/rule/";
|
||||
private static final String fileJavaPath = "build/version/java/";
|
||||
private static final String fileClassPath = "build/version/class/";
|
||||
private static final Logger log = LoggerFactory.getLogger(OSSFileLoad.class);
|
||||
|
||||
public static Result<Object> streamingDownload(String fileName) throws IOException {
|
||||
String source = null;
|
||||
// 创建 OSSClient 实例
|
||||
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
// 判断 bucket 是否存在
|
||||
|
@ -39,16 +41,17 @@ public class OSSFileLoad {
|
|||
System.out.println("bucket不存在");
|
||||
return Result.error("bucket不存在");
|
||||
}
|
||||
Boolean flag_file = ossClient.doesObjectExist(bucketName, filePath+fileName);
|
||||
Boolean flag_file = ossClient.doesObjectExist(bucketName, fileJavaPath+fileName+ MethodSuffix.JAVASUFFIX);
|
||||
if (!flag_file) {
|
||||
System.out.println("预下载文件不存在");
|
||||
return Result.error("预下载文件不存在");
|
||||
}
|
||||
// 本地文件下载路径
|
||||
String localPath = "C:\\Users\\13636\\Desktop\\test\\"+fileName;
|
||||
String localPath = "home/" + fileName + MethodSuffix.JAVASUFFIX;
|
||||
|
||||
try {
|
||||
// 从OSS下载文件
|
||||
InputStream inputStream = ossClient.getObject(bucketName, filePath+fileName).getObjectContent();
|
||||
InputStream inputStream = ossClient.getObject(bucketName, fileJavaPath + fileName + MethodSuffix.JAVASUFFIX).getObjectContent();
|
||||
File downloadFile = new File(localPath);
|
||||
FileOutputStream outputStream = new FileOutputStream(downloadFile);
|
||||
|
||||
|
@ -69,25 +72,74 @@ public class OSSFileLoad {
|
|||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
//对路径里的.java文件进行编译
|
||||
System.out.println("第一步");
|
||||
SourceCodeCompiler.javaCompilerPath("C:\\Users\\13636\\Desktop\\test\\");
|
||||
System.out.println("第二步");
|
||||
File outputDir = new File("C:\\Users\\13636\\Desktop\\test\\com\\muyu\\generate\\"); // 或者是你指定的其他输出目录
|
||||
System.out.println("第三步");
|
||||
File[] classFiles = outputDir.listFiles(); // 获取输出目录中的所有文件
|
||||
if (classFiles != null) {
|
||||
for (File classFile : classFiles) {
|
||||
if (classFile.getName().endsWith(".class")) {
|
||||
System.out.println("找到class文件 " + classFile.getName());
|
||||
}
|
||||
}
|
||||
//把.class文件存入oss中
|
||||
}else {
|
||||
System.out.println("没有找到文件");
|
||||
System.out.println("执行编译");
|
||||
FilesCompilerLoad.javaCompiler(fileName);
|
||||
// SourceCodeCompiler.javaCompilerPath("home/");
|
||||
// System.out.println("第二步");
|
||||
// File outputDir = new File("home/"); // 或者是你指定的其他输出目录
|
||||
// System.out.println("第三步");
|
||||
// File[] classFiles = outputDir.listFiles(); // 获取输出目录中的所有文件
|
||||
// if (classFiles != null) {
|
||||
// for (File classFile : classFiles) {
|
||||
// if (classFile.getName().endsWith(".class")) {
|
||||
// System.out.println("找到class文件 " + classFile.getName());
|
||||
//// 把.class文件存入oss中
|
||||
// }
|
||||
// }
|
||||
// }else {
|
||||
// System.out.println("没有找到文件");
|
||||
// }
|
||||
return Result.success(source);
|
||||
}
|
||||
|
||||
public static Result<Object> streamingClassDownload(String fileName) throws IOException {
|
||||
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不存在");
|
||||
}
|
||||
return Result.success();
|
||||
Boolean flag_file = ossClient.doesObjectExist(bucketName, fileClassPath+fileName+ MethodSuffix.CLASSSUFFIX);
|
||||
if (!flag_file) {
|
||||
System.out.println("预下载文件不存在");
|
||||
return Result.error("预下载文件不存在");
|
||||
}
|
||||
// 本地文件下载路径
|
||||
String localPath = "/home/lib/com/muyu/generate/" + fileName + MethodSuffix.CLASSSUFFIX;
|
||||
|
||||
try {
|
||||
log.info("执行下载class文件:[{}]",localPath);
|
||||
// 从OSS下载文件
|
||||
InputStream inputStream = ossClient.getObject(bucketName, fileClassPath + fileName + MethodSuffix.CLASSSUFFIX).getObjectContent();
|
||||
File downloadFile = new File(localPath);
|
||||
log.info("下载地址:[{}]",downloadFile);
|
||||
FileOutputStream outputStream = new FileOutputStream(downloadFile);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
while ((len = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, len);
|
||||
}
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
|
||||
System.out.println("存放路径:" + localPath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭OSSClient
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
//对路径里的.class文件进行编译
|
||||
log.info("执行编译class:[{}]",fileName);
|
||||
FilesCompilerLoad.classLoad(fileName);
|
||||
return Result.success(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
package com.muyu.upload;
|
||||
|
||||
import com.aliyun.oss.ClientException;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.OSSException;
|
||||
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
|
||||
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectResult;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import com.muyu.compile.FilesCompilerLoad;
|
||||
import com.muyu.constant.MethodSuffix;
|
||||
import com.muyu.load.OSSFileLoad;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
|
@ -23,6 +20,7 @@ import java.nio.charset.StandardCharsets;
|
|||
* @name:ALiYunUpload
|
||||
* @Date:2024/8/30 下午7:05
|
||||
*/
|
||||
@Log4j2
|
||||
public class ALiYunUpload {
|
||||
|
||||
// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写
|
||||
|
@ -34,22 +32,20 @@ public class ALiYunUpload {
|
|||
// Bucket名称
|
||||
private static final String bucketName = "java-web-generating-class" ;
|
||||
|
||||
public static Result<Object> uploadFiles(String content, String fileName) {
|
||||
public static Result<Object> uploadJavaFiles(String JavaContent, String fileName) {
|
||||
|
||||
|
||||
System.out.println(content);
|
||||
System.out.println(JavaContent);
|
||||
|
||||
System.out.println(fileName);
|
||||
|
||||
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传到OSS后文件保存的目录,例如:folder/subfolder/,最后以斜杠结尾
|
||||
String objectName = "build/version/rule/"+fileName+".java";
|
||||
String objectName = "build/version/java/" + fileName + MethodSuffix.JAVASUFFIX;
|
||||
|
||||
try {
|
||||
// 将内容转换为字节数组输入流
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(JavaContent.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// 构造上传请求
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
||||
|
@ -72,4 +68,34 @@ public class ALiYunUpload {
|
|||
|
||||
}
|
||||
|
||||
public static Result<Object> uploadClassFiles(String fileName,String filePath) {
|
||||
|
||||
System.out.println(fileName+ MethodSuffix.CLASSSUFFIX);
|
||||
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 上传到OSS后文件保存的目录,例如:folder/subfolder/,最后以斜杠结尾
|
||||
String objectName = "build/version/class/"+fileName+ MethodSuffix.CLASSSUFFIX;
|
||||
|
||||
try {
|
||||
|
||||
ossClient.putObject(bucketName, objectName, new File(filePath));
|
||||
|
||||
log.info("文件[{}]存储成功",fileName+ MethodSuffix.CLASSSUFFIX);
|
||||
log.info("开始拉取....");
|
||||
OSSFileLoad.streamingClassDownload(fileName);
|
||||
return Result.success(null,"文件"+fileName+".class"+"存储成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.info("文件[{}]存储失败",fileName+ MethodSuffix.CLASSSUFFIX+"错误信息:[{}]"+e.getMessage());
|
||||
return Result.error(null,"文件"+fileName+".class"+"存储失败");
|
||||
} finally {
|
||||
// 关闭OSSClient
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@ package com.muyu.util;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import javax.tools.ToolProvider;
|
||||
import javax.tools.*;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
public class SourceCodeCompiler {
|
||||
|
||||
|
@ -60,8 +60,9 @@ public class SourceCodeCompiler {
|
|||
try {
|
||||
//通过源文件获取到想要编译的java类源代码迭代器,包括所有的内部类,其中每一个类都是一个JavaFileObjects,也被称为一个汇编单元
|
||||
Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjects(file);
|
||||
List<Object> list = Arrays.asList("-classpath","home","-verbose","-d", "home/",javaFileObjects);
|
||||
//生成编译任务
|
||||
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, Arrays.asList("-d","C:\\Users\\13636\\Desktop\\test\\"), null, javaFileObjects);
|
||||
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, Arrays.asList("-d","home/"), null, javaFileObjects);
|
||||
//执行编译任务
|
||||
task.call();
|
||||
}catch (Exception e){
|
||||
|
@ -69,4 +70,18 @@ public class SourceCodeCompiler {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*可以编译单个java源代码
|
||||
* @param filePath
|
||||
*/
|
||||
public static void javaCompilerFile(String filePath){
|
||||
try {
|
||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
int results = compiler.run(null, null, null, filePath);
|
||||
System.out.println((results == 0)?"编译成功":"编译失败");
|
||||
}catch (Exception e){
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.muyu.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.RuleData;
|
||||
import com.muyu.common.domain.RuleVersion;
|
||||
import com.muyu.common.domain.req.RuleDataAddReq;
|
||||
import com.muyu.common.domain.req.RuleDataUpdReq;
|
||||
import com.muyu.common.domain.req.RuleVersionAddReq;
|
||||
import com.muyu.common.domain.req.RuleVersionUpdReq;
|
||||
import com.muyu.common.domain.resp.RuleVersionResp;
|
||||
|
@ -59,13 +56,8 @@ public class RuleVersionController {
|
|||
@Operation(summary = "规则版本接口添加",description = "根据客户需求创建对应规则版本")
|
||||
public Result<String> add(
|
||||
@Validated @RequestBody RuleVersionAddReq ruleVersionAddReq
|
||||
) throws IOException {
|
||||
){
|
||||
ruleVersionService.save(RuleVersion.addBuild(ruleVersionAddReq));
|
||||
Result<Object> objectResult = ALiYunUpload.uploadFiles(ruleVersionAddReq.getRuleVersionText(), ruleVersionAddReq.getRuleVersionType());
|
||||
System.out.println(objectResult.getMsg());
|
||||
Result<Object> result = OSSFileLoad.streamingDownload(ruleVersionAddReq.getRuleVersionType() + ".java");
|
||||
System.out.println("--------------");
|
||||
System.out.println(result.getData());
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
|
@ -133,6 +125,37 @@ public class RuleVersionController {
|
|||
return Result.success(ruleVersionService.generatedCode(ruleVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID修改版本代码
|
||||
* @param ruleVersionId
|
||||
* @param ruleVersionUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/updText/{ruleVersionId}")
|
||||
@Operation(summary = "通过ID修改规则版本代码",description = "进行版本更新时操作")
|
||||
public Result<Object> updText(
|
||||
@PathVariable("ruleVersionId") Long ruleVersionId,
|
||||
@Validated @RequestBody RuleVersionUpdReq ruleVersionUpdReq
|
||||
){
|
||||
ruleVersionService.updateById(RuleVersion.updBuild(ruleVersionUpdReq,() -> ruleVersionId));
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本测试
|
||||
* @param ruleVersionAddReq
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@PostMapping("/compileLoad")
|
||||
@Operation(summary = "版本测试",description = "版本测试")
|
||||
public Result<String> compileLoad(
|
||||
@Validated @RequestBody RuleVersionAddReq ruleVersionAddReq
|
||||
) throws IOException {
|
||||
Result<Object> objectResult = ALiYunUpload.uploadJavaFiles(ruleVersionAddReq.getRuleVersionText(), ruleVersionAddReq.getRuleVersionType());
|
||||
System.out.println(objectResult.getMsg());
|
||||
OSSFileLoad.streamingDownload(ruleVersionAddReq.getRuleVersionType());
|
||||
return Result.success(null,"测试成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue