Commit 7681019
committed
Fix integration test failures and implement staleness detection
This commit fixes test failures and implements staleness detection via
staging directory to prevent caching artifacts with future timestamps
due to clock skew or orphaned files from git branch switches.
Root Causes Fixed:
1. Issue74Test/DuplicateGoalsTest: hasUsefulArtifacts logic too aggressive
2. Compile-only builds: NullPointerException during artifact restoration
3. Clock skew vulnerability: Future timestamps cause wrong cache entries
Staleness Detection Solution - 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
- Fixed state lifecycle bug where save() was removing ProjectCacheState
before restoreRenamedArtifacts() could restore files
- Updated method signatures to accept MavenSession for multimodule root resolution
Changes:
- CacheControllerImpl: Staging directory infrastructure with atomic restore
- BuildCacheMojosExecutionStrategy: Integrated move before mojos, restore after save
- hasUsefulArtifacts: Allow POM projects with plugin executions
- artifactDto: Always set filePath for directories
- restoreRenamedArtifacts: Use atomic Files.move() to prevent race conditions
- Added: GitCheckoutStaleArtifactTest for single-module validation
- Added: GitCheckoutStaleMultimoduleTest for multimodule validation
All 74 unit tests pass.1 parent 9e86503 commit 7681019
File tree
14 files changed
+729
-48
lines changed- src
- main/java/org/apache/maven/buildcache
- 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
14 files changed
+729
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
Lines changed: 41 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 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
153 | 168 | | |
154 | 169 | | |
155 | | - | |
156 | 170 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
168 | 190 | | |
169 | 191 | | |
170 | 192 | | |
| |||
244 | 266 | | |
245 | 267 | | |
246 | 268 | | |
| 269 | + | |
247 | 270 | | |
248 | 271 | | |
249 | 272 | | |
| |||
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