protected final String getModule() { String module = controls.getModule(); if (null == module || module.length() == 0) { return getModuleDefault(); } return module; }
public void setModule(String module) { controls.setModule(module); }
protected void launchServer(boolean includeTestSources, String jsInteropMode, String logLevel) { try { String cpSep = File.pathSeparator; String cp = getClasspath(includeTestSources, cpSep); cp = alterClasspath(cp, cpSep); LinkedList<String> paths = getSourcePaths(includeTestSources); for (String path : paths.toArray(new String[paths.size()])) { File pathFile = new File(path); if (pathFile.exists()) { if (path.endsWith("classes")) { cp += cpSep + pathFile; paths.remove(path); } } } for (File path : classpath) { if (path.getAbsolutePath().endsWith("classes")) { cp = path + cpSep + cp; } else { cp += cpSep + path; } } X_Log.debug("Codeserver classpath", cp); int debugPort = debugPort(); int len = debugPort > 0 ? 12 : 10; final String[] cmdArray = new String[len]; cmdArray[0] = // path to java executable System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; cmdArray[1] = "-cp"; cmdArray[2] = cp.replaceAll("(\\s)", "\\\\$1"); int pos = 3; if (debugPort > 0) { cmdArray[pos++] = "-Xdebug"; cmdArray[pos++] = "-agentlib:jdwp=transport=dt_socket,address=localhost:" + debugPort + ",server=y,suspend=y,timeout=" + debugTimeout(); System.out.println("Waiting to attach debugger on port " + debugPort + " for 10 seconds"); } cmdArray[pos++] = "com.google.gwt.dev.codeserver.CodeServer"; cmdArray[pos++] = "-port"; cmdArray[pos++] = Integer.toString(getPort()); cmdArray[pos++] = "-XjsInteropMode"; cmdArray[pos++] = jsInteropMode; cmdArray[pos++] = "-logLevel"; cmdArray[pos++] = logLevel; String[] srcArray = toCli(paths); len = 1 + cmdArray.length + srcArray.length; final String[] exec = new String[len]; pos = cmdArray.length; System.arraycopy(cmdArray, 0, exec, 0, pos); System.arraycopy(srcArray, 0, exec, pos, srcArray.length); exec[exec.length - 1] = getModule(); String toRun = Arrays.asList(exec).toString().replaceAll(", ", " "); if (X_Log.loggable(LogLevel.TRACE)) X_Log.trace("exec:\n", toRun.substring(1, toRun.length() - 1)); try { Process handle = Runtime.getRuntime().exec(exec); if (debugPort > 0) { System.out.println("Not monitoring logs to avoid interfering with debugger"); } else { logger.monitor(handle, getModule()); } if (getWidth() < 1000) { Rectangle b = getBounds(); b.width = 1000; b.height = 600; setBounds(b); } final String module = getModule(); final JPanel wrap = new JPanel(new FlowLayout()); JButton restart = new JButton( new AbstractAction("Kill & Restart") { @Override public void actionPerformed(ActionEvent e) { logger.stop(module); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { try { Process handle = Runtime.getRuntime().exec(exec); logger.monitor(handle, getModule()); } catch (Exception ex) { ex.printStackTrace(); } } }); } }); JButton kill = new JButton( new AbstractAction("Kill") { @Override public void actionPerformed(ActionEvent e) { logger.stop(module); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { controls.remove(wrap); repaint(); } }); } }); wrap.add(restart); wrap.add(kill); controls.add(getModule(), wrap); } catch (IOException e) { e.printStackTrace(); logger.log("Startup failure", e); } } catch (Exception ex) { System.out.println(ex.toString()); ex.printStackTrace(); add(new JLabel(ex.toString()), BorderLayout.WEST); } }