mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
remove compiler
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
package cn.hutool.core.compiler;
|
||||
|
||||
import cn.hutool.core.compress.ZipUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.reflect.ConstructorUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Java源码编译器测试
|
||||
*
|
||||
* @author lzpeng
|
||||
*/
|
||||
public class JavaSourceCompilerTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void compilerATest(){
|
||||
final boolean compile = CompilerUtil.compile(FileUtil.file("test-compile/a/A.java").getAbsolutePath());
|
||||
Assert.assertTrue(compile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试编译Java源码
|
||||
*/
|
||||
@Test
|
||||
public void testCompile() throws ClassNotFoundException {
|
||||
// 依赖A,编译B和C
|
||||
final File libFile = ZipUtil.zip(FileUtil.file("lib.jar"),
|
||||
new String[]{"a/A.class", "a/A$1.class", "a/A$InnerClass.class"},
|
||||
new InputStream[]{
|
||||
FileUtil.getInputStream("test-compile/a/A.class"),
|
||||
FileUtil.getInputStream("test-compile/a/A$1.class"),
|
||||
FileUtil.getInputStream("test-compile/a/A$InnerClass.class")
|
||||
});
|
||||
Console.log(libFile.getAbsolutePath());
|
||||
final ClassLoader classLoader = CompilerUtil.getCompiler(null)
|
||||
.addSource(FileUtil.file("test-compile/b/B.java"))
|
||||
.addSource("c.C", FileUtil.readUtf8String("test-compile/c/C.java"))
|
||||
.addLibrary(libFile)
|
||||
// .addLibrary(FileUtil.file("D:\\m2_repo\\cn\\hutool\\hutool-all\\5.5.7\\hutool-all-5.5.7.jar"))
|
||||
.compile();
|
||||
final Class<?> clazz = classLoader.loadClass("c.C");
|
||||
final Object obj = ConstructorUtil.newInstance(clazz);
|
||||
Assert.assertTrue(String.valueOf(obj).startsWith("c.C@"));
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
package a;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.ConsoleTable;
|
||||
import cn.hutool.core.lang.caller.CallerUtil;
|
||||
|
||||
public class A {
|
||||
private class InnerClass {
|
||||
}
|
||||
|
||||
public A() {
|
||||
new InnerClass() {{
|
||||
int i = 0;
|
||||
Console.log("初始化 " + getClass() + " 的调用链为: ");
|
||||
Class<?> caller = CallerUtil.getCaller(i);
|
||||
while (caller != null) {
|
||||
Console.log("{} {}", caller, caller.getClassLoader());
|
||||
caller = CallerUtil.getCaller(++i);
|
||||
}
|
||||
}};
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
package b;
|
||||
import a.A;
|
||||
|
||||
public class B {
|
||||
public B() {
|
||||
new A();
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -1,9 +0,0 @@
|
||||
package c;
|
||||
|
||||
import b.B;
|
||||
|
||||
public class C {
|
||||
public C() {
|
||||
new B();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user