diff -r 30713016fbce extexecution/manifest.mf
--- a/extexecution/manifest.mf Tue Jul 22 15:19:59 2008 +0200
+++ b/extexecution/manifest.mf Tue Jul 22 16:59:33 2008 +0200
@@ -2,5 +2,5 @@
AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.netbeans.modules.extexecution/0
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/extexecution/resources/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.7
+OpenIDE-Module-Specification-Version: 1.8
diff -r 30713016fbce extexecution/src/org/netbeans/modules/extexecution/api/ExternalProcessBuilder.java
--- a/extexecution/src/org/netbeans/modules/extexecution/api/ExternalProcessBuilder.java Tue Jul 22 15:19:59 2008 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,325 +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.extexecution.api;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.prefs.Preferences;
-import org.openide.util.NbPreferences;
-import org.openide.util.Parameters;
-import org.openide.util.Utilities;
-
-/**
- * Utility class to make the external process creation easier.
- *
- * Builder handle command, working directory, PATH
variable and HTTP proxy.
- *
- * This class is not thread safe.
- *
- * @author Petr Hejl
- * @see #create()
- */
-public final class ExternalProcessBuilder {
-
- // FIXME: get rid of those proxy constants as soon as some NB Proxy API is available
- private static final String USE_PROXY_AUTHENTICATION = "useProxyAuthentication"; // NOI18N
-
- private static final String PROXY_AUTHENTICATION_USERNAME = "proxyAuthenticationUsername"; // NOI18N
-
- private static final String PROXY_AUTHENTICATION_PASSWORD = "proxyAuthenticationPassword"; // NOI18N
-
- private final String command;
-
- private File workingDirectory;
-
- private boolean redirectErrorStream;
-
- private final List arguments = new ArrayList();
-
- private final List paths = new ArrayList();
-
- private final Map envVariables = new HashMap();
-
- /**
- * Creates the new builder that will create the process by running
- * given executable. Arguments must not be part of the string.
- *
- * @param executable executable to run
- */
- public ExternalProcessBuilder(String executable) {
- this.command = executable;
- }
-
- /**
- * Sets this builder's working directory. Process subsequently created
- * by {@link #create()} method will be executed with this directory
- * as current working dir.
- *
- * Note that each process has always working directory even when not
- * configured explicitly (the value of user.dir
property).
- *
- * @param workingDirectory working directory
- * @return this process builder
- */
- public ExternalProcessBuilder workingDirectory(File workingDirectory) {
- Parameters.notNull("workingDirectory", workingDirectory);
-
- this.workingDirectory = workingDirectory;
- return this;
- }
-
- /**
- * Configures whether the error stream of created process should be
- * redirected to standard output.
- *
- * If passed value is true
error stream will be redirected
- * to standard output.
- *
- * @param redirectErrorStream if true
error stream will be
- * redirected to standard output
- * @return this process builder
- */
- public ExternalProcessBuilder redirectErrorStream(boolean redirectErrorStream) {
- this.redirectErrorStream = redirectErrorStream;
- return this;
- }
-
- /**
- * Configures the additional path to add to the PATH
variable.
- *
- * In the group of paths added by this call the last added path will
- * be the first one in the PATH
variable.
- *
- * @param path path to add to PATH
variable
- * @return this process builder
- */
- public ExternalProcessBuilder prependPath(File path) {
- Parameters.notNull("path", path);
-
- paths.add(path);
- return this;
- }
-
- /**
- * Configures the additional argument for the command. Arguments are added
- * in the same order in which they are added.
- *
- * @param argument command argument to add
- * @return this process builder
- */
- public ExternalProcessBuilder addArgument(String argument) {
- Parameters.notNull("arg", argument);
-
- arguments.add(argument);
- return this;
- }
-
- /**
- * Configures the additional environment variable for the command.
- *
- * @param name name of the variable
- * @param value value of the variable
- * @return this process builder
- * @see #create()
- */
- public ExternalProcessBuilder addEnvironmentVariable(String name, String value) {
- Parameters.notNull("name", name);
- Parameters.notNull("value", value);
-
- envVariables.put(name, value);
- return this;
- }
-
- /**
- * Creates the new {@link Process} based on the properties configured
- * in this builder.
- *
- * Process is created by executing the command with configured arguments.
- * If custom working directory is specified it is used otherwise value
- * of system property user.dir
is used as working dir.
- *
- * Environment variables are prepared in following way:
- *
- * - Get table of system environment variables.
- *
- Put all environment variables configured by
- * {@link #addEnvironmentVariable(java.lang.String, java.lang.String)}.
- * This rewrites system variables if conflict occurs.
- *
- Get
PATH
variable and append all paths added
- * by {@link #prependPath(java.io.File)}. The order of paths in PATH
- * variable is reversed to order of addition (the last added is the first
- * one in PATH
). Original content of PATH
follows
- * the added content.
- * - HTTP proxy settings are configured (http.proxyHost and http.proxyPort
- * variables).
- *
- * @return the new {@link Process} based on the properties configured
- * in this builder
- */
- public Process create() throws IOException {
- List commandL = new ArrayList();
-
- commandL.add(command);
-
- List args = buildArguments();
- commandL.addAll(args);
- String[] command = commandL.toArray(new String[commandL.size()]);
-
- if ((command != null) && Utilities.isWindows()) {
- for (int i = 0; i < command.length; i++) {
- if ((command[i] != null) && (command[i].indexOf(' ') != -1) &&
- (command[i].indexOf('"') == -1)) { // NOI18N
- command[i] = '"' + command[i] + '"'; // NOI18N
- }
- }
- }
- ProcessBuilder pb = new ProcessBuilder(command);
- if (workingDirectory != null) {
- pb.directory(workingDirectory);
- }
-
- Map pbEnv = pb.environment();
- Map env = buildEnvironment(pbEnv);
- pbEnv.putAll(env);
- adjustProxy(pb);
- pb.redirectErrorStream(redirectErrorStream);
- return pb.start();
- }
-
- // package level for unit testing
- Map buildEnvironment(Map original) {
- Map ret = new HashMap(original);
- ret.putAll(envVariables);
-
- // Find PATH environment variable - on Windows it can be some other
- // case and we should use whatever it has.
- String pathName = "PATH"; // NOI18N
-
- if (Utilities.isWindows()) {
- pathName = "Path"; // NOI18N
-
- for (String key : ret.keySet()) {
- if ("PATH".equals(key.toUpperCase(Locale.ENGLISH))) { // NOI18N
- pathName = key;
-
- break;
- }
- }
- }
-
- // TODO use StringBuilder
- String currentPath = ret.get(pathName);
-
- if (currentPath == null) {
- currentPath = "";
- }
-
- for (File path : paths) {
- currentPath = path.getAbsolutePath().replace(" ", "\\ ") //NOI18N
- + File.pathSeparator + currentPath;
- }
-
- if (!"".equals(currentPath.trim())) {
- ret.put(pathName, currentPath);
- }
- return ret;
- }
-
- private List buildArguments() {
- return new ArrayList(arguments);
- }
-
- private void adjustProxy(ProcessBuilder pb) {
- String proxy = getNetBeansHttpProxy();
- if (proxy != null) {
- Map env = pb.environment();
- if ((env.get("HTTP_PROXY") == null) && (env.get("http_proxy") == null)) { // NOI18N
- env.put("HTTP_PROXY", proxy); // NOI18N
- env.put("http_proxy", proxy); // NOI18N
- }
- // PENDING - what if proxy was null so the user has TURNED off
- // proxies while there is still an environment variable set - should
- // we honor their environment, or honor their NetBeans proxy
- // settings (e.g. unset HTTP_PROXY in the environment before
- // launching plugin?
- }
- }
-
- /**
- * FIXME: get rid of the whole method as soon as some NB Proxy API is
- * available.
- */
- private static String getNetBeansHttpProxy() {
- // FIXME use ProxySelector
-
- String host = System.getProperty("http.proxyHost"); // NOI18N
-
- if (host == null) {
- return null;
- }
-
- String portHttp = System.getProperty("http.proxyPort"); // NOI18N
- int port;
-
- try {
- port = Integer.parseInt(portHttp);
- } catch (NumberFormatException e) {
- port = 8080;
- }
-
- Preferences prefs = NbPreferences.root().node("org/netbeans/core"); // NOI18N
- boolean useAuth = prefs.getBoolean(USE_PROXY_AUTHENTICATION, false);
- String auth = "";
- if (useAuth) {
- auth = prefs.get(PROXY_AUTHENTICATION_USERNAME, "") + ":" + prefs.get(PROXY_AUTHENTICATION_PASSWORD, "") + '@'; // NOI18N
- }
-
- // Gem requires "http://" in front of the port name if it's not already there
- if (host.indexOf(':') == -1) {
- host = "http://" + auth + host; // NOI18N
- }
-
- return host + ":" + port; // NOI18N
- }
-}
diff -r 30713016fbce extexecution/src/org/netbeans/modules/extexecution/api/ExternalProcessCreator.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/extexecution/src/org/netbeans/modules/extexecution/api/ExternalProcessCreator.java Tue Jul 22 16:59:33 2008 +0200
@@ -0,0 +1,419 @@
+/*
+ * 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.api;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.prefs.Preferences;
+import org.openide.util.NbPreferences;
+import org.openide.util.Parameters;
+import org.openide.util.Utilities;
+
+/**
+ * Utility class to make the external process creation easier.
+ *
+ * Builder handle command, working directory, PATH
variable and HTTP proxy.
+ *
+ * This class is immutable.
+ *
+ * @author Petr Hejl
+ * @see #call()
+ */
+public final class ExternalProcessCreator implements Callable {
+
+ // FIXME: get rid of those proxy constants as soon as some NB Proxy API is available
+ private static final String USE_PROXY_AUTHENTICATION = "useProxyAuthentication"; // NOI18N
+
+ private static final String PROXY_AUTHENTICATION_USERNAME = "proxyAuthenticationUsername"; // NOI18N
+
+ private static final String PROXY_AUTHENTICATION_PASSWORD = "proxyAuthenticationPassword"; // NOI18N
+
+ private final String executable;
+
+ private final File workingDirectory;
+
+ private final boolean redirectErrorStream;
+
+ private final List arguments = new ArrayList();
+
+ private final List paths = new ArrayList();
+
+ private final Map envVariables = new HashMap();
+
+ /**
+ * Creates the new creator that will create the process by running
+ * given executable. Arguments must not be part of the string.
+ *
+ * @param executable executable to run
+ */
+ public ExternalProcessCreator(String executable) {
+ this.executable = executable;
+ this.workingDirectory = null;
+ this.redirectErrorStream = false;
+ }
+
+ private ExternalProcessCreator(Builder builder) {
+ this.executable = builder.executable;
+ this.workingDirectory = builder.workingDirectory;
+ this.redirectErrorStream = builder.redirectErrorStream;
+ this.arguments.addAll(builder.arguments);
+ this.paths.addAll(builder.paths);
+ this.envVariables.putAll(builder.envVariables);
+ }
+
+ /**
+ * Returns a creator with configured working directory. Process
+ * subsequently created by the {@link #call()} method on returned creator
+ * will be executed with this directory as current working dir.
+ *
+ * The default value is null
. Note that each process has
+ * always working directory even when not configured explicitly (the value
+ * of user.dir
property).
+ *
+ * All other properties of the returned creator are inherited from
+ * this
.
+ *
+ * @param workingDirectory working directory
+ * @return new creator with configured working directory
+ */
+ public ExternalProcessCreator workingDirectory(File workingDirectory) {
+ Parameters.notNull("workingDirectory", workingDirectory);
+
+ Builder builder = new Builder(this);
+ return new ExternalProcessCreator(builder.workingDirectory(workingDirectory));
+ }
+
+ /**
+ * Returns a creator with configured error stream redirection. If configured
+ * value is true
process subsequently created by
+ * the {@link #call()} method on returned creator will redirect the error
+ * stream to the standard output stream.
+ *
+ * The default value is false
.
+ *
+ * All other properties of the returned creator are inherited from
+ * this
.
+ *
+ * @param redirectErrorStream if true
error stream will be
+ * redirected to standard output
+ * @return new creator with configured error stream redirection
+ */
+ public ExternalProcessCreator redirectErrorStream(boolean redirectErrorStream) {
+ Builder builder = new Builder(this);
+ return new ExternalProcessCreator(builder.redirectErrorStream(redirectErrorStream));
+ }
+
+ /**
+ * Returns a creator with additional path in PATH
variable.
+ *
+ * In the group of paths added by this call the last added path will
+ * be the first one in the PATH
variable.
+ *
+ * By default no additional paths are added to PATH
variable.
+ *
+ * All other properties of the returned creator are inherited from
+ * this
.
+ *
+ * @param path path to add to PATH
variable
+ * @return new creator with additional path in PATH
variable
+ */
+ public ExternalProcessCreator prependPath(File path) {
+ Parameters.notNull("path", path);
+
+ Builder builder = new Builder(this);
+ return new ExternalProcessCreator(builder.prependPath(path));
+ }
+
+ /**
+ * Returns a creator with additional argument for the command. Arguments
+ * are passed to executable in the same order in which they are added.
+ *
+ * By default no additional arguments are passed to executable.
+ *
+ * All other properties of the returned creator are inherited from
+ * this
.
+ *
+ * @param argument command argument to add
+ * @return new creator with additional argument for the command
+ */
+ public ExternalProcessCreator addArgument(String argument) {
+ Parameters.notNull("argument", argument);
+
+ Builder builder = new Builder(this);
+ return new ExternalProcessCreator(builder.addArgument(argument));
+ }
+
+ /**
+ * Returns a creator with additional environment variable for the command.
+ *
+ * By default no additional environment variables are configured.
+ *
+ * All other properties of the returned creator are inherited from
+ * this
.
+ *
+ * @param name name of the variable
+ * @param value value of the variable
+ * @return new creator with additional environment variable for the command
+ * @see #call()
+ */
+ public ExternalProcessCreator addEnvironmentVariable(String name, String value) {
+ Parameters.notNull("name", name);
+ Parameters.notNull("value", value);
+
+ Builder builder = new Builder(this);
+ return new ExternalProcessCreator(builder.addEnvironmentVariable(name, value));
+ }
+
+ /**
+ * Creates the new {@link Process} based on the properties configured
+ * in this creator.
+ *
+ * Process is created by executing the executable with configured arguments.
+ * If custom working directory is specified it is used otherwise value
+ * of system property user.dir
is used as working dir.
+ *
+ * Environment variables are prepared in following way:
+ *
+ * - Get table of system environment variables.
+ *
- Put all environment variables configured by
+ * {@link #addEnvironmentVariable(java.lang.String, java.lang.String)}.
+ * This rewrites system variables if conflict occurs.
+ *
- Get
PATH
variable and append all paths added
+ * by {@link #prependPath(java.io.File)}. The order of paths in PATH
+ * variable is reversed to order of addition (the last added is the first
+ * one in PATH
). Original content of PATH
follows
+ * the added content.
+ * - HTTP proxy settings for the spawned process are stored as
+ *
http_proxy
environment variable
+ * (http://username:password@host:port/
).
+ *
+ * @return the new {@link Process} based on the properties configured
+ * in this builder
+ */
+ public Process call() throws IOException {
+ List commandL = new ArrayList();
+
+ commandL.add(executable);
+
+ List args = buildArguments();
+ commandL.addAll(args);
+ String[] command = commandL.toArray(new String[commandL.size()]);
+
+ if ((command != null) && Utilities.isWindows()) {
+ for (int i = 0; i < command.length; i++) {
+ if ((command[i] != null) && (command[i].indexOf(' ') != -1) &&
+ (command[i].indexOf('"') == -1)) { // NOI18N
+ command[i] = '"' + command[i] + '"'; // NOI18N
+ }
+ }
+ }
+ ProcessBuilder pb = new ProcessBuilder(command);
+ if (workingDirectory != null) {
+ pb.directory(workingDirectory);
+ }
+
+ Map pbEnv = pb.environment();
+ Map env = buildEnvironment(pbEnv);
+ pbEnv.putAll(env);
+ adjustProxy(pb);
+ pb.redirectErrorStream(redirectErrorStream);
+ return pb.start();
+ }
+
+ // package level for unit testing
+ Map buildEnvironment(Map original) {
+ Map ret = new HashMap(original);
+ ret.putAll(envVariables);
+
+ // Find PATH environment variable - on Windows it can be some other
+ // case and we should use whatever it has.
+ String pathName = "PATH"; // NOI18N
+
+ if (Utilities.isWindows()) {
+ pathName = "Path"; // NOI18N
+
+ for (String key : ret.keySet()) {
+ if ("PATH".equals(key.toUpperCase(Locale.ENGLISH))) { // NOI18N
+ pathName = key;
+
+ break;
+ }
+ }
+ }
+
+ // TODO use StringBuilder
+ String currentPath = ret.get(pathName);
+
+ if (currentPath == null) {
+ currentPath = "";
+ }
+
+ for (File path : paths) {
+ currentPath = path.getAbsolutePath().replace(" ", "\\ ") //NOI18N
+ + File.pathSeparator + currentPath;
+ }
+
+ if (!"".equals(currentPath.trim())) {
+ ret.put(pathName, currentPath);
+ }
+ return ret;
+ }
+
+ private List buildArguments() {
+ return new ArrayList(arguments);
+ }
+
+ private void adjustProxy(ProcessBuilder pb) {
+ String proxy = getNetBeansHttpProxy();
+ if (proxy != null) {
+ Map env = pb.environment();
+ if ((env.get("HTTP_PROXY") == null) && (env.get("http_proxy") == null)) { // NOI18N
+ env.put("HTTP_PROXY", proxy); // NOI18N
+ env.put("http_proxy", proxy); // NOI18N
+ }
+ // PENDING - what if proxy was null so the user has TURNED off
+ // proxies while there is still an environment variable set - should
+ // we honor their environment, or honor their NetBeans proxy
+ // settings (e.g. unset HTTP_PROXY in the environment before
+ // launching plugin?
+ }
+ }
+
+ /**
+ * FIXME: get rid of the whole method as soon as some NB Proxy API is
+ * available.
+ */
+ private static String getNetBeansHttpProxy() {
+ // FIXME use ProxySelector
+
+ String host = System.getProperty("http.proxyHost"); // NOI18N
+
+ if (host == null) {
+ return null;
+ }
+
+ String portHttp = System.getProperty("http.proxyPort"); // NOI18N
+ int port;
+
+ try {
+ port = Integer.parseInt(portHttp);
+ } catch (NumberFormatException e) {
+ port = 8080;
+ }
+
+ Preferences prefs = NbPreferences.root().node("org/netbeans/core"); // NOI18N
+ boolean useAuth = prefs.getBoolean(USE_PROXY_AUTHENTICATION, false);
+ String auth = "";
+ if (useAuth) {
+ auth = prefs.get(PROXY_AUTHENTICATION_USERNAME, "") + ":" + prefs.get(PROXY_AUTHENTICATION_PASSWORD, "") + '@'; // NOI18N
+ }
+
+ // Gem requires "http://" in front of the port name if it's not already there
+ if (host.indexOf(':') == -1) {
+ host = "http://" + auth + host; // NOI18N
+ }
+
+ return host + ":" + port; // NOI18N
+ }
+
+ private static class Builder {
+
+ private final String executable;
+
+ private File workingDirectory;
+
+ private boolean redirectErrorStream;
+
+ private List arguments = new ArrayList();
+
+ private List paths = new ArrayList();
+
+ private Map envVariables = new HashMap();
+
+ public Builder(ExternalProcessCreator creator) {
+ this.executable = creator.executable;
+ this.workingDirectory = creator.workingDirectory;
+ this.redirectErrorStream = creator.redirectErrorStream;
+ this.arguments.addAll(creator.arguments);
+ this.paths.addAll(creator.paths);
+ this.envVariables.putAll(creator.envVariables);
+ }
+
+ public Builder workingDirectory(File workingDirectory) {
+ assert workingDirectory != null;
+
+ this.workingDirectory = workingDirectory;
+ return this;
+ }
+
+ public Builder redirectErrorStream(boolean redirectErrorStream) {
+ this.redirectErrorStream = redirectErrorStream;
+ return this;
+ }
+
+ public Builder prependPath(File path) {
+ assert path != null;
+
+ paths.add(path);
+ return this;
+ }
+
+ public Builder addArgument(String argument) {
+ assert argument != null;
+
+ arguments.add(argument);
+ return this;
+ }
+
+ public Builder addEnvironmentVariable(String name, String value) {
+ assert name != null;
+ assert value != null;
+
+ envVariables.put(name, value);
+ return this;
+ }
+ }
+}
diff -r 30713016fbce extexecution/test/unit/src/org/netbeans/modules/extexecution/api/ExternalProcessBuilderTest.java
--- a/extexecution/test/unit/src/org/netbeans/modules/extexecution/api/ExternalProcessBuilderTest.java Tue Jul 22 15:19:59 2008 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +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.extexecution.api;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import org.netbeans.junit.NbTestCase;
-
-/**
- *
- * @author Petr Hejl
- */
-public class ExternalProcessBuilderTest extends NbTestCase {
-
- public ExternalProcessBuilderTest(String name) {
- super(name);
- }
-
- public void testEnvironment() {
- ExternalProcessBuilder builder = new ExternalProcessBuilder("command");
- builder.addEnvironmentVariable("test1", "value1");
- builder.addEnvironmentVariable("test2", "value2");
-
- Map env = new HashMap(
- builder.buildEnvironment(Collections.emptyMap()));
- assertEquals("value1", env.remove("test1"));
- assertEquals("value2", env.remove("test2"));
- assertTrue(env.isEmpty());
- }
-
- public void testPath() {
- ExternalProcessBuilder builder = new ExternalProcessBuilder("command");
- Map original = new HashMap();
- original.put("PATH", "original");
-
- // original path
- Map env = new HashMap(
- builder.buildEnvironment(original));
- assertEquals("original", env.remove("PATH"));
- assertTrue(env.isEmpty());
-
- // some added path
- File addedPath = new File("addedPath");
- builder.prependPath(addedPath);
- env = new HashMap(builder.buildEnvironment(original));
- assertEquals(addedPath.getAbsolutePath() + File.pathSeparator + "original", env.remove("PATH"));
- assertTrue(env.isEmpty());
-
- // yet another path
- File nextPath = new File("nextPath");
- builder.prependPath(nextPath);
- env = new HashMap(builder.buildEnvironment(original));
- assertEquals(
- nextPath.getAbsolutePath() + File.pathSeparator
- + addedPath.getAbsolutePath() + File.pathSeparator
- + "original", env.remove("PATH"));
- assertTrue(env.isEmpty());
- }
-}
diff -r 30713016fbce extexecution/test/unit/src/org/netbeans/modules/extexecution/api/ExternalProcessCreatorTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/extexecution/test/unit/src/org/netbeans/modules/extexecution/api/ExternalProcessCreatorTest.java Tue Jul 22 16:59:33 2008 +0200
@@ -0,0 +1,98 @@
+/*
+ * 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.api;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.netbeans.junit.NbTestCase;
+
+/**
+ *
+ * @author Petr Hejl
+ */
+public class ExternalProcessCreatorTest extends NbTestCase {
+
+ public ExternalProcessCreatorTest(String name) {
+ super(name);
+ }
+
+ public void testEnvironment() {
+ ExternalProcessCreator creator = new ExternalProcessCreator("command");
+ creator = creator.addEnvironmentVariable("test1", "value1");
+ creator = creator.addEnvironmentVariable("test2", "value2");
+
+ Map env = new HashMap(
+ creator.buildEnvironment(Collections.emptyMap()));
+ assertEquals("value1", env.remove("test1"));
+ assertEquals("value2", env.remove("test2"));
+ assertTrue(env.isEmpty());
+ }
+
+ public void testPath() {
+ ExternalProcessCreator creator = new ExternalProcessCreator("command");
+ Map original = new HashMap();
+ original.put("PATH", "original");
+
+ // original path
+ Map env = new HashMap(
+ creator.buildEnvironment(original));
+ assertEquals("original", env.remove("PATH"));
+ assertTrue(env.isEmpty());
+
+ // some added path
+ File addedPath = new File("addedPath");
+ creator = creator.prependPath(addedPath);
+ env = new HashMap(creator.buildEnvironment(original));
+ assertEquals(addedPath.getAbsolutePath() + File.pathSeparator + "original", env.remove("PATH"));
+ assertTrue(env.isEmpty());
+
+ // yet another path
+ File nextPath = new File("nextPath");
+ creator = creator.prependPath(nextPath);
+ env = new HashMap(creator.buildEnvironment(original));
+ assertEquals(
+ nextPath.getAbsolutePath() + File.pathSeparator
+ + addedPath.getAbsolutePath() + File.pathSeparator
+ + "original", env.remove("PATH"));
+ assertTrue(env.isEmpty());
+ }
+}