Map<String,String> variables = new HashMap<String,String>();
variables.put("workspace_loc", runtime.getProject().getWorkspace().getRoot().getLocation().toFile().getAbsolutePath());
variables.put("project_loc", runtime.getProject().getLocation().toFile().getAbsolutePath());
variables.put("wga_appbase", wgaDeployment.getWebappDir().getAbsolutePath());
variables.put("wga_workdir", wgaDeployment.getWorkDir().getAbsolutePath());
IPreferenceStore store = WGADesignerPlugin.getDefault().getPreferenceStore();
variables.put("tomcat_server_port", Integer.toString(store.getInt(PreferenceConstants.TOMCAT_SERVER_PORT)));
variables.put("tomcat_http_port", Integer.toString(store.getInt(PreferenceConstants.TOMCAT_HTTP_PORT)));
variables.put("tomcat_redirect_port", Integer.toString(store.getInt(PreferenceConstants.TOMCAT_REDIRECT_PORT)));
File orgCatalinaBase = runtime.getCatalinaBase().getLocation().toFile();
// create new temp catalinabase directory
File catalinaBase = new File(WGADesignerPlugin.getDefault().getStateLocation().toFile(), "tomcat_current");
if (!catalinaBase.exists()) {
catalinaBase.mkdir();
}
WGUtils.delTree(catalinaBase, false);
// copy current conf from workspace
File tmpConf = new File(catalinaBase, "conf");
WGUtils.copyDirContent(new File(orgCatalinaBase, "conf"), tmpConf);
// copy current lib from workspace
File tmpLib = new File(catalinaBase, "lib");
WGUtils.copyDirContent(new File(orgCatalinaBase, "lib"), tmpLib);
File orgServerXML = new File(orgCatalinaBase, "conf/server.xml");
File serverXML = new File(tmpConf, "server.xml");
FileUtils.copyWithVariableSubstitution(orgServerXML, serverXML, variables, VAR_PREFIX, VAR_SUFFIX);
StringBuffer programArguments = new StringBuffer();
Iterator<String> prgArgs = getPrgArgs(START_COMMAND, serverXML).iterator();
while (prgArgs.hasNext()) {
programArguments.append(" " + prgArgs.next());
}
List<String> vmArgs = getVmArgs(_catalinaHome, catalinaBase, true);
// B00005D9E
vmArgs.add("-Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false");
// add wga startup arguments
vmArgs.addAll(runtime.getWGALaunchVMArguments());
Iterator<String> it = vmArgs.iterator();
StringBuffer jvmArguments = new StringBuffer();
while (it.hasNext()) {
jvmArguments.append(" " + it.next());
}
IVMInstall vmInstall = WGAExecutionEnvironment.findVMInstallById(runtime.getConfiguration().getExecutionEnvironmentId());
if (vmInstall == null) {
vmInstall = JavaRuntime.getDefaultVMInstall();
}
List<IPath> classPath = getClasspath(_catalinaHome, vmInstall.getInstallLocation());
String[] bootClasspath = new String[0];
_tomcatInstance = VMRuntime.runVM("WGA Runtime", vmInstall, MAIN_CLASS, classPath, bootClasspath, jvmArguments.toString(), programArguments.toString(), store.getBoolean(PreferenceConstants.JAVA_DEBUG), store.getBoolean(PreferenceConstants.JAVA_DEBUG), false);
_currentRuntime = runtime;
//notifyListeners(TomcatServerStateListener.STATE_RUNNING);
}
}