public static ChangeItem performTask(String _gitPath, String myDir, String yourDir)
      throws IOException {

    // ChangedFilesSet is a union set for storing all changed files
    // Files are uniquely existing in the set
    Output exeResult;
    String[] ChangedFiles;
    HashSet<Object> ChangedFilesSet = new HashSet<Object>();

    // Prepare the command
    String[] gitFilesArgs = {"log", "-1", "--pretty=format:\"\"", "--name-only"};

    // Execute command in myDir
    exeResult = RunIt.execute(_gitPath, gitFilesArgs, myDir, false);
    ChangedFiles = exeResult.getOutput().split("\n");
    for (String s : ChangedFiles) ChangedFilesSet.add(s);

    // Execute command in yourDir
    exeResult = RunIt.execute(_gitPath, gitFilesArgs, myDir, false);
    ChangedFiles = exeResult.getOutput().split("\n");
    for (String s : ChangedFiles) ChangedFilesSet.add(s);

    ChangeItem files = new ChangeItem();

    if (!myDir.endsWith(File.separator)) myDir = myDir + File.separator;

    if (!yourDir.endsWith(File.separator)) yourDir = yourDir + File.separator;

    int i = 1;
    for (Object s : ChangedFilesSet) {

      List<String> myFileLines = fileToLines(myDir + s);
      List<String> urFileLines = fileToLines(yourDir + s);

      DiffRowGenerator.Builder builder = new DiffRowGenerator.Builder();
      builder.showInlineDiffs(false);
      DiffRowGenerator dfg = builder.build();
      List<DiffRow> rows = dfg.generateDiffRows(myFileLines, urFileLines);

      String contentLines = "";
      for (DiffRow dr : rows) {
        if (dr.getTag() == DiffRow.Tag.DELETE)
          //					System.out.println("-\t" + dr.getOldLine());
          contentLines = contentLines + "-\t" + dr.getOldLine() + "\n";
        else if (dr.getTag() == DiffRow.Tag.INSERT)
          //					System.out.println("+\t" + dr.getNewLine());
          contentLines = contentLines + "+\t" + dr.getNewLine() + "\n";
        else if (dr.getTag() == DiffRow.Tag.CHANGE) {
          //					System.out.println("+-\t" + dr.getNewLine());
          contentLines = contentLines + "+\t" + dr.getNewLine() + "\n";
          contentLines = contentLines + "-\t" + dr.getOldLine() + "\n";
        }
      }
      files.changedFiles.add(i, (String) s);
      files.changedFilesContents.add(i, contentLines);
      i++;
    }
    return files;
  }
Exemple #2
0
 /**
  * Runs a command twice. A not-nice hack for those times when executions don't seem to be coming
  * out consistently.
  *
  * @param command
  * @param args
  * @param path
  * @return
  * @throws IOException
  */
 public static Output executeTwice(String command, String[] args, String path, boolean getStatus)
     throws IOException {
   execute(command, args, path, false);
   Output result = execute(command, args, path, getStatus);
   return result;
 }