diff --git a/pom.xml b/pom.xml index 6b6eb7a..8d025f1 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,8 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo. processor utils - test + test/processors + test/app diff --git a/test/README.md b/test/app/README.md similarity index 100% rename from test/README.md rename to test/app/README.md diff --git a/test/pom.xml b/test/app/pom.xml similarity index 80% rename from test/pom.xml rename to test/app/pom.xml index 490efee..52d89d6 100644 --- a/test/pom.xml +++ b/test/app/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.bsc.maven - maven-processor-plugin-test + maven-processor-plugin-test-app jar MAVEN PROCESSOR PLUGIN TEST @@ -17,8 +17,8 @@ - org.bsc.util - processor-utils + ${project.groupId} + maven-processor-plugin-test-processors ${project.version} @@ -48,70 +48,55 @@ PROCESSOR PLUGIN org.bsc.maven maven-processor-plugin ${project.version} - - - - - - - process-test - - process-test - - process-test-classes - - ${basedir}/src/site - - - ${user.home}/src - ./src/main/java - - - false - - org.bsc.maven.plugin.processor.test.TestWikiProcessor - - - - true - - - - - - process process - process-classes + process-sources - ${basedir}/src/site - + + true false - true + false - org.bsc.maven.plugin.processor.test.TestWikiProcessor + org.bsc.maven.plugin.processor.test.TestGenerateSourceProcessor - + + diff --git a/test/src/main/docker/Dockerfile b/test/app/src/main/docker/Dockerfile similarity index 100% rename from test/src/main/docker/Dockerfile rename to test/app/src/main/docker/Dockerfile diff --git a/test/src/main/docker/mvn-entrypoint.sh b/test/app/src/main/docker/mvn-entrypoint.sh similarity index 100% rename from test/src/main/docker/mvn-entrypoint.sh rename to test/app/src/main/docker/mvn-entrypoint.sh diff --git a/test/src/main/docker/settings-docker.xml b/test/app/src/main/docker/settings-docker.xml similarity index 100% rename from test/src/main/docker/settings-docker.xml rename to test/app/src/main/docker/settings-docker.xml diff --git a/test/src/main/docker/toolchains.xml b/test/app/src/main/docker/toolchains.xml similarity index 100% rename from test/src/main/docker/toolchains.xml rename to test/app/src/main/docker/toolchains.xml diff --git a/test/app/src/main/java/org/bsc/maven/plugin/processor/test/SampleClass.java b/test/app/src/main/java/org/bsc/maven/plugin/processor/test/SampleClass.java new file mode 100644 index 0000000..823444f --- /dev/null +++ b/test/app/src/main/java/org/bsc/maven/plugin/processor/test/SampleClass.java @@ -0,0 +1,13 @@ +package org.bsc.maven.plugin.processor.test; + +@GenerateClass +public class SampleClass { + + final public String id; + final public String name; + + public SampleClass(String id, String name ) { + this.name = name; + this.id = id; + } +} diff --git a/test/processors/pom.xml b/test/processors/pom.xml new file mode 100644 index 0000000..83811b5 --- /dev/null +++ b/test/processors/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + + org.bsc.maven + maven-processor-plugin-test-processors + jar + MAVEN PROCESSOR PLUGIN TEST::Processor + + + + org.bsc.maven + maven-processor-plugin-parent + 4.6-SNAPSHOT + + + + + + org.bsc.util + processor-utils + ${project.version} + + + + + + diff --git a/test/src/main/java/org/bsc/maven/plugin/processor/test/ParameterDocumentation.java b/test/processors/src/main/java/org/bsc/maven/plugin/processor/test/GenerateClass.java similarity index 68% rename from test/src/main/java/org/bsc/maven/plugin/processor/test/ParameterDocumentation.java rename to test/processors/src/main/java/org/bsc/maven/plugin/processor/test/GenerateClass.java index f8515d8..cd49753 100644 --- a/test/src/main/java/org/bsc/maven/plugin/processor/test/ParameterDocumentation.java +++ b/test/processors/src/main/java/org/bsc/maven/plugin/processor/test/GenerateClass.java @@ -6,10 +6,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.SOURCE) -@Target({ ElementType.PARAMETER}) -public @interface ParameterDocumentation { - - String value() default ""; - - +@Target({ ElementType.TYPE}) +public @interface GenerateClass { } diff --git a/test/processors/src/main/java/org/bsc/maven/plugin/processor/test/TestGenerateSourceProcessor.java b/test/processors/src/main/java/org/bsc/maven/plugin/processor/test/TestGenerateSourceProcessor.java new file mode 100644 index 0000000..449ea8d --- /dev/null +++ b/test/processors/src/main/java/org/bsc/maven/plugin/processor/test/TestGenerateSourceProcessor.java @@ -0,0 +1,74 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.bsc.maven.plugin.processor.test; + +import org.bsc.processor.BaseAbstractProcessor; + +import javax.annotation.processing.Filer; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.tools.FileObject; +import javax.tools.StandardLocation; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Set; + +import static java.lang.String.format; + +/** + * + * @author softphone + * + * + */ +//@SupportedSourceVersion(SourceVersion.RELEASE_8) +@SupportedSourceVersion(SourceVersion.RELEASE_9) +//@SupportedOptions( {"subfolder", "filepath", "templateUri"}) +@SupportedAnnotationTypes( { "org.bsc.maven.plugin.processor.test.GenerateClass" }) +public class TestGenerateSourceProcessor extends BaseAbstractProcessor { + + void writeSourceCode( Element e ) { + + final java.net.URL url = getClass().getClassLoader().getResource("GeneratedClass_java.txt"); + try { + + final FileObject source = super.createSourceOutputFile( Paths.get("test"), Paths.get("GeneratedClass.java") ); + + try( java.io.OutputStream os = source.openOutputStream(); java.io.InputStream is = url.openStream() ) { + os.write(is.readAllBytes()); + } + + } catch (Exception ex) { + error( format("error writing source file [%s]", url ), ex); + } + } + /** + * + * @param annotations + * @param roundEnv + * @return + */ + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) return false; + + super.elementStreamFromAnnotations( annotations, roundEnv, e -> true ) + .peek( System.out::println) + .forEach( this::writeSourceCode ); + + return true; + } + + +} diff --git a/test/processors/src/main/resources/GeneratedClass_java.txt b/test/processors/src/main/resources/GeneratedClass_java.txt new file mode 100644 index 0000000..97c2a94 --- /dev/null +++ b/test/processors/src/main/resources/GeneratedClass_java.txt @@ -0,0 +1,6 @@ +package test; + +public class GeneratedClass { + + +} \ No newline at end of file diff --git a/test/src/main/java/org/bsc/maven/plugin/processor/test/ServiceDocumentation.java b/test/src/main/java/org/bsc/maven/plugin/processor/test/ServiceDocumentation.java deleted file mode 100644 index 6fea188..0000000 --- a/test/src/main/java/org/bsc/maven/plugin/processor/test/ServiceDocumentation.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.bsc.maven.plugin.processor.test; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - - -@Retention(RetentionPolicy.SOURCE) -@Target({ ElementType.METHOD}) -public @interface ServiceDocumentation { - - public String since() default ""; - - public String value() default ""; - - public String note() default ""; -} diff --git a/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessor.java b/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessor.java deleted file mode 100644 index 3f9d427..0000000 --- a/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessor.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package org.bsc.maven.plugin.processor.test; - -import org.bsc.processor.BaseAbstractProcessor; - -import javax.annotation.processing.Filer; -import javax.annotation.processing.RoundEnvironment; -import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedSourceVersion; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.TypeElement; -import javax.tools.FileObject; -import javax.tools.StandardLocation; -import java.io.IOException; -import java.util.Set; - -/** - * - * @author softphone - * - * - */ -//@SupportedSourceVersion(SourceVersion.RELEASE_8) -@SupportedSourceVersion(SourceVersion.RELEASE_9) -@SupportedAnnotationTypes( "*" ) -//@SupportedOptions( {"subfolder", "filepath", "templateUri"}) -//@SupportedAnnotationTypes( {"javax.ws.rs.GET", "javax.ws.rs.PUT", "javax.ws.rs.POST", "javax.ws.rs.DELETE"}) -public class TestWikiProcessor extends BaseAbstractProcessor { - - /** - * - * @param filer - * @return - * @throws IOException - */ - protected FileObject getResourceFormClassPath(Filer filer, final String resource, final String packageName) throws IOException { - final FileObject f = filer.getResource(StandardLocation.CLASS_PATH, packageName, resource); - - //java.io.Reader r = f.openReader(true); // ignoreEncodingErrors - try(java.io.InputStream is = f.openInputStream()) { - - if (is == null) { - warn("resource [%s] not found!", resource); - return null; - } - } - return f; - } - - /** - * - * @param annotations - * @param roundEnv - * @return - */ - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - if (roundEnv.processingOver()) return false; - - final java.util.Map optionMap = processingEnv.getOptions(); - - info( "====> PROCESSOR RUN"); - optionMap.entrySet().forEach( k -> info( "\t[%s] = [%s]", k.getKey(), k.getValue())); - - for( TypeElement e : annotations ) { - - for (Element re : roundEnv.getElementsAnnotatedWith(e)) { - - if( re.getKind()==ElementKind.METHOD) { - - info( "[%s], Element [%s] is [%s]", re.getEnclosingElement(), re.getKind(), re.getSimpleName() ); - - } - } - } - - return true; - } - - -} diff --git a/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessorClass.java b/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessorClass.java deleted file mode 100644 index e3093d4..0000000 --- a/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessorClass.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.bsc.maven.plugin.processor.test; - -public class TestWikiProcessorClass { - - @ServiceDocumentation("service1") - public void service1() { - - - } - - @ServiceDocumentation("service2") - public void service2( @ParameterDocumentation("param1") String param1) { - - - } -} diff --git a/test/src/main/resources/ConfluenceWikiTemplate.txt b/test/src/main/resources/ConfluenceWikiTemplate.txt deleted file mode 100644 index f83f988..0000000 --- a/test/src/main/resources/ConfluenceWikiTemplate.txt +++ /dev/null @@ -1,21 +0,0 @@ - -{toc} - -h1. SERVICES -\\ -h2. ${service.name} -|*Description:* | ${service.description} | -| *Since:* | ${service.since} | -| *Notes:* | ${service.notes} | -| *Security:* | ${service.security} | -| *Usage:* | ${service.verb} ${service.path} | -| *Consumes* | ${service.consumes} | -| *Produces:* | ${service.produces} | -| *Parameters* | {quote} -|| name || default || description || -| ${param.name} | ${param.default} | ${param.description} | - -{quote}| -\\ ----- - diff --git a/utils/src/main/java/org/bsc/processor/BaseAbstractProcessor.java b/utils/src/main/java/org/bsc/processor/BaseAbstractProcessor.java index dc07fa4..931a9c3 100644 --- a/utils/src/main/java/org/bsc/processor/BaseAbstractProcessor.java +++ b/utils/src/main/java/org/bsc/processor/BaseAbstractProcessor.java @@ -20,6 +20,8 @@ import java.util.stream.Collector; import java.util.stream.Stream; +import static java.util.Optional.empty; + /** * * @author bsorrentino @@ -114,6 +116,20 @@ protected > R toMapObject( AnnotationMirr } + /** + * + * @param moduleAndPkg + * @param relativeName + * @return + * @throws IOException + */ + protected FileObject getResourceFormClassPath( + String moduleAndPkg, + String relativeName ) throws IOException + { + return processingEnv.getFiler() + .getResource(StandardLocation.CLASS_PATH, moduleAndPkg, relativeName); + } /** * @@ -127,15 +143,12 @@ protected FileObject createSourceOutputFile( Path filePath ) throws IOException { - final Filer filer = processingEnv.getFiler(); - - final Element e = null; - FileObject res = filer.createResource( - StandardLocation.SOURCE_OUTPUT, - subfolder.toString(), - filePath.toString(), - e); - return res; + return processingEnv.getFiler() + .createResource( StandardLocation.SOURCE_OUTPUT, + subfolder.toString(), + filePath.toString(), + null); + }