Cleaned up the code a little to not exit with 0 in case of an error.

This commit is contained in:
Christofer Dutz 2017-07-13 10:14:17 +02:00 committed by rfscholte
parent 1a920c765e
commit a3787b7307
1 changed files with 21 additions and 19 deletions

40
maven-wrapper/mvnw vendored
View File

@ -217,32 +217,34 @@ import java.nio.channels.*;
public class MavenWrapperDownloader { public class MavenWrapperDownloader {
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("Downloader started"); System.out.println("- Downloader started");
String url="http://central.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar"; String url="http://central.maven.org/maven2/io/takari/maven-wrapper/0.2.1/maven-wrapper-0.2.1.jar";
File baseDirectory = new File(args[0]); File baseDirectory = new File(args[0]);
System.out.println("Using base directory: " + baseDirectory.getAbsolutePath()); System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
File outputFile = new File(baseDirectory.getAbsolutePath() File outputFile = new File(baseDirectory.getAbsolutePath(), ".mvn/wrapper/maven-wrapper.jar");
, ".mvn/wrapper/maven-wrapper.jar");
if(!outputFile.getParentFile().exists()) { if(!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
} }
System.out.println("Downloading to: " + outputFile.getAbsolutePath()); System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
downloadFileFromURL(url, outputFile); try {
System.out.println("Done"); downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
} }
public static void downloadFileFromURL(String urlString, File destination) { public static void downloadFileFromURL(String urlString, File destination) throws Exception {
try { URL website = new URL(urlString);
URL website = new URL(urlString); ReadableByteChannel rbc;
ReadableByteChannel rbc; rbc = Channels.newChannel(website.openStream());
rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream(destination);
FileOutputStream fos = new FileOutputStream(destination); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); fos.close();
fos.close(); rbc.close();
rbc.close();
} catch (Throwable e) {
e.printStackTrace();
}
} }
} }