diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 721db48b141..33ee63035b8 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -749,8 +749,22 @@ public class Main } else { - // Downloads performed - fileInitializers.add(new MavenLocalRepoFileInitializer()); + // Downloads are allowed to be performed + + // Setup Maven Local Repo + Path localRepoDir = args.getMavenLocalRepoDir(); + if (localRepoDir != null) + { + // Use provided local repo directory + fileInitializers.add(new MavenLocalRepoFileInitializer(localRepoDir)); + } + else + { + // No no local repo directory (direct downloads) + fileInitializers.add(new MavenLocalRepoFileInitializer()); + } + + // Normal URL downloads fileInitializers.add(new UriFileInitializer()); } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 2077f2d6776..41ac0e7ad98 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -23,6 +23,7 @@ import static org.eclipse.jetty.start.UsageException.*; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; @@ -555,6 +556,46 @@ public class StartArgs return System.getProperty("main.class",mainclass); } + public Path getMavenLocalRepoDir() + { + // Try property first + String localRepo = getProperties().getString("maven.local.repo"); + + if (Utils.isBlank(localRepo)) + { + // Try jetty specific env variable + localRepo = System.getenv("JETTY_MAVEN_LOCAL_REPO"); + } + + if (Utils.isBlank(localRepo)) + { + // Try generic env variable + localRepo = System.getenv("MAVEN_LOCAL_REPO"); + } + + // TODO: load & use $HOME/.m2/settings.xml ? + // TODO: possibly use Eclipse Aether to manage it ? + // TODO: see https://bugs.eclipse.org/bugs/show_bug.cgi?id=449511 + + // Still blank? then its not specified + if (Utils.isBlank(localRepo)) + { + return null; + } + + Path localRepoDir = new File(localRepo).toPath(); + localRepoDir = localRepoDir.normalize().toAbsolutePath(); + if (Files.exists(localRepoDir) && Files.isDirectory(localRepoDir)) + { + return localRepoDir; + } + + StartLog.warn("Not a valid maven local repository directory: %s",localRepoDir); + + // Not a valid repository directory, skip it + return null; + } + public String getModuleGraphFilename() { return moduleGraphFilename; @@ -1050,5 +1091,4 @@ public class StartArgs builder.append("]"); return builder.toString(); } - } diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/fileinits/MavenLocalRepoFileInitializer.java b/jetty-start/src/main/java/org/eclipse/jetty/start/fileinits/MavenLocalRepoFileInitializer.java index 6aca80597e3..f48b3777fd6 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/fileinits/MavenLocalRepoFileInitializer.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/fileinits/MavenLocalRepoFileInitializer.java @@ -112,6 +112,7 @@ public class MavenLocalRepoFileInitializer extends UriFileInitializer implements // Grab copy from local repository (download if needed to local // repository) Path localRepoFile = getLocalRepoFile(coords); + StartLog.log("COPY","%s to %s",localRepoFile,file); Files.copy(localRepoFile,file); } else