--- a/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java Fri Mar 13 12:31:32 2009 +0100 +++ a/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java Fri Mar 13 15:38:46 2009 +0300 @@ -42,6 +42,7 @@ package org.netbeans.updater; import java.io.*; +import java.lang.reflect.Method; import java.util.*; import java.util.jar.*; @@ -97,6 +98,8 @@ public static final String UPDATER_JAR = "updater.jar"; // NOI18N public static final String AUTOUPDATE_UPDATER_JAR_PATH = "netbeans/modules/ext/" + UPDATER_JAR; // NOI18N + + public static final String EXECUTABLE_FILES_ENTRY = "Info/executable.list"; /** files that are supposed to be installed (when running inside the ide) */ private Collection forInstall; @@ -354,6 +357,7 @@ try { jarFile = new JarFile (nbm); Enumeration entries = jarFile.entries(); + List executableFiles = readExecutableFilesList(jarFile); while( entries.hasMoreElements() ) { JarEntry entry = (JarEntry) entries.nextElement(); checkStop(); @@ -383,6 +387,9 @@ destFile.getParentFile ().mkdirs (); } bytesRead = copyStreams( jarFile.getInputStream( entry ), new FileOutputStream( destFile ), bytesRead ); + if(executableFiles.contains(pathTo)) { + chmod(destFile); + } UpdaterFrame.setProgressValue( bytesRead ); } } else if ( entry.getName().startsWith( UPDATE_MAIN_DIR )&& @@ -455,7 +462,74 @@ t.deleteUnusedFiles (); } } - + + private List readExecutableFilesList(JarFile jarFile) { + List list = new ArrayList(); + JarEntry executableFilesEntry = jarFile.getJarEntry(EXECUTABLE_FILES_ENTRY); + if (executableFilesEntry != null) { + BufferedInputStream bis = null; + try { + bis = new BufferedInputStream(jarFile.getInputStream(executableFilesEntry)); + byte[] buffer = new byte[8192]; + int c = 0; + StringBuilder sb = new StringBuilder(); + while ((c = bis.read(buffer)) != -1) { + sb.append(new String(buffer, 0, c)); + } + String[] lines = sb.toString().trim().split("(?:\r\n|\n|\r)"); + for (String s : lines) { + if (s.trim().length() > 0) { + list.add(s); + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (bis != null) { + try { + bis.close(); + } catch (IOException e) { + } + } + } + } + return list; + } + + private void chmod(File executableFile) { + if(isWindows()) { + return; + } + if (System.getProperty("java.version").startsWith("1.5")) { + // Find chmod + File chmod = new File("/bin/chmod"); // NOI18N + if (!chmod.isFile()) { + chmod = new File("/usr/bin/chmod"); // NOI18N + } + if (chmod.isFile()) { + Process process = null; + try { + process = new ProcessBuilder(chmod.getAbsolutePath(), "a+x", executableFile.getAbsolutePath()).start(); + process.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (process != null) { + process.destroy(); + } + } + } + } else { + // Determine if java.io.File.setExecutable method is supported + try { + Method setExecutableMethod = File.class.getMethod("setExecutable", Boolean.TYPE, Boolean.TYPE); + setExecutableMethod.invoke(executableFile, true, false); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + public static boolean trickyDeleteOnWindows(File destFile) { assert isWindows() : "Call it only on Windows but system is " + System.getProperty("os.name"); File f = new File(destFile.getParentFile(), destFile.getName());