Skip to content

Commit

Permalink
[SCM-947] Improve ChangeLogMojo by using ChangeLogRequest
Browse files Browse the repository at this point in the history
This closes #109
  • Loading branch information
cquoss authored and michael-o committed Aug 7, 2021
1 parent 4cafe0f commit f21ca5a
Showing 1 changed file with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.maven.scm.ScmBranch;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.changelog.ChangeLogScmRequest;
import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
import org.apache.maven.scm.command.changelog.ChangeLogSet;
import org.apache.maven.scm.provider.ScmProvider;
Expand All @@ -47,6 +48,7 @@
public class ChangeLogMojo
extends AbstractScmMojo
{

private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

/**
Expand Down Expand Up @@ -109,6 +111,24 @@ public class ChangeLogMojo
@Parameter( property = "scmVersion" )
private String scmVersion;

/**
* The branch name (TODO find out what this is for).
*/
@Parameter( property = "scmBranch" )
private String scmBranch;

/**
* The number of change log items to return.
*/
@Parameter( property = "limit" )
private Integer limit;

/**
* The number of days to look back for change log items to return.
*/
@Parameter( property = "numDays" )
private Integer numDays;

/**
* {@inheritDoc}
*/
Expand All @@ -125,24 +145,58 @@ public void execute()

ScmProvider provider = getScmManager().getProviderByRepository( repository );

ScmVersion startRev =
getScmVersion( StringUtils.isEmpty( startScmVersionType ) ? VERSION_TYPE_REVISION
: startScmVersionType, startScmVersion );
ScmVersion endRev =
getScmVersion( StringUtils.isEmpty( endScmVersionType ) ? VERSION_TYPE_REVISION
: endScmVersionType, endScmVersion );
ChangeLogScmRequest request = new ChangeLogScmRequest( repository, getFileSet() );

request.setDatePattern( dateFormat );

if ( StringUtils.isNotEmpty( startDate ) )
{
request.setStartDate( parseDate( localFormat, startDate ) );
}

if ( StringUtils.isNotEmpty( endDate ) )
{
request.setEndDate( parseDate( localFormat, endDate ) );
}

if ( StringUtils.isNotEmpty( startScmVersion ) )
{
ScmVersion startRev =
getScmVersion( StringUtils.isEmpty( startScmVersionType ) ? VERSION_TYPE_REVISION
: startScmVersionType, startScmVersion );
request.setStartRevision( startRev );
}

ChangeLogScmResult result;
if ( startRev != null || endRev != null )
if ( StringUtils.isNotEmpty( endScmVersion ) )
{
result = provider.changeLog( repository, getFileSet(), startRev, endRev, dateFormat );
ScmVersion endRev =
getScmVersion( StringUtils.isEmpty( endScmVersionType ) ? VERSION_TYPE_REVISION
: endScmVersionType, endScmVersion );
request.setEndRevision( endRev );
}
else

request.setLimit( limit );

if ( numDays != null )
{
result = provider.changeLog( repository, getFileSet(), this.parseDate( localFormat, this.startDate ),
this.parseDate( localFormat, this.endDate ), 0,
(ScmBranch) getScmVersion( scmVersionType, scmVersion ), dateFormat );
request.setNumDays( numDays );
}

if ( StringUtils.isNotEmpty( scmVersion ) )
{
ScmVersion rev =
getScmVersion( StringUtils.isEmpty( scmVersionType ) ? VERSION_TYPE_REVISION
: scmVersionType, scmVersion );
request.setRevision( rev );
}

if ( StringUtils.isNotEmpty( scmBranch ) )
{
request.setScmBranch( new ScmBranch( scmBranch ) );
}

ChangeLogScmResult result = provider.changeLog( request );

checkResult( result );

ChangeLogSet changeLogSet = result.getChangeLog();
Expand Down

0 comments on commit f21ca5a

Please sign in to comment.