AsgcCompiler代码优化.

This commit is contained in:
aoshiguchen
2022-09-10 01:27:31 +08:00
parent f44d77914f
commit 7c2f0fa783
3 changed files with 42 additions and 46 deletions
@@ -69,7 +69,7 @@ public class AsgcCompiler {
this.standardJavaFileManager = javaCompiler.getStandardFileManager(collector, null, null);
this.isSaveClassFile = false;
this.generatorCodeSavePath = GlobalConfig.getGeneratorCodeSavePath();
this.dynamicClassLoader = new DynamicClassLoader(this, classLoader);
this.dynamicClassLoader = new DynamicClassLoader(classLoader, this);
addOption("-Xlint:unchecked");
addOption("-implicit:class");
@@ -40,7 +40,7 @@ public class DynamicClassLoader extends ClassLoader {
super(classLoader);
}
public DynamicClassLoader(AsgcCompiler compiler, ClassLoader classLoader) {
public DynamicClassLoader(ClassLoader classLoader, AsgcCompiler compiler) {
super(classLoader);
this.compiler = compiler;
}
@@ -55,18 +55,16 @@ public class DynamicClassLoader extends ClassLoader {
if (null != byteCode) {
return super.defineClass(name, byteCode.getByteCode(), 0, byteCode.getByteCode().length);
}
Class<?> ret = doFindClass(name);
if (null != ret) {
return ret;
if (null != this.compiler) {
Class<?> ret = doFindClass(name, compiler.getClasspathList());
if (null != ret) {
return ret;
}
}
return super.findClass(name);
}
private Class<?> doFindClass(String name) throws ClassNotFoundException {
if (null == compiler) {
return null;
}
List<String> classpathList = compiler.getClasspathList();
private Class<?> doFindClass(String name, List<String> classpathList) throws ClassNotFoundException {
if (CollectionUtil.isEmpty(classpathList)) {
return null;
}
+34 -36
View File
@@ -32,54 +32,52 @@
</dependency>
</dependencies>
<!-- <build>-->
<!-- <finalName>${artifactId}</finalName>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- <version>2.1.3.RELEASE</version>-->
<!-- <configuration>-->
<!-- <executable>true</executable>-->
<!-- <mainClass>fun.asgc.neutrino.proxy.server.ProxyServer</mainClass>-->
<!-- <classifier>exec</classifier>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>repackage</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.3.RELEASE</version>
<configuration>
<archive>
<manifest>
<!--这里指定要运行的main类-->
<mainClass>fun.asgc.neutrino.proxy.server.ProxyServer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<mainClass>fun.asgc.neutrino.proxy.server.ProxyServer</mainClass>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <artifactId>maven-assembly-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <archive>-->
<!-- <manifest>-->
<!-- &lt;!&ndash;这里指定要运行的main类&ndash;&gt;-->
<!-- <mainClass>fun.asgc.neutrino.proxy.server.ProxyServer</mainClass>-->
<!-- </manifest>-->
<!-- </archive>-->
<!-- <descriptorRefs>-->
<!-- <descriptorRef>jar-with-dependencies</descriptorRef>-->
<!-- </descriptorRefs>-->
<!-- </configuration>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>make-assembly</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>single</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
</project>