Skip to content

Commit d44d1be

Browse files
mensindaslawekjaranowski
authored andcommitted
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.
1 parent 0b8b00b commit d44d1be

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/it/setup_annotation-verify-plugin/src/main/java/org.apache.maven.plugins.compiler.it/SourcePathReadGoal.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,12 @@ public class SourcePathReadGoal extends AbstractMojo {
4747
public void execute() throws MojoExecutionException, MojoFailureException {
4848
if (sourceClass != null) {
4949
getLog().info("Checking compile source roots for: '" + sourceClass + "'");
50-
List<String> roots = project.getCompileSourceRoots();
51-
roots.add(project.getModel().getBuild().getOutputDirectory() + "/../generated-sources/annotations");
52-
assertGeneratedSourceFileFor(sourceClass, roots);
50+
assertGeneratedSourceFileFor(sourceClass, project.getCompileSourceRoots());
5351
}
5452

5553
if (testSourceClass != null) {
5654
getLog().info("Checking test-compile source roots for: '" + testSourceClass + "'");
57-
List<String> roots = project.getTestCompileSourceRoots();
58-
roots.add(
59-
project.getModel().getBuild().getOutputDirectory() + "/../generated-test-sources/test-annotations");
60-
assertGeneratedSourceFileFor(testSourceClass, roots);
55+
assertGeneratedSourceFileFor(testSourceClass, project.getTestCompileSourceRoots());
6156
}
6257
}
6358

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,39 @@ protected final Optional<Path> getModuleDeclaration(final Set<File> sourceFiles)
703703
private boolean targetOrReleaseSet;
704704

705705
@Override
706-
@SuppressWarnings("checkstyle:MethodLength")
707706
public void execute() throws MojoExecutionException, CompilationFailureException {
707+
try {
708+
executeReal();
709+
} finally {
710+
addGeneratedSourcesToProject();
711+
}
712+
}
713+
714+
private void addGeneratedSourcesToProject() {
715+
File generatedSourcesDirectory = getGeneratedSourcesDirectory();
716+
if (generatedSourcesDirectory == null) {
717+
return;
718+
}
719+
720+
String generatedSourcesPath = generatedSourcesDirectory.getAbsolutePath();
721+
722+
if (isTestCompile()) {
723+
getLog().debug("Adding " + generatedSourcesPath
724+
+ " to the project test-compile source roots but NOT the actual test-compile source roots:\n "
725+
+ StringUtils.join(project.getTestCompileSourceRoots().iterator(), "\n "));
726+
727+
project.addTestCompileSourceRoot(generatedSourcesPath);
728+
} else {
729+
getLog().debug("Adding " + generatedSourcesPath
730+
+ " to the project compile source roots but NOT the actual compile source roots:\n "
731+
+ StringUtils.join(project.getCompileSourceRoots().iterator(), "\n "));
732+
733+
project.addCompileSourceRoot(generatedSourcesPath);
734+
}
735+
}
736+
737+
@SuppressWarnings("checkstyle:MethodLength")
738+
private void executeReal() throws MojoExecutionException, CompilationFailureException {
708739
// ----------------------------------------------------------------------
709740
// Look up the compiler. This is done before other code than can
710741
// cause the mojo to return before the lookup is done possibly resulting

0 commit comments

Comments
 (0)