3232import java .nio .file .Paths ;
3333import java .util .Collection ;
3434import java .util .LinkedHashSet ;
35+ import java .util .Map ;
3536import java .util .Set ;
3637import java .util .logging .Logger ;
3738import org .apache .maven .model .Model ;
@@ -53,17 +54,20 @@ public class Downloader {
5354 private final Set <URI > repos ;
5455 private final boolean cacheDownloads ;
5556 private final HttpDownloader httpDownloader ;
57+ private final Map <Coordinates , Path > knownPaths ;
5658
5759 public Downloader (
5860 Netrc netrc ,
5961 Path localRepository ,
6062 Collection <URI > repositories ,
6163 EventListener listener ,
62- boolean cacheDownloads ) {
64+ boolean cacheDownloads ,
65+ Map <Coordinates , Path > knownPaths ) {
6366 this .localRepository = localRepository ;
6467 this .repos = Set .copyOf (repositories );
6568 this .cacheDownloads = cacheDownloads ;
6669 this .httpDownloader = new HttpDownloader (netrc , listener );
70+ this .knownPaths = knownPaths != null ? Map .copyOf (knownPaths ) : Map .of ();
6771 }
6872
6973 public DownloadResult download (Coordinates coords ) {
@@ -119,11 +123,16 @@ private DownloadResult performDownload(Coordinates coordsToUse, String path) {
119123 Set <URI > repos = new LinkedHashSet <>();
120124
121125 Path pathInRepo = null ;
122-
123- // Check the local cache for the path first
124- Path cachedResult = localRepository .resolve (path );
125- if (Files .exists (cachedResult )) {
126- pathInRepo = cachedResult ;
126+ Path knownPath = knownPaths .get (coordsToUse );
127+
128+ if (knownPath != null && Files .exists (knownPath )) {
129+ pathInRepo = knownPath ;
130+ } else {
131+ // Check the local cache for the path first
132+ Path cachedResult = localRepository .resolve (path );
133+ if (Files .exists (cachedResult )) {
134+ pathInRepo = cachedResult ;
135+ }
127136 }
128137
129138 String rjeAssumePresent = System .getenv ("RJE_ASSUME_PRESENT" );
@@ -141,6 +150,7 @@ private DownloadResult performDownload(Coordinates coordsToUse, String path) {
141150 repos .add (repo );
142151 downloaded = true ;
143152
153+ Path cachedResult = localRepository .resolve (path );
144154 if (cacheDownloads && !cachedResult .equals (pathInRepo )) {
145155 try {
146156 Files .createDirectories (cachedResult .getParent ());
@@ -150,10 +160,10 @@ private DownloadResult performDownload(Coordinates coordsToUse, String path) {
150160 }
151161 }
152162 }
153- } else if (assumedDownloaded ) { // path is set
163+ } else if (assumedDownloaded ) {
154164 LOG .fine (String .format ("Assuming %s is cached%n" , coordsToUse ));
155165 downloaded = true ;
156- } else if (httpDownloader .head (buildUri (repo , path ))) { // path is set
166+ } else if (httpDownloader .head (buildUri (repo , path ))) {
157167 LOG .fine (String .format ("Checking head of %s%n" , coordsToUse ));
158168 repos .add (repo );
159169 downloaded = true ;
0 commit comments