Skip to content

Commit

Permalink
issue #92 - tests refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Jan 29, 2021
1 parent e108170 commit ed08c34
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 206 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<modules>
<module>processor</module>
<module>utils</module>
<module>test</module>
<module>test/processors</module>
<module>test/app</module>
</modules>
<dependencyManagement>
<dependencies>
Expand Down
File renamed without changes.
81 changes: 33 additions & 48 deletions test/pom.xml → test/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-test</artifactId>
<artifactId>maven-processor-plugin-test-app</artifactId>
<packaging>jar</packaging>
<name>MAVEN PROCESSOR PLUGIN TEST</name>
<description></description>
Expand All @@ -17,8 +17,8 @@
<dependencies>

<dependency>
<groupId>org.bsc.util</groupId>
<artifactId>processor-utils</artifactId>
<groupId>${project.groupId}</groupId>
<artifactId>maven-processor-plugin-test-processors</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down Expand Up @@ -48,70 +48,55 @@ PROCESSOR PLUGIN
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>${project.version}</version>
<dependencies>
<!--
<dependency>
<groupId>org.bsc</groupId>
<artifactId>jaxrs-wiki-processor</artifactId>
<version>2.2</version>
</dependency>
-->
</dependencies>
<executions>

<execution>

<id>process-test</id>
<goals>
<goal>process-test</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<outputDirectory>${basedir}/src/site</outputDirectory>

<additionalSourceDirectories>
<item>${user.home}/src</item>
<item>./src/main/java</item>
</additionalSourceDirectories>

<failOnError>false</failOnError>
<processors>
<processor>org.bsc.maven.plugin.processor.test.TestWikiProcessor</processor>
</processors>

<options>
<test>true</test>
</options>
</configuration>


</execution>

<execution>

<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>process-classes</phase>
<phase>process-sources</phase>
<configuration>
<outputDirectory>${basedir}/src/site</outputDirectory>

<!--
<additionalSourceDirectories>
<item>${basedir}/src/main/java</item>
</additionalSourceDirectories>

-->
<addOutputDirectoryToCompilationSources>true</addOutputDirectoryToCompilationSources>
<failOnError>false</failOnError>
<skipSourcesUnchanged>true</skipSourcesUnchanged>
<skipSourcesUnchanged>false</skipSourcesUnchanged>
<processors>
<processor>org.bsc.maven.plugin.processor.test.TestWikiProcessor</processor>
<processor>org.bsc.maven.plugin.processor.test.TestGenerateSourceProcessor</processor>
</processors>

<!--
<options>
<test>false</test>
</options>
-->
</configuration>

<!--
<execution>
<id>process-test</id>
<goals>
<goal>process-test</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<additionalSourceDirectories>
<item>${user.home}/src</item>
<item>src/main/java</item>
</additionalSourceDirectories>
<failOnError>false</failOnError>
<processors>
<processor>org.bsc.maven.plugin.processor.test.TestGenerateSourceProcessor</processor>
</processors>
<options>
<test>true</test>
</options>
</configuration>
</execution>
-->

</execution>
</executions>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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;
}
}
28 changes: 28 additions & 0 deletions test/processors/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-test-processors</artifactId>
<packaging>jar</packaging>
<name>MAVEN PROCESSOR PLUGIN TEST::Processor</name>
<description></description>

<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.6-SNAPSHOT</version>
</parent>

<dependencies>

<dependency>
<groupId>org.bsc.util</groupId>
<artifactId>processor-utils</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (roundEnv.processingOver()) return false;

super.elementStreamFromAnnotations( annotations, roundEnv, e -> true )
.peek( System.out::println)
.forEach( this::writeSourceCode );

return true;
}


}
6 changes: 6 additions & 0 deletions test/processors/src/main/resources/GeneratedClass_java.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package test;

public class GeneratedClass {


}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ed08c34

Please sign in to comment.