remove compiler

This commit is contained in:
Looly
2023-03-03 18:03:59 +08:00
parent 0f06e591bb
commit a99dd899d6
19 changed files with 1 additions and 813 deletions

View File

@@ -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@"));
}
}

View File

@@ -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);
}
}};
}
}

View File

@@ -1,8 +0,0 @@
package b;
import a.A;
public class B {
public B() {
new A();
}
}

View File

@@ -1,9 +0,0 @@
package c;
import b.B;
public class C {
public C() {
new B();
}
}