diff --git a/bootstrap/src/main/java/coursier/Bootstrap.java b/bootstrap/src/main/java/coursier/Bootstrap.java index a0494fa00..e531768d6 100644 --- a/bootstrap/src/main/java/coursier/Bootstrap.java +++ b/bootstrap/src/main/java/coursier/Bootstrap.java @@ -131,7 +131,7 @@ public class Bootstrap { return new File(jarDir, fileName); } - static List getLocalURLs(List urls, final File jarDir, String bootstrapProtocol) { + static List getLocalURLs(List urls, final File jarDir, String bootstrapProtocol) throws MalformedURLException { ThreadFactory threadFactory = new ThreadFactory() { // from scalaz Strategy.DefaultDaemonThreadFactory @@ -149,6 +149,7 @@ public class Bootstrap { new ExecutorCompletionService<>(pool); List localURLs = new ArrayList<>(); + List missingURLs = new ArrayList<>(); for (URL url : urls) { @@ -157,40 +158,51 @@ public class Bootstrap { if (protocol.equals("file") || protocol.equals(bootstrapProtocol)) { localURLs.add(url); } else { - final URL url0 = url; + File dest = localFile(jarDir, url); - completionService.submit(new Callable() { - @Override - public URL call() throws Exception { - File dest = localFile(jarDir, url0); - - if (!dest.exists()) { - System.err.println("Downloading " + url0); - try { - URLConnection conn = url0.openConnection(); - long lastModified = conn.getLastModified(); - InputStream s = conn.getInputStream(); - byte[] b = readFullySync(s); - Files.write(dest.toPath(), b); - dest.setLastModified(lastModified); - } catch (Exception e) { - System.err.println("Error while downloading " + url0 + ": " + e.getMessage() + ", ignoring it"); - throw e; - } - } - - return dest.toURI().toURL(); - } - }); + if (dest.exists()) { + localURLs.add(dest.toURI().toURL()); + } else { + missingURLs.add(url); + } } } + for (final URL url : missingURLs) { + completionService.submit(new Callable() { + @Override + public URL call() throws Exception { + File dest = localFile(jarDir, url); + + if (!dest.exists()) { + try { + URLConnection conn = url.openConnection(); + long lastModified = conn.getLastModified(); + InputStream s = conn.getInputStream(); + byte[] b = readFullySync(s); + Files.write(dest.toPath(), b); + dest.setLastModified(lastModified); + } catch (Exception e) { + System.err.println("Error while downloading " + url + ": " + e.getMessage() + ", ignoring it"); + throw e; + } + } + + return dest.toURI().toURL(); + } + }); + } + try { while (localURLs.size() < urls.size()) { Future future = completionService.take(); try { URL url = future.get(); localURLs.add(url); + int nowMissing = urls.size() - localURLs.size(); + String clearLine = "\033[2K"; + String up = "\033[1A"; + System.err.print(clearLine + "Downloaded " + (missingURLs.size() - nowMissing) + " missing file(s) / " + missingURLs.size() + "\n" + up); } catch (ExecutionException ex) { // Error message already printed from the Callable above System.exit(255);