| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The stale source scanner assumes every Java source produces a mapped output, causing zero-byte compilation units to trigger recompilation on every invocation. Filter zero-byte stale candidates only for one-output-per-input compilers and only when no mapped output exists. This preserves detection when an existing source is truncated and leaves aggregate-output compilers unchanged. Add a regression test that compiles an empty source twice and verifies that the second invocation is up to date. Fixes apache#1000.
There was a problem hiding this comment.
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Fixes incremental compilation change detection so that truly empty Java sources (0 bytes) don’t cause perpetual recompilation when no mapped output exists, while preserving detection for truncated sources that previously produced outputs.
Changes:
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java | Filters stale sources to avoid recompile loops for empty sources without mapped outputs. |
| src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java | Adds regression test ensuring second compilation is up-to-date for empty source. |
| src/test/resources/unit/compiler-empty-source-change-detection-test/plugin-config.xml | Provides test-specific compiler plugin configuration and directories. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| for (File source : includedSources) { | ||
| String relativePath = | ||
| rootFile.toPath().relativize(source.toPath()).toString(); | ||
| boolean outputExists = mapping.getTargetFiles(outputDirectory, relativePath).stream() | ||
| .anyMatch(File::exists); | ||
| // A zero-byte compilation unit legitimately produces no class. Keep it stale if an output | ||
| // exists, however, so that truncating an existing source is still detected as a change. | ||
| if (Files.size(source.toPath()) != 0 || outputExists) { | ||
| staleSources.add(source); | ||
| } | ||
| } |
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
| String relativePath = | ||
| rootFile.toPath().relativize(source.toPath()).toString(); | ||
| boolean outputExists = mapping.getTargetFiles(outputDirectory, relativePath).stream() |
There was a problem hiding this comment.
The string is passed to the getTargetFiles method which uses it to construct File instance. OS specific separators are appropriate.
Sorry, something went wrong.
There was a problem hiding this comment.
While java.io.File (and Java's NIO layer on Windows) can parse backslashes, Maven plugins like maven-war-plugin or maven-ear-plugin do not just write files to disk—they map them into archives (ZIP, JAR, WAR, EAR).
The finding is valid; relying on Path#toString() for target mappings in archive-building plugins frequently causes Windows-specific regressions.
Sorry, something went wrong.
There was a problem hiding this comment.
While java.io.File (and Java's NIO layer on Windows) can parse backslashes, Maven plugins like maven-war-plugin or maven-ear-plugin do not just write files to disk—they map them into archives (ZIP, JAR, WAR, EAR).
1. **Archive Entry Standards:** ZIP and JAR specifications mandate that entry names use forward slashes (`/`) as path separators, regardless of the host operating system. 2. **Map/Cache Lookups:** If target paths are stored as keys in a `Map` or `Set` (e.g., to track packaged or copied files, check for staleness, or prevent duplicates), a path string containing `\` on Windows will not match an entry lookup using `/`. This leads to cross-platform bugs where builds behave differently on Windows versus Unix. 3. **Java's `File` Flexibility:** Ironically, Java's `File` constructor on Windows accepts forward slashes (`/`) natively and normalizes them internally. Therefore, forcing platform-specific separators via `Path#toString()` introduces risks for map keys and archive matching without providing any functional benefit to the `File` constructor itself.The finding is valid; relying on Path#toString() for target mappings in archive-building plugins frequently causes Windows-specific regressions.
I am sorry, but this is irrelevant in the face of what the org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping implementations actually do. The AI is wrong.
Sorry, something went wrong.
| <compileSourceRoot>${basedir}/target/test-classes/unit/compiler-empty-source-change-detection-test/src/main/java</compileSourceRoot> | ||
| </compileSourceRoots> | ||
| <compilerId>javac</compilerId> | ||
| <release>17</release> |
There was a problem hiding this comment.
Fixed.
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (4)src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java:132
Log log = mock(Log.class);
compilerMojo.setLog(log);
compilerMojo.execute();
src/test/java/org/apache/maven/plugin/compiler/CompilerMojoTest.java:136
verify(log).info("Nothing to compile - all classes are up to date.");
src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java:1569
for (File source : includedSources) {
if (Files.size(source.toPath()) != 0) {
staleSources.add(source);
} else {
src/test/resources/unit/compiler-empty-source-change-detection-test/plugin-config.xml:24
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The stale source scanner assumes every Java source produces a mapped output, causing zero-byte compilation units to trigger recompilation on every invocation.
This change filters zero-byte stale candidates only for one-output-per-input compilers and only when no mapped output exists. This preserves detection when an existing source is truncated while leaving aggregate-output compilers unchanged.
A regression test compiles an empty source twice and verifies that the second invocation reports all classes as up to date.
Fixes #1000.
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
A more thorough check will be performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.