Eclipseplugins
MergetoolOperation.java
1 package com.proalpha.pds.gitutils.common;
2 
3 import java.io.File;
4 import java.io.IOException;
5 import java.lang.reflect.InvocationTargetException;
6 import java.util.ArrayList;
7 import java.util.List;
8 
9 import org.eclipse.swt.custom.BusyIndicator;
10 import org.eclipse.swt.widgets.Display;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 
20 public class MergetoolOperation {
21 
22  private final Logger logger = LoggerFactory.getLogger(MergetoolOperation.class);
23  private List<String> fileList;
24  private File workingDir;
25 
26  public MergetoolOperation(File workingDir, List<String> fileList) {
27  this.workingDir = workingDir;
28  this.fileList = fileList;
29  }
30 
38  public void execute() {
39  Runnable r = new Runnable() {
40 
41  @Override
42  public void run() {
43  if (!fileList.isEmpty()) {
44  for (String fileToMerge : fileList) {
45 
46  List<String> commands = new ArrayList<String>();
47  commands.add("CMD");
48  commands.add("/C");
49  commands.add("git mergetool " + fileToMerge);
50 
51  ProcessBuilder pb = new ProcessBuilder(commands);
52  pb.directory(workingDir);
53 
54  logger.debug("Running commands " + commands + " in " + workingDir);
55  try {
56  pb.start();
57  } catch (IOException e) {
58  // TODO Auto-generated catch block
59  logger.error("Process MergetoolOperation throws an IOException", e);
60  }
61  }
62  }
63  }
64  };
65  BusyIndicator.showWhile(Display.getCurrent(), r);
66  }
67 }