Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[MRELEASE-787] release:prepare-with-pom fails when suppressCommitBefo…

…reTag is used.

Contributed by John R Fallows
Reviewed by Robert Scholte
Now also includes junit tests

git-svn-id: https://svn.apache.org/repos/asf/maven/release/trunk@1394740 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit ae0854777b73e3ea7b5bae7950a26c57423c67ca 1 parent e4c0bc3
@rfscholte rfscholte authored
View
34 ...e-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhase.java
@@ -19,6 +19,10 @@
* under the License.
*/
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
@@ -33,10 +37,6 @@
import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
import org.apache.maven.shared.release.util.ReleaseUtil;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Remove release POMs.
*
@@ -69,8 +69,6 @@ private ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvir
if ( releaseDescriptor.isGenerateReleasePoms() )
{
- logInfo( result, "Removing release POMs..." );
-
removeReleasePoms( releaseDescriptor, releaseEnvironment, simulate, result, reactorProjects );
}
else
@@ -96,7 +94,29 @@ private void removeReleasePoms( ReleaseDescriptor releaseDescriptor, ReleaseEnvi
releasePoms.add( ReleaseUtil.getReleasePom( project ) );
}
- removeReleasePomsFromScm( releaseDescriptor, releaseEnvironment, simulate, result, releasePoms );
+ if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() )
+ {
+ removeReleasePomsFromFilesystem( simulate, result, releasePoms );
+ }
+ else
+ {
+ removeReleasePomsFromScm( releaseDescriptor, releaseEnvironment, simulate, result, releasePoms );
+ }
+ }
+
+ private void removeReleasePomsFromFilesystem( boolean simulate, ReleaseResult result, List<File> releasePoms )
+ {
+ if ( simulate )
+ {
+ logInfo( result, "Full run would be removing " + releasePoms );
+ }
+ else
+ {
+ for ( File releasePom : releasePoms )
+ {
+ releasePom.delete();
+ }
+ }
}
private void removeReleasePomsFromScm( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment,
View
71 ...nager/src/test/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhaseTest.java
@@ -26,7 +26,9 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -42,9 +44,11 @@
import org.apache.maven.scm.manager.ScmManagerStub;
import org.apache.maven.scm.provider.ScmProvider;
import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.shared.release.ReleaseResult;
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
import org.apache.maven.shared.release.util.ReleaseUtil;
+import org.codehaus.plexus.util.IOUtil;
/**
* Test the remove release POMs phase.
@@ -146,6 +150,73 @@ public void testSimulateBasicPom()
// never invoke scmProviderMock
verifyNoMoreInteractions( scmProviderMock );
}
+
+ public void testExecuteWithSuppressCommitBeforeTag() throws Exception
+ {
+ // prepare
+ List<MavenProject> reactorProjects = createReactorProjects( "basic-pom" );
+ ReleaseDescriptor config = createReleaseDescriptor();
+ config.setSuppressCommitBeforeTagOrBranch( true );
+ config.setGenerateReleasePoms( true );
+
+ ScmProvider scmProviderMock = mock( ScmProvider.class );
+
+ ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
+ stub.setScmProvider( scmProviderMock );
+
+ // execute
+ ReleaseResult result = phase.execute( config, new DefaultReleaseEnvironment(), reactorProjects );
+
+ BufferedReader reader = null;
+ try
+ {
+ reader = new BufferedReader( new StringReader( result.getOutput() ) );
+
+ assertEquals( "[INFO] Removing release POM for 'Unnamed - groupId:artifactId:jar:1.0-SNAPSHOT'..." , reader.readLine() );
+ assertEquals( "Expected EOF", null, reader.readLine() );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ // never invoke scmProviderMock
+ verifyNoMoreInteractions( scmProviderMock );
+ }
+
+ public void testSimulateWithSuppressCommitBeforeTag() throws Exception
+ {
+ // prepare
+ List<MavenProject> reactorProjects = createReactorProjects( "basic-pom" );
+ ReleaseDescriptor config = createReleaseDescriptor();
+ config.setSuppressCommitBeforeTagOrBranch( true );
+ config.setGenerateReleasePoms( true );
+
+ ScmProvider scmProviderMock = mock( ScmProvider.class );
+
+ ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.ROLE );
+ stub.setScmProvider( scmProviderMock );
+
+ // execute
+ ReleaseResult result = phase.simulate( config, new DefaultReleaseEnvironment(), reactorProjects );
+
+ BufferedReader reader = null;
+ try
+ {
+ reader = new BufferedReader( new StringReader( result.getOutput() ) );
+
+ assertEquals( "[INFO] Removing release POM for 'Unnamed - groupId:artifactId:jar:1.0-SNAPSHOT'..." , reader.readLine() );
+ assertEquals( "[INFO] Full run would be removing [" + reactorProjects.get( 0 ).getFile().getParent() + File.separator + "release-pom.xml]", reader.readLine() );
+ assertEquals( "Expected EOF", null, reader.readLine() );
+ }
+ finally
+ {
+ IOUtil.close( reader );
+ }
+
+ // never invoke scmProviderMock
+ verifyNoMoreInteractions( scmProviderMock );
+ }
private List<MavenProject> createReactorProjects( String path )
throws Exception
View
6 pom.xml
@@ -127,6 +127,12 @@
<system>Jenkins</system>
<url>https://builds.apache.org/hudson/job/maven-release/</url>
</ciManagement>
+
+ <contributors>
+ <contributor>
+ <name>John R Fallows</name>
+ </contributor>
+ </contributors>
<properties>
<scmVersion>1.8</scmVersion>
Please sign in to comment.
Something went wrong with that request. Please try again.