Skip to content

Commit

Permalink
Merge branch 'release/4.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Oct 1, 2020
2 parents 4afd4c4 + fa1f52a commit a611d0b
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 34 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This plugin was born as the 'alter ego' of maven apt plugin [apt-maven-plugin](h

Date | Version | Info
--- | --- | ---
**Oct 01, 2020** | [Release 4.4](https://github.com/bsorrentino/maven-annotation-plugin/releases/tag/v4.4) | merge PR #87. Thanks to [Martijn Dashorst](https://github.com/dashorst)
**Sep 25, 2020** | [Release 4.3](https://github.com/bsorrentino/maven-annotation-plugin/releases/tag/v4.3) | merge PR #85. Thanks to [Martijn Dashorst](https://github.com/dashorst)
**Aug 03, 2020** | [Release 4.2](https://github.com/bsorrentino/maven-annotation-plugin/releases/tag/v4.2) | merge PR #84. Thanks to [DemonicTutor](https://github.com/DemonicTutor)
**Aug 03, 2020** | [Release 4.2-jdk8](https://github.com/bsorrentino/maven-annotation-plugin/releases/tag/v4.2-jdk8) | merge PR #84. Thanks to [DemonicTutor](https://github.com/DemonicTutor)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<packaging>pom</packaging>
<version>4.3</version>
<version>4.4</version>
<name>MAVEN PROCESSOR PLUGIN PARENT</name>
<description>A maven plugin to process annotation for jdk6 at compile time

Expand Down
2 changes: 1 addition & 1 deletion processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.3</version>
<version>4.4</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand All @@ -80,7 +81,9 @@
import org.sonatype.aether.util.artifact.DefaultArtifact;
*/
// 3.1.0
import static java.lang.String.format;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.joining;


/**
Expand Down Expand Up @@ -419,7 +422,7 @@ private String buildModulePath()

return getClasspathElements(new java.util.LinkedHashSet<>())
.stream()
.collect(Collectors.joining( File.pathSeparator) );
.collect(joining( File.pathSeparator) );
}

/**
Expand Down Expand Up @@ -564,7 +567,7 @@ private List<String> prepareOptions( JavaCompiler compiler ) {

if( getLog().isDebugEnabled() ) {
for (String option : options) {
getLog().debug(String.format("javac option: %s", option));
getLog().debug(format("javac option: %s", option));
}
}

Expand All @@ -573,7 +576,13 @@ private List<String> prepareOptions( JavaCompiler compiler ) {
}

private boolean isSourcesUnchanged( List<JavaFileObject> allSources ) throws IOException {
long maxSourceDate = allSources.stream().map(JavaFileObject::getLastModified).max(Long::compare).get();
if (!areSourceFilesSameAsPreviousRun(allSources))
return false;

long maxSourceDate = allSources.stream()
.map(JavaFileObject::getLastModified)
.max(Long::compare)
.orElse(Long.MIN_VALUE);

// use atomic long for effectively final wrapper around long variable
final AtomicLong maxOutputDate = new AtomicLong(Long.MIN_VALUE);
Expand All @@ -596,7 +605,41 @@ private boolean isSourcesUnchanged( List<JavaFileObject> allSources ) throws IOE
}

return maxSourceDate <= maxOutputDate.get();
}

/**
* Checks the list of {@code allSources} against the stored list of source files in a previous run.
*
* @param allSources
* @return {@code true} when the filenames of the previous run matches exactly with the current run.
* @throws IOException
*/
private boolean areSourceFilesSameAsPreviousRun(List<JavaFileObject> allSources) throws IOException {
Path sourceFileList = outputDirectory.toPath().resolve(".maven-processor-source-files.txt");
try {
if (!Files.exists(sourceFileList)) {
getLog().debug("File with previous sources " + sourceFileList + " not found, treating as first run");
return false;
}

Set<String> previousSourceFiles = new HashSet<>(Files.readAllLines(sourceFileList));
Set<String> currentSourceFiles = allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet());
if (getLog().isDebugEnabled()) {
final String removedSourceFiles = previousSourceFiles.stream()
.filter(f -> !currentSourceFiles.contains(f))
.collect(joining("\n"));
getLog().debug(format("removed source files:\n%s", removedSourceFiles));

final String newSourceFiles = currentSourceFiles.stream()
.filter(f -> !previousSourceFiles.contains(f))
.collect(joining("\n"));
getLog().debug(format("new source files:\n%s", newSourceFiles));
}
return previousSourceFiles.equals(currentSourceFiles);
} finally {
outputDirectory.mkdirs();
Files.write(sourceFileList, allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet()));
}
}

private void executeWithExceptionsHandled() throws Exception
Expand Down Expand Up @@ -644,14 +687,14 @@ private void executeWithExceptionsHandled() throws Exception
continue;
}

getLog().debug( String.format( "processing source directory [%s]", sourceDir.getPath()) );
getLog().debug( format( "processing source directory [%s]", sourceDir.getPath()) );

if( !sourceDir.exists() ) {
getLog().warn( String.format("source directory [%s] doesn't exist! Processor task will be skipped!", sourceDir.getPath()));
getLog().warn( format("source directory [%s] doesn't exist! Processor task will be skipped!", sourceDir.getPath()));
continue;
}
if( !sourceDir.isDirectory() ) {
getLog().warn( String.format("source directory [%s] is invalid! Processor task will be skipped!", sourceDir.getPath()));
getLog().warn( format("source directory [%s] is invalid! Processor task will be skipped!", sourceDir.getPath()));
continue;
}

Expand All @@ -669,17 +712,17 @@ private void executeWithExceptionsHandled() throws Exception
if (null != kind)
switch (kind) {
case ERROR:
getLog().error(String.format("diagnostic: %s", diagnostic));
getLog().error(format("diagnostic: %s", diagnostic));
break;
case MANDATORY_WARNING:
case WARNING:
getLog().warn(String.format("diagnostic: %s", diagnostic));
getLog().warn(format("diagnostic: %s", diagnostic));
break;
case NOTE:
getLog().info(String.format("diagnostic: %s", diagnostic));
getLog().info(format("diagnostic: %s", diagnostic));
break;
case OTHER:
getLog().info(String.format("diagnostic: %s", diagnostic));
getLog().info(format("diagnostic: %s", diagnostic));
break;
default:
break;
Expand All @@ -691,7 +734,7 @@ private void executeWithExceptionsHandled() throws Exception
java.util.Set< Map.Entry<String,String>> pSet = systemProperties.entrySet();

for ( Map.Entry<String,String> e : pSet ) {
getLog().debug( String.format("set system property : [%s] = [%s]", e.getKey(), e.getValue() ));
getLog().debug( format("set system property : [%s] = [%s]", e.getKey(), e.getValue() ));
System.setProperty(e.getKey(), e.getValue());
}

Expand Down Expand Up @@ -721,10 +764,10 @@ private void executeWithExceptionsHandled() throws Exception
}
}

getLog().debug(String.format("** Discovered %d java sources in %s", sourceCount, f.getAbsolutePath()));
getLog().debug(format("** Discovered %d java sources in %s", sourceCount, f.getAbsolutePath()));

} catch (Exception ex) {
getLog().warn(String.format("Problem reading source archive [%s]", artifact.getFile().getPath()));
getLog().warn(format("Problem reading source archive [%s]", artifact.getFile().getPath()));
getLog().debug(ex);
}
});
Expand Down Expand Up @@ -768,11 +811,11 @@ private void executeWithExceptionsHandled() throws Exception
charset = Charset.forName(encoding);
}
catch( IllegalCharsetNameException ex1 ) {
getLog().warn( String.format("the given charset name [%s] is illegal!. default is used", encoding ));
getLog().warn( format("the given charset name [%s] is illegal!. default is used", encoding ));
charset = null;
}
catch( UnsupportedCharsetException ex2 ) {
getLog().warn( String.format("the given charset name [%s] is unsupported!. default is used", encoding ));
getLog().warn( format("the given charset name [%s] is unsupported!. default is used", encoding ));
charset = null;
}
}
Expand Down Expand Up @@ -857,7 +900,7 @@ private void addCompilerArguments(List<String> options) {
for (String arg : compilerArguments.split(" ")) {
if (!StringUtils.isEmpty(arg)) {
arg = arg.trim();
getLog().debug(String.format("Adding compiler arg: %s", arg));
getLog().debug(format("Adding compiler arg: %s", arg));
options.add(arg);
}
}
Expand All @@ -866,9 +909,9 @@ private void addCompilerArguments(List<String> options) {
for( java.util.Map.Entry<String,Object> e : optionMap.entrySet() ) {

if( !StringUtils.isEmpty(e.getKey()) && e.getValue()!=null ) {
String opt = String.format("-A%s=%s", e.getKey().trim(), e.getValue().toString().trim());
String opt = format("-A%s=%s", e.getKey().trim(), e.getValue().toString().trim());
options.add( opt );
getLog().debug(String.format("Adding compiler arg: %s", opt));
getLog().debug(format("Adding compiler arg: %s", opt));
}
}

Expand All @@ -879,7 +922,7 @@ private void addOutputToSourcesIfNeeded()
{
final Boolean add = addOutputDirectoryToCompilationSources;
if (add == null || add.booleanValue()) {
getLog().debug(String.format("Source directory: %s added", outputDirectory));
getLog().debug(format("Source directory: %s added", outputDirectory));
addCompileSourceRoot(project, outputDirectory.getAbsolutePath());
}
}
Expand Down Expand Up @@ -950,7 +993,7 @@ private Artifact resolveSourceArtifact( Artifact dep ) throws ArtifactResolution
request.setArtifact( artifact );
request.setRepositories(remoteRepos);

getLog().debug( String.format("Resolving artifact %s from %s", artifact, remoteRepos ));
getLog().debug( format("Resolving artifact %s from %s", artifact, remoteRepos ));

final ArtifactResult result = repoSystem.resolveArtifact( repoSession, request );

Expand All @@ -976,7 +1019,7 @@ private void processSourceArtifacts( Consumer<Artifact> closure ) {
}

} catch (ArtifactResolutionException ex) {
getLog().warn( String.format(" sources for artifact [%s] not found!", dep.toString()));
getLog().warn( format(" sources for artifact [%s] not found!", dep.toString()));
getLog().debug(ex);

}
Expand Down
13 changes: 4 additions & 9 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.3</version>
<version>4.4</version>
</parent>

<dependencies>
Expand Down Expand Up @@ -76,7 +76,7 @@ PROCESSOR PLUGIN

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

<options>
Expand All @@ -99,17 +99,12 @@ PROCESSOR PLUGIN

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

<failOnError>false</failOnError>
<skipSourcesUnchanged>true</skipSourcesUnchanged>
<processors>
<processor>org.bsc.maven.plugin.processor.test.TESTWikiProcessor</processor>
<!--
<processor>org.bsc.jaxrs.JAXRSWikiProcessor</processor>
-->
<processor>org.bsc.maven.plugin.processor.test.TestWikiProcessor</processor>
</processors>

<options>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@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 {
public class TestWikiProcessor extends BaseAbstractProcessor {

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.bsc.maven.plugin.processor.test;

public class TestWikiProcessorClass {

@ServiceDocumentation("service1")
public void service1() {


}

@ServiceDocumentation("service2")
public void service2( @ParameterDocumentation("param1") String param1) {


}
}
4 changes: 4 additions & 0 deletions test/src/site/.maven-processor-source-files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Users/bsorrentino/WORKSPACES/GITHUB.me/maven-annotation-plugin/test/src/main/java/org/bsc/maven/plugin/processor/test/ParameterDocumentation.java
/Users/bsorrentino/WORKSPACES/GITHUB.me/maven-annotation-plugin/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessor.java
/Users/bsorrentino/WORKSPACES/GITHUB.me/maven-annotation-plugin/test/src/main/java/org/bsc/maven/plugin/processor/test/ServiceDocumentation.java
/Users/bsorrentino/WORKSPACES/GITHUB.me/maven-annotation-plugin/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessorClass.java
2 changes: 1 addition & 1 deletion utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.3</version>
<version>4.4</version>
</parent>

<properties>
Expand Down

0 comments on commit a611d0b

Please sign in to comment.