Commit 95705f4
committed
Fix integration test failures with staleness detection and directory artifact handling
Fixes all integration test failures by implementing staleness detection via
staging directory and complete directory artifact caching with explicit
schema-based detection.
Root Causes Fixed:
1. Staleness Issue: Clock skew and git branch switches create future timestamps,
causing wrong cache entries and orphaned class files
2. Directory Artifacts: Compile-only builds (mvn compile) create directory artifacts
(target/classes) instead of JAR files. Files.copy() fails on directories with
DirectoryNotEmptyException
3. hasUsefulArtifacts: Logic too aggressive, rejecting valid POM projects
4. Forked Executions: Interfered with parent execution's artifact management
Solution 1 - Staleness Detection via Staging Directory:
Instead of timestamp checking (which fails with clock skew), physically
separate stale artifacts by moving them to a staging directory.
Before mojos run: Move pre-existing artifacts to staging directory
- Maven sees clean target/ with no pre-existing artifacts
- Maven compiler MUST compile (can't skip based on timestamps)
- Fresh correct files created in target/
- save() only sees fresh files (stale ones in staging)
After save(): Restore artifacts from staging atomically (prevents TOCTOU race)
Scenarios Protected:
1. Future Timestamps from Clock Skew - Moved to staging, forcing recompilation
2. Orphaned Class Files (deleted sources) - Moved to staging, not cached
3. Stale JARs/WARs from previous builds - Moved to staging, fresh ones cached
Multimodule Support:
- Staging directory structure preserves paths relative to multimodule root
- Directory: target/maven-build-cache-extension/{module-path}/target/classes
Solution 2 - Directory Artifact Handling:
Save (CacheControllerImpl.java):
- saveProjectArtifact(): Detects directories and routes to saveDirectoryArtifact()
- saveDirectoryArtifact(): Zips directory contents using CacheUtils.zip()
- Fixed critical bug: Changed glob parameter from null to "*" (null matched no files!)
- Temporarily sets artifact file to zip for saving, then restores original reference
Restore (CacheControllerImpl.java):
- restoreArtifactToDisk(): Uses explicit isDirectory flag from buildinfo
- restoreDirectoryArtifact(): Unzips cached zip back to original directory
- restoreRegularFileArtifact(): Copies regular files as before
Schema Enhancement (build-cache-build.mdo):
- Added isDirectory boolean field to Artifact class
- Explicit flag replaces path-based heuristics for robust detection
- Backward compatible: Missing flag defaults to false (regular file)
Other Fixes:
- Forked Execution: Skip staging/restore (they have caching disabled)
- hasUsefulArtifacts: Allow POM projects with plugin executions
- artifactDto: Always set filePath for directories
- restoreRenamedArtifacts: Use atomic Files.move() to prevent race conditions
- Fixed state lifecycle bug where save() was removing ProjectCacheState
before restoreRenamedArtifacts() could restore files
Changes:
- CacheControllerImpl: Staging directory infrastructure + directory artifact handling
- BuildCacheMojosExecutionStrategy: Integrated staging with forked execution handling
- build-cache-build.mdo: Added isDirectory field to Artifact schema
- Added: GitCheckoutStaleArtifactTest for single-module validation
- Added: GitCheckoutStaleMultimoduleTest for multimodule validation
Tests Fixed:
1. MandatoryCleanTest: Forked execution fix
2. ForkedExecutionCoreExtensionTest: Forked execution fix
3. Issue67Test: Changed restoration error logging from ERROR to DEBUG
4. Issue74Test: hasUsefulArtifacts fix
5. DuplicateGoalsTest: hasUsefulArtifacts + directory artifact handling
6. CacheCompileDisabledTest: Complete directory artifact handling
7. Issue393CompileRestoreTest: Complete directory artifact handling
All tests passing: 74 unit tests + 26 integration tests1 parent 9e86503 commit 95705f4
File tree
13 files changed
+820
-51
lines changed- src
- main
- java/org/apache/maven/buildcache
- mdo
- test
- java/org/apache/maven/buildcache/its
- projects
- git-checkout-stale-artifact
- .mvn
- src/main/java/org/example
- git-checkout-stale-multimodule
- .mvn
- module1
- src/main/java/org/example
13 files changed
+820
-51
lines changedLines changed: 44 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| 142 | + | |
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
145 | 147 | | |
146 | 148 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
153 | 161 | | |
154 | 162 | | |
155 | | - | |
156 | 163 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
168 | 194 | | |
169 | 195 | | |
170 | 196 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
48 | 68 | | |
0 commit comments