diff mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java @ 266:643fa1236f4e

Fix file encoding * * * Fix line-endings
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Wed, 20 Jul 2011 12:04:08 +0400
parents b7d0ddf3df33
children d6ee18f4a547
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Thu Jul 07 14:11:32 2011 +0400
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommandUtil.java	Wed Jul 20 12:04:08 2011 +0400
@@ -1,119 +1,119 @@
-/*
- * Copyright 2000-2011 JetBrains s.r.o.
- *
- * 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 jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
-
-import com.intellij.execution.configurations.GeneralCommandLine;
-import jetbrains.buildServer.ExecResult;
-import jetbrains.buildServer.SimpleCommandLineProcessRunner;
-import jetbrains.buildServer.log.Loggers;
-import jetbrains.buildServer.util.StringUtil;
-import jetbrains.buildServer.vcs.VcsException;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Collections;
-import java.util.Set;
-
-public class CommandUtil {
-  private static final int DEFAULT_COMMAND_TIMEOUT_SEC = 3600;
-
-  public static void checkCommandFailed(@NotNull String cmdName, @NotNull ExecResult res) throws VcsException {
-    if (res.getExitCode() != 0 || res.getException() != null) {
-      commandFailed(cmdName, res);
-    }
-    if (res.getStderr().length() > 0) {
-      Loggers.VCS.warn("Error output produced by: " + cmdName);
-      Loggers.VCS.warn(res.getStderr());
-    }
-  }
-
-  public static void commandFailed(final String cmdName, final ExecResult res) throws VcsException {
-    String stderr = res.getStderr();
-    String stdout = res.getStdout();
-    String exceptionMessage = getExceptionMessage(res);
-    final String message = "'" + cmdName + "' command failed.\n" +
-            (!StringUtil.isEmpty(stderr) ? "stderr: " + stderr + "\n" : "") +
-            (!StringUtil.isEmpty(stdout) ? "stdout: " + stdout + "\n" : "") +
-            (exceptionMessage != null ? "exception: " + exceptionMessage : "");
-    Loggers.VCS.warn(message);
-    if (hasImportantException(res)) {
-      Loggers.VCS.error("Error during executing '" + cmdName + "'", res.getException());
-    }
-    throw new VcsException(message);
-  }
-
-  @Nullable
-  private static String getExceptionMessage(ExecResult result) {
-    Throwable exception = result.getException();
-    String message = null;
-    if (exception != null) {
-      message = exception.getMessage();
-      if (message == null) {
-        message = exception.getClass().getName();
-      }
-    }
-    return message;
-  }
-
-  private static boolean hasImportantException(ExecResult result) {
-    Throwable exception = result.getException();
-    if (exception != null) {
-      return exception instanceof NullPointerException;
-    } else {
-      return false;
-    }
-  }
-
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
-    return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, Collections.<String>emptySet());
-  }
-
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, @NotNull Set<String> privateData) throws VcsException {
-    return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, privateData);
-  }
-
-  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, final int executionTimeout, @NotNull Set<String> privateData) throws VcsException {
-    String cmdStr = removePrivateData(cli.getCommandLineString(), privateData);
-    Loggers.VCS.debug("Run command: " + cmdStr);
-    ExecResult res = SimpleCommandLineProcessRunner.runCommand(cli, null, new SimpleCommandLineProcessRunner.RunCommandEventsAdapter() {
-      @Override
-      public Integer getOutputIdleSecondsTimeout() {
-        return executionTimeout;
-      }
-    });
-
-    removePrivateData(privateData, res);
-
-    CommandUtil.checkCommandFailed(cmdStr, res);
-    Loggers.VCS.debug(res.getStdout());
-    return res;
-  }
-
-  private static void removePrivateData(final Set<String> privateData, final ExecResult res) {
-    res.setStdout(removePrivateData(res.getStdout(), privateData));
-    res.setStderr(removePrivateData(res.getStderr(), privateData));
-  }
-
-  public static String removePrivateData(final String str, final Set<String> privateData) {
-    String result = str;
-    for (String data: privateData) {
-      if (data == null || data.length() == 0) continue;
-      result = result.replace(data, "******");
-    }
-
-    return result;
-  }
-}
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * 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 jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
+
+import com.intellij.execution.configurations.GeneralCommandLine;
+import jetbrains.buildServer.ExecResult;
+import jetbrains.buildServer.SimpleCommandLineProcessRunner;
+import jetbrains.buildServer.log.Loggers;
+import jetbrains.buildServer.util.StringUtil;
+import jetbrains.buildServer.vcs.VcsException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.Set;
+
+public class CommandUtil {
+  private static final int DEFAULT_COMMAND_TIMEOUT_SEC = 3600;
+
+  public static void checkCommandFailed(@NotNull String cmdName, @NotNull ExecResult res) throws VcsException {
+    if (res.getExitCode() != 0 || res.getException() != null) {
+      commandFailed(cmdName, res);
+    }
+    if (res.getStderr().length() > 0) {
+      Loggers.VCS.warn("Error output produced by: " + cmdName);
+      Loggers.VCS.warn(res.getStderr());
+    }
+  }
+
+  public static void commandFailed(final String cmdName, final ExecResult res) throws VcsException {
+    String stderr = res.getStderr();
+    String stdout = res.getStdout();
+    String exceptionMessage = getExceptionMessage(res);
+    final String message = "'" + cmdName + "' command failed.\n" +
+            (!StringUtil.isEmpty(stderr) ? "stderr: " + stderr + "\n" : "") +
+            (!StringUtil.isEmpty(stdout) ? "stdout: " + stdout + "\n" : "") +
+            (exceptionMessage != null ? "exception: " + exceptionMessage : "");
+    Loggers.VCS.warn(message);
+    if (hasImportantException(res)) {
+      Loggers.VCS.error("Error during executing '" + cmdName + "'", res.getException());
+    }
+    throw new VcsException(message);
+  }
+
+  @Nullable
+  private static String getExceptionMessage(ExecResult result) {
+    Throwable exception = result.getException();
+    String message = null;
+    if (exception != null) {
+      message = exception.getMessage();
+      if (message == null) {
+        message = exception.getClass().getName();
+      }
+    }
+    return message;
+  }
+
+  private static boolean hasImportantException(ExecResult result) {
+    Throwable exception = result.getException();
+    if (exception != null) {
+      return exception instanceof NullPointerException;
+    } else {
+      return false;
+    }
+  }
+
+  public static ExecResult runCommand(@NotNull GeneralCommandLine cli) throws VcsException {
+    return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, Collections.<String>emptySet());
+  }
+
+  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, @NotNull Set<String> privateData) throws VcsException {
+    return runCommand(cli, DEFAULT_COMMAND_TIMEOUT_SEC, privateData);
+  }
+
+  public static ExecResult runCommand(@NotNull GeneralCommandLine cli, final int executionTimeout, @NotNull Set<String> privateData) throws VcsException {
+    String cmdStr = removePrivateData(cli.getCommandLineString(), privateData);
+    Loggers.VCS.debug("Run command: " + cmdStr);
+    ExecResult res = SimpleCommandLineProcessRunner.runCommand(cli, null, new SimpleCommandLineProcessRunner.RunCommandEventsAdapter() {
+      @Override
+      public Integer getOutputIdleSecondsTimeout() {
+        return executionTimeout;
+      }
+    });
+
+    removePrivateData(privateData, res);
+
+    CommandUtil.checkCommandFailed(cmdStr, res);
+    Loggers.VCS.debug(res.getStdout());
+    return res;
+  }
+
+  private static void removePrivateData(final Set<String> privateData, final ExecResult res) {
+    res.setStdout(removePrivateData(res.getStdout(), privateData));
+    res.setStderr(removePrivateData(res.getStderr(), privateData));
+  }
+
+  public static String removePrivateData(final String str, final Set<String> privateData) {
+    String result = str;
+    for (String data: privateData) {
+      if (data == null || data.length() == 0) continue;
+      result = result.replace(data, "******");
+    }
+
+    return result;
+  }
+}