@@ -49,8 +49,11 @@ public class JvmManager {
49
49
50
50
public static String getCommandString (String project , String repo , String version , String downloadJsonURL ,
51
51
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" );
54
57
Type TT_mapStringString = new TypeToken <HashMap <String , Object >>() {
55
58
}.getType ();
56
59
// chreat the gson object, this is the parsing factory
@@ -123,6 +126,7 @@ public static boolean isExecutable(ZipArchiveEntry entry) {
123
126
// executable: 0001 (0x01)
124
127
return (unixMode & 0x49 ) != 0 ;
125
128
}
129
+
126
130
private static void unzip (File path , String dir ) throws Exception {
127
131
String fileBaseName = FilenameUtils .getBaseName (path .getName ().toString ());
128
132
Path destFolderPath = new File (dir ).toPath ();
@@ -139,12 +143,12 @@ private static void unzip(File path, String dir) throws Exception {
139
143
Files .createDirectories (entryPath .getParent ());
140
144
try (InputStream in = zipFile .getInputStream (entry )) {
141
145
try {
142
- //ar.setExternalAttributes(entry.extraAttributes);
146
+ // ar.setExternalAttributes(entry.extraAttributes);
143
147
if (entry .isUnixSymlink ()) {
144
148
String text = new BufferedReader (new InputStreamReader (in , StandardCharsets .UTF_8 ))
145
149
.lines ().collect (Collectors .joining ("\n " ));
146
150
Path target = Paths .get ("." , text );
147
- System .out .println ("Creating symlink " + entryPath + " with " + target );
151
+ System .out .println ("Creating symlink " + entryPath + " with " + target );
148
152
149
153
Files .createSymbolicLink (entryPath , target );
150
154
continue ;
@@ -155,7 +159,7 @@ private static void unzip(File path, String dir) throws Exception {
155
159
try (OutputStream out = new FileOutputStream (entryPath .toFile ())) {
156
160
IOUtils .copy (in , out );
157
161
}
158
- if (isExecutable (entry )) {
162
+ if (isExecutable (entry )) {
159
163
entryPath .toFile ().setExecutable (true );
160
164
}
161
165
}
@@ -204,38 +208,43 @@ private static String bits(byte b) {
204
208
205
209
private static File download (String version , String downloadJsonURL , long sizeOfJson , ProgressBar progress ,
206
210
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
- });
220
211
File folder = new File (bindir + version + "/" );
221
212
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 );
232
243
}
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 ();
238
246
}
247
+ System .out .println ("Using JVM " +exe .getAbsolutePath ());
239
248
return exe ;
240
249
}
241
250
}
0 commit comments