Skip to content

Commit

Permalink
Merge branch 'release/4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Sep 25, 2020
2 parents 10f5517 + 382dfb7 commit 57abc67
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 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
--- | --- | ---
**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)
**Jul 30, 2020** | [Release 4.1](https://github.com/bsorrentino/maven-annotation-plugin/releases/tag/v4.1) | Release based on JDK9 and above
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.2</version>
<version>4.3</version>
<name>MAVEN PROCESSOR PLUGIN PARENT</name>
<description>A maven plugin to process annotation for jdk6 at compile time

Expand Down
4 changes: 2 additions & 2 deletions 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.2</version>
<version>4.3</version>
</parent>

<properties>
Expand Down Expand Up @@ -191,7 +191,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.10</version>
<version>0.12</version>
<configuration>
<message>Creating site for ${project.version}</message>
<server>github</server>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
Expand Down Expand Up @@ -269,6 +275,15 @@ public abstract class AbstractAnnotationProcessorMojo extends AbstractMojo
@Parameter(defaultValue = "false", property = "fork")
protected boolean fork;

/**
* Set this to true to skip annotation processing when there are no changes in the source files
* compared to the generated files.
*
* @since 4.3
*/
@Parameter(defaultValue = "false", property = "skipSourcesUnchangedAnnotationProcessing")
protected boolean skipSourcesUnchanged;

/**
* Maven Session
*
Expand Down Expand Up @@ -557,6 +572,33 @@ 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();

// use atomic long for effectively final wrapper around long variable
final AtomicLong maxOutputDate = new AtomicLong(Long.MIN_VALUE);

Files.walkFileTree(outputDirectory.toPath(), new SimpleFileVisitor<>() {
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException
{
if(Files.isRegularFile(file)) {
maxOutputDate.updateAndGet(t -> Math.max(t, file.toFile().lastModified()));
}
return FileVisitResult.CONTINUE;
}
});

if(getLog().isDebugEnabled())
{
getLog().debug("max source file date: " + maxSourceDate + ", max output date: " + maxOutputDate
.get());
}

return maxSourceDate <= maxOutputDate.get();

}

private void executeWithExceptionsHandled() throws Exception
{
if (outputDirectory == null)
Expand Down Expand Up @@ -755,6 +797,10 @@ private void executeWithExceptionsHandled() throws Exception
return;
}

if(skipSourcesUnchanged && isSourcesUnchanged(allSources)) {
getLog().info( "no source file(s) change(s) detected! Processor task will be skipped");
return;
}
final List<String> options = prepareOptions( compiler );

final CompilationTask task = compiler.getTask(
Expand Down
2 changes: 1 addition & 1 deletion 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.2</version>
<version>4.3</version>
</parent>

<dependencies>
Expand Down
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.2</version>
<version>4.3</version>
</parent>

<properties>
Expand Down

0 comments on commit 57abc67

Please sign in to comment.