From dc02031081713452112c3112171404b3b654882e Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Sat, 27 Feb 2016 14:17:44 +0100 Subject: [PATCH] Fix standalone bootstrap generation --- .../src/main/java/coursier/Bootstrap.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/bootstrap/src/main/java/coursier/Bootstrap.java b/bootstrap/src/main/java/coursier/Bootstrap.java index 9caa2e4ec..c27a3b459 100644 --- a/bootstrap/src/main/java/coursier/Bootstrap.java +++ b/bootstrap/src/main/java/coursier/Bootstrap.java @@ -50,6 +50,15 @@ public class Bootstrap { return content.split("\n"); } + /** + * + * @param jarDir can be null if nothing should be downloaded! + * @param isolationIDs + * @param bootstrapProtocol + * @param loader + * @return + * @throws IOException + */ static Map readIsolationContexts(File jarDir, String[] isolationIDs, String bootstrapProtocol, ClassLoader loader) throws IOException { final Map perContextURLs = new LinkedHashMap(); @@ -151,6 +160,14 @@ public class Bootstrap { } } + /** + * + * @param urls + * @param jarDir: can be null if nothing should be downloaded! + * @param bootstrapProtocol + * @return + * @throws MalformedURLException + */ static List getLocalURLs(List urls, final File jarDir, String bootstrapProtocol) throws MalformedURLException { ThreadFactory threadFactory = new ThreadFactory() { @@ -178,6 +195,8 @@ public class Bootstrap { if (protocol.equals("file") || protocol.equals(bootstrapProtocol)) { localURLs.add(url); } else { + assert jarDir != null : "Should not happen, not supposed to download things"; + File dest = localFile(jarDir, url); if (dest.exists()) { @@ -190,6 +209,8 @@ public class Bootstrap { final Random random = new Random(); for (final URL url : missingURLs) { + assert jarDir != null : "Should not happen, not supposed to download things"; + completionService.submit(new Callable() { @Override public URL call() throws Exception { @@ -326,13 +347,17 @@ public class Bootstrap { String mainClass0 = System.getProperty("bootstrap.mainClass"); String jarDir0 = System.getProperty("bootstrap.jarDir"); - final File jarDir = new File(jarDir0); + File jarDir = null; - if (jarDir.exists()) { - if (!jarDir.isDirectory()) - exit("Error: " + jarDir0 + " is not a directory"); - } else if (!jarDir.mkdirs()) - System.err.println("Warning: cannot create " + jarDir0 + ", continuing anyway."); + if (jarDir0 != null) { + jarDir = new File(jarDir0); + + if (jarDir.exists()) { + if (!jarDir.isDirectory()) + exit("Error: " + jarDir0 + " is not a directory"); + } else if (!jarDir.mkdirs()) + System.err.println("Warning: cannot create " + jarDir0 + ", continuing anyway."); + } Random rng = new Random(); String protocol = "bootstrap" + rng.nextLong();