From cb7191dfff7939026504c169db626b2a2fcbddb2 Mon Sep 17 00:00:00 2001 From: Martijn Dashorst Date: Sun, 27 Sep 2020 14:51:35 +0200 Subject: [PATCH 1/6] Start work on 4.4-SNAPSHOT --- 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 230cc9c..0031708 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.bsc.maven maven-processor-plugin-parent pom - 4.3 + 4.4-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 b798483..0188712 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 + 4.4-SNAPSHOT diff --git a/test/pom.xml b/test/pom.xml index 29ffc4b..e459842 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -11,7 +11,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.3 + 4.4-SNAPSHOT diff --git a/utils/pom.xml b/utils/pom.xml index c9552be..eeb16db 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -31,7 +31,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.3 + 4.4-SNAPSHOT From 1f6c708506ea959920f54a7873b82e3fab76bf77 Mon Sep 17 00:00:00 2001 From: Martijn Dashorst Date: Sun, 27 Sep 2020 15:10:57 +0200 Subject: [PATCH 2/6] Detects file additions/deletions for skipping When you remove a file from the source tree, the modification checker doesn't take into account the removed file as an update. Because the file no longer exists, it doesn't have a modification date, and it will not count in determining whether the last generation was older than the modification in the sources. This commit detects source file modifications of the nature of additions and deletions by using a tracking file in the output folder (`.maven-processor-source-files.txt`). This file contains a list of all the files in the source folders, which is checked against the current list of source files. When the file doesn't exist or if the sets of files don't match, it is treated as a change. When they match exactly, the modification time check is still run. A sample run without additions/removals in the source files: ``` [DEBUG] (f) skipSourcesUnchanged = true [DEBUG] (f) sourceDirectory = /Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java [DEBUG] -- end configuration -- [DEBUG] Source directory: /Users/dashorst/IdeaProjects/iridium/common/entities/target/generated-sources/apt added [DEBUG] processing source directory [/Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java] [DEBUG] removed source files: [] [DEBUG] new source files: [] [DEBUG] max source file date: 1601210991895, max output date: 1601211873845 [INFO] no source file(s) change(s) detected! Processor task will be skipped ``` When a file was removed: ``` [DEBUG] (f) skipSourcesUnchanged = true [DEBUG] (f) sourceDirectory = /Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java [DEBUG] -- end configuration -- [DEBUG] Source directory: /Users/dashorst/IdeaProjects/iridium/common/entities/target/generated-sources/apt added [DEBUG] processing source directory [/Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java] [DEBUG] removed source files: [/Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java/nl/topicus/platinum/entities/Afdeling.java] [DEBUG] new source files: [] [WARNING] No processors specified. Using default discovery mechanism. [DEBUG] javac option: -cp ``` When the file is re-added: ``` [DEBUG] (f) skipSourcesUnchanged = true [DEBUG] (f) sourceDirectory = /Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java [DEBUG] -- end configuration -- [DEBUG] Source directory: /Users/dashorst/IdeaProjects/iridium/common/entities/target/generated-sources/apt added [DEBUG] processing source directory [/Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java] [DEBUG] removed source files: [] [DEBUG] new source files: [/Users/dashorst/IdeaProjects/iridium/common/entities/src/main/java/nl/topicus/platinum/entities/Afdeling.java] [WARNING] No processors specified. Using default discovery mechanism. [DEBUG] javac option: -cp ``` Fixes #86 --- .../AbstractAnnotationProcessorMojo.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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 e74f954..39ebebd 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 @@ -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; @@ -573,7 +574,13 @@ private List prepareOptions( JavaCompiler compiler ) { } private boolean isSourcesUnchanged( List 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); @@ -596,7 +603,41 @@ private boolean isSourcesUnchanged( List 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 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 previousSourceFiles = new HashSet<>(Files.readAllLines(sourceFileList)); + Set currentSourceFiles = allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet()); + if (getLog().isDebugEnabled()) { + Set removedSourceFiles = previousSourceFiles.stream() + .filter(f -> !currentSourceFiles.contains(f)) + .collect(Collectors.toSet()); + getLog().debug("removed source files: " + removedSourceFiles); + + Set newSourceFiles = currentSourceFiles.stream() + .filter(f -> !previousSourceFiles.contains(f)) + .collect(Collectors.toSet()); + getLog().debug("new source files: " + newSourceFiles); + } + return previousSourceFiles.equals(currentSourceFiles); + } finally { + outputDirectory.mkdirs(); + Files.write(sourceFileList, allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet())); + } } private void executeWithExceptionsHandled() throws Exception From 9646e901989224dc3912d16f0101d5de1882206a Mon Sep 17 00:00:00 2001 From: bartolomeo sorrentino Date: Thu, 1 Oct 2020 16:29:27 +0200 Subject: [PATCH 3/6] update debug message --- .../AbstractAnnotationProcessorMojo.java | 54 ++++++++++--------- 1 file changed, 28 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 39ebebd..0002bc7 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 @@ -81,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; /** @@ -420,7 +422,7 @@ private String buildModulePath() return getClasspathElements(new java.util.LinkedHashSet<>()) .stream() - .collect(Collectors.joining( File.pathSeparator) ); + .collect(joining( File.pathSeparator) ); } /** @@ -565,7 +567,7 @@ private List 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)); } } @@ -623,15 +625,15 @@ private boolean areSourceFilesSameAsPreviousRun(List allSources) Set previousSourceFiles = new HashSet<>(Files.readAllLines(sourceFileList)); Set currentSourceFiles = allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet()); if (getLog().isDebugEnabled()) { - Set removedSourceFiles = previousSourceFiles.stream() + final String removedSourceFiles = previousSourceFiles.stream() .filter(f -> !currentSourceFiles.contains(f)) - .collect(Collectors.toSet()); - getLog().debug("removed source files: " + removedSourceFiles); + .collect(joining("\n")); + getLog().debug(format("removed source files:\n%s", removedSourceFiles)); - Set newSourceFiles = currentSourceFiles.stream() + final String newSourceFiles = currentSourceFiles.stream() .filter(f -> !previousSourceFiles.contains(f)) - .collect(Collectors.toSet()); - getLog().debug("new source files: " + newSourceFiles); + .collect(joining("\n")); + getLog().debug(format("new source files:\n%s", newSourceFiles)); } return previousSourceFiles.equals(currentSourceFiles); } finally { @@ -685,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; } @@ -710,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; @@ -732,7 +734,7 @@ private void executeWithExceptionsHandled() throws Exception java.util.Set< Map.Entry> pSet = systemProperties.entrySet(); for ( Map.Entry 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()); } @@ -762,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); } }); @@ -809,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; } } @@ -898,7 +900,7 @@ private void addCompilerArguments(List 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); } } @@ -907,9 +909,9 @@ private void addCompilerArguments(List options) { for( java.util.Map.Entry 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)); } } @@ -920,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()); } } @@ -991,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 ); @@ -1017,7 +1019,7 @@ private void processSourceArtifacts( Consumer 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); } From 692074de91c1440ba3fee1090484f39e4994a8b5 Mon Sep 17 00:00:00 2001 From: bartolomeo sorrentino Date: Thu, 1 Oct 2020 16:30:14 +0200 Subject: [PATCH 4/6] refine integration test --- test/pom.xml | 11 +++-------- ...WikiProcessor.java => TestWikiProcessor.java} | 2 +- .../processor/test/TestWikiProcessorClass.java | 16 ++++++++++++++++ test/src/site/.maven-processor-source-files.txt | 4 ++++ 4 files changed, 24 insertions(+), 9 deletions(-) rename test/src/main/java/org/bsc/maven/plugin/processor/test/{TESTWikiProcessor.java => TestWikiProcessor.java} (97%) create mode 100644 test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessorClass.java create mode 100644 test/src/site/.maven-processor-source-files.txt diff --git a/test/pom.xml b/test/pom.xml index e459842..af75ed3 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -76,7 +76,7 @@ PROCESSOR PLUGIN false - org.bsc.maven.plugin.processor.test.TESTWikiProcessor + org.bsc.maven.plugin.processor.test.TestWikiProcessor @@ -99,17 +99,12 @@ PROCESSOR PLUGIN ${basedir}/src/main/java - false + true - org.bsc.maven.plugin.processor.test.TESTWikiProcessor - + org.bsc.maven.plugin.processor.test.TestWikiProcessor 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 similarity index 97% rename from test/src/main/java/org/bsc/maven/plugin/processor/test/TESTWikiProcessor.java rename to test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessor.java index 55a2c6c..3f9d427 100644 --- 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 @@ -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 { /** * 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 new file mode 100644 index 0000000..e3093d4 --- /dev/null +++ b/test/src/main/java/org/bsc/maven/plugin/processor/test/TestWikiProcessorClass.java @@ -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) { + + + } +} diff --git a/test/src/site/.maven-processor-source-files.txt b/test/src/site/.maven-processor-source-files.txt new file mode 100644 index 0000000..6256132 --- /dev/null +++ b/test/src/site/.maven-processor-source-files.txt @@ -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 From 1714e8977800c50af33383c801d82bb4c08c92ab Mon Sep 17 00:00:00 2001 From: bartolomeo sorrentino Date: Thu, 1 Oct 2020 16:47:30 +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 0031708..43a4dde 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.bsc.maven maven-processor-plugin-parent pom - 4.4-SNAPSHOT + 4.4 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 0188712..610734c 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.4-SNAPSHOT + 4.4 diff --git a/test/pom.xml b/test/pom.xml index af75ed3..89b26e6 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -11,7 +11,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.4-SNAPSHOT + 4.4 diff --git a/utils/pom.xml b/utils/pom.xml index eeb16db..56d14d4 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -31,7 +31,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.4-SNAPSHOT + 4.4 From fa1f52af0d550c992f9d9f74cd9e0c937917a88e Mon Sep 17 00:00:00 2001 From: bartolomeo sorrentino Date: Thu, 1 Oct 2020 16:47: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 59f164f..69f1cd3 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 --- | --- | --- +**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)