Lines 42-47
Link Here
|
42 |
package org.netbeans.updater; |
42 |
package org.netbeans.updater; |
43 |
|
43 |
|
44 |
import java.io.*; |
44 |
import java.io.*; |
|
|
45 |
import java.lang.reflect.Method; |
45 |
import java.util.*; |
46 |
import java.util.*; |
46 |
import java.util.jar.*; |
47 |
import java.util.jar.*; |
47 |
|
48 |
|
Lines 97-102
Link Here
|
97 |
|
98 |
|
98 |
public static final String UPDATER_JAR = "updater.jar"; // NOI18N |
99 |
public static final String UPDATER_JAR = "updater.jar"; // NOI18N |
99 |
public static final String AUTOUPDATE_UPDATER_JAR_PATH = "netbeans/modules/ext/" + UPDATER_JAR; // NOI18N |
100 |
public static final String AUTOUPDATE_UPDATER_JAR_PATH = "netbeans/modules/ext/" + UPDATER_JAR; // NOI18N |
|
|
101 |
|
102 |
public static final String EXECUTABLE_FILES_ENTRY = "Info/executable.list"; |
100 |
|
103 |
|
101 |
/** files that are supposed to be installed (when running inside the ide) */ |
104 |
/** files that are supposed to be installed (when running inside the ide) */ |
102 |
private Collection<File> forInstall; |
105 |
private Collection<File> forInstall; |
Lines 354-359
Link Here
|
354 |
try { |
357 |
try { |
355 |
jarFile = new JarFile (nbm); |
358 |
jarFile = new JarFile (nbm); |
356 |
Enumeration entries = jarFile.entries(); |
359 |
Enumeration entries = jarFile.entries(); |
|
|
360 |
List <String> executableFiles = readExecutableFilesList(jarFile); |
357 |
while( entries.hasMoreElements() ) { |
361 |
while( entries.hasMoreElements() ) { |
358 |
JarEntry entry = (JarEntry) entries.nextElement(); |
362 |
JarEntry entry = (JarEntry) entries.nextElement(); |
359 |
checkStop(); |
363 |
checkStop(); |
Lines 383-388
Link Here
|
383 |
destFile.getParentFile ().mkdirs (); |
387 |
destFile.getParentFile ().mkdirs (); |
384 |
} |
388 |
} |
385 |
bytesRead = copyStreams( jarFile.getInputStream( entry ), new FileOutputStream( destFile ), bytesRead ); |
389 |
bytesRead = copyStreams( jarFile.getInputStream( entry ), new FileOutputStream( destFile ), bytesRead ); |
|
|
390 |
if(executableFiles.contains(pathTo)) { |
391 |
chmod(destFile); |
392 |
} |
386 |
UpdaterFrame.setProgressValue( bytesRead ); |
393 |
UpdaterFrame.setProgressValue( bytesRead ); |
387 |
} |
394 |
} |
388 |
} else if ( entry.getName().startsWith( UPDATE_MAIN_DIR )&& |
395 |
} else if ( entry.getName().startsWith( UPDATE_MAIN_DIR )&& |
Lines 455-461
Link Here
|
455 |
t.deleteUnusedFiles (); |
462 |
t.deleteUnusedFiles (); |
456 |
} |
463 |
} |
457 |
} |
464 |
} |
458 |
|
465 |
|
|
|
466 |
private List<String> readExecutableFilesList(JarFile jarFile) { |
467 |
List<String> list = new ArrayList(); |
468 |
JarEntry executableFilesEntry = jarFile.getJarEntry(EXECUTABLE_FILES_ENTRY); |
469 |
if (executableFilesEntry != null) { |
470 |
BufferedInputStream bis = null; |
471 |
try { |
472 |
bis = new BufferedInputStream(jarFile.getInputStream(executableFilesEntry)); |
473 |
byte[] buffer = new byte[8192]; |
474 |
int c = 0; |
475 |
StringBuilder sb = new StringBuilder(); |
476 |
while ((c = bis.read(buffer)) != -1) { |
477 |
sb.append(new String(buffer, 0, c)); |
478 |
} |
479 |
String[] lines = sb.toString().trim().split("(?:\r\n|\n|\r)"); |
480 |
for (String s : lines) { |
481 |
if (s.trim().length() > 0) { |
482 |
list.add(s); |
483 |
} |
484 |
} |
485 |
} catch (Exception e) { |
486 |
e.printStackTrace(); |
487 |
} finally { |
488 |
if (bis != null) { |
489 |
try { |
490 |
bis.close(); |
491 |
} catch (IOException e) { |
492 |
} |
493 |
} |
494 |
} |
495 |
} |
496 |
return list; |
497 |
} |
498 |
|
499 |
private void chmod(File executableFile) { |
500 |
if(isWindows()) { |
501 |
return; |
502 |
} |
503 |
if (System.getProperty("java.version").startsWith("1.5")) { |
504 |
// Find chmod |
505 |
File chmod = new File("/bin/chmod"); // NOI18N |
506 |
if (!chmod.isFile()) { |
507 |
chmod = new File("/usr/bin/chmod"); // NOI18N |
508 |
} |
509 |
if (chmod.isFile()) { |
510 |
Process process = null; |
511 |
try { |
512 |
process = new ProcessBuilder(chmod.getAbsolutePath(), "a+x", executableFile.getAbsolutePath()).start(); |
513 |
process.waitFor(); |
514 |
} catch (Exception e) { |
515 |
e.printStackTrace(); |
516 |
} finally { |
517 |
if (process != null) { |
518 |
process.destroy(); |
519 |
} |
520 |
} |
521 |
} |
522 |
} else { |
523 |
// Determine if java.io.File.setExecutable method is supported |
524 |
try { |
525 |
Method setExecutableMethod = File.class.getMethod("setExecutable", Boolean.TYPE, Boolean.TYPE); |
526 |
setExecutableMethod.invoke(executableFile, true, false); |
527 |
} catch (Exception e) { |
528 |
e.printStackTrace(); |
529 |
} |
530 |
} |
531 |
} |
532 |
|
459 |
public static boolean trickyDeleteOnWindows(File destFile) { |
533 |
public static boolean trickyDeleteOnWindows(File destFile) { |
460 |
assert isWindows() : "Call it only on Windows but system is " + System.getProperty("os.name"); |
534 |
assert isWindows() : "Call it only on Windows but system is " + System.getProperty("os.name"); |
461 |
File f = new File(destFile.getParentFile(), destFile.getName()); |
535 |
File f = new File(destFile.getParentFile(), destFile.getName()); |