+ private final static String DEFAULT_DATA_DIR = "data";
+ private final static String DEFAULT_EXEC_DIR = "exec";
+ private final static String DEFAULT_VMARGS = "-Xmx128m";
+ private final static String DEFAULT_PROGRAM_ARGS = "-console";
+
+ /** Sets default values on this configuration. */
+ public static void setDefaults(ILaunchConfigurationWorkingCopy wc,
+ Boolean isEclipse) {
+ try {
+ if (isEclipse) {
+ wc.setAttribute(IPDELauncherConstants.USE_DEFAULT, false);
+ wc.setAttribute(IPDELauncherConstants.USE_PRODUCT, false);
+ }
+
+ wc.setAttribute(ATTR_ADD_JVM_PATHS, false);
+ wc.setAttribute(ATTR_ADDITIONAL_VM_ARGS, DEFAULT_VMARGS);
+ wc.setAttribute(ATTR_ADDITIONAL_PROGRAM_ARGS, DEFAULT_PROGRAM_ARGS);
+
+ // Defaults
+ String originalVmArgs = wc.getAttribute(
+ IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
+ wc.setAttribute(ATTR_DEFAULT_VM_ARGS, originalVmArgs);
+ wc.setAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, true);
+ } catch (CoreException e) {
+ Shell shell = Display.getCurrent().getActiveShell();
+ ErrorDialog.openError(shell, "Error",
+ "Cannot execute initalize configuration", e.getStatus());
+ }
+ }
+
+ /** Find the working directory based on this properties file. */
+ public static String findWorkingDirectory(IFile propertiesFile) {
+ try {
+ IProject project = propertiesFile.getProject();
+ IPath parent = propertiesFile.getProjectRelativePath()
+ .removeLastSegments(1);
+ IFolder execFolder = project.getFolder(parent
+ .append(DEFAULT_EXEC_DIR));
+ if (!execFolder.exists())
+ execFolder.create(true, true, null);
+ IFolder launchFolder = project.getFolder(execFolder
+ .getProjectRelativePath().append(
+ extractName(propertiesFile)));
+ if (!launchFolder.exists())
+ launchFolder.create(true, true, null);
+ return "${workspace_loc:"
+ + launchFolder.getFullPath().toString().substring(1) + "}";
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("Cannot create working directory", e);
+ }
+ }
+
+ /** Extract the launch configuration name from the properties file. */
+ public static String extractName(IFile propertiesFile) {
+ IPath path = propertiesFile.getFullPath();
+ IPath pathNoExt = path.removeFileExtension();
+ return pathNoExt.segment(pathNoExt.segmentCount() - 1);
+
+ }
+