package com.ibm.ServerWizard2; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.Enumeration; import java.util.Vector; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.swing.JOptionPane; import com.ibm.ServerWizard2.utility.GithubFile; import com.ibm.ServerWizard2.utility.MyLogFormatter; import com.ibm.ServerWizard2.view.DialogHandler; import com.ibm.ServerWizard2.view.MessagePopup; public class Launcher { public final static String JAR_NAME = "serverwiz2"; public final static String ZIP_NAME = "serverwiz2_lib.zip"; public final static String REPOSITORY= "open-power/serverwiz/"; public final static Logger LOGGER = Logger.getLogger(Launcher.class.getName()); public Launcher() { } public static void main(String[] args) { MessagePopup dm = new MessagePopup("ServerWiz2 Launcher", 5); dm.open(); String version = "latest"; boolean forceUpdate=false; boolean forceLocal=false; for (int i=0;i commandLine = new Vector(); commandLine.add("java"); if (isMac) { commandLine.add("-XstartOnFirstThread"); } commandLine.add("-jar"); commandLine.add(jar.getLocalPath()); for (String arg : args) { commandLine.add(arg); } if (updated) { commandLine.add("-v"); commandLine.add(version); } try { Thread.sleep(1500); } catch (Exception e) { } Thread t=run(commandLine); try { t.join(); } catch (Exception e) { } dm.close(); } public static Thread run(Vector commandLine) { String commandLineStr=""; for (String c : commandLine) { commandLineStr=commandLineStr+c+" "; } LOGGER.info("Running: "+commandLineStr); try { final ProcessBuilder builder = new ProcessBuilder(commandLine).redirectErrorStream(true); final Process process = builder.start(); Thread thread = new Thread(new Runnable() { public void run() { InputStreamReader in = new InputStreamReader(process.getInputStream()); BufferedReader inb = new BufferedReader(in); String thisLine; try { while ((thisLine = inb.readLine()) != null) { LOGGER.info(thisLine); } } catch (IOException e) { LOGGER.info(e.toString()); e.printStackTrace(); } } }); thread.start(); return thread; //final int exitValue = process.waitFor(); } catch (Exception e) { LOGGER.info(e.toString()); e.printStackTrace(); } return null; } public static String getWorkingDir() { // gets working directory whether running as jar or from eclipse File f = new File("").getAbsoluteFile(); String workingDir = f.getAbsolutePath() + System.getProperty("file.separator"); return workingDir; } public static String getArchFilename(String prefix) { return prefix + "_" + getOSName() + getArchName() + ".jar"; } private static String getOSName() { String osNameProperty = System.getProperty("os.name"); if (osNameProperty == null) { throw new RuntimeException("os.name property is not set"); } else { osNameProperty = osNameProperty.toLowerCase(); } if (osNameProperty.contains("win")) { return "win"; } else if (osNameProperty.contains("linux") || osNameProperty.contains("nix")) { return "linux"; } else if (osNameProperty.contains("mac")) { return "macosx"; } else { throw new RuntimeException("Unknown OS name: " + osNameProperty); } } private static String getArchName() { String osArch = System.getProperty("os.arch"); LOGGER.info("Arch: "+osArch); if (osArch != null && osArch.contains("64")) { return "64"; } else { return "32"; } } public static void unzip(String file, String outputDir) throws Exception { ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File entryDestination = new File(outputDir, entry.getName()); entryDestination.getParentFile().mkdirs(); if (entry.isDirectory()) { entryDestination.mkdirs(); } else { LOGGER.info("Unzipping: "+entryDestination.getPath()); Files.copy(zipFile.getInputStream(entry), entryDestination.toPath(),StandardCopyOption.REPLACE_EXISTING); } } zipFile.close(); } }