[MNG-6410] Add groupId to --resume-from suggestion if artifactId is not unique in reactor

This closes #166
This commit is contained in:
Łukasz Dywicki 2018-05-11 15:46:05 +02:00 committed by Michael Osipov
parent 39fdaad967
commit 864d180edf
1 changed files with 31 additions and 2 deletions

View File

@ -1006,8 +1006,8 @@ public class MavenCli
{ {
slf4jLogger.error( "" ); slf4jLogger.error( "" );
slf4jLogger.error( "After correcting the problems, you can resume the build with the command" ); slf4jLogger.error( "After correcting the problems, you can resume the build with the command" );
slf4jLogger.error( buffer().a( " " ).strong( "mvn <goals> -rf :" slf4jLogger.error( buffer().a( " " ).strong( "mvn <goals> -rf "
+ project.getArtifactId() ).toString() ); + getResumeFrom( result.getTopologicallySortedProjects(), project ) ).toString() );
} }
if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( cliRequest.request.getReactorFailureBehavior() ) ) if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( cliRequest.request.getReactorFailureBehavior() ) )
@ -1027,6 +1027,35 @@ public class MavenCli
} }
} }
/**
* A helper method to determine the value to resume the build with {@code -rf} taking into account the
* edge case where multiple modules in the reactor have the same artifactId.
* <p>
* {@code -rf :artifactId} will pick up the first module which matches, but when multiple modules in the
* reactor have the same artifactId, effective failed module might be later in build reactor.
* This means that developer will either have to type groupId or wait for build execution of all modules
* which were fine, but they are still before one which reported errors.
* <p>Then the returned value is {@code groupId:artifactId} when there is a name clash and
* {@code :artifactId} if there is no conflict.
*
* @param mavenProjects Maven projects which are part of build execution.
* @param failedProject Project which has failed.
* @return Value for -rf flag to resume build exactly from place where it failed ({@code :artifactId} in
* general and {@code groupId:artifactId} when there is a name clash).
*/
private String getResumeFrom( List<MavenProject> mavenProjects, MavenProject failedProject )
{
for ( MavenProject buildProject : mavenProjects )
{
if ( failedProject.getArtifactId().equals( buildProject.getArtifactId() ) && !failedProject.equals(
buildProject ) )
{
return failedProject.getGroupId() + ":" + failedProject.getArtifactId();
}
}
return ":" + failedProject.getArtifactId();
}
private void logSummary( ExceptionSummary summary, Map<String, String> references, String indent, private void logSummary( ExceptionSummary summary, Map<String, String> references, String indent,
boolean showErrors ) boolean showErrors )
{ {