package gw.vark.it;
import gw.util.ProcessStarter;
import gw.util.Shell;
import java.io.File;
import java.util.List;
@SuppressWarnings("UnusedDeclaration")
public enum Debug {
SOCKET,
SHMEM
}
private final File _buildFile;
private File _workingDir;
private String _args = "";
private Debug _debug;
_buildFile = buildFile;
}
_workingDir = dir;
return (T)this;
}
_args = args;
return (T)this;
}
@SuppressWarnings("UnusedDeclaration")
_debug = debug;
return (T)this;
}
public ProcessStarter
build() {
String javaCommand = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
StringBuilder command = new StringBuilder(javaCommand);
command.append(" -Daardvark.dev=true");
if (_debug != null) {
if (_debug == Debug.SOCKET) {
command.append(" -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
}
else {
command.append(" -Xdebug -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=aardvark");
}
}
command.append(" -classpath ").append(join(createClasspath()));
command.append(" ").append(getMainClass());
if (_buildFile != null) {
command.append(" -f ").append(_buildFile);
}
command.append(" ").append(_args);
System.out.println(command);
ProcessStarter process = Shell.buildProcess(command.toString());
process.getEnvironment().remove("CLASSPATH");
if (_workingDir != null) {
process.setDirectory(_workingDir);
}
return process;
}
private static String
join(List<File> classpath) {
StringBuilder sb = new StringBuilder();
for (File element : classpath) {
if (sb.length() > 0) {
sb.append(File.pathSeparator);
}
sb.append(element.getAbsolutePath());
}
return sb.toString();
}
}