diff -r 319e1ef53880 extexecution/external/winp-1.6-SNAPSHOT.jar --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extexecution/external/winp-1.6-SNAPSHOT.jar Fri Jul 11 16:49:04 2008 +0200 @@ -0,0 +1,1 @@ +<<>> diff -r 319e1ef53880 extexecution/nbproject/project.properties --- a/extexecution/nbproject/project.properties Thu Jul 10 18:07:52 2008 +0200 +++ b/extexecution/nbproject/project.properties Fri Jul 11 16:49:04 2008 +0200 @@ -1,3 +1,6 @@ is.autoload=true javac.source=1.5 javadoc.arch=${basedir}/arch.xml + +cp.extra=external/winp-1.6-SNAPSHOT.jar +release.external/winp-1.6-SNAPSHOT.jar=modules/ext/winp.jar \ No newline at end of file diff -r 319e1ef53880 extexecution/nbproject/project.xml --- a/extexecution/nbproject/project.xml Thu Jul 10 18:07:52 2008 +0200 +++ b/extexecution/nbproject/project.xml Fri Jul 11 16:49:04 2008 +0200 @@ -107,6 +107,10 @@ org.netbeans.modules.extexecution.api.print org.netbeans.modules.extexecution.api.input + + ext/winp.jar + external/winp-1.6-SNAPSHOT.jar + diff -r 319e1ef53880 extexecution/release/modules/lib/winp.dll Binary file extexecution/release/modules/lib/winp.dll has changed diff -r 319e1ef53880 extexecution/src/org/netbeans/modules/extexecution/KillableProcess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extexecution/src/org/netbeans/modules/extexecution/KillableProcess.java Fri Jul 11 16:49:04 2008 +0200 @@ -0,0 +1,107 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.extexecution; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.jvnet.winp.NotWindowsException; +import org.jvnet.winp.WinProcess; +import org.jvnet.winp.WinpException; +import org.openide.util.Utilities; + +/** + * + * @author Petr Hejl + */ +public class KillableProcess extends Process { + + private static final Logger LOGGER = Logger.getLogger(KillableProcess.class.getName()); + + private final Process delegate; + + private WinProcess winProcess; + + public KillableProcess(Process delegate) { + this.delegate = delegate; + try { + if (Utilities.isWindows() && !(delegate instanceof KillableProcess)) { + this.winProcess = new WinProcess(delegate); + } else { + this.winProcess = null; + } + } catch (NotWindowsException ex) { + LOGGER.log(Level.INFO, null, ex); + this.winProcess = null; + } + } + + public int waitFor() throws InterruptedException { + return delegate.waitFor(); + } + + public OutputStream getOutputStream() { + return delegate.getOutputStream(); + } + + public InputStream getInputStream() { + return delegate.getInputStream(); + } + + public InputStream getErrorStream() { + return delegate.getErrorStream(); + } + + public int exitValue() { + return delegate.exitValue(); + } + + public void destroy() { + try { + if (winProcess != null) { + winProcess.killRecursively(); + } + } catch (WinpException ex) { + LOGGER.log(Level.INFO, null, ex); + } + delegate.destroy(); + } +} diff -r 319e1ef53880 extexecution/src/org/netbeans/modules/extexecution/api/ExecutionService.java --- a/extexecution/src/org/netbeans/modules/extexecution/api/ExecutionService.java Thu Jul 10 18:07:52 2008 +0200 +++ b/extexecution/src/org/netbeans/modules/extexecution/api/ExecutionService.java Fri Jul 11 16:49:04 2008 +0200 @@ -68,6 +68,7 @@ import javax.swing.AbstractAction; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; +import org.netbeans.modules.extexecution.KillableProcess; import org.netbeans.modules.extexecution.ProcessInputStream; import org.netbeans.modules.extexecution.api.ExecutionDescriptor.InputProcessorFactory; import org.netbeans.modules.extexecution.api.ExecutionDescriptor.LineConvertorFactory; @@ -197,7 +198,7 @@ public Integer call() throws Exception { boolean interrupted = false; - Process process = null; + KillableProcess process = null; Integer ret = null; ExecutorService executor = null; @@ -217,7 +218,8 @@ return null; } - process = processCreator.call(); + process = new KillableProcess(processCreator.call()); + synchronized (RUNNING_PROCESSES) { RUNNING_PROCESSES.add(process); } diff -r 319e1ef53880 groovy.grails/src/org/netbeans/modules/groovy/grails/KillableProcess.java --- a/groovy.grails/src/org/netbeans/modules/groovy/grails/KillableProcess.java Thu Jul 10 18:07:52 2008 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,201 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - * - * Contributor(s): - * - * Portions Copyrighted 2008 Sun Microsystems, Inc. - */ - -package org.netbeans.modules.groovy.grails; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.openide.execution.NbProcessDescriptor; -import org.openide.util.Utilities; - -/** - * - * @author Petr Hejl - */ -public class KillableProcess extends Process { - - private static final Logger LOGGER = Logger.getLogger(KillableProcess.class.getName()); - - private static final long TIMEOUT = 5000; - - private final Process nativeProcess; - - private final File directory; - - public KillableProcess(Process nativeProcess, File directory) { - this.nativeProcess = nativeProcess; - this.directory = directory; - } - - @Override - public void destroy() { - if (!Utilities.isWindows()) { - nativeProcess.destroy(); - return; - } - - // wmic process where name="cmd.exe" get processid, commandline - String params[] = {"process", "where", "name=\"cmd.exe\"", // NOI18N - "get", "processid,commandline" }; // NOI18N - - WindowsExecutor executor = new WindowsExecutor("wmic.exe", - Utilities.escapeParameters(params), directory.getName()); - - Thread t = new Thread(executor); - t.start(); - - try { - t.join(TIMEOUT); - } catch (InterruptedException ex) { - LOGGER.log(Level.FINEST, null, ex); - } - - // kill running server using taskkill - String pidToKill = executor.getPid(); - - if (pidToKill != null) { - WindowsExecutor killer = new WindowsExecutor( - "taskkill.exe", "/F /PID " + pidToKill + " /T", null); - - Thread tk = new Thread(killer); - tk.start(); - } else { - nativeProcess.destroy(); - } - } - - @Override - public InputStream getErrorStream() { - return nativeProcess.getErrorStream(); - } - - @Override - public InputStream getInputStream() { - return nativeProcess.getInputStream(); - } - - @Override - public OutputStream getOutputStream() { - return nativeProcess.getOutputStream(); - } - - @Override - public int waitFor() throws InterruptedException { - return nativeProcess.waitFor(); - } - - @Override - public int exitValue() { - return nativeProcess.exitValue(); - } - - private static class WindowsExecutor implements Runnable { - - private final String cmd; - - private final String args; - - private final String nameToFilter; - - private String pid; - - public WindowsExecutor(String cmd, String args, String nameToFilter) { - this.cmd = cmd; - this.args = args; - this.nameToFilter = nameToFilter; - } - - public String getPid() { - return pid; - } - - public void run() { - NbProcessDescriptor cmdProcessDesc = new NbProcessDescriptor(cmd, args); - - try { - Process utilityProcess = cmdProcessDesc.exec(null, null, true, null); - - if (utilityProcess == null) { - return; - } - - utilityProcess.getOutputStream().close(); - - // we wait till the process finishes. De-coupling is done a layer above. - try { - utilityProcess.waitFor(); - } catch (InterruptedException ex) { - LOGGER.log(Level.FINEST, null, ex); - } - - if (nameToFilter == null) { - return; - } - - BufferedReader procOutput = new BufferedReader( - new InputStreamReader(utilityProcess.getInputStream())); - try { - String errString; - while ((errString = procOutput.readLine()) != null) { - - String regEx = ".*grails.bat +run-app +REM NB:" + nameToFilter + ".*"; // NOI18N - - if (errString.matches(regEx)) { - String nbTag = "REM NB:" + nameToFilter; // NOI18N - int idx = errString.indexOf(nbTag); - idx = idx + nbTag.length(); - pid = errString.substring(idx).trim(); - LOGGER.log(Level.FINEST, "Found: " + pid); - } - } - } finally { - procOutput.close(); - } - } catch (IOException ex) { - LOGGER.log(Level.INFO, "Project exec() problem", ex); - } - } - } -} diff -r 319e1ef53880 groovy.grails/src/org/netbeans/modules/groovy/grails/api/GrailsRuntime.java --- a/groovy.grails/src/org/netbeans/modules/groovy/grails/api/GrailsRuntime.java Thu Jul 10 18:07:52 2008 +0200 +++ b/groovy.grails/src/org/netbeans/modules/groovy/grails/api/GrailsRuntime.java Fri Jul 11 16:49:04 2008 +0200 @@ -53,7 +53,6 @@ import org.netbeans.api.java.platform.JavaPlatformManager; import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; -import org.netbeans.modules.groovy.grails.KillableProcess; import org.netbeans.modules.groovy.grails.RuntimeHelper; import org.netbeans.modules.groovy.grails.server.GrailsInstance; import org.netbeans.modules.groovy.grails.server.GrailsInstanceProvider; @@ -420,9 +419,8 @@ "JAVA_HOME=" + javaHome // NOI18N }; - Process process = new KillableProcess( - grailsProcessDesc.exec(null, envp, true, descriptor.getDirectory()), - descriptor.getDirectory()); + Process process = + grailsProcessDesc.exec(null, envp, true, descriptor.getDirectory()); checkForServer(descriptor, process); return process;