Skip to content

Commit

Permalink
[MRELEASE-1079] add edge case support: root pom inherits scm
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed May 26, 2022
1 parent 1d5a846 commit 1c6f2c3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,18 @@ private void transform( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment
{
result.setStartTime( ( startTime >= 0 ) ? startTime : System.currentTimeMillis() );

boolean first = true;
for ( MavenProject project : reactorProjects )
{
logInfo( result, "Transforming '" + project.getName() + "'..." );

transformProject( project, releaseDescriptor, releaseEnvironment, simulate, result );
transformProject( project, first, releaseDescriptor, releaseEnvironment, simulate, result );
first = false;
}
}

private void transformProject( MavenProject project, ReleaseDescriptor releaseDescriptor,
ReleaseEnvironment releaseEnvironment, boolean simulate,
ReleaseResult result )
private void transformProject( MavenProject project, boolean first, ReleaseDescriptor releaseDescriptor,
ReleaseEnvironment releaseEnvironment, boolean simulate, ReleaseResult result )
throws ReleaseExecutionException, ReleaseFailureException
{
File pomFile = ReleaseUtil.getStandardPom( project );
Expand Down Expand Up @@ -244,7 +245,7 @@ private void transformProject( MavenProject project, ReleaseDescriptor releaseDe
}
}

transformDocument( project, etl.getModel(), releaseDescriptor, scmRepository, result,
transformDocument( project, first, etl.getModel(), releaseDescriptor, scmRepository, result,
simulate );

File outputFile;
Expand All @@ -261,9 +262,9 @@ private void transformProject( MavenProject project, ReleaseDescriptor releaseDe

}

private void transformDocument( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor,
ScmRepository scmRepository, ReleaseResult result,
boolean simulate )
private void transformDocument( MavenProject project, boolean first, Model modelTarget,
ReleaseDescriptor releaseDescriptor, ScmRepository scmRepository,
ReleaseResult result, boolean simulate )
throws ReleaseExecutionException, ReleaseFailureException
{
Model model = project.getModel();
Expand Down Expand Up @@ -356,7 +357,7 @@ private void transformDocument( MavenProject project, Model modelTarget, Release
}
}

transformScm( project, modelTarget, releaseDescriptor, projectId, scmRepository, result );
transformScm( project, first, modelTarget, releaseDescriptor, projectId, scmRepository, result );

if ( properties != null )
{
Expand Down Expand Up @@ -646,16 +647,17 @@ protected abstract String getOriginalVersion( ReleaseDescriptor releaseDescripto
* <p>transformScm.</p>
*
* @param project a {@link org.apache.maven.project.MavenProject} object
* @param first is first project in reactor
* @param modelTarget a {@link org.apache.maven.model.Model} object
* @param releaseDescriptor a {@link org.apache.maven.shared.release.config.ReleaseDescriptor} object
* @param projectId a {@link java.lang.String} object
* @param scmRepository a {@link org.apache.maven.scm.repository.ScmRepository} object
* @param result a {@link org.apache.maven.shared.release.ReleaseResult} object
* @throws org.apache.maven.shared.release.ReleaseExecutionException if any.
*/
protected abstract void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor,
String projectId, ScmRepository scmRepository,
ReleaseResult result )
protected abstract void transformScm( MavenProject project, boolean first, Model modelTarget,
ReleaseDescriptor releaseDescriptor, String projectId,
ScmRepository scmRepository, ReleaseResult result )
throws ReleaseExecutionException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ protected final String getPomSuffix()
}

@Override
protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor,
String projectId, ScmRepository scmRepository, ReleaseResult result )
protected void transformScm( MavenProject project, boolean first, Model modelTarget,
ReleaseDescriptor releaseDescriptor, String projectId, ScmRepository scmRepository,
ReleaseResult result )
{
// We are only updating versions no mods to scm needed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ protected final String getPomSuffix()
}

@Override
protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor,
String projectId, ScmRepository scmRepository, ReleaseResult result )
throws ReleaseExecutionException
protected void transformScm( MavenProject project, boolean first, Model modelTarget,
ReleaseDescriptor releaseDescriptor, String projectId, ScmRepository scmRepository,
ReleaseResult result )
throws ReleaseExecutionException
{
// If SCM is null in original model, it is inherited, no mods needed
if ( project.getScm() != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ protected final String getPomSuffix()
}

@Override
protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor,
String projectId, ScmRepository scmRepository, ReleaseResult result )
protected void transformScm( MavenProject project, boolean first, Model modelTarget,
ReleaseDescriptor releaseDescriptor, String projectId, ScmRepository scmRepository,
ReleaseResult result )
{
// If SCM is null in original model, it is inherited, no mods needed
if ( project.getScm() != null )
if ( project.getOriginalModel().getScm() != null || ( first && project.getScm() != null ) )
{
Scm scmRoot = modelTarget.getScm();
if ( scmRoot != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ protected final String getPomSuffix()
}

@Override
protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor,
String projectId, ScmRepository scmRepository, ReleaseResult result )
protected void transformScm( MavenProject project, boolean first, Model modelTarget,
ReleaseDescriptor releaseDescriptor, String projectId, ScmRepository scmRepository,
ReleaseResult result )
throws ReleaseExecutionException
{
// If SCM is null in original model, it is inherited, no mods needed
if ( project.getOriginalModel().getScm() != null )
if ( project.getOriginalModel().getScm() != null || ( first && project.getScm() != null ) )
{
Scm scmRoot = modelTarget.getScm();
if ( scmRoot != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void testRewriteInterpolatedVersionsDifferentVersion()
}
}

//@Test TODO fix
@Test
public void testRewriteBasicPomWithInheritedScm()
throws Exception
{
Expand Down Expand Up @@ -449,7 +449,7 @@ protected ReleaseDescriptorBuilder createDescriptorFromProjects( List<MavenProje
return builder;
}

//@Test TODO fix
@Test
public void testRewritePomWithExternallyReleasedParent()
throws Exception
{
Expand Down

0 comments on commit 1c6f2c3

Please sign in to comment.