This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 138116
Collapse All | Expand All

(-)a/extexecution/apichanges.xml (+16 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
    <changes>
109
    <changes>
110
111
        <change>
112
            <api name="extexecution_api"/>
113
            <summary>New SPI for improved external process termination</summary>
114
            <version major="1" minor="16"/>
115
            <date day="1" month="7" year="2008"/>
116
            <author login="mkleint"/>
117
            <compatibility binary="compatible" source="compatible" semantic="compatible"/>
118
            <description>
119
120
            </description>
121
            <class package="org.netbeans.spi.extexecution.destroy" name="DestroyUtils"/>
122
            <class package="org.netbeans.spi.extexecution.destroy" name="ProcessDestroyPerformer"/>
123
            <issue number="138116"/>
124
        </change>
125
110
        <change>
126
        <change>
111
            <api name="extexecution_api"/>
127
            <api name="extexecution_api"/>
112
            <summary>Configurable charset for process streams</summary>
128
            <summary>Configurable charset for process streams</summary>
(-)a/extexecution/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
AutoUpdate-Show-In-Client: false
2
AutoUpdate-Show-In-Client: false
3
OpenIDE-Module: org.netbeans.modules.extexecution/2
3
OpenIDE-Module: org.netbeans.modules.extexecution/2
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/extexecution/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/extexecution/resources/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.15
5
OpenIDE-Module-Specification-Version: 1.16
6
6
(-)a/extexecution/nbproject/project.xml (+1 lines)
Lines 110-115 Link Here
110
                <package>org.netbeans.api.extexecution</package>
110
                <package>org.netbeans.api.extexecution</package>
111
                <package>org.netbeans.api.extexecution.print</package>
111
                <package>org.netbeans.api.extexecution.print</package>
112
                <package>org.netbeans.api.extexecution.input</package>
112
                <package>org.netbeans.api.extexecution.input</package>
113
                <package>org.netbeans.spi.extexecution.destroy</package>
113
            </public-packages>
114
            </public-packages>
114
        </data>
115
        </data>
115
    </configuration>
116
    </configuration>
(-)a/extexecution/src/org/netbeans/api/extexecution/ExternalProcessBuilder.java (-1 / +12 lines)
Lines 41-58 Link Here
41
41
42
import java.io.File;
42
import java.io.File;
43
import java.io.IOException;
43
import java.io.IOException;
44
import java.io.InputStream;
45
import java.io.OutputStream;
44
import java.util.ArrayList;
46
import java.util.ArrayList;
47
import java.util.Collections;
45
import java.util.HashMap;
48
import java.util.HashMap;
46
import java.util.Iterator;
49
import java.util.Iterator;
47
import java.util.List;
50
import java.util.List;
48
import java.util.Locale;
51
import java.util.Locale;
49
import java.util.Map;
52
import java.util.Map;
53
import java.util.UUID;
50
import java.util.concurrent.Callable;
54
import java.util.concurrent.Callable;
51
import java.util.logging.Level;
55
import java.util.logging.Level;
52
import java.util.logging.Logger;
56
import java.util.logging.Logger;
53
import java.util.prefs.Preferences;
57
import java.util.prefs.Preferences;
54
import org.netbeans.api.annotations.common.CheckReturnValue;
58
import org.netbeans.api.annotations.common.CheckReturnValue;
55
import org.netbeans.api.annotations.common.NonNull;
59
import org.netbeans.api.annotations.common.NonNull;
60
import org.netbeans.modules.extexecution.WrapperProcess;
61
import org.netbeans.spi.extexecution.destroy.DestroyUtils;
56
import org.openide.util.NbPreferences;
62
import org.openide.util.NbPreferences;
57
import org.openide.util.Parameters;
63
import org.openide.util.Parameters;
58
import org.openide.util.Utilities;
64
import org.openide.util.Utilities;
Lines 282-291 Link Here
282
        Map<String, String> pbEnv = pb.environment();
288
        Map<String, String> pbEnv = pb.environment();
283
        Map<String, String> env = buildEnvironment(pbEnv);
289
        Map<String, String> env = buildEnvironment(pbEnv);
284
        pbEnv.putAll(env);
290
        pbEnv.putAll(env);
291
        String uuid = UUID.randomUUID().toString();
292
        pbEnv.put(DestroyUtils.KEY_UUID, uuid);
285
        adjustProxy(pb);
293
        adjustProxy(pb);
286
        pb.redirectErrorStream(redirectErrorStream);
294
        pb.redirectErrorStream(redirectErrorStream);
287
        logProcess(Level.FINE, pb);
295
        logProcess(Level.FINE, pb);
288
        return pb.start();
296
        WrapperProcess wp = new WrapperProcess(pb.start(), uuid);
297
        return wp;
289
    }
298
    }
290
299
291
    /**
300
    /**
Lines 472-475 Link Here
472
            return this;
481
            return this;
473
        }
482
        }
474
    }
483
    }
484
485
475
}
486
}
(-)e037d7739650 (+90 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.extexecution;
41
42
import java.io.InputStream;
43
import java.io.OutputStream;
44
import java.util.Collections;
45
import org.netbeans.spi.extexecution.destroy.DestroyUtils;
46
47
/**
48
 *
49
 * @author mkleint
50
 */
51
public class WrapperProcess extends Process {
52
        private final String uuid;
53
        private final Process del;
54
55
        public WrapperProcess(Process delegate, String uuid) {
56
            this.del = delegate;
57
            this.uuid = uuid;
58
        }
59
60
        @Override
61
        public OutputStream getOutputStream() {
62
            return del.getOutputStream();
63
        }
64
65
        @Override
66
        public InputStream getInputStream() {
67
            return del.getInputStream();
68
        }
69
70
        @Override
71
        public InputStream getErrorStream() {
72
            return del.getErrorStream();
73
        }
74
75
        @Override
76
        public int waitFor() throws InterruptedException {
77
            return del.waitFor();
78
        }
79
80
        @Override
81
        public int exitValue() {
82
            return del.exitValue();
83
        }
84
85
        @Override
86
        public void destroy() {
87
            DestroyUtils.destroy(del, Collections.singletonMap(DestroyUtils.KEY_UUID, uuid));
88
        }
89
90
}
(-)e037d7739650 (+85 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.extexecution.destroy;
41
42
import java.util.Map;
43
import org.netbeans.modules.extexecution.WrapperProcess;
44
import org.openide.util.Lookup;
45
46
/**
47
 * Utility class capable of properly terminating external process along with any
48
 * child processes created during execution.
49
 *
50
 * @author mkleint
51
 * @since 1.16
52
 */
53
public class DestroyUtils {
54
55
    private DestroyUtils() {
56
57
    }
58
59
    /**
60
     * The default environment variable key to be used to identify process trees
61
     * in <code>destroy</code> method.
62
     */
63
    public static final String KEY_UUID = "NB_EXEC_PROCESS_UUID"; //NOI18N
64
65
    /**
66
     * Destroys the process passed as parameter and attempts to terminate all child
67
     * processes created during the process' execution.
68
     * @param prcs process to kill
69
     * @param env Map containing environment variable names and values.
70
     *            Any process running with such envvar's value will be terminated.
71
     *            Improves localization of child processes.
72
     */
73
    public static void destroy(Process prcs, Map<String, String> env) {
74
        if (prcs instanceof WrapperProcess) {
75
            prcs.destroy();
76
            return;
77
        }
78
        ProcessDestroyPerformer pdp = Lookup.getDefault().lookup(ProcessDestroyPerformer.class);
79
        if (pdp != null) {
80
            pdp.destroy(prcs, env);
81
        } else {
82
            prcs.destroy();
83
        }
84
    }
85
}
(-)e037d7739650 (+69 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.spi.extexecution.destroy;
41
42
import java.util.Map;
43
44
/**
45
 * A service capable of properly terminating external process along with any
46
 * child processes created during execution.
47
 *
48
 * Note: not to be implemented by modules, might not be present in all versions of
49
 * the application.
50
 * Please use <code>DestroyUtils.destroy()</code> for accessing the service.
51
 *
52
 * @author mkleint
53
 * @since 1.16
54
 */
55
public interface ProcessDestroyPerformer {
56
57
    /**
58
     * Destroys the process passed as parameter and attempts to terminate all child
59
     * processes created during the process' execution.
60
     * @param process process to kill
61
     * @param env Map containing environment variable names and values.
62
     *            Any process running with such envvar's value will be terminated.
63
     *            Improves localization of child processes.
64
     *
65
     * @param process
66
     * @param env
67
     */
68
    void destroy(Process process, Map<String, String> env);
69
}
(-)e037d7739650 (+48 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
/**
43
 * The support SPI for terminating external processes.
44
 *
45
 * @see org.netbeans.spi.extexecution.destroy.DestroyUtils
46
 */
47
package org.netbeans.spi.extexecution.destroy;
48

Return to bug 138116