/**
  * Helper function to add system properties that tell Grails to debug run-app or test-app in as a
  * forked process in debugging mode.
  *
  * <p>These properties are added only if applicable. I.e. recent enough graisl version and this is
  * a debug-mode launch.
  *
  * <p>In the process of adding the arguments, we will pick a free port.
  *
  * @return Chosen debug port or -1 if not launching in forked debug mode.
  */
 private int addForkedModeDebuggingArgs(ILaunchConfiguration conf, String mode, List<String> args)
     throws IOException {
   // TODO Auto-generated method stub
   if (!ILaunchManager.DEBUG_MODE.equals(mode)) {
     return -1;
   }
   GrailsVersion version = GrailsLaunchArgumentUtils.getGrailsVersion(conf);
   if (GrailsVersion.V_2_3_.compareTo(version) > 0) {
     return -1; // Disable this feature for pre Grails 2.3.
   }
   int debugPort = portFinder.findUniqueFreePort();
   args.add("-Dgrails.project.fork.run.debug=true");
   args.add("-Dgrails.project.fork.test.debug=true");
   String debugArgs = "-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=" + debugPort;
   args.add("-Dgrails.project.fork.run.debugArgs=" + debugArgs);
   args.add("-Dgrails.project.fork.test.debugArgs=" + debugArgs);
   return debugPort;
 }
 /**
  * Add a system property arg to set killport for Grails 2.3 and higher.
  *
  * @param project
  * @return An array of kill ports to try in order to ask Grails forked process to terminate.
  */
 private ArrayList<Integer> addKillPortArg(IProject project, List<String> vmArgs) {
   ArrayList<Integer> ports = null;
   if (project != null) {
     if (GrailsVersion.V_2_3_.compareTo(GrailsVersion.getEclipseGrailsVersion(project)) <= 0) {
       ports = new ArrayList<Integer>(2); // Will have 1 or two elements not more.
       int serverPort = GrailsWorkspace.get().create(project).getServerPort();
       if (serverPort != DependencyData.UNKNOWN_PORT) {
         ports.add(serverPort + 1);
       }
       // The next bit really only expected to work in in Grails 2.3
       try {
         int allocatedKillPort = portFinder.findUniqueFreePort();
         vmArgs.add("-Dgrails.forked.kill.port=" + allocatedKillPort);
         ports.add(allocatedKillPort);
       } catch (IOException e) {
         // non fatal... log and proceed
         GrailsCoreActivator.log(e);
       }
     }
   }
   return ports;
 }