org.apache.maven.scm.ScmFile Java Examples

The following examples show how to use org.apache.maven.scm.ScmFile. 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: ModuleCalculator.java    From incremental-module-builder with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate the modules which needed to be rebuilt based on the list of changes from SCM.
 * 
 * @param projectRootpath Root path of the project.
 * @return The list of modules which needed to be rebuilt.
 */
public List<MavenProject> calculateChangedModules( Path projectRootpath )
{
    // TODO: Think about if we got only pom packaging modules? Do we
    // need to do something special there?
    List<MavenProject> result = new ArrayList<>();
    for ( MavenProject project : projectList )
    {
        Path relativize = projectRootpath.relativize( project.getBasedir().toPath() );
        for ( ScmFile fileItem : changeList )
        {
            boolean startsWith = new File( fileItem.getPath() ).toPath().startsWith( relativize );
            logger.debug( "startswith: " + startsWith + " " + fileItem.getPath() + " " + relativize );
            if ( startsWith )
            {
                if ( !result.contains( project ) )
                {
                    result.add( project );
                }
            }
        }
    }
    return result;
}
 
Example #2
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 #3
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 #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: 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 #6
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 #7
Source File: CreateMojo.java    From buildnumber-maven-plugin with MIT License 5 votes vote down vote up
private boolean doLocalModificationExist( StringBuilder message )
    throws MojoExecutionException
{
    boolean result = false;

    getLog().debug( "Verifying there are no local modifications ..." );

    List<ScmFile> changedFiles;

    try
    {
        changedFiles = getStatus();
    }
    catch ( ScmException e )
    {
        throw new MojoExecutionException( "An error has occurred while checking scm status.", e );
    }

    if ( !changedFiles.isEmpty() )
    {
        for ( ScmFile file : changedFiles )
        {
            message.append( file.toString() );

            message.append( System.lineSeparator() );
        }

        result = true;
    }

    return result;
}
 
Example #8
Source File: CreateMojo.java    From buildnumber-maven-plugin with MIT License 5 votes vote down vote up
public List<ScmFile> update()
    throws MojoExecutionException
{
    try
    {
        ScmRepository repository = getScmRepository();

        ScmProvider scmProvider = scmManager.getProviderByRepository( repository );

        UpdateScmResult result = scmProvider.update( repository, new ScmFileSet( scmDirectory ) );

        if ( result == null )
        {
            return Collections.emptyList();
        }

        checkResult( result );

        if ( result instanceof UpdateScmResultWithRevision )
        {
            String revision = ( (UpdateScmResultWithRevision) result ).getRevision();
            getLog().info( "Got a revision during update: " + revision );
            this.revision = revision;
        }

        return result.getUpdatedFiles();
    }
    catch ( ScmException e )
    {
        throw new MojoExecutionException( "Couldn't update project. " + e.getMessage(), e );
    }

}
 
Example #9
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 #10
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 #11
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 #12
Source File: ModuleCalculator.java    From incremental-module-builder with Apache License 2.0 4 votes vote down vote up
/**
 * @param projectList The list of Maven Projects which are in the reactor.
 * @param changeList The list of changes within this structure.
 */
public ModuleCalculator( List<MavenProject> projectList, List<ScmFile> changeList )
{
    this.projectList = Objects.requireNonNull( projectList, "projectList is not allowed to be null." );
    this.changeList = Objects.requireNonNull( changeList, "changeList is not allowed to be null." );
}
 
Example #13
Source File: CreateMojo.java    From buildnumber-maven-plugin with MIT License 4 votes vote down vote up
public void execute()
    throws MojoExecutionException, MojoFailureException
{
    String buildIsTainted = "ok";
    
    if ( skip )
    {
        getLog().info( "Skipping execution." );
        return;
    }

    if ( providerImplementations != null )
    {
        changeProviderImplementation();
    }
    Date now = Calendar.getInstance().getTime();
    if ( format != null )
    {
        if ( items == null )
        {
            throw new MojoExecutionException( " if you set a format, you must provide at least one item, "
                + "please check documentation " );
        }
        Object[] itemAry = handleItems( now );

        revision = format( itemAry );
    }
    else
    {
        // Check if the plugin has already run.
        revision = project.getProperties().getProperty( this.buildNumberPropertyName );
        if ( this.getRevisionOnlyOnce && revision != null )
        {
            getLog().debug( "Revision available from previous execution" );
            return;
        }

        if ( doCheck )
        {
            StringBuilder message = new StringBuilder();
            if ( doLocalModificationExist( message ) )
            {
                buildIsTainted = "tainted";
                if ( failTheBuild )
                {
                    throw new MojoExecutionException( "Cannot create the build number because you have local modifications : \n"
                        + message );

                }
            }
        }
        else
        {
            getLog().debug( "Checking for local modifications: skipped." );
        }

        if ( session.getSettings().isOffline() )
        {
            getLog().info( "maven is executed in offline mode, Updating project files from SCM: skipped." );
        }
        else
        {
            if ( doUpdate )
            {
                // we update your local repo
                // even after you commit, your revision stays the same until you update, thus this
                // action
                List<ScmFile> changedFiles = update();
                for ( ScmFile file : changedFiles )
                {
                    getLog().debug( "Updated: " + file );
                }
                if ( changedFiles.size() == 0 )
                {
                    getLog().debug( "No files needed updating." );
                }
            }
            else
            {
                getLog().debug( "Updating project files from SCM: skipped." );
            }
        }
        revision = getRevision();
    }

    if ( project != null )
    {
        buildNumberAndTimeStampForReactorProjects( now, buildIsTainted );
    }
}
 
Example #14
Source File: CreateMojo.java    From buildnumber-maven-plugin with MIT License 4 votes vote down vote up
public List<ScmFile> getStatus()
    throws ScmException
{

    ScmRepository repository = getScmRepository();

    ScmProvider scmProvider = scmManager.getProviderByRepository( repository );

    StatusScmResult result = scmProvider.status( repository, new ScmFileSet( scmDirectory ) );

    if ( result == null )
    {
        return Collections.emptyList();
    }

    checkResult( result );

    return result.getChangedFiles();

}
 
Example #15
Source File: ScmMojoTest.java    From pitest with Apache License 2.0 4 votes vote down vote up
private void setupToReturnNoModifiedFiles() throws ScmException {
  when(this.manager.status(any(ScmRepository.class), any(ScmFileSet.class)))
      .thenReturn(new StatusScmResult("", Collections.<ScmFile> emptyList()));
}