@@ -49,8 +49,11 @@ public class JvmManager {
4949
5050 public static String getCommandString (String project , String repo , String version , String downloadJsonURL ,
5151 long sizeOfJson , ProgressBar progress , String bindir ) throws Exception {
52-
53- File exe = download (version , downloadJsonURL , sizeOfJson , progress , bindir , "jvm.json" );
52+ if (version ==null )
53+ throw new RuntimeException ("Version can not be null" );
54+ File exe ;
55+
56+ exe = download (version , downloadJsonURL , sizeOfJson , progress , bindir , "jvm.json" );
5457 Type TT_mapStringString = new TypeToken <HashMap <String , Object >>() {
5558 }.getType ();
5659 // chreat the gson object, this is the parsing factory
@@ -123,6 +126,7 @@ public static boolean isExecutable(ZipArchiveEntry entry) {
123126 // executable: 0001 (0x01)
124127 return (unixMode & 0x49 ) != 0 ;
125128 }
129+
126130 private static void unzip (File path , String dir ) throws Exception {
127131 String fileBaseName = FilenameUtils .getBaseName (path .getName ().toString ());
128132 Path destFolderPath = new File (dir ).toPath ();
@@ -139,12 +143,12 @@ private static void unzip(File path, String dir) throws Exception {
139143 Files .createDirectories (entryPath .getParent ());
140144 try (InputStream in = zipFile .getInputStream (entry )) {
141145 try {
142- //ar.setExternalAttributes(entry.extraAttributes);
146+ // ar.setExternalAttributes(entry.extraAttributes);
143147 if (entry .isUnixSymlink ()) {
144148 String text = new BufferedReader (new InputStreamReader (in , StandardCharsets .UTF_8 ))
145149 .lines ().collect (Collectors .joining ("\n " ));
146150 Path target = Paths .get ("." , text );
147- System .out .println ("Creating symlink " + entryPath + " with " + target );
151+ System .out .println ("Creating symlink " + entryPath + " with " + target );
148152
149153 Files .createSymbolicLink (entryPath , target );
150154 continue ;
@@ -155,7 +159,7 @@ private static void unzip(File path, String dir) throws Exception {
155159 try (OutputStream out = new FileOutputStream (entryPath .toFile ())) {
156160 IOUtils .copy (in , out );
157161 }
158- if (isExecutable (entry )) {
162+ if (isExecutable (entry )) {
159163 entryPath .toFile ().setExecutable (true );
160164 }
161165 }
@@ -204,38 +208,43 @@ private static String bits(byte b) {
204208
205209 private static File download (String version , String downloadJsonURL , long sizeOfJson , ProgressBar progress ,
206210 String bindir , String filename ) throws MalformedURLException , IOException , FileNotFoundException {
207- URL url = new URL (downloadJsonURL );
208- URLConnection connection = url .openConnection ();
209- InputStream is = connection .getInputStream ();
210- ProcessInputStream pis = new ProcessInputStream (is , (int ) sizeOfJson );
211- pis .addListener (new Listener () {
212- @ Override
213- public void process (double percent ) {
214- System .out .println ("Download percent " + percent );
215- Platform .runLater (() -> {
216- progress .setProgress (percent );
217- });
218- }
219- });
220211 File folder = new File (bindir + version + "/" );
221212 File exe = new File (bindir + version + "/" + filename );
222-
223- if (!folder .exists () || !exe .exists ()) {
224- System .out .println ("Start Downloading " + filename );
225- folder .mkdirs ();
226- exe .createNewFile ();
227- byte dataBuffer [] = new byte [1024 ];
228- int bytesRead ;
229- FileOutputStream fileOutputStream = new FileOutputStream (exe .getAbsoluteFile ());
230- while ((bytesRead = pis .read (dataBuffer , 0 , 1024 )) != -1 ) {
231- fileOutputStream .write (dataBuffer , 0 , bytesRead );
213+ try {
214+ URL url = new URL (downloadJsonURL );
215+ URLConnection connection = url .openConnection ();
216+ InputStream is = connection .getInputStream ();
217+ ProcessInputStream pis = new ProcessInputStream (is , (int ) sizeOfJson );
218+ pis .addListener (new Listener () {
219+ @ Override
220+ public void process (double percent ) {
221+ System .out .println ("Download percent " + percent );
222+ Platform .runLater (() -> {
223+ progress .setProgress (percent );
224+ });
225+ }
226+ });
227+
228+ if (!folder .exists () || !exe .exists ()) {
229+ System .out .println ("Start Downloading " + filename );
230+ folder .mkdirs ();
231+ exe .createNewFile ();
232+ byte dataBuffer [] = new byte [1024 ];
233+ int bytesRead ;
234+ FileOutputStream fileOutputStream = new FileOutputStream (exe .getAbsoluteFile ());
235+ while ((bytesRead = pis .read (dataBuffer , 0 , 1024 )) != -1 ) {
236+ fileOutputStream .write (dataBuffer , 0 , bytesRead );
237+ }
238+ fileOutputStream .close ();
239+ pis .close ();
240+ System .out .println ("Finished downloading " + filename );
241+ } else {
242+ System .out .println ("Not downloadeing, it existst " + filename );
232243 }
233- fileOutputStream .close ();
234- pis .close ();
235- System .out .println ("Finished downloading " + filename );
236- } else {
237- System .out .println ("Not downloadeing, it existst " + filename );
244+ } catch (Throwable t ) {
245+ t .printStackTrace ();
238246 }
247+ System .out .println ("Using JVM " +exe .getAbsolutePath ());
239248 return exe ;
240249 }
241250}
0 commit comments