Slightly better output from boostrap JARs

This commit is contained in:
Alexandre Archambault 2016-01-29 12:51:08 +01:00
parent c0bc52f53e
commit 71878ce3e9
1 changed files with 37 additions and 25 deletions

View File

@ -131,7 +131,7 @@ public class Bootstrap {
return new File(jarDir, fileName);
}
static List<URL> getLocalURLs(List<URL> urls, final File jarDir, String bootstrapProtocol) {
static List<URL> getLocalURLs(List<URL> 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<URL> localURLs = new ArrayList<>();
List<URL> 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<URL>() {
@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<URL>() {
@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<URL> 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);