From c6dbeb9bb1e5709a4e2831776530e9229410b094 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Wed, 5 Aug 2020 18:15:28 +0200 Subject: [PATCH 1/6] uodate site-maven-plugin version --- processor/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/pom.xml b/processor/pom.xml index ce27f3d..8cf2408 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -191,7 +191,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo. com.github.github site-maven-plugin - 0.10 + 0.12 Creating site for ${project.version} github From be4e8404052f7e6f3a3889df528f2082e85413ee Mon Sep 17 00:00:00 2001 From: Martijn Dashorst Date: Wed, 23 Sep 2020 11:13:10 +0200 Subject: [PATCH 2/6] Start 4.3-SNAPSHOT development --- pom.xml | 2 +- processor/pom.xml | 2 +- test/pom.xml | 2 +- utils/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 81a2d37..0eab17f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.bsc.maven maven-processor-plugin-parent pom - 4.2 + 4.3-SNAPSHOT MAVEN PROCESSOR PLUGIN PARENT A maven plugin to process annotation for jdk6 at compile time diff --git a/processor/pom.xml b/processor/pom.xml index ce27f3d..5a2f164 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -13,7 +13,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo. org.bsc.maven maven-processor-plugin-parent - 4.2 + 4.3-SNAPSHOT diff --git a/test/pom.xml b/test/pom.xml index 907458c..5d8dcee 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -11,7 +11,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.2 + 4.3-SNAPSHOT diff --git a/utils/pom.xml b/utils/pom.xml index c374c92..e0072c7 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -31,7 +31,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.2 + 4.3-SNAPSHOT From 30861dbad2fef670127974bffc93043900b1d688 Mon Sep 17 00:00:00 2001 From: Martijn Dashorst Date: Wed, 23 Sep 2020 11:30:39 +0200 Subject: [PATCH 3/6] Implement lastModified check for sources The annotation processor should be able to skip the annotation processing if the sources haven't changed since the last processing. This will speed up project builds considerably since for example the JPA metamodel generator will not run if the entities haven't been modified, which will save the compiler of having to recompile your whole module. Using the option `skipWithoutSourceChanges` you can enable this behavior. By default it is turned off to maintain the current behavior. This change doesn't track individual files, as there need not be a 1-1 mapping between the origin of the annotation processor and the generated sources. The plugin rather determines from all source locations what the most recent last modified time is, and does the same for all the files in the output folder. This cuts down rebuild times on my current project by a half or so (going from over 2 minutes to just 1 minute). --- .../AbstractAnnotationProcessorMojo.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java index 905870a..7d67078 100644 --- a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java +++ b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java @@ -54,7 +54,14 @@ 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.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; @@ -269,6 +276,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 = "skipAnnotationProcessingWithoutSourceChanges") + protected boolean skipWithoutSourceChanges; + /** * Maven Session * @@ -755,6 +771,32 @@ private void executeWithExceptionsHandled() throws Exception return; } + long maxSourceDate = allSources.stream().map(JavaFileObject::getLastModified).max(Long::compare).get(); + + // use atomic long for effectively final wrapper around long variable + 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()); + } + + if(skipWithoutSourceChanges && maxSourceDate <= maxOutputDate.get()) { + getLog().info( "no source file(s) change(s) detected! Processor task will be skipped"); + return; + } final List options = prepareOptions( compiler ); final CompilationTask task = compiler.getTask( From 2bf7bedb068e64da084e57b9108c904ea42e32a8 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Thu, 24 Sep 2020 12:03:51 +0200 Subject: [PATCH 4/6] merged PR #85 renamed property from 'skipWithoutSourceChanges' to 'skipSourcesUnchanged' put PR code in a new method 'isSourcesUnchanged( List<> allSources )' --- .../AbstractAnnotationProcessorMojo.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java index 7d67078..e74f954 100644 --- a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java +++ b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java @@ -61,7 +61,6 @@ import java.nio.file.attribute.BasicFileAttributes; import java.util.*; import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; @@ -282,8 +281,8 @@ public abstract class AbstractAnnotationProcessorMojo extends AbstractMojo * * @since 4.3 */ - @Parameter(defaultValue = "false", property = "skipAnnotationProcessingWithoutSourceChanges") - protected boolean skipWithoutSourceChanges; + @Parameter(defaultValue = "false", property = "skipSourcesUnchangedAnnotationProcessing") + protected boolean skipSourcesUnchanged; /** * Maven Session @@ -573,6 +572,33 @@ private List prepareOptions( JavaCompiler compiler ) { } + private boolean isSourcesUnchanged( List 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) @@ -771,29 +797,7 @@ private void executeWithExceptionsHandled() throws Exception return; } - long maxSourceDate = allSources.stream().map(JavaFileObject::getLastModified).max(Long::compare).get(); - - // use atomic long for effectively final wrapper around long variable - 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()); - } - - if(skipWithoutSourceChanges && maxSourceDate <= maxOutputDate.get()) { + if(skipSourcesUnchanged && isSourcesUnchanged(allSources)) { getLog().info( "no source file(s) change(s) detected! Processor task will be skipped"); return; } From db87a0476c03596049c06bcfe887686e5b0fcbe6 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Fri, 25 Sep 2020 17:28:27 +0200 Subject: [PATCH 5/6] set release version --- pom.xml | 2 +- processor/pom.xml | 2 +- test/pom.xml | 2 +- utils/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0eab17f..230cc9c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.bsc.maven maven-processor-plugin-parent pom - 4.3-SNAPSHOT + 4.3 MAVEN PROCESSOR PLUGIN PARENT A maven plugin to process annotation for jdk6 at compile time diff --git a/processor/pom.xml b/processor/pom.xml index 3e9ed07..b798483 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -13,7 +13,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo. org.bsc.maven maven-processor-plugin-parent - 4.3-SNAPSHOT + 4.3 diff --git a/test/pom.xml b/test/pom.xml index 5d8dcee..29ffc4b 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -11,7 +11,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.3-SNAPSHOT + 4.3 diff --git a/utils/pom.xml b/utils/pom.xml index e0072c7..c9552be 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -31,7 +31,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.3-SNAPSHOT + 4.3 From 382dfb7fe61851a83d182cb35b6be9a62654b879 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Fri, 25 Sep 2020 17:31:42 +0200 Subject: [PATCH 6/6] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f96f01d..59f164f 100644 --- a/README.md +++ b/README.md @@ -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