public void testChangeSet() {
    ArrayList<String> lines = new ArrayList<String>();
    lines.add("Some header junk we should ignore...");
    lines.add("header line 2");
    lines.add("commit 123abc456def");
    lines.add("tree 789ghi012jkl");
    lines.add("parent 345mno678pqr");
    lines.add("author John Author <*****@*****.**> 1234567 -0600");
    lines.add("commiter John Committer <*****@*****.**> 1234567 -0600");
    lines.add("");
    lines.add("    Commit title.");
    lines.add("    Commit extended description.");
    lines.add("");
    lines.add(
        ":000000 123456 0000000000000000000000000000000000000000 123abc456def789abc012def345abc678def901a A\tsrc/test/add.file");
    lines.add(
        ":123456 000000 123abc456def789abc012def345abc678def901a 0000000000000000000000000000000000000000 D\tsrc/test/deleted.file");
    lines.add(
        ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 M\tsrc/test/modified.file");
    lines.add(
        ":123456 789012 123abc456def789abc012def345abc678def901a bc234def567abc890def123abc456def789abc01 R012\tsrc/test/renamedFrom.file\tsrc/test/renamedTo.file");
    GitChangeSet changeSet = new GitChangeSet(lines);

    Assert.assertEquals("123abc456def", changeSet.getId());
    Assert.assertEquals("Commit title.", changeSet.getMsg());
    Assert.assertEquals("Commit title.\nCommit extended description.\n", changeSet.getComment());
    HashSet<String> expectedAffectedPaths = new HashSet<String>(7);
    expectedAffectedPaths.add("src/test/add.file");
    expectedAffectedPaths.add("src/test/deleted.file");
    expectedAffectedPaths.add("src/test/modified.file");
    expectedAffectedPaths.add("src/test/renamedFrom.file\tsrc/test/renamedTo.file");
    Assert.assertEquals(expectedAffectedPaths, changeSet.getAffectedPaths());

    Collection<Path> actualPaths = changeSet.getPaths();
    Assert.assertEquals(4, actualPaths.size());
    for (Path path : actualPaths) {
      if ("src/test/add.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.ADD, path.getEditType());
        Assert.assertNull(path.getSrc());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getDst());
      } else if ("src/test/deleted.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.DELETE, path.getEditType());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc());
        Assert.assertNull(path.getDst());
      } else if ("src/test/modified.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.EDIT, path.getEditType());
        Assert.assertEquals("123abc456def789abc012def345abc678def901a", path.getSrc());
        Assert.assertEquals("bc234def567abc890def123abc456def789abc01", path.getDst());
      } else if ("src/test/renamedFrom.file\tsrc/test/renamedTo.file".equals(path.getPath())) {
        Assert.assertEquals(EditType.EDIT, path.getEditType());
        Assert.assertNull(path.getSrc());
        Assert.assertNull(path.getDst());
      } else {
        Assert.fail("Unrecognized path.");
      }
    }
  }
 @Test
 public void testGetAffectedPaths() {
   assertTrue(changeSet.getAffectedPaths().isEmpty());
 }
示例#3
0
  @Override
  public Boolean isRevExcluded(
      GitSCM scm, GitClient git, GitChangeSet commit, TaskListener listener, BuildData buildData) {
    Collection<String> paths = commit.getAffectedPaths();
    if (paths.isEmpty()) { // nothing modified, so no need to compute any of this
      return true;
    }

    List<Pattern> included = getIncludedPatterns();
    List<Pattern> excluded = getExcludedPatterns();

    // Assemble the list of included paths
    List<String> includedPaths = new ArrayList<String>(paths.size());
    if (!included.isEmpty()) {
      for (String path : paths) {
        for (Pattern pattern : included) {
          if (pattern.matcher(path).matches()) {
            includedPaths.add(path);
            break;
          }
        }
      }
    } else {
      includedPaths.addAll(paths);
    }

    // Assemble the list of excluded paths
    List<String> excludedPaths = new ArrayList<String>();
    if (!excluded.isEmpty()) {
      for (String path : includedPaths) {
        for (Pattern pattern : excluded) {
          if (pattern.matcher(path).matches()) {
            excludedPaths.add(path);
            break;
          }
        }
      }
    }

    if (excluded.isEmpty() && !included.isEmpty() && includedPaths.isEmpty()) {
      listener
          .getLogger()
          .println(
              "Ignored commit "
                  + commit.getCommitId()
                  + ": No paths matched included region whitelist");
      return true;
    } else if (includedPaths.size() == excludedPaths.size()) {
      // If every affected path is excluded, return true.
      listener
          .getLogger()
          .println(
              "Ignored commit "
                  + commit.getCommitId()
                  + ": Found only excluded paths: "
                  + Util.join(excludedPaths, ", "));
      return true;
    }

    return null;
  }