5151import java .util .concurrent .Future ;
5252import java .util .concurrent .FutureTask ;
5353import java .util .concurrent .atomic .AtomicBoolean ;
54- import java .util .function .Consumer ;
54+ import java .util .function .Function ;
5555import java .util .regex .Pattern ;
5656
57- import org .apache .commons .io .FileUtils ;
5857import org .apache .commons .io .FilenameUtils ;
5958import org .apache .commons .lang3 .StringUtils ;
6059import org .apache .commons .lang3 .mutable .MutableBoolean ;
@@ -306,14 +305,15 @@ private boolean canIgnoreMissingSegment(MavenProject project, Build info, List<M
306305 return true ;
307306 }
308307
309- private Consumer <File > createRestorationToDiskConsumer (final MavenProject project , final Artifact artifact ) {
308+ private Function <File , File > createRestorationToDiskConsumer (final MavenProject project , final Artifact artifact ) {
309+
310310 if (cacheConfig .isRestoreOnDiskArtifacts () && MavenProjectInput .isRestoreOnDiskArtifacts (project )) {
311311
312+ Path restorationPath = project .getBasedir ().toPath ().resolve (artifact .getFilePath ());
312313 final AtomicBoolean restored = new AtomicBoolean (false );
313314 return file -> {
314315 // Set to restored even if it fails later, we don't want multiple try
315316 if (restored .compareAndSet (false , true )) {
316- Path restorationPath = project .getBasedir ().toPath ().resolve (artifact .getFilePath ());
317317 verifyRestorationInsideProject (project , restorationPath );
318318 try {
319319 Files .createDirectories (restorationPath .getParent ());
@@ -324,10 +324,11 @@ private Consumer<File> createRestorationToDiskConsumer(final MavenProject projec
324324 }
325325 LOGGER .debug ("Restored file on disk ({} to {})" , artifact .getFileName (), restorationPath );
326326 }
327+ return restorationPath .toFile ();
327328 };
328329 }
329330 // Return a consumer doing nothing
330- return file -> {} ;
331+ return file -> file ;
331332 }
332333
333334 private boolean isPathInsideProject (final MavenProject project , Path path ) {
@@ -434,7 +435,7 @@ private RestoredArtifact restoredArtifact(
434435 String artifactType ,
435436 String artifactClassifier ,
436437 Future <File > artifactFile ,
437- Consumer < File > restoreToDiskConsumer ) {
438+ Function < File , File > restoreToDiskConsumer ) {
438439 ArtifactHandler handler = null ;
439440
440441 if (artifactType != null ) {
@@ -462,24 +463,14 @@ private Future<File> createDownloadTask(
462463 final FutureTask <File > downloadTask = new FutureTask <>(() -> {
463464 LOGGER .debug ("Downloading artifact {}" , artifact .getArtifactId ());
464465 final Path artifactFile = localCache .getArtifactFile (context , cacheResult .getSource (), artifact );
465- final Path targetDir = Paths .get (project .getBuild ().getDirectory ());
466- final Path targetArtifact = targetDir .resolve (project .getBuild ().getFinalName ()
467- + (artifact .getClassifier () != null ? "-" .concat (artifact .getClassifier ()) : "" )
468- + "." .concat (FilenameUtils .getExtension (artifact .getFileName ())));
469466
470467 if (!Files .exists (artifactFile )) {
471468 throw new FileNotFoundException ("Missing file for cached build, cannot restore. File: " + artifactFile );
472469 }
473470 LOGGER .debug ("Downloaded artifact " + artifact .getArtifactId () + " to: " + artifactFile );
474-
475- File downloadFile = restoreArtifactHandler
471+ return restoreArtifactHandler
476472 .adjustArchiveArtifactVersion (project , originalVersion , artifactFile )
477473 .toFile ();
478- // Need to restore artifact to project build directory, so it can be saved into cached incremental build
479- FileUtils .copyFile (downloadFile , targetArtifact .toFile ());
480- LOGGER .debug ("Restored artifact " + artifact .getArtifactId () + " to: " + targetArtifact );
481-
482- return targetArtifact .toFile ();
483474 });
484475 if (!cacheConfig .isLazyRestore ()) {
485476 downloadTask .run ();
0 commit comments