This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch maven-compiler-plugin-3.x
in repository https://gitbox.apache.org/repos/asf/maven-compiler-plugin.git


The following commit(s) were added to refs/heads/maven-compiler-plugin-3.x by 
this push:
     new d44d1be  Add generatedSourcesPath back to the maven project
d44d1be is described below

commit d44d1bee9698947b5fbfc566ce54eaa91e257ec9
Author: Daniel Mensinger <d.mensin...@tup.com>
AuthorDate: Tue Mar 11 11:10:38 2025 +0100

    Add generatedSourcesPath back to the maven project
    
    This is a followup for for #191 to add the generatedSourcesPath back
    to the maven project paths as the final step of the mojo.
---
 .../SourcePathReadGoal.java                        |  9 ++----
 .../plugin/compiler/AbstractCompilerMojo.java      | 33 +++++++++++++++++++++-
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git 
a/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
 
b/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
index d3691fa..46b7d2b 100644
--- 
a/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
+++ 
b/src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java
@@ -47,17 +47,12 @@ public class SourcePathReadGoal extends AbstractMojo {
     public void execute() throws MojoExecutionException, MojoFailureException {
         if (sourceClass != null) {
             getLog().info("Checking compile source roots for: '" + sourceClass 
+ "'");
-            List<String> roots = project.getCompileSourceRoots();
-            roots.add(project.getModel().getBuild().getOutputDirectory() + 
"/../generated-sources/annotations");
-            assertGeneratedSourceFileFor(sourceClass, roots);
+            assertGeneratedSourceFileFor(sourceClass, 
project.getCompileSourceRoots());
         }
 
         if (testSourceClass != null) {
             getLog().info("Checking test-compile source roots for: '" + 
testSourceClass + "'");
-            List<String> roots = project.getTestCompileSourceRoots();
-            roots.add(
-                    project.getModel().getBuild().getOutputDirectory() + 
"/../generated-test-sources/test-annotations");
-            assertGeneratedSourceFileFor(testSourceClass, roots);
+            assertGeneratedSourceFileFor(testSourceClass, 
project.getTestCompileSourceRoots());
         }
     }
 
diff --git 
a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java 
b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
index 5631892..b12f6a1 100644
--- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
+++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
@@ -703,8 +703,39 @@ public abstract class AbstractCompilerMojo extends 
AbstractMojo {
     private boolean targetOrReleaseSet;
 
     @Override
-    @SuppressWarnings("checkstyle:MethodLength")
     public void execute() throws MojoExecutionException, 
CompilationFailureException {
+        try {
+            executeReal();
+        } finally {
+            addGeneratedSourcesToProject();
+        }
+    }
+
+    private void addGeneratedSourcesToProject() {
+        File generatedSourcesDirectory = getGeneratedSourcesDirectory();
+        if (generatedSourcesDirectory == null) {
+            return;
+        }
+
+        String generatedSourcesPath = 
generatedSourcesDirectory.getAbsolutePath();
+
+        if (isTestCompile()) {
+            getLog().debug("Adding " + generatedSourcesPath
+                    + " to the project test-compile source roots but NOT the 
actual test-compile source roots:\n  "
+                    + 
StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n  "));
+
+            project.addTestCompileSourceRoot(generatedSourcesPath);
+        } else {
+            getLog().debug("Adding " + generatedSourcesPath
+                    + " to the project compile source roots but NOT the actual 
compile source roots:\n  "
+                    + 
StringUtils.join(project.getCompileSourceRoots().iterator(), "\n  "));
+
+            project.addCompileSourceRoot(generatedSourcesPath);
+        }
+    }
+
+    @SuppressWarnings("checkstyle:MethodLength")
+    private void executeReal() throws MojoExecutionException, 
CompilationFailureException {
         // 
----------------------------------------------------------------------
         // Look up the compiler. This is done before other code than can
         // cause the mojo to return before the lookup is done possibly 
resulting

Reply via email to