org.apache.maven.scm.ScmFileStatus Java Examples

The following examples show how to use org.apache.maven.scm.ScmFileStatus. 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
Source File: ModuleCalculatorTest.java    From incremental-module-builder with Apache License 2.0 6 votes vote down vote up
@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 File: ScmMojo.java    From pitest with 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 File: ScmMojo.java    From pitest with 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
Source File: ModuleCalculatorTest.java    From incremental-module-builder with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: ScmMojoTest.java    From pitest with 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 #6
Source File: ScmMojoTest.java    From pitest with 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 #7
Source File: ScmMojoTest.java    From pitest with 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 #8
Source File: ScmMojoTest.java    From pitest with 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 #9
Source File: ScmMojoTest.java    From pitest with 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 #10
Source File: ScmMojoTest.java    From pitest with 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 File: ScmMojo.java    From pitest with 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 #12
Source File: ScmMojo.java    From pitest with 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 #13
Source File: ModuleCalculatorTest.java    From incremental-module-builder with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: ModuleCalculatorTest.java    From incremental-module-builder with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: ModuleCalculatorTest.java    From incremental-module-builder with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: ScmMojo.java    From pitest with Apache License 2.0 4 votes vote down vote up
private static Function<String, ScmFileStatus> stringToMavenScmStatus() {
  return a -> ScmStatus.valueOf(a.toUpperCase()).getStatus();
}
 
Example #17
Source File: ScmStatusTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldMapTheStringAddedToTheRightScmFileStatus() {
  assertEquals(ScmFileStatus.ADDED, ScmStatus.valueOf("ADDED").getStatus());
}
 
Example #18
Source File: ScmStatusTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldMapTheStringModifiedToTheRightScmFileStatus() {
  assertEquals(ScmFileStatus.MODIFIED, ScmStatus.valueOf("MODIFIED")
      .getStatus());
}
 
Example #19
Source File: ScmStatusTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldMapTheStringUnknownToTheRightScmFileStatus() {
  assertEquals(ScmFileStatus.UNKNOWN, ScmStatus.valueOf("UNKNOWN")
      .getStatus());
}
 
Example #20
Source File: ScmMojo.java    From pitest with 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 #21
Source File: ScmMojo.java    From pitest with 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 #22
Source File: HgOutputConsumer.java    From buildnumber-maven-plugin with MIT License 4 votes vote down vote up
@Override
public void doConsume( ScmFileStatus status, String line )
{
    output = line;
}
 
Example #23
Source File: ScmMojoTest.java    From pitest with 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 File: ScmMojoTest.java    From pitest with 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;
}