Compare commits
No commits in common. "e4fcf5fadd10b75192fd61c3f6e47e436f2a57b8" and "6153133e0ae6ba8fbc2d841bc887a2893fd758a4" have entirely different histories.
e4fcf5fadd
...
6153133e0a
BIN
HelloWorld.class
BIN
HelloWorld.class
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }
|
|
|
@ -28,12 +28,6 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-security</artifactId>
|
<artifactId>cloud-common-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.aliyun.oss</groupId>
|
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
|
||||||
<version>3.17.4</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.muyu.utils;
|
package com.muyu.utils;
|
||||||
|
|
||||||
|
|
||||||
import com.aliyun.oss.OSS;
|
import com.aliyun.oss.OSS;
|
||||||
|
|
||||||
import com.aliyun.oss.OSSClientBuilder;
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
|
|
||||||
import com.aliyun.oss.model.PutObjectRequest;
|
import com.aliyun.oss.model.PutObjectRequest;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
|
@ -43,12 +43,7 @@
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
<!-- //创建测试工程,引入依赖-->
|
|
||||||
=======
|
|
||||||
<!-- //创建测试工程,引入依赖-->
|
<!-- //创建测试工程,引入依赖-->
|
||||||
>>>>>>> 6153133e0ae6ba8fbc2d841bc887a2893fd758a4
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
@ -60,10 +55,7 @@
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
<version>2.3.1</version>
|
<version>2.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
|
|
||||||
>>>>>>> 6153133e0ae6ba8fbc2d841bc887a2893fd758a4
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.activation</groupId>
|
<groupId>javax.activation</groupId>
|
||||||
<artifactId>activation</artifactId>
|
<artifactId>activation</artifactId>
|
||||||
|
@ -121,11 +113,6 @@
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
|
|
||||||
|
|
||||||
=======
|
|
||||||
>>>>>>> 6153133e0ae6ba8fbc2d841bc887a2893fd758a4
|
|
||||||
<!-- <!– XllJob定时任务 –>-->
|
<!-- <!– XllJob定时任务 –>-->
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>com.muyu</groupId>-->
|
<!-- <groupId>com.muyu</groupId>-->
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class EngIneController extends BaseController {
|
||||||
@PutMapping("/getRuleEngineInfo/{id}")
|
@PutMapping("/getRuleEngineInfo/{id}")
|
||||||
public Result getRuleEngineInfo(@PathVariable(name = "id") Long id) {
|
public Result getRuleEngineInfo(@PathVariable(name = "id") Long id) {
|
||||||
//使用mabits-plus-plus的查询方法
|
//使用mabits-plus-plus的查询方法
|
||||||
// engIneService.getRuleEngineInfo(id);
|
// engIneService.getRuleEngineInfo(id);
|
||||||
EngineVersionListResp engineConfigListResp = engIneService.getRuleEngineInfo(id);
|
EngineVersionListResp engineConfigListResp = engIneService.getRuleEngineInfo(id);
|
||||||
return Result.success(engineConfigListResp);
|
return Result.success(engineConfigListResp);
|
||||||
}
|
}
|
||||||
|
@ -209,15 +209,15 @@ public class EngIneController extends BaseController {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/generate")
|
@PostMapping("/generate")
|
||||||
public EngineVersion generate(@RequestBody EngineVersion engineVersion) {
|
public EngineVersion generate(@RequestBody EngineVersion engineVersion) {
|
||||||
EngineMaintenance byId = engIneService.selectById(engineVersion.getId());
|
EngineMaintenance byId = engIneService.selectById(engineVersion.getId());
|
||||||
byId.setName("generate" + "_" + byId.getEngineCode() + "_" + engineVersion.getVersionCode());
|
byId.setName("generate" + "_" + byId.getEngineCode() + "_" + engineVersion.getVersionCode());
|
||||||
engineVersion.setRuleContent(GenerateConstant.generateConstant(byId, engineVersion));
|
engineVersion.setRuleContent(GenerateConstant.generateConstant(byId, engineVersion));
|
||||||
return engineVersion;
|
return engineVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过id查询版本version信息 传入id 和 versionId
|
* 通过id查询版本version信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("/findVersionById/{id}")
|
@GetMapping("/findVersionById/{id}")
|
||||||
public Result findVersionById(@PathVariable("id") Long id) {
|
public Result findVersionById(@PathVariable("id") Long id) {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//<<<<<<< HEAD
|
|
||||||
//package com.muyu.input;
|
//package com.muyu.input;
|
||||||
//
|
//
|
||||||
//import com.aliyun.oss.ClientException;
|
//import com.aliyun.oss.ClientException;
|
||||||
|
@ -8,12 +7,14 @@
|
||||||
//import com.aliyun.oss.OSSException;
|
//import com.aliyun.oss.OSSException;
|
||||||
//import com.aliyun.oss.model.PutObjectRequest;
|
//import com.aliyun.oss.model.PutObjectRequest;
|
||||||
//import com.aliyun.oss.model.PutObjectResult;
|
//import com.aliyun.oss.model.PutObjectResult;
|
||||||
|
//
|
||||||
//import java.io.FileInputStream;
|
//import java.io.FileInputStream;
|
||||||
//import java.io.InputStream;
|
//import java.io.InputStream;
|
||||||
//
|
//
|
||||||
//public class Demo {
|
//public class Demo {
|
||||||
//
|
//
|
||||||
// public static void main(String[] args) throws Exception {
|
// public static void main(String[] args) throws Exception {
|
||||||
|
//
|
||||||
// // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
// // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
||||||
// String endpoint = "https://oss-cn-shanghai.aliyuncs.com";
|
// String endpoint = "https://oss-cn-shanghai.aliyuncs.com";
|
||||||
// // 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
|
// // 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
|
||||||
|
@ -21,10 +22,10 @@
|
||||||
// // 填写Bucket名称,例如examplebucket。
|
// // 填写Bucket名称,例如examplebucket。
|
||||||
// String bucketName = "011811";
|
// String bucketName = "011811";
|
||||||
// // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
|
// // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
|
||||||
// String objectName = "localpath\\examplefile.txt";
|
// String objectName = "cloud-etl-engine\\cloud-etl-engine\\cloud-etl-server\\target\\cloud-engine.jar";
|
||||||
// // 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。
|
// // 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。
|
||||||
// // 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
// // 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||||
// String filePath= "C:\\Users\\qdm\\Desktop\\Project\\CLOUD-ETL-UI-ENGINE\\cloud-etl-engine\\cloud-etl-server\\target\\";
|
// String filePath = "D:\\cloud-etl-engine\\cloud-etl-engine\\cloud-etl-server\\target\\cloud-engine.jar";
|
||||||
//
|
//
|
||||||
// // 创建OSSClient实例。
|
// // 创建OSSClient实例。
|
||||||
// OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
|
// OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
|
||||||
|
@ -53,67 +54,8 @@
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
|
// public static void main1(String[] args) {
|
||||||
|
// System.out.println("你好世界");
|
||||||
|
// }
|
||||||
//}
|
//}
|
||||||
//=======
|
|
||||||
////package com.muyu.input;
|
|
||||||
////
|
|
||||||
////import com.aliyun.oss.ClientException;
|
|
||||||
////import com.aliyun.oss.OSS;
|
|
||||||
////import com.aliyun.oss.common.auth.*;
|
|
||||||
////import com.aliyun.oss.OSSClientBuilder;
|
|
||||||
////import com.aliyun.oss.OSSException;
|
|
||||||
////import com.aliyun.oss.model.PutObjectRequest;
|
|
||||||
////import com.aliyun.oss.model.PutObjectResult;
|
|
||||||
////
|
|
||||||
////import java.io.FileInputStream;
|
|
||||||
////import java.io.InputStream;
|
|
||||||
////
|
|
||||||
////public class Demo {
|
|
||||||
////
|
|
||||||
//// public static void main(String[] args) throws Exception {
|
|
||||||
////
|
|
||||||
//// // Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。
|
|
||||||
//// String endpoint = "https://oss-cn-shanghai.aliyuncs.com";
|
|
||||||
//// // 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
|
|
||||||
//// EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
|
|
||||||
//// // 填写Bucket名称,例如examplebucket。
|
|
||||||
//// String bucketName = "011811";
|
|
||||||
//// // 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
|
|
||||||
//// String objectName = "cloud-etl-engine\\cloud-etl-engine\\cloud-etl-server\\target\\cloud-engine.jar";
|
|
||||||
//// // 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。
|
|
||||||
//// // 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
|
||||||
//// String filePath = "D:\\cloud-etl-engine\\cloud-etl-engine\\cloud-etl-server\\target\\cloud-engine.jar";
|
|
||||||
////
|
|
||||||
//// // 创建OSSClient实例。
|
|
||||||
//// OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);
|
|
||||||
////
|
|
||||||
//// try {
|
|
||||||
//// InputStream inputStream = new FileInputStream(filePath);
|
|
||||||
//// // 创建PutObjectRequest对象。
|
|
||||||
//// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
|
||||||
//// // 创建PutObject请求。
|
|
||||||
//// PutObjectResult result = ossClient.putObject(putObjectRequest);
|
|
||||||
//// } catch (OSSException oe) {
|
|
||||||
//// System.out.println("Caught an OSSException, which means your request made it to OSS, "
|
|
||||||
//// + "but was rejected with an error response for some reason.");
|
|
||||||
//// System.out.println("Error Message:" + oe.getErrorMessage());
|
|
||||||
//// System.out.println("Error Code:" + oe.getErrorCode());
|
|
||||||
//// System.out.println("Request ID:" + oe.getRequestId());
|
|
||||||
//// System.out.println("Host ID:" + oe.getHostId());
|
|
||||||
//// } catch (ClientException ce) {
|
|
||||||
//// System.out.println("Caught an ClientException, which means the client encountered "
|
|
||||||
//// + "a serious internal problem while trying to communicate with OSS, "
|
|
||||||
//// + "such as not being able to access the network.");
|
|
||||||
//// System.out.println("Error Message:" + ce.getMessage());
|
|
||||||
//// } finally {
|
|
||||||
//// if (ossClient != null) {
|
|
||||||
//// ossClient.shutdown();
|
|
||||||
//// }
|
|
||||||
//// }
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// public static void main1(String[] args) {
|
|
||||||
//// System.out.println("你好世界");
|
|
||||||
//// }
|
|
||||||
////}
|
|
||||||
//>>>>>>> 6153133e0ae6ba8fbc2d841bc887a2893fd758a4
|
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
package com.muyu.javacomplier;
|
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
|
|
||||||
import javax.tools.*;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
@Log4j2
|
|
||||||
public class JavaCompilerDemo {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String sourceCode = "public class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello, world!\"); } }";
|
|
||||||
String fileName = "HelloWorld.java";
|
|
||||||
try {
|
|
||||||
// 将源代码写入文件
|
|
||||||
writeToFile(fileName, sourceCode);
|
|
||||||
|
|
||||||
// 获取Java编译器实例
|
|
||||||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
|
||||||
|
|
||||||
// 设置编译参数
|
|
||||||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
|
|
||||||
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
|
|
||||||
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(Arrays.asList(fileName));
|
|
||||||
|
|
||||||
// 执行编译
|
|
||||||
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits);
|
|
||||||
log.info("数据是:{}"+task);
|
|
||||||
boolean success = task.call();
|
|
||||||
|
|
||||||
// 处理编译结果
|
|
||||||
if (success) {
|
|
||||||
System.out.println("编译成功");
|
|
||||||
} else {
|
|
||||||
System.out.println("编译失败");
|
|
||||||
diagnostics.getDiagnostics().forEach(d -> System.out.format("Line %d, Column %d: %s%n", d.getLineNumber(), d.getColumnNumber(), d.getMessage(null)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 释放资源
|
|
||||||
fileManager.close();
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void writeToFile(String fileName, String sourceCode) throws IOException {
|
|
||||||
try (FileWriter writer = new FileWriter(fileName)) {
|
|
||||||
writer.write(sourceCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package com.itranswarp.compiler;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.tools.JavaCompiler;
|
|
||||||
import javax.tools.JavaFileObject;
|
|
||||||
import javax.tools.StandardJavaFileManager;
|
|
||||||
import javax.tools.ToolProvider;
|
|
||||||
import javax.tools.JavaCompiler.CompilationTask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In-memory compile Java source code as String.
|
|
||||||
*
|
|
||||||
* @author michael
|
|
||||||
*/
|
|
||||||
public class JavaStringCompiler {
|
|
||||||
|
|
||||||
JavaCompiler compiler;
|
|
||||||
StandardJavaFileManager stdManager;
|
|
||||||
|
|
||||||
public JavaStringCompiler() {
|
|
||||||
this.compiler = ToolProvider.getSystemJavaCompiler();
|
|
||||||
this.stdManager = compiler.getStandardFileManager(null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compile a Java source file in memory.
|
|
||||||
*
|
|
||||||
* @param fileName
|
|
||||||
* Java file name, e.g. "Test.java"
|
|
||||||
* @param source
|
|
||||||
* The source code as String.
|
|
||||||
* @return The compiled results as Map that contains class name as key,
|
|
||||||
* class binary as value.
|
|
||||||
* @throws IOException
|
|
||||||
* If compile error.
|
|
||||||
*/
|
|
||||||
public Map<String, byte[]> compile(String fileName, String source) throws IOException {
|
|
||||||
try (MemoryJavaFileManager manager = new MemoryJavaFileManager(stdManager)) {
|
|
||||||
JavaFileObject javaFileObject = manager.makeStringSource(fileName, source);
|
|
||||||
CompilationTask task = compiler.getTask(null, manager, null, null, null, Arrays.asList(javaFileObject));
|
|
||||||
Boolean result = task.call();
|
|
||||||
if (result == null || !result.booleanValue()) {
|
|
||||||
throw new RuntimeException("Compilation failed.");
|
|
||||||
}
|
|
||||||
return manager.getClassBytes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load class from compiled classes.
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* Full class name.
|
|
||||||
* @param classBytes
|
|
||||||
* Compiled results as a Map.
|
|
||||||
* @return The Class instance.
|
|
||||||
* @throws ClassNotFoundException
|
|
||||||
* If class not found.
|
|
||||||
* @throws IOException
|
|
||||||
* If load error.
|
|
||||||
*/
|
|
||||||
public Class<?> loadClass(String name, Map<String, byte[]> classBytes) throws ClassNotFoundException, IOException {
|
|
||||||
try (MemoryClassLoader classLoader = new MemoryClassLoader(classBytes)) {
|
|
||||||
return classLoader.loadClass(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.muyu.javacomplier;
|
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load class from byte[] which is compiled in memory.
|
|
||||||
*
|
|
||||||
* @author michael
|
|
||||||
*/
|
|
||||||
class MemoryClassLoader extends URLClassLoader {
|
|
||||||
|
|
||||||
// class name to class bytes:
|
|
||||||
Map<String, byte[]> classBytes = new HashMap<String, byte[]>();
|
|
||||||
|
|
||||||
public MemoryClassLoader(Map<String, byte[]> classBytes) {
|
|
||||||
super(new URL[0], MemoryClassLoader.class.getClassLoader());
|
|
||||||
this.classBytes.putAll(classBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
byte[] buf = classBytes.get(name);
|
|
||||||
if (buf == null) {
|
|
||||||
return super.findClass(name);
|
|
||||||
}
|
|
||||||
classBytes.remove(name);
|
|
||||||
return defineClass(name, buf, 0, buf.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,96 +0,0 @@
|
||||||
package com.itranswarp.compiler;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.FilterOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.nio.CharBuffer;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.tools.FileObject;
|
|
||||||
import javax.tools.ForwardingJavaFileManager;
|
|
||||||
import javax.tools.JavaFileManager;
|
|
||||||
import javax.tools.JavaFileObject;
|
|
||||||
import javax.tools.JavaFileObject.Kind;
|
|
||||||
import javax.tools.SimpleJavaFileObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* In-memory java file manager.
|
|
||||||
*
|
|
||||||
* @author michael
|
|
||||||
*/
|
|
||||||
class MemoryJavaFileManager extends ForwardingJavaFileManager<JavaFileManager> {
|
|
||||||
|
|
||||||
// compiled classes in bytes:
|
|
||||||
final Map<String, byte[]> classBytes = new HashMap<String, byte[]>();
|
|
||||||
|
|
||||||
MemoryJavaFileManager(JavaFileManager fileManager) {
|
|
||||||
super(fileManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, byte[]> getClassBytes() {
|
|
||||||
return new HashMap<String, byte[]>(this.classBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flush() throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
classBytes.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, Kind kind,
|
|
||||||
FileObject sibling) throws IOException {
|
|
||||||
if (kind == Kind.CLASS) {
|
|
||||||
return new MemoryOutputJavaFileObject(className);
|
|
||||||
} else {
|
|
||||||
return super.getJavaFileForOutput(location, className, kind, sibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JavaFileObject makeStringSource(String name, String code) {
|
|
||||||
return new MemoryInputJavaFileObject(name, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class MemoryInputJavaFileObject extends SimpleJavaFileObject {
|
|
||||||
|
|
||||||
final String code;
|
|
||||||
|
|
||||||
MemoryInputJavaFileObject(String name, String code) {
|
|
||||||
super(URI.create("string:///" + name), Kind.SOURCE);
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
|
|
||||||
return CharBuffer.wrap(code);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MemoryOutputJavaFileObject extends SimpleJavaFileObject {
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
MemoryOutputJavaFileObject(String name) {
|
|
||||||
super(URI.create("string:///" + name), Kind.CLASS);
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OutputStream openOutputStream() {
|
|
||||||
return new FilterOutputStream(new ByteArrayOutputStream()) {
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException {
|
|
||||||
out.close();
|
|
||||||
ByteArrayOutputStream bos = (ByteArrayOutputStream) out;
|
|
||||||
classBytes.put(name, bos.toByteArray());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
package com.muyu.cloud.rule.utils.upload;
|
|
||||||
|
|
||||||
import com.aliyun.oss.OSSClient;
|
|
||||||
import com.aliyun.oss.model.GetObjectRequest;
|
|
||||||
import com.aliyun.oss.model.ObjectMetadata;
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
|
|
||||||
public class OssDownload {
|
|
||||||
|
|
||||||
// 阿里云 endpoint
|
|
||||||
private static final String endpoint = "oss-cn-wulanchabu.aliyuncs.com";
|
|
||||||
// 阿里云 accessKeyId
|
|
||||||
private static final String accessKeyId = "LTAI5t8mk6aWqDq5w6WA49et";
|
|
||||||
// 阿里云 accessKeySecret
|
|
||||||
private static final String accessKeySecret = "SuLwzfEOruGOs1RSCq4vA1Bcf1849R";
|
|
||||||
// bucket
|
|
||||||
private static final String bucketName = "oss-1209";
|
|
||||||
// OSS文件路径
|
|
||||||
private static final String filePath = "build/rule/version/";
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue