@@ -168,7 +168,11 @@ public CacheControllerImpl(
168168 @ Override
169169 @ Nonnull
170170 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 ) {
172176 final String highestPhase = lifecyclePhasesHelper .resolveHighestLifecyclePhase (project , mojoExecutions );
173177
174178 if (!lifecyclePhasesHelper .isLaterPhaseThanClean (highestPhase )) {
@@ -177,30 +181,33 @@ public CacheResult findCachedBuild(
177181
178182 String projectName = getVersionlessProjectKey (project );
179183
180- ProjectsInputInfo inputInfo = projectInputCalculator .calculateInput (project );
184+ ProjectsInputInfo inputInfo = projectInputCalculator .calculateInput (project , inputZone );
181185
182186 final CacheContext context = new CacheContext (project , inputInfo , session );
183187
184- CacheResult result = empty (context );
188+ CacheResult result = empty (context , inputZone );
185189 if (!skipCache ) {
186190
187- LOGGER .info ("Attempting to restore project {} from build cache" , projectName );
191+ LOGGER .info ("Attempting to restore project {} from build cache zone {} " , projectName , inputZone );
188192
189193 // remote build first
190194 if (cacheConfig .isRemoteCacheEnabled ()) {
191- result = findCachedBuild (mojoExecutions , context );
195+ result = findCachedBuild (mojoExecutions , context , inputZone );
192196 if (!result .isSuccess () && result .getContext () != null ) {
193197 LOGGER .info ("Remote cache is incomplete or missing, trying local build for {}" , projectName );
194198 }
195199 }
196200
197201 if (!result .isSuccess () && result .getContext () != null ) {
198- CacheResult localBuild = findLocalBuild (mojoExecutions , context );
202+ CacheResult localBuild = findLocalBuild (mojoExecutions , context , inputZone );
199203 if (localBuild .isSuccess () || (localBuild .isPartialSuccess () && !result .isPartialSuccess ())) {
200204 result = localBuild ;
201205 } else {
202206 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 );
204211 }
205212 }
206213 } else {
@@ -212,39 +219,43 @@ public CacheResult findCachedBuild(
212219 return result ;
213220 }
214221
215- private CacheResult findCachedBuild (List <MojoExecution > mojoExecutions , CacheContext context ) {
222+ private CacheResult findCachedBuild (List <MojoExecution > mojoExecutions , CacheContext context , Zone inputZone ) {
216223 Optional <Build > cachedBuild = Optional .empty ();
217224 try {
218- cachedBuild = localCache .findBuild (context );
225+ cachedBuild = localCache .findBuild (context , inputZone );
219226 if (cachedBuild .isPresent ()) {
220- return analyzeResult (context , mojoExecutions , cachedBuild .get ());
227+ return analyzeResult (context , mojoExecutions , inputZone , cachedBuild .get ());
221228 }
222229 } catch (Exception e ) {
223230 LOGGER .error ("Cannot read cached remote build" , e );
224231 }
225- return cachedBuild .map (build -> failure (build , context )).orElseGet (() -> empty (context ));
232+ return cachedBuild .map (build -> failure (build , context , inputZone )).orElseGet (() -> empty (context , inputZone ));
226233 }
227234
228- private CacheResult findLocalBuild (List <MojoExecution > mojoExecutions , CacheContext context ) {
235+ private CacheResult findLocalBuild (List <MojoExecution > mojoExecutions , CacheContext context , Zone inputZone ) {
229236 Optional <Build > localBuild = Optional .empty ();
230237 try {
231- localBuild = localCache .findLocalBuild (context );
238+ localBuild = localCache .findLocalBuild (context , inputZone );
232239 if (localBuild .isPresent ()) {
233- return analyzeResult (context , mojoExecutions , localBuild .get ());
240+ return analyzeResult (context , mojoExecutions , inputZone , localBuild .get ());
234241 }
235242 } catch (Exception e ) {
236243 LOGGER .error ("Cannot read local build" , e );
237244 }
238- return localBuild .map (build -> failure (build , context )).orElseGet (() -> empty (context ));
245+ return localBuild .map (build -> failure (build , context , inputZone )).orElseGet (() -> empty (context , inputZone ));
239246 }
240247
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 ) {
242250 try {
243251 final ProjectsInputInfo inputInfo = context .getInputInfo ();
244252 String projectName = getVersionlessProjectKey (context .getProject ());
245253
246254 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 ());
248259 LOGGER .debug ("Cached build details: {}" , build );
249260
250261 final String cacheImplementationVersion = build .getCacheImplementationVersion ();
@@ -263,12 +274,12 @@ private CacheResult analyzeResult(CacheContext context, List<MojoExecution> mojo
263274 "Cached build doesn't contains all requested plugin executions "
264275 + "(missing: {}), cannot restore" ,
265276 missingMojos );
266- return failure (build , context );
277+ return failure (build , context , inputZone );
267278 }
268279
269280 if (!isCachedSegmentPropertiesPresent (context .getProject (), build , cachedSegment )) {
270281 LOGGER .info ("Cached build violates cache rules, cannot restore" );
271- return failure (build , context );
282+ return failure (build , context , inputZone );
272283 }
273284
274285 final String highestRequestPhase =
@@ -281,15 +292,15 @@ private CacheResult analyzeResult(CacheContext context, List<MojoExecution> mojo
281292 projectName ,
282293 build .getHighestCompletedGoal (),
283294 highestRequestPhase );
284- return partialSuccess (build , context );
295+ return partialSuccess (build , context , inputZone );
285296 }
286297
287- return success (build , context );
298+ return success (build , context , inputZone );
288299
289300 } catch (Exception e ) {
290301 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 );
293304 }
294305 }
295306
@@ -389,8 +400,8 @@ public ArtifactRestorationReport restoreProjectArtifacts(CacheResult cacheResult
389400 // Set this value before trying the restoration, to keep a trace of the attempt if it fails
390401 restorationReport .setRestoredFilesInProjectDirectory (true );
391402 // 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 );
394405 restoreGeneratedSources (attachedArtifactInfo , attachedArtifactFile , project );
395406 }
396407 } else {
@@ -462,7 +473,8 @@ private Future<File> createDownloadTask(
462473 String originalVersion ) {
463474 final FutureTask <File > downloadTask = new FutureTask <>(() -> {
464475 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 );
466478
467479 if (!Files .exists (artifactFile )) {
468480 throw new FileNotFoundException ("Missing file for cached build, cannot restore. File: " + artifactFile );
@@ -482,7 +494,8 @@ private Future<File> createDownloadTask(
482494 public void save (
483495 CacheResult cacheResult ,
484496 List <MojoExecution > mojoExecutions ,
485- Map <String , MojoExecutionEvent > executionEvents ) {
497+ Map <String , MojoExecutionEvent > executionEvents ,
498+ Zone outputZone ) {
486499 CacheContext context = cacheResult .getContext ();
487500
488501 if (context == null || context .getInputInfo () == null ) {
@@ -526,19 +539,19 @@ public void save(
526539 build .getDto ().set_final (cacheConfig .isSaveToRemoteFinal ());
527540 cacheResults .put (getVersionlessProjectKey (project ), rebuilded (cacheResult , build ));
528541
529- localCache .beforeSave (context );
542+ localCache .beforeSave (context , outputZone );
530543
531544 // if package phase presence means new artifacts were packaged
532545 if (project .hasLifecyclePhase ("package" )) {
533546 if (projectArtifact .getFile () != null ) {
534- localCache .saveArtifactFile (cacheResult , projectArtifact );
547+ localCache .saveArtifactFile (cacheResult , outputZone , projectArtifact );
535548 }
536549 for (org .apache .maven .artifact .Artifact attachedArtifact : attachedArtifacts ) {
537550 if (attachedArtifact .getFile () != null ) {
538551 boolean storeArtifact =
539552 isOutputArtifact (attachedArtifact .getFile ().getName ());
540553 if (storeArtifact ) {
541- localCache .saveArtifactFile (cacheResult , attachedArtifact );
554+ localCache .saveArtifactFile (cacheResult , outputZone , attachedArtifact );
542555 } else {
543556 LOGGER .debug (
544557 "Skipping attached project artifact '{}' = "
@@ -549,7 +562,7 @@ public void save(
549562 }
550563 }
551564
552- localCache .saveBuildInfo (cacheResult , build );
565+ localCache .saveBuildInfo (cacheResult , outputZone , build );
553566
554567 if (cacheConfig .isBaselineDiffEnabled ()) {
555568 produceDiffReport (cacheResult , build );
@@ -558,7 +571,7 @@ public void save(
558571 } catch (Exception e ) {
559572 LOGGER .error ("Failed to save project, cleaning cache. Project: {}" , project , e );
560573 try {
561- localCache .clearCache (context );
574+ localCache .clearCache (context , outputZone );
562575 } catch (Exception ex ) {
563576 LOGGER .error ("Failed to clean cache due to unexpected error:" , ex );
564577 }
@@ -567,7 +580,7 @@ public void save(
567580
568581 public void produceDiffReport (CacheResult cacheResult , Build build ) {
569582 MavenProject project = cacheResult .getContext ().getProject ();
570- Optional <Build > baselineHolder = remoteCache .findBaselineBuild (project );
583+ Optional <Build > baselineHolder = remoteCache .findBaselineBuild (project , cacheResult . getInputZone () );
571584 if (baselineHolder .isPresent ()) {
572585 Build baseline = baselineHolder .get ();
573586 String outputDirectory = project .getBuild ().getDirectory ();
@@ -841,10 +854,10 @@ public void saveCacheReport(MavenSession session) {
841854 projectReport .setLifecycleMatched (checksumMatched && result .isSuccess ());
842855 projectReport .setSource (String .valueOf (result .getSource ()));
843856 if (result .getSource () == CacheSource .REMOTE ) {
844- projectReport .setUrl (remoteCache .getResourceUrl (context , BUILDINFO_XML ));
857+ projectReport .setUrl (remoteCache .getResourceUrl (context , result . getInputZone (), BUILDINFO_XML ));
845858 } else if (result .getSource () == CacheSource .BUILD && cacheConfig .isSaveToRemote ()) {
846859 projectReport .setSharedToRemote (true );
847- projectReport .setUrl (remoteCache .getResourceUrl (context , BUILDINFO_XML ));
860+ projectReport .setUrl (remoteCache .getResourceUrl (context , result . getInputZone (), BUILDINFO_XML ));
848861 }
849862 cacheReport .addProject (projectReport );
850863 }
0 commit comments