diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/AsgcCompiler.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/AsgcCompiler.java index 9ae41dff..128c4151 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/AsgcCompiler.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/AsgcCompiler.java @@ -68,6 +68,7 @@ public class AsgcCompiler { this.dynamicClassLoader = new DynamicClassLoader(classLoader); addOption("-Xlint:unchecked"); + addOption("-implicit:class"); addOption("-source", "1.8"); addOption("-target", "1.8"); } @@ -124,7 +125,6 @@ public class AsgcCompiler { JavaFileManager javaFileManager = new DynamicJavaFileManager(standardJavaFileManager, dynamicClassLoader); Boolean result = javaCompiler.getTask(null, javaFileManager, collector, getOptions(), null, Lists.newArrayList(new StringSource(className, sourceCode))).call(); if (!result || collector.getDiagnostics().size() > 0) { -// collector.getDiagnostics().forEach(item -> log.error(item.toString())); if (!result || collector.getDiagnostics().size() > 0) { for (Diagnostic diagnostic : collector.getDiagnostics()) { switch (diagnostic.getKind()) { @@ -141,8 +141,7 @@ public class AsgcCompiler { } } - log.error("warring: {}", getWarnings()); - log.error("error: {}", getErrors()); + log(); } } @@ -169,4 +168,15 @@ public class AsgcCompiler { public List getWarnings() { return diagnosticToString(warnings); } + + private void log() { + List warnings = getWarnings(); + List errors = getErrors(); + if (!CollectionUtil.isEmpty(warnings)) { + log.warn(warnings.stream().collect(Collectors.joining())); + } + if (!CollectionUtil.isEmpty(errors)) { + log.warn(errors.stream().collect(Collectors.joining())); + } + } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/DynamicCompile.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/DynamicCompile.java new file mode 100644 index 00000000..af0932b5 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/DynamicCompile.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.aop.compiler; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/26 + */ +public @interface DynamicCompile { + +} diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/DynamicCompileProcess.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/DynamicCompileProcess.java new file mode 100644 index 00000000..959832b4 --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/compiler/DynamicCompileProcess.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.aop.compiler; + +import javax.annotation.processing.*; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import java.util.Set; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/26 + */ +@SupportedAnnotationTypes("DynamicCompile") +@SupportedSourceVersion(SourceVersion.RELEASE_8) +public class DynamicCompileProcess extends AbstractProcessor { + +// @Override +// public synchronized void init(ProcessingEnvironment processingEnv) { +// super.init(processingEnv); +// } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + processingEnv.getMessager().printMessage( Diagnostic.Kind.ERROR, "---------Hello World!"); + return true; + } + +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/compiler/PackageInternalsFinderTest.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/compiler/PackageInternalsFinderTest.java new file mode 100644 index 00000000..7744160e --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/aop/compiler/PackageInternalsFinderTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2022 aoshiguchen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package fun.asgc.neutrino.core.aop.compiler; + +import org.junit.Test; + +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.util.List; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/26 + */ +public class PackageInternalsFinderTest { + + @Test + public void testFilePathContainWhitespace() throws IOException { + PackageInternalsFinder finder = new PackageInternalsFinder(this.getClass().getClassLoader()); + List fileObjectList= finder.find("fun.asgc.neutrino.core.aop.compiler"); + System.out.println(fileObjectList); + } + +}