aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/shell
diff options
context:
space:
mode:
authorGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-16 13:34:57 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-16 13:34:57 +0000
commitefe7f66b9c8e3eae7e3f6a953af9b88111b34cd1 (patch)
tree5d6a772ad9e20f1b9407bd9700a76380202541d6 /src/main/java/com/google/devtools/build/lib/shell
parent33d0368f977bc71b82c59cddd29cb556da37a97f (diff)
Remove shell.Shell. The windows support is unused.
-- MOS_MIGRATED_REVID=86427416
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/shell')
-rw-r--r--src/main/java/com/google/devtools/build/lib/shell/Command.java63
-rw-r--r--src/main/java/com/google/devtools/build/lib/shell/Shell.java132
2 files changed, 1 insertions, 194 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/shell/Command.java b/src/main/java/com/google/devtools/build/lib/shell/Command.java
index ab4a7fc971..70c5f8a1a6 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/Command.java
+++ b/src/main/java/com/google/devtools/build/lib/shell/Command.java
@@ -177,25 +177,6 @@ public final class Command {
}
/**
- * <p>Creates a new {@link Command} for the given command line elements.
- * Subsequent calls to {@link #execute()} will use the JVM's working
- * directory and environment.</p>
- *
- * <p>Note: be careful when setting useShell to <code>true</code>; you
- * may inadvertently expose a security hole. See
- * {@link #Command(String, Map, File)}.</p>
- *
- * @param commandLineElements elements of raw command line to execute
- * @param useShell if true, command is executed using a shell interpreter
- * (e.g. <code>/bin/sh</code> on Linux); if false, command is executed
- * exactly as given
- * @throws IllegalArgumentException if commandLine is null or empty
- */
- public Command(final String[] commandLineElements, final boolean useShell) {
- this(commandLineElements, useShell, null, null);
- }
-
- /**
* Creates a new {@link Command} for the given command line elements. The
* command line is executed exactly as given, without a shell. The given
* environment variables and working directory are used in subsequent
@@ -211,37 +192,11 @@ public final class Command {
public Command(final String[] commandLineElements,
final Map<String, String> environmentVariables,
final File workingDirectory) {
- this(commandLineElements, false, environmentVariables, workingDirectory);
- }
-
- /**
- * <p>Creates a new {@link Command} for the given command line elements. The
- * given environment variables and working directory are used in subsequent
- * calls to {@link #execute()}.</p>
- *
- * <p>Note: be careful when setting useShell to <code>true</code>; you
- * may inadvertently expose a security hole. See
- * {@link #Command(String, Map, File)}.</p>
- *
- * @param commandLineElements elements of raw command line to execute
- * @param useShell if true, command is executed using a shell interpreter
- * (e.g. <code>/bin/sh</code> on Linux); if false, command is executed
- * exactly as given
- * @param environmentVariables environment variables to replace JVM's
- * environment variables; may be null
- * @param workingDirectory working directory for execution; if null, current
- * working directory is used
- * @throws IllegalArgumentException if commandLine is null or empty
- */
- public Command(final String[] commandLineElements,
- final boolean useShell,
- final Map<String, String> environmentVariables,
- final File workingDirectory) {
if (commandLineElements == null || commandLineElements.length == 0) {
throw new IllegalArgumentException("command line is null or empty");
}
this.processBuilder =
- new ProcessBuilder(maybeAddShell(commandLineElements, useShell));
+ new ProcessBuilder(commandLineElements);
if (environmentVariables != null) {
// TODO(bazel-team) remove next line eventually; it is here to mimic old
// Runtime.exec() behavior
@@ -251,22 +206,6 @@ public final class Command {
this.processBuilder.directory(workingDirectory);
}
- private static String[] maybeAddShell(final String[] commandLineElements,
- final boolean useShell) {
- if (useShell) {
- final StringBuilder builder = new StringBuilder();
- for (final String element : commandLineElements) {
- if (builder.length() > 0) {
- builder.append(' ');
- }
- builder.append(element);
- }
- return Shell.getPlatformShell().shellify(builder.toString());
- } else {
- return commandLineElements;
- }
- }
-
/**
* @return raw command line elements to be executed
*/
diff --git a/src/main/java/com/google/devtools/build/lib/shell/Shell.java b/src/main/java/com/google/devtools/build/lib/shell/Shell.java
deleted file mode 100644
index 2cae24ec15..0000000000
--- a/src/main/java/com/google/devtools/build/lib/shell/Shell.java
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright 2014 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.shell;
-
-import java.util.logging.Logger;
-
-/**
- * <p>Represents an OS shell, such as "cmd" on Windows or "sh" on Unix-like
- * platforms. Currently, Linux and Windows XP are supported.</p>
- *
- * <p>This class encapsulates shell-specific logic, like how to
- * create a command line that uses the shell to invoke another command.
- */
-public abstract class Shell {
-
- private static final Logger log =
- Logger.getLogger("com.google.devtools.build.lib.shell.Shell");
-
- private static final Shell platformShell;
-
- static {
- final String osName = System.getProperty("os.name");
- if ("Linux".equals(osName)) {
- platformShell = new SHShell();
- } else if ("Windows XP".equals(osName)) {
- platformShell = new WindowsCMDShell();
- } else {
- log.severe("OS not supported; will not be able to execute commands");
- platformShell = null;
- }
- log.config("Loaded shell support '" + platformShell +
- "' for OS '" + osName + "'");
- }
-
- private Shell() {
- // do nothing
- }
-
- /**
- * @return {@link Shell} subclass appropriate for the current platform
- * @throws UnsupportedOperationException if no such subclass exists
- */
- public static Shell getPlatformShell() {
- if (platformShell == null) {
- throw new UnsupportedOperationException("OS is not supported");
- }
- return platformShell;
- }
-
- /**
- * Creates a command line suitable for execution by
- * {@link Runtime#exec(String[])} from the given command string,
- * a command line which uses a shell appropriate for a particular
- * platform to execute the command (e.g. "/bin/sh" on Linux).
- *
- * @param command command for which to create a command line
- * @return String[] suitable for execution by
- * {@link Runtime#exec(String[])}
- */
- public abstract String[] shellify(final String command);
-
-
- /**
- * Represents the <code>sh</code> shell commonly found on Unix-like
- * operating systems, including Linux.
- */
- private static final class SHShell extends Shell {
-
- /**
- * <p>Returns a command line which uses <code>cmd</code> to execute
- * the {@link Command}. Given the command <code>foo bar baz</code>,
- * for example, this will return a String array corresponding
- * to the command line:</p>
- *
- * <p><code>/bin/sh -c "foo bar baz"</code></p>
- *
- * <p>That is, it always returns a 3-element array.</p>
- *
- * @param command command for which to create a command line
- * @return String[] suitable for execution by
- * {@link Runtime#exec(String[])}
- */
- @Override public String[] shellify(final String command) {
- if (command == null || command.length() == 0) {
- throw new IllegalArgumentException("command is null or empty");
- }
- return new String[] { "/bin/sh", "-c", command };
- }
-
- }
-
- /**
- * Represents the Windows command shell <code>cmd</code>.
- */
- private static final class WindowsCMDShell extends Shell {
-
- /**
- * <p>Returns a command line which uses <code>cmd</code> to execute
- * the {@link Command}. Given the command <code>foo bar baz</code>,
- * for example, this will return a String array corresponding
- * to the command line:</p>
- *
- * <p><code>cmd /S /C "foo bar baz"</code></p>
- *
- * <p>That is, it always returns a 4-element array.</p>
- *
- * @param command command for which to create a command line
- * @return String[] suitable for execution by
- * {@link Runtime#exec(String[])}
- */
- @Override public String[] shellify(final String command) {
- if (command == null || command.length() == 0) {
- throw new IllegalArgumentException("command is null or empty");
- }
- return new String[] { "cmd", "/S", "/C", command };
- }
-
- }
-
-}