From 5a6e53da1ca13517c16f45d03273f4d88525ed71 Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Thu, 13 Jul 2017 10:14:17 +0200 Subject: [PATCH] Cleaned up the code a little to not exit with 0 in case of an error. --- maven-wrapper/mvnw | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/maven-wrapper/mvnw b/maven-wrapper/mvnw index bc09d18ad6..9e810d3654 100755 --- a/maven-wrapper/mvnw +++ b/maven-wrapper/mvnw @@ -217,32 +217,34 @@ import java.nio.channels.*; public class MavenWrapperDownloader { 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"; File baseDirectory = new File(args[0]); - System.out.println("Using base directory: " + baseDirectory.getAbsolutePath()); - File outputFile = new File(baseDirectory.getAbsolutePath() - , ".mvn/wrapper/maven-wrapper.jar"); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + File outputFile = new File(baseDirectory.getAbsolutePath(), ".mvn/wrapper/maven-wrapper.jar"); if(!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } - System.out.println("Downloading to: " + outputFile.getAbsolutePath()); - downloadFileFromURL(url, outputFile); - System.out.println("Done"); + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + 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) { - try { - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } catch (Throwable e) { - e.printStackTrace(); - } + public static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); } }