@@ -168,7 +168,11 @@ public CacheControllerImpl(
168
168
@ Override
169
169
@ Nonnull
170
170
public CacheResult findCachedBuild (
171
- MavenSession session , MavenProject project , List <MojoExecution > mojoExecutions , boolean skipCache ) {
171
+ MavenSession session ,
172
+ MavenProject project ,
173
+ List <MojoExecution > mojoExecutions ,
174
+ Zone inputZone ,
175
+ boolean skipCache ) {
172
176
final String highestPhase = lifecyclePhasesHelper .resolveHighestLifecyclePhase (project , mojoExecutions );
173
177
174
178
if (!lifecyclePhasesHelper .isLaterPhaseThanClean (highestPhase )) {
@@ -177,30 +181,33 @@ public CacheResult findCachedBuild(
177
181
178
182
String projectName = getVersionlessProjectKey (project );
179
183
180
- ProjectsInputInfo inputInfo = projectInputCalculator .calculateInput (project );
184
+ ProjectsInputInfo inputInfo = projectInputCalculator .calculateInput (project , inputZone );
181
185
182
186
final CacheContext context = new CacheContext (project , inputInfo , session );
183
187
184
- CacheResult result = empty (context );
188
+ CacheResult result = empty (context , inputZone );
185
189
if (!skipCache ) {
186
190
187
- LOGGER .info ("Attempting to restore project {} from build cache" , projectName );
191
+ LOGGER .info ("Attempting to restore project {} from build cache zone {} " , projectName , inputZone );
188
192
189
193
// remote build first
190
194
if (cacheConfig .isRemoteCacheEnabled ()) {
191
- result = findCachedBuild (mojoExecutions , context );
195
+ result = findCachedBuild (mojoExecutions , context , inputZone );
192
196
if (!result .isSuccess () && result .getContext () != null ) {
193
197
LOGGER .info ("Remote cache is incomplete or missing, trying local build for {}" , projectName );
194
198
}
195
199
}
196
200
197
201
if (!result .isSuccess () && result .getContext () != null ) {
198
- CacheResult localBuild = findLocalBuild (mojoExecutions , context );
202
+ CacheResult localBuild = findLocalBuild (mojoExecutions , context , inputZone );
199
203
if (localBuild .isSuccess () || (localBuild .isPartialSuccess () && !result .isPartialSuccess ())) {
200
204
result = localBuild ;
201
205
} else {
202
206
LOGGER .info (
203
- "Local build was not found by checksum {} for {}" , inputInfo .getChecksum (), projectName );
207
+ "Local build was not found by checksum {} for {} and zone {}" ,
208
+ inputInfo .getChecksum (),
209
+ projectName ,
210
+ inputZone );
204
211
}
205
212
}
206
213
} else {
@@ -212,39 +219,43 @@ public CacheResult findCachedBuild(
212
219
return result ;
213
220
}
214
221
215
- private CacheResult findCachedBuild (List <MojoExecution > mojoExecutions , CacheContext context ) {
222
+ private CacheResult findCachedBuild (List <MojoExecution > mojoExecutions , CacheContext context , Zone inputZone ) {
216
223
Optional <Build > cachedBuild = Optional .empty ();
217
224
try {
218
- cachedBuild = localCache .findBuild (context );
225
+ cachedBuild = localCache .findBuild (context , inputZone );
219
226
if (cachedBuild .isPresent ()) {
220
- return analyzeResult (context , mojoExecutions , cachedBuild .get ());
227
+ return analyzeResult (context , mojoExecutions , inputZone , cachedBuild .get ());
221
228
}
222
229
} catch (Exception e ) {
223
230
LOGGER .error ("Cannot read cached remote build" , e );
224
231
}
225
- return cachedBuild .map (build -> failure (build , context )).orElseGet (() -> empty (context ));
232
+ return cachedBuild .map (build -> failure (build , context , inputZone )).orElseGet (() -> empty (context , inputZone ));
226
233
}
227
234
228
- private CacheResult findLocalBuild (List <MojoExecution > mojoExecutions , CacheContext context ) {
235
+ private CacheResult findLocalBuild (List <MojoExecution > mojoExecutions , CacheContext context , Zone inputZone ) {
229
236
Optional <Build > localBuild = Optional .empty ();
230
237
try {
231
- localBuild = localCache .findLocalBuild (context );
238
+ localBuild = localCache .findLocalBuild (context , inputZone );
232
239
if (localBuild .isPresent ()) {
233
- return analyzeResult (context , mojoExecutions , localBuild .get ());
240
+ return analyzeResult (context , mojoExecutions , inputZone , localBuild .get ());
234
241
}
235
242
} catch (Exception e ) {
236
243
LOGGER .error ("Cannot read local build" , e );
237
244
}
238
- return localBuild .map (build -> failure (build , context )).orElseGet (() -> empty (context ));
245
+ return localBuild .map (build -> failure (build , context , inputZone )).orElseGet (() -> empty (context , inputZone ));
239
246
}
240
247
241
- private CacheResult analyzeResult (CacheContext context , List <MojoExecution > mojoExecutions , Build build ) {
248
+ private CacheResult analyzeResult (
249
+ CacheContext context , List <MojoExecution > mojoExecutions , Zone inputZone , Build build ) {
242
250
try {
243
251
final ProjectsInputInfo inputInfo = context .getInputInfo ();
244
252
String projectName = getVersionlessProjectKey (context .getProject ());
245
253
246
254
LOGGER .info (
247
- "Found cached build, restoring {} from cache by checksum {}" , projectName , inputInfo .getChecksum ());
255
+ "Found cached build, restoring {} from cache zone {} by checksum {}" ,
256
+ projectName ,
257
+ inputZone ,
258
+ inputInfo .getChecksum ());
248
259
LOGGER .debug ("Cached build details: {}" , build );
249
260
250
261
final String cacheImplementationVersion = build .getCacheImplementationVersion ();
@@ -263,12 +274,12 @@ private CacheResult analyzeResult(CacheContext context, List<MojoExecution> mojo
263
274
"Cached build doesn't contains all requested plugin executions "
264
275
+ "(missing: {}), cannot restore" ,
265
276
missingMojos );
266
- return failure (build , context );
277
+ return failure (build , context , inputZone );
267
278
}
268
279
269
280
if (!isCachedSegmentPropertiesPresent (context .getProject (), build , cachedSegment )) {
270
281
LOGGER .info ("Cached build violates cache rules, cannot restore" );
271
- return failure (build , context );
282
+ return failure (build , context , inputZone );
272
283
}
273
284
274
285
final String highestRequestPhase =
@@ -281,15 +292,15 @@ private CacheResult analyzeResult(CacheContext context, List<MojoExecution> mojo
281
292
projectName ,
282
293
build .getHighestCompletedGoal (),
283
294
highestRequestPhase );
284
- return partialSuccess (build , context );
295
+ return partialSuccess (build , context , inputZone );
285
296
}
286
297
287
- return success (build , context );
298
+ return success (build , context , inputZone );
288
299
289
300
} catch (Exception e ) {
290
301
LOGGER .error ("Failed to restore project" , e );
291
- localCache .clearCache (context );
292
- return failure (build , context );
302
+ localCache .clearCache (context , inputZone );
303
+ return failure (build , context , inputZone );
293
304
}
294
305
}
295
306
@@ -389,8 +400,8 @@ public ArtifactRestorationReport restoreProjectArtifacts(CacheResult cacheResult
389
400
// Set this value before trying the restoration, to keep a trace of the attempt if it fails
390
401
restorationReport .setRestoredFilesInProjectDirectory (true );
391
402
// generated sources artifact
392
- final Path attachedArtifactFile =
393
- localCache . getArtifactFile ( context , cacheResult .getSource (), attachedArtifactInfo );
403
+ final Path attachedArtifactFile = localCache . getArtifactFile (
404
+ context , cacheResult .getSource (), cacheResult . getInputZone (), attachedArtifactInfo );
394
405
restoreGeneratedSources (attachedArtifactInfo , attachedArtifactFile , project );
395
406
}
396
407
} else {
@@ -462,7 +473,8 @@ private Future<File> createDownloadTask(
462
473
String originalVersion ) {
463
474
final FutureTask <File > downloadTask = new FutureTask <>(() -> {
464
475
LOGGER .debug ("Downloading artifact {}" , artifact .getArtifactId ());
465
- final Path artifactFile = localCache .getArtifactFile (context , cacheResult .getSource (), artifact );
476
+ final Path artifactFile =
477
+ localCache .getArtifactFile (context , cacheResult .getSource (), cacheResult .getInputZone (), artifact );
466
478
467
479
if (!Files .exists (artifactFile )) {
468
480
throw new FileNotFoundException ("Missing file for cached build, cannot restore. File: " + artifactFile );
@@ -482,7 +494,8 @@ private Future<File> createDownloadTask(
482
494
public void save (
483
495
CacheResult cacheResult ,
484
496
List <MojoExecution > mojoExecutions ,
485
- Map <String , MojoExecutionEvent > executionEvents ) {
497
+ Map <String , MojoExecutionEvent > executionEvents ,
498
+ Zone outputZone ) {
486
499
CacheContext context = cacheResult .getContext ();
487
500
488
501
if (context == null || context .getInputInfo () == null ) {
@@ -526,19 +539,19 @@ public void save(
526
539
build .getDto ().set_final (cacheConfig .isSaveToRemoteFinal ());
527
540
cacheResults .put (getVersionlessProjectKey (project ), rebuilded (cacheResult , build ));
528
541
529
- localCache .beforeSave (context );
542
+ localCache .beforeSave (context , outputZone );
530
543
531
544
// if package phase presence means new artifacts were packaged
532
545
if (project .hasLifecyclePhase ("package" )) {
533
546
if (projectArtifact .getFile () != null ) {
534
- localCache .saveArtifactFile (cacheResult , projectArtifact );
547
+ localCache .saveArtifactFile (cacheResult , outputZone , projectArtifact );
535
548
}
536
549
for (org .apache .maven .artifact .Artifact attachedArtifact : attachedArtifacts ) {
537
550
if (attachedArtifact .getFile () != null ) {
538
551
boolean storeArtifact =
539
552
isOutputArtifact (attachedArtifact .getFile ().getName ());
540
553
if (storeArtifact ) {
541
- localCache .saveArtifactFile (cacheResult , attachedArtifact );
554
+ localCache .saveArtifactFile (cacheResult , outputZone , attachedArtifact );
542
555
} else {
543
556
LOGGER .debug (
544
557
"Skipping attached project artifact '{}' = "
@@ -549,7 +562,7 @@ public void save(
549
562
}
550
563
}
551
564
552
- localCache .saveBuildInfo (cacheResult , build );
565
+ localCache .saveBuildInfo (cacheResult , outputZone , build );
553
566
554
567
if (cacheConfig .isBaselineDiffEnabled ()) {
555
568
produceDiffReport (cacheResult , build );
@@ -558,7 +571,7 @@ public void save(
558
571
} catch (Exception e ) {
559
572
LOGGER .error ("Failed to save project, cleaning cache. Project: {}" , project , e );
560
573
try {
561
- localCache .clearCache (context );
574
+ localCache .clearCache (context , outputZone );
562
575
} catch (Exception ex ) {
563
576
LOGGER .error ("Failed to clean cache due to unexpected error:" , ex );
564
577
}
@@ -567,7 +580,7 @@ public void save(
567
580
568
581
public void produceDiffReport (CacheResult cacheResult , Build build ) {
569
582
MavenProject project = cacheResult .getContext ().getProject ();
570
- Optional <Build > baselineHolder = remoteCache .findBaselineBuild (project );
583
+ Optional <Build > baselineHolder = remoteCache .findBaselineBuild (project , cacheResult . getInputZone () );
571
584
if (baselineHolder .isPresent ()) {
572
585
Build baseline = baselineHolder .get ();
573
586
String outputDirectory = project .getBuild ().getDirectory ();
@@ -841,10 +854,10 @@ public void saveCacheReport(MavenSession session) {
841
854
projectReport .setLifecycleMatched (checksumMatched && result .isSuccess ());
842
855
projectReport .setSource (String .valueOf (result .getSource ()));
843
856
if (result .getSource () == CacheSource .REMOTE ) {
844
- projectReport .setUrl (remoteCache .getResourceUrl (context , BUILDINFO_XML ));
857
+ projectReport .setUrl (remoteCache .getResourceUrl (context , result . getInputZone (), BUILDINFO_XML ));
845
858
} else if (result .getSource () == CacheSource .BUILD && cacheConfig .isSaveToRemote ()) {
846
859
projectReport .setSharedToRemote (true );
847
- projectReport .setUrl (remoteCache .getResourceUrl (context , BUILDINFO_XML ));
860
+ projectReport .setUrl (remoteCache .getResourceUrl (context , result . getInputZone (), BUILDINFO_XML ));
848
861
}
849
862
cacheReport .addProject (projectReport );
850
863
}
0 commit comments