Java Code Examples for org.apache.maven.scm.ScmFileStatus

The following examples show how to use org.apache.maven.scm.ScmFileStatus. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Ignore
public void shouldResultInThreeModules()
{
    // TODO: Think about this test case. What
    // should be returned for the root module ?
    // If i call mvn -pl root ... it will not work?
    Path root = baseDir.toPath();
    List<ScmFile> changeList = Arrays.asList( 
      new ScmFile( "domain/subdomain/pom.xml", ScmFileStatus.MODIFIED ),
      new ScmFile( "domain/pom.xml", ScmFileStatus.MODIFIED ),
      new ScmFile( "pom.xml", ScmFileStatus.MODIFIED ) 
    );
    moduleCalculator = new ModuleCalculator( projectList, changeList );
    List<MavenProject> changedModules = moduleCalculator.calculateChangedModules( root );

    assertThat( changedModules ).hasSize( 3 ).containsOnly( domain, subdomain, parent );
}
 
Example 2
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 6 votes vote down vote up
private Set<String> findModifiedPaths() throws MojoExecutionException {
  try {
    final ScmRepository repository = this.manager
        .makeScmRepository(getSCMConnection());
    final File scmRoot = scmRoot();
    this.getLog().info("Scm root dir is " + scmRoot);

    final Set<ScmFileStatus> statusToInclude = makeStatusSet();
    final Set<String> modifiedPaths;
    if (analyseLastCommit) {
      modifiedPaths = lastCommitChanges(statusToInclude, repository, scmRoot);
    } else if (originBranch != null && destinationBranch != null) {
      modifiedPaths = changesBetweenBranchs(originBranch, destinationBranch, statusToInclude, repository, scmRoot);
    } else {
      modifiedPaths = localChanges(statusToInclude, repository, scmRoot);
    }
    return modifiedPaths;
  } catch (final ScmException e) {
    throw new MojoExecutionException("Error while querying scm", e);
  }

}
 
Example 3
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 6 votes vote down vote up
private Set<String> pathsAffectedByChange(ChangeLogScmRequest scmRequest, Set<ScmFileStatus> statusToInclude, int limit) throws ScmException {
  Set<String> affected = new LinkedHashSet<>();
  ChangeLogScmResult changeLogScmResult = this.manager.changeLog(scmRequest);
  if (changeLogScmResult.isSuccess()) {
    List<ChangeSet> changeSets = limit(changeLogScmResult.getChangeLog().getChangeSets(),limit);
    for (ChangeSet change : changeSets) {
      List<ChangeFile> files = change.getFiles();
      for (final ChangeFile changeFile : files) {
        if (statusToInclude.contains(changeFile.getAction())) {
          affected.add(changeFile.getName());
        }
      }
    }
  }
  return affected;
}
 
Example 4
@Test
public void shouldResultInASingleModule()
{
    Path root = baseDir.toPath();
    List<ScmFile> changeList =
        Arrays.asList( new ScmFile( "domain/src/main/java/com/test.java", ScmFileStatus.MODIFIED ) );
    moduleCalculator = new ModuleCalculator( projectList, changeList );
    List<MavenProject> changedModules = moduleCalculator.calculateChangedModules( root );

    assertThat( changedModules ).hasSize( 1 ).containsExactly( domain );
}
 
Example 5
@Test
public void shouldResultInTwoModules()
{
    Path root = baseDir.toPath();
    List<ScmFile> changeList =
        Arrays.asList( new ScmFile( "domain/src/main/java/com/test.java", ScmFileStatus.MODIFIED ),
                       new ScmFile( "assembly/pom.xml", ScmFileStatus.MODIFIED ) );
    moduleCalculator = new ModuleCalculator( projectList, changeList );
    List<MavenProject> changedModules = moduleCalculator.calculateChangedModules( root );

    assertThat( changedModules ).hasSize( 2 ).containsOnly( domain, assembly );
}
 
Example 6
@Test
public void shouldResultInTwoModulesTwoChangesInSingleModule()
{
    Path root = baseDir.toPath();
    List<ScmFile> changeList =
        Arrays.asList( new ScmFile( "domain/src/main/java/com/test.java", ScmFileStatus.MODIFIED ),
                       new ScmFile( "domain/src/main/java/Anton.java", ScmFileStatus.MODIFIED ),
                       new ScmFile( "assembly/pom.xml", ScmFileStatus.MODIFIED ) );

    moduleCalculator = new ModuleCalculator( projectList, changeList );
    List<MavenProject> changedModules = moduleCalculator.calculateChangedModules( root );

    assertThat( changedModules ).hasSize( 2 ).containsOnly( domain, assembly );
}
 
Example 7
@Test
public void shouldResultInTwoModulesDomainAndSubDomain()
{
    Path root = baseDir.toPath();
    List<ScmFile> changeList = Arrays.asList( new ScmFile( "domain/subdomain/pom.xml", ScmFileStatus.MODIFIED ),
                                              new ScmFile( "domain/pom.xml", ScmFileStatus.MODIFIED ) );
    moduleCalculator = new ModuleCalculator( projectList, changeList );
    List<MavenProject> changedModules = moduleCalculator.calculateChangedModules( root );

    assertThat( changedModules ).hasSize( 2 ).containsOnly( domain, subdomain );
}
 
Example 8
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 5 votes vote down vote up
private Set<String> localChanges(Set<ScmFileStatus> statusToInclude, ScmRepository repository, File scmRoot) throws ScmException {
  final StatusScmResult status = this.manager.status(repository,
          new ScmFileSet(scmRoot));
  Set<String> affected = new LinkedHashSet<>();
  for (final ScmFile file : status.getChangedFiles()) {
    if (statusToInclude.contains(file.getStatus())) {
      affected.add(file.getPath());
    }
  }
  return affected;
}
 
Example 9
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 5 votes vote down vote up
private Set<ScmFileStatus> makeStatusSet() {
  if ((this.include == null) || this.include.isEmpty()) {
    return new HashSet<>(Arrays.asList(
        ScmStatus.ADDED.getStatus(), ScmStatus.MODIFIED.getStatus()));
  }
  final Set<ScmFileStatus> s = new HashSet<>();
  FCollection.mapTo(this.include, stringToMavenScmStatus(), s);
  return s;
}
 
Example 10
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testClassesAddedToScmAreMutationTested() throws Exception {
  setupConnection();
  setFileWithStatus(ScmFileStatus.ADDED);
  this.testee.execute();
  verify(this.executionStrategy).execute(any(File.class),
      any(ReportOptions.class), any(PluginServices.class), anyMap());
}
 
Example 11
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
private void setFileWithStatus(final ScmFileStatus status)
    throws ScmException {
  when(this.manager.status(any(ScmRepository.class), any(ScmFileSet.class)))
      .thenReturn(
          new StatusScmResult("", Arrays.asList(new ScmFile(
              "foo/bar/Bar.java", status))));
}
 
Example 12
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testModifiedClassesAreMutationTested() throws Exception {
  setupConnection();
  setFileWithStatus(ScmFileStatus.MODIFIED);
  this.testee.execute();
  verify(this.executionStrategy).execute(any(File.class),
      any(ReportOptions.class), any(PluginServices.class), anyMap());
}
 
Example 13
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testUnknownAndDeletedClassesAreNotMutationTested()
    throws Exception {
  setupConnection();
  when(this.manager.status(any(ScmRepository.class), any(ScmFileSet.class)))
      .thenReturn(
          new StatusScmResult("", Arrays.asList(new ScmFile(
              "foo/bar/Bar.java", ScmFileStatus.DELETED), new ScmFile(
              "foo/bar/Bar.java", ScmFileStatus.UNKNOWN))));
  this.testee.execute();
  verify(this.executionStrategy, never()).execute(any(File.class),
      any(ReportOptions.class), any(PluginServices.class), anyMap());
}
 
Example 14
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testCanOverrideInspectedStatus() throws Exception {
  setupConnection();
  setFileWithStatus(ScmFileStatus.UNKNOWN);
  configurePitMojo(
      this.testee,
      createPomWithConfiguration("<include><value>DELETED</value><value>UNKNOWN</value></include>"));
  this.testee.execute();
  verify(this.executionStrategy, times(1)).execute(any(File.class),
      any(ReportOptions.class), any(PluginServices.class), anyMap());
}
 
Example 15
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testDoesNotAnalysePomProjects() throws Exception {
  setupConnection();
  setFileWithStatus(ScmFileStatus.MODIFIED);
  when(this.project.getPackaging()).thenReturn("pom");
  this.testee.execute();
  verify(this.executionStrategy, never()).execute(any(File.class),
      any(ReportOptions.class), any(PluginServices.class), anyMap());
}
 
Example 16
Source Project: buildnumber-maven-plugin   Source File: HgOutputConsumer.java    License: MIT License 4 votes vote down vote up
@Override
public void doConsume( ScmFileStatus status, String line )
{
    output = line;
}
 
Example 17
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 4 votes vote down vote up
private Set<String> lastCommitChanges(Set<ScmFileStatus> statusToInclude, ScmRepository repository, File scmRoot) throws ScmException {
  ChangeLogScmRequest scmRequest = new ChangeLogScmRequest(repository, new ScmFileSet(scmRoot));
  scmRequest.setLimit(1);
  return pathsAffectedByChange(scmRequest, statusToInclude, 1);
}
 
Example 18
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 4 votes vote down vote up
private Set<String> changesBetweenBranchs(String origine, String destination, Set<ScmFileStatus> statusToInclude, ScmRepository repository, File scmRoot) throws ScmException {
  ChangeLogScmRequest scmRequest = new ChangeLogScmRequest(repository, new ScmFileSet(scmRoot));
  scmRequest.setScmBranch(new ScmBranch(destination + ".." + origine));
  return pathsAffectedByChange(scmRequest, statusToInclude, NO_LIMIT);
}
 
Example 19
Source Project: pitest   Source File: ScmMojo.java    License: Apache License 2.0 4 votes vote down vote up
private static Function<String, ScmFileStatus> stringToMavenScmStatus() {
  return a -> ScmStatus.valueOf(a.toUpperCase()).getStatus();
}
 
Example 20
Source Project: pitest   Source File: ScmStatusTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void shouldMapTheStringAddedToTheRightScmFileStatus() {
  assertEquals(ScmFileStatus.ADDED, ScmStatus.valueOf("ADDED").getStatus());
}
 
Example 21
Source Project: pitest   Source File: ScmStatusTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void shouldMapTheStringModifiedToTheRightScmFileStatus() {
  assertEquals(ScmFileStatus.MODIFIED, ScmStatus.valueOf("MODIFIED")
      .getStatus());
}
 
Example 22
Source Project: pitest   Source File: ScmStatusTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void shouldMapTheStringUnknownToTheRightScmFileStatus() {
  assertEquals(ScmFileStatus.UNKNOWN, ScmStatus.valueOf("UNKNOWN")
      .getStatus());
}
 
Example 23
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
private ChangeSet aChangeSetWithAddedFile() {
  return new ChangeSet(new Date(), "", "", Arrays.asList(aChangeFile(ScmFileStatus.ADDED)));
}
 
Example 24
Source Project: pitest   Source File: ScmMojoTest.java    License: Apache License 2.0 4 votes vote down vote up
private ChangeFile aChangeFile(ScmFileStatus fileStatus) {
  ChangeFile changeFile = new ChangeFile("foo/bar/Bar.java");
  changeFile.setAction(fileStatus);
  return changeFile;
}