Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-02-11 08:31:53 +0000
committerEike Stepper2012-02-11 08:31:53 +0000
commit5bba0148931feee992f47bfef5ffa54ecbc2235d (patch)
tree2b0806528edc2517979078814d7fcc61b0fbb6f2
parent0e3a76f8c2f0aa8dc039dc716f9176c3003f6c06 (diff)
downloadcdo-5bba0148931feee992f47bfef5ffa54ecbc2235d.tar.gz
cdo-5bba0148931feee992f47bfef5ffa54ecbc2235d.tar.xz
cdo-5bba0148931feee992f47bfef5ffa54ecbc2235d.zip
Using ProcessBuilder
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/ApplyPatchToGitAction.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/GitBash.java32
2 files changed, 56 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/ApplyPatchToGitAction.java b/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/ApplyPatchToGitAction.java
index 6163c9ef15..0e1a482b38 100644
--- a/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/ApplyPatchToGitAction.java
+++ b/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/ApplyPatchToGitAction.java
@@ -33,6 +33,7 @@ import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
@@ -242,10 +243,36 @@ public class ApplyPatchToGitAction extends BaseSelectionListenerAction implement
{
Shell shell = targetPart.getSite().getShell();
File workTree = repository.getWorkTree();
- String command = "apply \"" + file.getAbsolutePath() + "\"";
+ String command = "git apply " + file.getAbsolutePath().replace('\\', '/');
GitBash.executeCommand(shell, workTree, command);
}
}
}
+
+ public static void main(String[] args) throws IOException, InterruptedException
+ {
+ File workTree = new File("C:\\develop\\git\\cdo");
+ String gitBash = "C:\\Program Files (x86)\\Git\\bin\\sh.exe";
+
+ ProcessBuilder builder = new ProcessBuilder(gitBash, "--login", "-c",
+ "git apply C:/develop/patches/git-patch-357613.txt");
+ builder.directory(workTree);
+ builder.redirectErrorStream(true);
+
+ Process process = builder.start();
+
+ // String prefix = "cmd /c cd \"" + workTree.getAbsolutePath() + "\" && \"" + gitBash + "\"";
+ // String command = "apply C:/develop/patches/git-patch-357613.txt";
+ // Process process = Runtime.getRuntime().exec(prefix + " " + command);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ System.out.println(line);
+ }
+
+ System.out.println(process.waitFor());
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/GitBash.java b/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/GitBash.java
index 41a08e484b..f7acb6a14c 100644
--- a/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/GitBash.java
+++ b/plugins/org.eclipse.emf.cdo.releng.gitbash/src/org/eclipse/emf/cdo/releng/gitbash/GitBash.java
@@ -19,13 +19,14 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
/**
* @author Eike Stepper
*/
public class GitBash
{
- private static final String GIT_BASH = "C:\\Program Files (x86)\\Git\\bin\\sh.exe";
+ private static final String DEFAULT_EXECUTABLE = "C:\\Program Files (x86)\\Git\\bin\\sh.exe";
/**
* The path to the Git Bash executable.
@@ -48,7 +49,7 @@ public class GitBash
if (executable == null)
{
- executable = openInputDialog(GIT_BASH, shell);
+ executable = openInputDialog(DEFAULT_EXECUTABLE, shell);
}
if (!new File(executable).isFile())
@@ -67,8 +68,31 @@ public class GitBash
try
{
String gitBash = getExecutable(shell);
- String prefix = "cmd /c cd \"" + workTree.getAbsolutePath() + "\" && \"" + gitBash + "\" --login -i ";
- Runtime.getRuntime().exec(prefix + command);
+
+ ProcessBuilder builder = new ProcessBuilder(gitBash, "--login", "-c", command);
+ builder.directory(workTree);
+ builder.redirectErrorStream(true);
+
+ Process process = builder.start();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+
+ StringBuilder output = new StringBuilder();
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ output.append(line);
+ output.append("\n");
+ }
+
+ int exitValue = process.waitFor();
+ if (exitValue == 0)
+ {
+ Activator.log("Command '" + command + "' executed successfully\n" + output);
+ }
+ else
+ {
+ throw new RuntimeException("Command '" + command + "' failed: " + exitValue + "\n" + output);
+ }
}
catch (RuntimeException ex)
{

Back to the top