As identified on
I think it boils down to the question if getCompileClasspathElements() returns the classes compiled fom generated sources as well, which could depend on a number of different factors depending on how the code generation is configured.
|
logInfo(mavenProject, "Parsing source files"); |
|
List<Path> dependencies = mavenProject.getCompileClasspathElements().stream() |
|
.distinct() |
|
.map(Paths::get) |
|
.collect(toList()); |
|
JavaTypeCache typeCache = new JavaTypeCache(); |
|
javaParserBuilder.classpath(dependencies).typeCache(typeCache); |
|
kotlinParserBuilder.classpath(dependencies).typeCache(new JavaTypeCache()); |
Right now we define generated sources as anything we find in the target/ directory, and parse those as source.
|
// Some annotation processors output generated sources to the /target directory. These are added for parsing but |
|
// should be filtered out of the final SourceFile list. |
|
List<Path> generatedSourcePaths = listJavaSources(mavenProject.getBasedir().toPath().resolve(mavenProject.getBuild().getDirectory())); |
|
List<Path> mainJavaSources = Stream.concat( |
|
generatedSourcePaths.stream(), |
|
listJavaSources(mavenProject.getBasedir().toPath().resolve(mavenProject.getBuild().getSourceDirectory())).stream() |
|
).collect(toList()); |
Before we then later filter out those generated sources.
|
//Filter out any generated source files from the returned list, as we do not want to apply the recipe to the |
|
//generated files. |
|
Path buildDirectory = baseDir.relativize(Paths.get(mavenProject.getBuild().getDirectory())); |
|
Stream<SourceFile> sourceFiles = Stream.concat(parsedJava, parsedKotlin) |
|
.filter(s -> !s.getSourcePath().startsWith(buildDirectory)) |
|
.map(addProvenance(baseDir, mainProjectProvenance, generatedSourcePaths)); |
It might be interesting to not parse those generated sources as source files but rather only as classpath entries. I'm not entirely sure that would work in all cases, but it could speed up builds for projects that heavily use generated sources.
As identified on
I think it boils down to the question if
getCompileClasspathElements()returns the classes compiled fom generated sources as well, which could depend on a number of different factors depending on how the code generation is configured.rewrite-maven-plugin/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java
Lines 317 to 324 in 0b8fc33
Right now we define generated sources as anything we find in the
target/directory, and parse those as source.rewrite-maven-plugin/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java
Lines 302 to 308 in 0b8fc33
Before we then later filter out those generated sources.
rewrite-maven-plugin/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java
Lines 341 to 346 in 9a9428f
It might be interesting to not parse those generated sources as source files but rather only as classpath entries. I'm not entirely sure that would work in all cases, but it could speed up builds for projects that heavily use generated sources.