Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRELEASE-1097] rework plugin output to clarify goal's phases #135

Merged
merged 5 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
michael-o marked this conversation as resolved.
Show resolved Hide resolved
<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;
michael-o marked this conversation as resolved.
Show resolved Hide resolved
return configStore.get().read( builder );
}
catch ( ReleaseDescriptorStoreException e )
{
updateListener( listener, e.getMessage(), ERROR );
michael-o marked this conversation as resolved.
Show resolved Hide resolved

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 );
michael-o marked this conversation as resolved.
Show resolved Hide resolved

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 );
michael-o marked this conversation as resolved.
Show resolved Hide resolved
}

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() );
michael-o marked this conversation as resolved.
Show resolved Hide resolved
}

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() ) )
michael-o marked this conversation as resolved.
Show resolved Hide resolved
{
// 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.codehaus.plexus.util.StringUtils;

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

/**
* Map projects to their new versions after release / into the next development cycle.
Expand Down Expand Up @@ -308,9 +309,8 @@ else if ( releaseDescriptor.isBranchCreation() )
{
messageKey = getMapversionPromptKey( releaseDescriptor );
}
String message =
MessageFormat.format( resourceBundle.getString( messageKey ), project.getName(),
projectId );
String message = MessageFormat.format( resourceBundle.getString( messageKey ), project.getName(),
hboutemy marked this conversation as resolved.
Show resolved Hide resolved
buffer().project( project.getArtifactId() ) );
nextVersion = prompter.prompt( message, suggestedVersion );

//@todo validate next version, maybe with DefaultArtifactVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

import java.io.File;
import java.net.URI;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -64,6 +65,7 @@
import org.codehaus.plexus.util.StringUtils;

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

/**
* Base class for rewriting phases.
Expand Down Expand Up @@ -199,9 +201,15 @@ private void transform( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment
{
result.setStartTime( ( startTime >= 0 ) ? startTime : System.currentTimeMillis() );

URI root = ReleaseUtil.getRootProject( reactorProjects ).getBasedir().toURI();

for ( MavenProject project : reactorProjects )
{
logInfo( result, "Transforming '" + project.getName() + "'..." );
URI pom = project.getFile().toURI();
logInfo( result,
"Transforming " + root.relativize( pom ).getPath() + ' '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that URI is not necessary here, but Path can make it relative too, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose going through a Path instead of an URI gives the exact same code/complexity/efficiency

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but URI has its problems and Path is a new solid API.

+ buffer().project( project.getArtifactId() ) + " '" + project.getName() + "'"
+ ( simulate ? " with ." + getPomSuffix() + " suffix" : "" ) + "..." );

transformProject( project, releaseDescriptor, releaseEnvironment, simulate, result );
}
Expand Down
Loading