Skip to content

Commit

Permalink
[MRELEASE-1097] rework plugin output to clarify goal's phases (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy authored May 29, 2022
1 parent ac65bef commit 6f9c8b7
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 174 deletions.
2 changes: 0 additions & 2 deletions maven-release-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@
<executions>
<execution>
<goals>
<goal>xpp3-reader</goal>
<goal>java</goal>
<goal>xpp3-writer</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public class DefaultReleaseManager
*/
private final AtomicReference<ReleaseDescriptorStore> configStore;

private static final int PHASE_SKIP = 0, PHASE_START = 1, PHASE_END = 2, GOAL_END = 12, ERROR = 99;

@Inject
public DefaultReleaseManager( Map<String, Strategy> strategies,
Map<String, ReleasePhase> releasePhases,
Expand Down Expand Up @@ -187,7 +185,7 @@ public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependen

for ( int idx = 0; idx <= index; idx++ )
{
updateListener( prepareRequest.getReleaseManagerListener(), preparePhases.get( idx ), PHASE_SKIP );
phaseSkip( prepareRequest.getReleaseManagerListener(), preparePhases.get( idx ) );
}

if ( index == preparePhases.size() - 1 )
Expand All @@ -212,7 +210,7 @@ else if ( index >= 0 )
throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" );
}

updateListener( prepareRequest.getReleaseManagerListener(), name, PHASE_START );
phaseStart( prepareRequest.getReleaseManagerListener(), name );

ReleaseResult phaseResult = null;
try
Expand Down Expand Up @@ -249,10 +247,10 @@ else if ( index >= 0 )
throw new ReleaseExecutionException( "Error writing release properties after completing phase", e );
}

updateListener( prepareRequest.getReleaseManagerListener(), name, PHASE_END );
phaseEnd( prepareRequest.getReleaseManagerListener() );
}

updateListener( prepareRequest.getReleaseManagerListener(), "prepare", GOAL_END );
goalEnd( prepareRequest.getReleaseManagerListener() );
}

@Override
Expand All @@ -277,16 +275,16 @@ public void rollback( ReleaseRollbackRequest rollbackRequest )
throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" );
}

updateListener( rollbackRequest.getReleaseManagerListener(), name, PHASE_START );
phaseStart( rollbackRequest.getReleaseManagerListener(), name );
phase.execute( releaseDescriptor,
rollbackRequest.getReleaseEnvironment(),
rollbackRequest.getReactorProjects() );
updateListener( rollbackRequest.getReleaseManagerListener(), name, PHASE_END );
phaseEnd( rollbackRequest.getReleaseManagerListener() );
}

//call release:clean so that resume will not be possible anymore after a rollback
clean( rollbackRequest );
updateListener( rollbackRequest.getReleaseManagerListener(), "rollback", GOAL_END );
goalEnd( rollbackRequest.getReleaseManagerListener() );
}

@Override
Expand Down Expand Up @@ -363,7 +361,7 @@ private void perform( ReleasePerformRequest performRequest, ReleaseResult result
throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" );
}

updateListener( performRequest.getReleaseManagerListener(), name, PHASE_START );
phaseStart( performRequest.getReleaseManagerListener(), name );

ReleaseResult phaseResult = null;
try
Expand All @@ -389,7 +387,7 @@ private void perform( ReleasePerformRequest performRequest, ReleaseResult result
}
}

updateListener( performRequest.getReleaseManagerListener(), name, PHASE_END );
phaseEnd( performRequest.getReleaseManagerListener() );
}

if ( BooleanUtils.isNotFalse( performRequest.getClean() ) )
Expand All @@ -398,7 +396,7 @@ private void perform( ReleasePerformRequest performRequest, ReleaseResult result
clean( performRequest );
}

updateListener( performRequest.getReleaseManagerListener(), "perform", GOAL_END );
goalEnd( performRequest.getReleaseManagerListener() );
}

@Override
Expand Down Expand Up @@ -445,7 +443,7 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" );
}

updateListener( branchRequest.getReleaseManagerListener(), name, PHASE_START );
phaseStart( branchRequest.getReleaseManagerListener(), name );

if ( dryRun )
{
Expand All @@ -459,15 +457,16 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
branchRequest.getReleaseEnvironment(),
branchRequest.getReactorProjects() );
}
updateListener( branchRequest.getReleaseManagerListener(), name, PHASE_END );

phaseEnd( branchRequest.getReleaseManagerListener() );
}

if ( !dryRun )
{
clean( branchRequest );
}

updateListener( branchRequest.getReleaseManagerListener(), "branch", GOAL_END );
goalEnd( branchRequest.getReleaseManagerListener() );
}

@Override
Expand Down Expand Up @@ -513,16 +512,16 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" );
}

updateListener( updateVersionsRequest.getReleaseManagerListener(), name, PHASE_START );
phaseStart( updateVersionsRequest.getReleaseManagerListener(), name );
phase.execute( releaseDescriptor,
updateVersionsRequest.getReleaseEnvironment(),
updateVersionsRequest.getReactorProjects() );
updateListener( updateVersionsRequest.getReleaseManagerListener(), name, PHASE_END );
phaseEnd( updateVersionsRequest.getReleaseManagerListener() );
}

clean( updateVersionsRequest );

updateListener( updateVersionsRequest.getReleaseManagerListener(), "updateVersions", GOAL_END );
goalEnd( updateVersionsRequest.getReleaseManagerListener() );
}

/**
Expand Down Expand Up @@ -560,15 +559,10 @@ private ReleaseDescriptorBuilder loadReleaseDescriptorBuilder( ReleaseDescriptor
{
try
{
updateListener( listener, "verify-release-configuration", PHASE_START );
ReleaseDescriptorBuilder result = configStore.get().read( builder );
updateListener( listener, "verify-release-configuration", PHASE_END );
return result;
return configStore.get().read( builder );
}
catch ( ReleaseDescriptorStoreException e )
{
updateListener( listener, e.getMessage(), ERROR );

throw new ReleaseExecutionException( "Error reading stored configuration: " + e.getMessage(), e );
}
}
Expand All @@ -592,8 +586,6 @@ protected void clean( AbstractReleaseRequest releaseRequest ) throws ReleaseFai
@Override
public void clean( ReleaseCleanRequest cleanRequest ) throws ReleaseFailureException
{
updateListener( cleanRequest.getReleaseManagerListener(), "cleanup", PHASE_START );

logger.info( "Cleaning up after release..." );

ReleaseDescriptor releaseDescriptor =
Expand All @@ -616,8 +608,6 @@ public void clean( ReleaseCleanRequest cleanRequest ) throws ReleaseFailureExcep
( (ResourceGenerator) phase ).clean( cleanRequest.getReactorProjects() );
}
}

updateListener( cleanRequest.getReleaseManagerListener(), "cleanup", PHASE_END );
}

void goalStart( ReleaseManagerListener listener, String goal, List<String> phases )
Expand All @@ -628,27 +618,43 @@ void goalStart( ReleaseManagerListener listener, String goal, List<String> phase
}
}

void updateListener( ReleaseManagerListener listener, String name, int state )
void goalEnd( ReleaseManagerListener listener )
{
if ( listener != null )
{
switch ( state )
{
case GOAL_END:
listener.goalEnd();
break;
case PHASE_SKIP:
listener.phaseSkip( name );
break;
case PHASE_START:
listener.phaseStart( name );
break;
case PHASE_END:
listener.phaseEnd();
break;
default:
listener.error( name );
}
listener.goalEnd();
}
}

void phaseSkip( ReleaseManagerListener listener, String name )
{
if ( listener != null )
{
listener.phaseSkip( name );
}
}

void phaseStart( ReleaseManagerListener listener, String name )
{
if ( listener != null )
{
listener.phaseStart( name );
}
}

void phaseEnd( ReleaseManagerListener listener )
{
if ( listener != null )
{
listener.phaseEnd();
}
}

void error( ReleaseManagerListener listener, String name )
{
if ( listener != null )
{
listener.error( name );
}
}

Expand Down Expand Up @@ -726,7 +732,10 @@ private void logInfo( ReleaseResult result, String message )

private void captureException( ReleaseResult result, ReleaseManagerListener listener, Exception e )
{
updateListener( listener, e.getMessage(), ERROR );
if ( listener != null )
{
listener.error( e.getMessage() );
}

result.appendError( e );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void nextPhase( String name )

public void goalStart( String goal, List<String> phases )
{
log.info( "starting " + buffer().strong( goal ) + " goal" + ( dryRun ? " in dry-run mode" : "" )
log.info( "starting " + buffer().mojo( goal ) + " goal" + ( dryRun ? " in dry-run mode" : "" )
+ ", composed of " + phases.size() + " phases: " + StringUtils.join( phases.iterator(), ", " ) );
currentPhase = -1;
this.phases = phases;
Expand All @@ -86,16 +86,9 @@ public void goalStart( String goal, List<String> phases )

public void phaseStart( String name )
{
if ( goal == null || ( ( currentPhase + 1 ) >= phases.size() ) )
{
// out of goal phase
log.info( "phase " + buffer().strong( name ) + ( dryRun ? " (dry-run)" : "" ) );
return;
}

nextPhase( name );
log.info( buffer().strong( "[" + goal + ( dryRun ? " dry-run" : "" ) + "] " ).toString() + ( currentPhase + 1 )
+ "/" + phases.size() + " " + buffer().strong( name ) );
log.info( ( currentPhase + 1 ) + "/" + phases.size() + ' ' + buffer().mojo( goal + ':' + name )
+ ( dryRun ? " dry-run" : "" ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public abstract class AbstractBackupPomsPhase
extends AbstractReleasePhase
{
private final String backupSuffix = ".releaseBackup";
protected static final String BACKUP_SUFFIX = ".releaseBackup";

/**
* <p>getPomBackup.</p>
Expand All @@ -46,7 +46,7 @@ protected File getPomBackup( MavenProject project )

if ( pomFile != null )
{
return new File( pomFile.getAbsolutePath() + backupSuffix );
return new File( pomFile.getAbsolutePath() + BACKUP_SUFFIX );
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.codehaus.plexus.util.StringUtils;

import static java.util.Objects.requireNonNull;
import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;

/**
* Input any variables that were not yet configured.
Expand Down Expand Up @@ -230,16 +231,18 @@ else if ( scmTagNameFormat != null )
if ( branchOperation )
{
tag = prompter.get().prompt( "What is the branch name for \"" + project.getName() + "\"? ("
+ project.getGroupId() + ":" + project.getArtifactId() + ")" );
+ buffer().project( project.getArtifactId() ) + ")" );
if ( StringUtils.isEmpty( tag ) )
{
throw new ReleaseExecutionException( "No branch name was given." );
}
}
else
{
tag = prompter.get().prompt( "What is the SCM release tag or label for \"" + project.getName()
+ "\"? (" + project.getGroupId() + ":" + project.getArtifactId() + ")", suggestedName );
tag = prompter.get().prompt(
"What is the SCM release tag or label for \"" + project.getName()
+ "\"? (" + buffer().project( project.getArtifactId() ) + ")",
suggestedName );
}
}
catch ( PrompterException e )
Expand Down
Loading

0 comments on commit 6f9c8b7

Please sign in to comment.