diff --git a/maven-release-api/pom.xml b/maven-release-api/pom.xml index 543900c35..cae47978d 100644 --- a/maven-release-api/pom.xml +++ b/maven-release-api/pom.xml @@ -17,7 +17,6 @@ ~ specific language governing permissions and limitations ~ under the License. --> - 4.0.0 diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseExecutionException.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseExecutionException.java index de529f9b8..c121f2e5e 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseExecutionException.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseExecutionException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,21 +16,19 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; /** * Exception occurring during release execution. * * @author Brett Porter */ -public class ReleaseExecutionException - extends Exception -{ +public class ReleaseExecutionException extends Exception { /** * Creates a new instance of ReleaseExecutionException without detail message. */ - public ReleaseExecutionException( String message ) - { - super( message ); + public ReleaseExecutionException(String message) { + super(message); } /** @@ -40,8 +36,7 @@ public ReleaseExecutionException( String message ) * * @param message the detail message. */ - public ReleaseExecutionException( String message, Throwable cause ) - { - super( message, cause ); + public ReleaseExecutionException(String message, Throwable cause) { + super(message, cause); } } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseFailureException.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseFailureException.java index b93f4ef82..342eda4cc 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseFailureException.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseFailureException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,17 +16,15 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; /** * A failure during the release process. * * @author Brett Porter */ -public class ReleaseFailureException - extends Exception -{ - public ReleaseFailureException( String message ) - { - super( message ); +public class ReleaseFailureException extends Exception { + public ReleaseFailureException(String message) { + super(message); } } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseResult.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseResult.java index 62fde5cd7..57f3f4c1c 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseResult.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/ReleaseResult.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -25,8 +24,7 @@ /** * @author Edwin Punzalan */ -public class ReleaseResult -{ +public class ReleaseResult { /** The result of the release. */ public static final int UNDEFINED = -1; /** The release was successful. */ @@ -42,32 +40,29 @@ public class ReleaseResult private long endTime; - private static final String LS = System.getProperty( "line.separator" ); + private static final String LS = System.getProperty("line.separator"); /** * Append Info message to the output. * @param message the message to append */ - public void appendInfo( String message ) - { - stdOut.append( "[INFO] " ).append( message ).append( LS ); + public void appendInfo(String message) { + stdOut.append("[INFO] ").append(message).append(LS); } /** * Append warning message to the output. * @param message the message to append */ - public void appendWarn( String message ) - { - stdOut.append( "[WARN] " ).append( message ).append( LS ); + public void appendWarn(String message) { + stdOut.append("[WARN] ").append(message).append(LS); } /** * Append debug message to the output. * @param message the message to append */ - public void appendDebug( String message ) - { - stdOut.append( "[DEBUG] " ).append( message ).append( LS ); + public void appendDebug(String message) { + stdOut.append("[DEBUG] ").append(message).append(LS); } /** @@ -75,11 +70,10 @@ public void appendDebug( String message ) * @param message the message to append * @param e the exception to append */ - public void appendDebug( String message, Exception e ) - { - appendDebug( message ); + public void appendDebug(String message, Exception e) { + appendDebug(message); - stdOut.append( getStackTrace( e ) ).append( LS ); + stdOut.append(getStackTrace(e)).append(LS); } /** @@ -87,11 +81,10 @@ public void appendDebug( String message, Exception e ) * * @param message the message to append */ - public void appendError( String message ) - { - stdOut.append( "[ERROR] " ).append( message ).append( LS ); + public void appendError(String message) { + stdOut.append("[ERROR] ").append(message).append(LS); - setResultCode( ERROR ); + setResultCode(ERROR); } /** @@ -99,9 +92,8 @@ public void appendError( String message ) * * @param e the exception to append */ - public void appendError( Exception e ) - { - appendError( getStackTrace( e ) ); + public void appendError(Exception e) { + appendError(getStackTrace(e)); } /** @@ -110,11 +102,10 @@ public void appendError( Exception e ) * @param message the message to append * @param e the exception to append */ - public void appendError( String message, Exception e ) - { - appendError( message ); + public void appendError(String message, Exception e) { + appendError(message); - stdOut.append( getStackTrace( e ) ).append( LS ); + stdOut.append(getStackTrace(e)).append(LS); } /** @@ -122,53 +113,44 @@ public void appendError( String message, Exception e ) * * @param message the message to append */ - public void appendOutput( String message ) - { - stdOut.append( message ); + public void appendOutput(String message) { + stdOut.append(message); } - public String getOutput() - { + public String getOutput() { return stdOut.toString(); } - public int getResultCode() - { + public int getResultCode() { return resultCode; } - public void setResultCode( int resultCode ) - { + public void setResultCode(int resultCode) { this.resultCode = resultCode; } - public long getStartTime() - { + public long getStartTime() { return startTime; } - public void setStartTime( long startTime ) - { + public void setStartTime(long startTime) { this.startTime = startTime; } - public long getEndTime() - { + public long getEndTime() { return endTime; } - public void setEndTime( long endTime ) - { + public void setEndTime(long endTime) { this.endTime = endTime; } - private String getStackTrace( Exception e ) - { + private String getStackTrace(Exception e) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); - PrintStream stream = new PrintStream( byteStream ); + PrintStream stream = new PrintStream(byteStream); - e.printStackTrace( stream ); + e.printStackTrace(stream); stream.flush(); diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptor.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptor.java index 26a078d80..ed653c746 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptor.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; import java.util.List; @@ -28,8 +27,7 @@ * * @author Robert Scholte */ -public interface ReleaseDescriptor -{ +public interface ReleaseDescriptor { /** * Get if updateDependencies is false, dependencies version won't be updated to the next development version. * @@ -117,7 +115,6 @@ public interface ReleaseDescriptor */ boolean isRemoteTagging(); - /** * Get if the scm provider should sign the tag. NOTE: currently only implemented with git-exe. * @@ -446,7 +443,7 @@ public interface ReleaseDescriptor * @return {@code String} The original version for the resolved snapshot dependency. * @param artifactKey the artifact key {@code String} */ - String getDependencyOriginalVersion( String artifactKey ); + String getDependencyOriginalVersion(String artifactKey); /** *

getDependencyReleaseVersion.

@@ -454,7 +451,7 @@ public interface ReleaseDescriptor * @return {@code String} the release version for the resolved snapshot dependency. * @param artifactKey the artifact key {@code String} */ - String getDependencyReleaseVersion( String artifactKey ); + String getDependencyReleaseVersion(String artifactKey); /** *

getDependencyDevelopmentVersion.

@@ -462,8 +459,7 @@ public interface ReleaseDescriptor * @return {@code String} the release version for the resolved snapshot dependency. * @param artifactKey the artifact key {@code String} */ - String getDependencyDevelopmentVersion( String artifactKey ); - + String getDependencyDevelopmentVersion(String artifactKey); /** *

getProjectOriginalVersion.

@@ -471,7 +467,7 @@ public interface ReleaseDescriptor * @param projectKey a {@link java.lang.String} object * @return a {@link java.lang.String} object */ - String getProjectOriginalVersion( String projectKey ); + String getProjectOriginalVersion(String projectKey); /** *

getProjectDevelopmentVersion.

@@ -479,7 +475,7 @@ public interface ReleaseDescriptor * @param projectKey a {@link java.lang.String} object * @return a {@link java.lang.String} object */ - String getProjectDevelopmentVersion( String projectKey ); + String getProjectDevelopmentVersion(String projectKey); /** *

getProjectReleaseVersion.

@@ -487,7 +483,7 @@ public interface ReleaseDescriptor * @param key a {@link java.lang.String} object * @return a {@link java.lang.String} object */ - String getProjectReleaseVersion( String key ); + String getProjectReleaseVersion(String key); /** *

getOriginalScmInfo.

@@ -495,7 +491,7 @@ public interface ReleaseDescriptor * @param projectKey the project key {@code String} * @return the original {@code Scm} information. */ - Scm getOriginalScmInfo( String projectKey ); + Scm getOriginalScmInfo(String projectKey); /** *

hasOriginalScmInfo.

@@ -503,8 +499,7 @@ public interface ReleaseDescriptor * @param projectKey the project key {@code String} * @return has original Scm info. */ - boolean hasOriginalScmInfo( String projectKey ); - + boolean hasOriginalScmInfo(String projectKey); // Modifiable /** @@ -513,7 +508,7 @@ public interface ReleaseDescriptor * @param versionlessKey a {@link java.lang.String} object * @param string a {@link java.lang.String} object */ - void addDependencyOriginalVersion( String versionlessKey, String string ); + void addDependencyOriginalVersion(String versionlessKey, String string); /** *

addDependencyReleaseVersion.

@@ -521,7 +516,7 @@ public interface ReleaseDescriptor * @param versionlessKey a {@link java.lang.String} object * @param version a {@link java.lang.String} object */ - void addDependencyReleaseVersion( String versionlessKey, String version ); + void addDependencyReleaseVersion(String versionlessKey, String version); /** *

addDependencyDevelopmentVersion.

@@ -529,7 +524,7 @@ public interface ReleaseDescriptor * @param versionlessKey a {@link java.lang.String} object * @param version a {@link java.lang.String} object */ - void addDependencyDevelopmentVersion( String versionlessKey, String version ); + void addDependencyDevelopmentVersion(String versionlessKey, String version); /** *

addReleaseVersion.

@@ -537,7 +532,7 @@ public interface ReleaseDescriptor * @param projectId a {@link java.lang.String} object * @param nextVersion a {@link java.lang.String} object */ - void addReleaseVersion( String projectId, String nextVersion ); + void addReleaseVersion(String projectId, String nextVersion); /** *

addDevelopmentVersion.

@@ -545,35 +540,35 @@ public interface ReleaseDescriptor * @param projectId a {@link java.lang.String} object * @param nextVersion a {@link java.lang.String} object */ - void addDevelopmentVersion( String projectId, String nextVersion ); + void addDevelopmentVersion(String projectId, String nextVersion); /** *

setScmReleaseLabel.

* * @param tag a {@link java.lang.String} object */ - void setScmReleaseLabel( String tag ); + void setScmReleaseLabel(String tag); /** *

setScmReleasedPomRevision.

* * @param scmRevision a {@link java.lang.String} object */ - void setScmReleasedPomRevision( String scmRevision ); + void setScmReleasedPomRevision(String scmRevision); /** *

setScmRelativePathProjectDirectory.

* * @param scmRelativePathProjectDirectory a {@link java.lang.String} object */ - void setScmRelativePathProjectDirectory( String scmRelativePathProjectDirectory ); + void setScmRelativePathProjectDirectory(String scmRelativePathProjectDirectory); /** *

setScmSourceUrl.

* * @param scmUrl a {@link java.lang.String} object */ - void setScmSourceUrl( String scmUrl ); + void setScmSourceUrl(String scmUrl); /** * Returns whether unresolved SNAPSHOT dependencies should automatically be resolved. diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/env/ReleaseEnvironment.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/env/ReleaseEnvironment.java index df3ea3d9e..6eae54ce4 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/env/ReleaseEnvironment.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/env/ReleaseEnvironment.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.env; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.env; import java.io.File; @@ -27,8 +26,7 @@ *

ReleaseEnvironment interface.

* */ -public interface ReleaseEnvironment -{ +public interface ReleaseEnvironment { /** Constant DEFAULT_MAVEN_EXECUTOR_ID="forked-path" */ String DEFAULT_MAVEN_EXECUTOR_ID = "forked-path"; diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePhase.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePhase.java index 898bc0af6..0422be7c5 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePhase.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.shared.release.ReleaseResult; import org.slf4j.Logger; @@ -28,13 +27,10 @@ * * @author Brett Porter */ -public abstract class AbstractReleasePhase - implements ReleasePhase -{ - private final Logger logger = LoggerFactory.getLogger( getClass() ); +public abstract class AbstractReleasePhase implements ReleasePhase { + private final Logger logger = LoggerFactory.getLogger(getClass()); - protected Logger getLogger() - { + protected Logger getLogger() { return logger; } @@ -44,10 +40,9 @@ protected Logger getLogger() * @param result a {@link org.apache.maven.shared.release.ReleaseResult} object * @param message a {@link java.lang.String} object */ - protected void logInfo( ReleaseResult result, String message ) - { - result.appendInfo( message ); - getLogger().info( message ); + protected void logInfo(ReleaseResult result, String message) { + result.appendInfo(message); + getLogger().info(message); } /** @@ -56,10 +51,9 @@ protected void logInfo( ReleaseResult result, String message ) * @param result a {@link org.apache.maven.shared.release.ReleaseResult} object * @param message a {@link java.lang.String} object */ - protected void logWarn( ReleaseResult result, String message ) - { - result.appendWarn( message ); - getLogger().warn( message ); + protected void logWarn(ReleaseResult result, String message) { + result.appendWarn(message); + getLogger().warn(message); } /** @@ -68,10 +62,9 @@ protected void logWarn( ReleaseResult result, String message ) * @param result a {@link org.apache.maven.shared.release.ReleaseResult} object * @param message a {@link java.lang.String} object */ - protected void logError( ReleaseResult result, String message ) - { - result.appendWarn( message ); - getLogger().error( message ); + protected void logError(ReleaseResult result, String message) { + result.appendWarn(message); + getLogger().error(message); } /** @@ -80,10 +73,9 @@ protected void logError( ReleaseResult result, String message ) * @param result a {@link org.apache.maven.shared.release.ReleaseResult} object * @param message a {@link java.lang.String} object */ - protected void logDebug( ReleaseResult result, String message ) - { - result.appendDebug( message ); - getLogger().debug( message ); + protected void logDebug(ReleaseResult result, String message) { + result.appendDebug(message); + getLogger().debug(message); } /** @@ -93,10 +85,9 @@ protected void logDebug( ReleaseResult result, String message ) * @param message a {@link java.lang.String} object * @param e a {@link java.lang.Exception} object */ - protected void logDebug( ReleaseResult result, String message, Exception e ) - { - result.appendDebug( message, e ); - getLogger().debug( message, e ); + protected void logDebug(ReleaseResult result, String message, Exception e) { + result.appendDebug(message, e); + getLogger().debug(message, e); } /** @@ -104,11 +95,10 @@ protected void logDebug( ReleaseResult result, String message, Exception e ) * * @return a {@link org.apache.maven.shared.release.ReleaseResult} object */ - protected ReleaseResult getReleaseResultSuccess() - { + protected ReleaseResult getReleaseResultSuccess() { ReleaseResult result = new ReleaseResult(); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ReleasePhase.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ReleasePhase.java index 1170856f9..5f9359be3 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ReleasePhase.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ReleasePhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; + +import java.util.List; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.release.ReleaseExecutionException; @@ -26,15 +27,12 @@ import org.apache.maven.shared.release.config.ReleaseDescriptor; import org.apache.maven.shared.release.env.ReleaseEnvironment; -import java.util.List; - /** * A phase in the release cycle. * * @author Brett Porter */ -public interface ReleasePhase -{ +public interface ReleasePhase { /** * Execute the phase. * @@ -45,9 +43,11 @@ public interface ReleasePhase * @throws ReleaseFailureException a failure during the execution of the phase * @return the release result */ - ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException; + ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException; /** * Simulate the phase, but don't make any changes to the project. @@ -59,8 +59,9 @@ ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment r * @throws ReleaseFailureException a failure during the execution of the phase * @return the release result */ - ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException; - + ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException; } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ResourceGenerator.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ResourceGenerator.java index 34e58a22a..a4fb86450 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ResourceGenerator.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/phase/ResourceGenerator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.util.List; @@ -30,13 +29,12 @@ * @author Robert Scholte * @since 3.0.0-M5 */ -public interface ResourceGenerator -{ +public interface ResourceGenerator { /** * Clean up after a phase if it leaves any additional files in the checkout. * * @param reactorProjects the reactor projects * @return the release result */ - ReleaseResult clean( List reactorProjects ); + ReleaseResult clean(List reactorProjects); } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/PolicyException.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/PolicyException.java index 2531d7f04..92c8c7336 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/PolicyException.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/PolicyException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,34 +16,31 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy; /** *

PolicyException class.

* * @since 2.5.1 (MRELEASE-431) */ -public class PolicyException - extends Exception -{ +public class PolicyException extends Exception { /** *

Constructor for PolicyException.

* * @param message a {@link java.lang.String} object */ - public PolicyException( String message ) - { - super( message ); + public PolicyException(String message) { + super(message); } - + /** *

Constructor for PolicyException.

* * @param message a {@link java.lang.String} object * @param exception a {@link java.lang.Exception} object */ - public PolicyException( String message, Exception exception ) - { - super( message, exception ); + public PolicyException(String message, Exception exception) { + super(message, exception); } } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java index c2abbc222..22fe295cf 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.naming; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.naming; import org.apache.maven.shared.release.policy.PolicyException; @@ -26,8 +25,7 @@ * * @since 3.0.0 (MRELEASE-979) */ -public interface NamingPolicy -{ +public interface NamingPolicy { /** *

getName.

* @@ -35,7 +33,5 @@ public interface NamingPolicy * @param request the {@code NamingPolicyRequest} * @throws org.apache.maven.shared.release.policy.PolicyException if exception in the policy */ - NamingPolicyResult getName( NamingPolicyRequest request ) - throws PolicyException; - + NamingPolicyResult getName(NamingPolicyRequest request) throws PolicyException; } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java index 2c9df7328..82e1224e7 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.naming; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.naming; /** *

NamingPolicyRequest class.

@@ -25,12 +24,11 @@ * @author Robert Scholte * @since 3.0.0-M5 */ -public class NamingPolicyRequest -{ +public class NamingPolicyRequest { private String groupId; - + private String artifactId; - + private String version; /** @@ -38,8 +36,7 @@ public class NamingPolicyRequest * * @return a {@link java.lang.String} object */ - public String getGroupId() - { + public String getGroupId() { return groupId; } @@ -49,8 +46,7 @@ public String getGroupId() * @param groupId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.policy.naming.NamingPolicyRequest} object */ - public NamingPolicyRequest setGroupId( String groupId ) - { + public NamingPolicyRequest setGroupId(String groupId) { this.groupId = groupId; return this; } @@ -60,8 +56,7 @@ public NamingPolicyRequest setGroupId( String groupId ) * * @return a {@link java.lang.String} object */ - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } @@ -71,8 +66,7 @@ public String getArtifactId() * @param artifactId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.policy.naming.NamingPolicyRequest} object */ - public NamingPolicyRequest setArtifactId( String artifactId ) - { + public NamingPolicyRequest setArtifactId(String artifactId) { this.artifactId = artifactId; return this; } @@ -82,8 +76,7 @@ public NamingPolicyRequest setArtifactId( String artifactId ) * * @return a {@link java.lang.String} object */ - public String getVersion() - { + public String getVersion() { return version; } @@ -93,8 +86,7 @@ public String getVersion() * @param version a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.policy.naming.NamingPolicyRequest} object */ - public NamingPolicyRequest setVersion( String version ) - { + public NamingPolicyRequest setVersion(String version) { this.version = version; return this; } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java index 8920bf338..daf654d0a 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.naming; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.naming; /** *

NamingPolicyResult class.

* * @since 3.0.0 (MRELEASE-979) */ -public class NamingPolicyResult -{ +public class NamingPolicyResult { /** * The tag or branch name to use. */ @@ -36,8 +34,7 @@ public class NamingPolicyResult * * @return a {@link java.lang.String} object */ - public String getName() - { + public String getName() { return name; } @@ -47,10 +44,8 @@ public String getName() * @param name a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.policy.naming.NamingPolicyResult} object */ - public NamingPolicyResult setName( String name ) - { + public NamingPolicyResult setName(String name) { this.name = name; return this; } - } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicy.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicy.java index 40c812cc0..037b4de10 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicy.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.version; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.version; import org.apache.maven.shared.release.policy.PolicyException; import org.apache.maven.shared.release.versions.VersionParseException; @@ -27,8 +26,7 @@ * * @since 2.5.1 (MRELEASE-431) */ -public interface VersionPolicy -{ +public interface VersionPolicy { /** *

getReleaseVersion.

* @@ -37,8 +35,7 @@ public interface VersionPolicy * @throws org.apache.maven.shared.release.policy.PolicyException if exception in the policy * @throws org.apache.maven.shared.release.versions.VersionParseException if exception parsing the version */ - VersionPolicyResult getReleaseVersion( VersionPolicyRequest request ) - throws PolicyException, VersionParseException; + VersionPolicyResult getReleaseVersion(VersionPolicyRequest request) throws PolicyException, VersionParseException; /** *

getDevelopmentVersion.

@@ -48,6 +45,6 @@ VersionPolicyResult getReleaseVersion( VersionPolicyRequest request ) * @throws org.apache.maven.shared.release.policy.PolicyException if exception in the policy * @throws org.apache.maven.shared.release.versions.VersionParseException if exception parsing the version */ - VersionPolicyResult getDevelopmentVersion( VersionPolicyRequest request ) - throws PolicyException, VersionParseException; + VersionPolicyResult getDevelopmentVersion(VersionPolicyRequest request) + throws PolicyException, VersionParseException; } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyRequest.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyRequest.java index 9c771089f..fffdd54fd 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyRequest.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.version; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.version; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.scm.provider.ScmProvider; @@ -28,11 +27,10 @@ * * @since 2.5.1 (MRELEASE-431) */ -public class VersionPolicyRequest -{ +public class VersionPolicyRequest { private String version; - + private Metadata metaData; private ScmRepository scmRepository; @@ -46,8 +44,7 @@ public class VersionPolicyRequest * * @return a {@link java.lang.String} object */ - public String getVersion() - { + public String getVersion() { return version; } @@ -57,30 +54,27 @@ public String getVersion() * @param version a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object */ - public VersionPolicyRequest setVersion( String version ) - { + public VersionPolicyRequest setVersion(String version) { this.version = version; return this; } - + /** *

Getter for the field metaData.

* * @return a {@link org.apache.maven.artifact.repository.metadata.Metadata} object */ - public Metadata getMetaData() - { + public Metadata getMetaData() { return metaData; } - + /** *

Setter for the field metaData.

* * @param metaData a {@link org.apache.maven.artifact.repository.metadata.Metadata} object * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object */ - public VersionPolicyRequest setMetaData( Metadata metaData ) - { + public VersionPolicyRequest setMetaData(Metadata metaData) { this.metaData = metaData; return this; } @@ -90,8 +84,7 @@ public VersionPolicyRequest setMetaData( Metadata metaData ) * * @return a {@link ScmRepository} object */ - public ScmRepository getScmRepository() - { + public ScmRepository getScmRepository() { return scmRepository; } @@ -101,8 +94,7 @@ public ScmRepository getScmRepository() * @param scmRepository The {@link ScmRepository} where the history can be retrieved. * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object */ - public VersionPolicyRequest setScmRepository( ScmRepository scmRepository ) - { + public VersionPolicyRequest setScmRepository(ScmRepository scmRepository) { this.scmRepository = scmRepository; return this; } @@ -112,8 +104,7 @@ public VersionPolicyRequest setScmRepository( ScmRepository scmRepository ) * * @return a {@link ScmProvider} object */ - public ScmProvider getScmProvider() - { + public ScmProvider getScmProvider() { return scmProvider; } @@ -123,8 +114,7 @@ public ScmProvider getScmProvider() * @param scmProvider The {@link ScmProvider} where the history can be retrieved. * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object */ - public VersionPolicyRequest setScmProvider( ScmProvider scmProvider ) - { + public VersionPolicyRequest setScmProvider(ScmProvider scmProvider) { this.scmProvider = scmProvider; return this; } @@ -134,8 +124,7 @@ public VersionPolicyRequest setScmProvider( ScmProvider scmProvider ) * * @return the {@link String} that contains the workingDirectory (can be null or empty). */ - public String getWorkingDirectory() - { + public String getWorkingDirectory() { return workingDirectory; } @@ -145,8 +134,7 @@ public String getWorkingDirectory() * @param workingDirectory The {@link String} that contains the workingDirectory (can be null or empty). * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object */ - public VersionPolicyRequest setWorkingDirectory( String workingDirectory ) - { + public VersionPolicyRequest setWorkingDirectory(String workingDirectory) { this.workingDirectory = workingDirectory; return this; } @@ -156,8 +144,7 @@ public VersionPolicyRequest setWorkingDirectory( String workingDirectory ) * * @return the {@link String} that contains the config (can be null or empty). */ - public String getConfig() - { + public String getConfig() { return config; } @@ -167,10 +154,8 @@ public String getConfig() * @param config The {@link String} that contains the config (can be null or empty). * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyRequest} object */ - public VersionPolicyRequest setConfig( String config ) - { + public VersionPolicyRequest setConfig(String config) { this.config = config; return this; } - } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyResult.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyResult.java index f1ccbf96b..a5002d5c3 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyResult.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/version/VersionPolicyResult.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.version; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.version; /** *

VersionPolicyResult class.

* * @since 2.5.1 (MRELEASE-431) */ -public class VersionPolicyResult -{ +public class VersionPolicyResult { private String version; /** @@ -33,8 +31,7 @@ public class VersionPolicyResult * * @return a {@link java.lang.String} object */ - public String getVersion() - { + public String getVersion() { return version; } @@ -44,10 +41,8 @@ public String getVersion() * @param version a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.policy.version.VersionPolicyResult} object */ - public VersionPolicyResult setVersion( String version ) - { + public VersionPolicyResult setVersion(String version) { this.version = version; return this; } - } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/strategy/Strategy.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/strategy/Strategy.java index b02b02bb1..64d40d9eb 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/strategy/Strategy.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/strategy/Strategy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.strategy; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.strategy; import java.util.List; @@ -28,36 +27,35 @@ * * @author Robert Scholte */ -public interface Strategy -{ +public interface Strategy { /** *

getPreparePhases.

* * @return The release phases to execute the calling the prepare goal */ List getPreparePhases(); - + /** *

getPerformPhases.

* * @return The release phases to execute the calling the perform goal */ List getPerformPhases(); - + /** *

getBranchPhases.

* * @return The release phases to execute the calling the branch goal */ List getBranchPhases(); - + /** *

getRollbackPhases.

* * @return The release phases to execute the calling the rollback goal */ List getRollbackPhases(); - + /** *

getUpdateVersionsPhases.

* diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/AetherVersion.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/AetherVersion.java index 7b3dd4816..96941dedc 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/AetherVersion.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/AetherVersion.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,31 +16,24 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; import org.eclipse.aether.util.version.GenericVersionScheme; import org.eclipse.aether.version.InvalidVersionSpecificationException; -class AetherVersion - implements org.eclipse.aether.version.Version -{ +class AetherVersion implements org.eclipse.aether.version.Version { private final org.eclipse.aether.version.Version version; - AetherVersion( String version ) - throws VersionParseException - { - try - { - this.version = new GenericVersionScheme().parseVersion( version ); - } - catch ( InvalidVersionSpecificationException e ) - { - throw new VersionParseException( e.getMessage() ); + AetherVersion(String version) throws VersionParseException { + try { + this.version = new GenericVersionScheme().parseVersion(version); + } catch (InvalidVersionSpecificationException e) { + throw new VersionParseException(e.getMessage()); } } @Override - public String toString() - { + public String toString() { return this.version.toString(); } @@ -52,8 +43,7 @@ public String toString() * @param other a {@link org.eclipse.aether.version.Version} object * @return a int */ - public int compareTo( org.eclipse.aether.version.Version other ) - { - return this.version.compareTo( other ); + public int compareTo(org.eclipse.aether.version.Version other) { + return this.version.compareTo(other); } } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/MavenArtifactVersion.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/MavenArtifactVersion.java index 51bc3a71c..dafc9959b 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/MavenArtifactVersion.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/MavenArtifactVersion.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,55 +16,44 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -class MavenArtifactVersion - implements Comparable -{ +class MavenArtifactVersion implements Comparable { private final ArtifactVersion version; - MavenArtifactVersion( String version ) - { - this.version = new DefaultArtifactVersion( version ); + MavenArtifactVersion(String version) { + this.version = new DefaultArtifactVersion(version); } - public int compareTo( MavenArtifactVersion o ) - { - return version.compareTo( o.version ); + public int compareTo(MavenArtifactVersion o) { + return version.compareTo(o.version); } @Override - public String toString() - { + public String toString() { return this.version.toString(); } @Override - public int hashCode() - { + public int hashCode() { return this.version.hashCode(); } - + @Override - public boolean equals( Object other ) - { - if ( this == other ) - { + public boolean equals(Object other) { + if (this == other) { return true; } - if ( other == null ) - { + if (other == null) { return false; } - if ( other instanceof MavenArtifactVersion ) - { - return version.equals( ( (MavenArtifactVersion) other ).version ); + if (other instanceof MavenArtifactVersion) { + return version.equals(((MavenArtifactVersion) other).version); } return false; } - - } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/Version.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/Version.java index 6548e55ff..c4a36a3a9 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/Version.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/Version.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; import java.util.Arrays; import java.util.List; @@ -31,9 +30,7 @@ /** *

Version class.

*/ -public class Version - implements Comparable, Cloneable -{ +public class Version implements Comparable, Cloneable { private final AetherVersion aetherVersion; private final MavenArtifactVersion mavenArtifactVersion; @@ -71,20 +68,21 @@ public class Version private static final String SNAPSHOT_IDENTIFIER = "SNAPSHOT"; private static final String DIGIT_SEPARATOR_STRING = "."; - + private static final String DEFAULT_ANNOTATION_REV_SEPARATOR = "-"; private static final String DEFAULT_BUILD_SEPARATOR = "-"; /** Constant STANDARD_PATTERN */ - public static final Pattern STANDARD_PATTERN = Pattern.compile( "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated - - // followed by digit (version - // digits 1.22.0, etc) - + "([-_])?" // optional - or _ (annotation separator) - + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.) - + "([-_])?" // optional - or _ (annotation revision separator) - + "(\\d*)" // digits (any digits after rc or beta is an annotation revision) - + "(?:([-_])?(.*?))?$" ); // - or _ followed everything else (build specifier) + public static final Pattern STANDARD_PATTERN = Pattern.compile( + "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated - + // followed by digit (version + // digits 1.22.0, etc) + + "([-_])?" // optional - or _ (annotation separator) + + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.) + + "([-_])?" // optional - or _ (annotation revision separator) + + "(\\d*)" // digits (any digits after rc or beta is an annotation revision) + + "(?:([-_])?(.*?))?$"); // - or _ followed everything else (build specifier) /* * * cmaki 02242009 FIX for non-digit release numbers, e.g. trunk-SNAPSHOT or just SNAPSHOT This alternate pattern @@ -92,11 +90,16 @@ public class Version */ // for SNAPSHOT releases only (possible versions include: trunk-SNAPSHOT or SNAPSHOT) /** Constant ALTERNATE_PATTERN */ - public static final Pattern ALTERNATE_PATTERN = Pattern.compile( "^(SNAPSHOT|[a-zA-Z]+[_-]SNAPSHOT)" ); - - private Version( List digits, String annotation, String annotationRevision, String buildSpecifier, - String annotationSeparator, String annotationRevSeparator, String buildSeparator ) - { + public static final Pattern ALTERNATE_PATTERN = Pattern.compile("^(SNAPSHOT|[a-zA-Z]+[_-]SNAPSHOT)"); + + private Version( + List digits, + String annotation, + String annotationRevision, + String buildSpecifier, + String annotationSeparator, + String annotationRevSeparator, + String buildSeparator) { this.digits = digits; this.annotation = annotation; this.annotationRevision = annotationRevision; @@ -104,9 +107,9 @@ private Version( List digits, String annotation, String annotationRevisi this.annotationSeparator = annotationSeparator; this.annotationRevSeparator = annotationRevSeparator; this.buildSeparator = buildSeparator; - this.strVersion = getVersionString( this, buildSpecifier, buildSeparator ); + this.strVersion = getVersionString(this, buildSpecifier, buildSeparator); - // for now no need to reparse, original version was valid + // for now no need to reparse, original version was valid this.aetherVersion = null; this.mavenArtifactVersion = null; } @@ -117,18 +120,15 @@ private Version( List digits, String annotation, String annotationRevisi * @param version a {@link java.lang.String} object * @throws org.apache.maven.shared.release.versions.VersionParseException if any. */ - public Version( String version ) - throws VersionParseException - { + public Version(String version) throws VersionParseException { this.strVersion = version; - this.aetherVersion = new AetherVersion( version ); - this.mavenArtifactVersion = new MavenArtifactVersion( version ); + this.aetherVersion = new AetherVersion(version); + this.mavenArtifactVersion = new MavenArtifactVersion(version); // FIX for non-digit release numbers, e.g. trunk-SNAPSHOT or just SNAPSHOT - Matcher matcher = ALTERNATE_PATTERN.matcher( strVersion ); + Matcher matcher = ALTERNATE_PATTERN.matcher(strVersion); // TODO: hack because it didn't support "SNAPSHOT" - if ( matcher.matches() ) - { + if (matcher.matches()) { annotation = null; digits = null; buildSpecifier = version; @@ -136,41 +136,32 @@ public Version( String version ) return; } - Matcher m = STANDARD_PATTERN.matcher( strVersion ); - if ( m.matches() ) - { - digits = parseDigits( m.group( DIGITS_INDEX ) ); - if ( !SNAPSHOT_IDENTIFIER.equals( m.group( ANNOTATION_INDEX ) ) ) - { - annotationSeparator = m.group( ANNOTATION_SEPARATOR_INDEX ); - annotation = nullIfEmpty( m.group( ANNOTATION_INDEX ) ); - - if ( StringUtils.isNotEmpty( m.group( ANNOTATION_REV_SEPARATOR_INDEX ) ) - && StringUtils.isEmpty( m.group( ANNOTATION_REVISION_INDEX ) ) ) - { - // The build separator was picked up as the annotation revision separator - buildSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX ); - buildSpecifier = nullIfEmpty( m.group( BUILD_SPECIFIER_INDEX ) ); - } - else - { - annotationRevSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX ); - annotationRevision = nullIfEmpty( m.group( ANNOTATION_REVISION_INDEX ) ); + Matcher m = STANDARD_PATTERN.matcher(strVersion); + if (m.matches()) { + digits = parseDigits(m.group(DIGITS_INDEX)); + if (!SNAPSHOT_IDENTIFIER.equals(m.group(ANNOTATION_INDEX))) { + annotationSeparator = m.group(ANNOTATION_SEPARATOR_INDEX); + annotation = nullIfEmpty(m.group(ANNOTATION_INDEX)); - buildSeparator = m.group( BUILD_SEPARATOR_INDEX ); - buildSpecifier = nullIfEmpty( m.group( BUILD_SPECIFIER_INDEX ) ); + if (StringUtils.isNotEmpty(m.group(ANNOTATION_REV_SEPARATOR_INDEX)) + && StringUtils.isEmpty(m.group(ANNOTATION_REVISION_INDEX))) { + // The build separator was picked up as the annotation revision separator + buildSeparator = m.group(ANNOTATION_REV_SEPARATOR_INDEX); + buildSpecifier = nullIfEmpty(m.group(BUILD_SPECIFIER_INDEX)); + } else { + annotationRevSeparator = m.group(ANNOTATION_REV_SEPARATOR_INDEX); + annotationRevision = nullIfEmpty(m.group(ANNOTATION_REVISION_INDEX)); + + buildSeparator = m.group(BUILD_SEPARATOR_INDEX); + buildSpecifier = nullIfEmpty(m.group(BUILD_SPECIFIER_INDEX)); } - } - else - { + } else { // Annotation was "SNAPSHOT" so populate the build specifier with that data - buildSeparator = m.group( ANNOTATION_SEPARATOR_INDEX ); - buildSpecifier = nullIfEmpty( m.group( ANNOTATION_INDEX ) ); + buildSeparator = m.group(ANNOTATION_SEPARATOR_INDEX); + buildSpecifier = nullIfEmpty(m.group(ANNOTATION_INDEX)); } - } - else - { - throw new VersionParseException( "Unable to parse the version string: \"" + version + "\"" ); + } else { + throw new VersionParseException("Unable to parse the version string: \"" + version + "\""); } } @@ -179,9 +170,8 @@ public Version( String version ) * * @return a boolean */ - public boolean isSnapshot() - { - return ArtifactUtils.isSnapshot( strVersion ); + public boolean isSnapshot() { + return ArtifactUtils.isSnapshot(strVersion); } /** @@ -189,8 +179,7 @@ public boolean isSnapshot() * * @return a {@link java.lang.String} object */ - public String toString() - { + public String toString() { return strVersion; } @@ -202,38 +191,30 @@ public String toString() * @param buildSeparator a {@link java.lang.String} object * @return a {@link java.lang.String} object */ - protected static String getVersionString( Version info, String buildSpecifier, String buildSeparator ) - { + protected static String getVersionString(Version info, String buildSpecifier, String buildSeparator) { StringBuilder sb = new StringBuilder(); - if ( info.digits != null ) - { - sb.append( joinDigitString( info.digits ) ); + if (info.digits != null) { + sb.append(joinDigitString(info.digits)); } - if ( StringUtils.isNotEmpty( info.annotation ) ) - { - sb.append( StringUtils.defaultString( info.annotationSeparator ) ); - sb.append( info.annotation ); + if (StringUtils.isNotEmpty(info.annotation)) { + sb.append(StringUtils.defaultString(info.annotationSeparator)); + sb.append(info.annotation); } - if ( StringUtils.isNotEmpty( info.annotationRevision ) ) - { - if ( StringUtils.isEmpty( info.annotation ) ) - { - sb.append( StringUtils.defaultString( info.annotationSeparator ) ); - } - else - { - sb.append( StringUtils.defaultString( info.annotationRevSeparator ) ); + if (StringUtils.isNotEmpty(info.annotationRevision)) { + if (StringUtils.isEmpty(info.annotation)) { + sb.append(StringUtils.defaultString(info.annotationSeparator)); + } else { + sb.append(StringUtils.defaultString(info.annotationRevSeparator)); } - sb.append( info.annotationRevision ); + sb.append(info.annotationRevision); } - if ( StringUtils.isNotEmpty( buildSpecifier ) ) - { - sb.append( StringUtils.defaultString( buildSeparator ) ); - sb.append( buildSpecifier ); + if (StringUtils.isNotEmpty(buildSpecifier)) { + sb.append(StringUtils.defaultString(buildSeparator)); + sb.append(buildSpecifier); } return sb.toString(); @@ -245,24 +226,21 @@ protected static String getVersionString( Version info, String buildSpecifier, S * @return a {@code String} containing the items in the list joined by "." period * @param digits the list of digits {@code List} */ - protected static String joinDigitString( List digits ) - { - return digits != null ? StringUtils.join( digits.iterator(), DIGIT_SEPARATOR_STRING ) : null; + protected static String joinDigitString(List digits) { + return digits != null ? StringUtils.join(digits.iterator(), DIGIT_SEPARATOR_STRING) : null; } /** * Splits the string on "." and returns a list containing each digit. - * + * * @param strDigits */ - private List parseDigits( String strDigits ) - { - return Arrays.asList( StringUtils.split( strDigits, DIGIT_SEPARATOR_STRING ) ); + private List parseDigits(String strDigits) { + return Arrays.asList(StringUtils.split(strDigits, DIGIT_SEPARATOR_STRING)); } - private static String nullIfEmpty( String s ) - { - return StringUtils.isEmpty( s ) ? null : s; + private static String nullIfEmpty(String s) { + return StringUtils.isEmpty(s) ? null : s; } /** @@ -270,18 +248,16 @@ private static String nullIfEmpty( String s ) * * @return a {@link java.util.List} object */ - public List getDigits() - { + public List getDigits() { return digits; } - + /** *

Getter for the field annotation.

* * @return a {@link java.lang.String} object */ - public String getAnnotation() - { + public String getAnnotation() { return annotation; } @@ -290,8 +266,7 @@ public String getAnnotation() * * @return a {@link java.lang.String} object */ - public String getAnnotationRevSeparator() - { + public String getAnnotationRevSeparator() { return annotationRevSeparator; } @@ -300,8 +275,7 @@ public String getAnnotationRevSeparator() * * @return a {@link java.lang.String} object */ - public String getAnnotationRevision() - { + public String getAnnotationRevision() { return annotationRevision; } @@ -310,8 +284,7 @@ public String getAnnotationRevision() * * @return a {@link java.lang.String} object */ - public String getBuildSeparator() - { + public String getBuildSeparator() { return buildSeparator; } @@ -320,48 +293,59 @@ public String getBuildSeparator() * * @return a {@link java.lang.String} object */ - public String getBuildSpecifier() - { + public String getBuildSpecifier() { return buildSpecifier; } - + /** *

Setter for the field digits.

* * @param newDigits the new list of digits * @return a new instance of Version */ - public Version setDigits( List newDigits ) - { - return new Version( newDigits, this.annotation, this.annotationRevision, this.buildSpecifier, - this.annotationSeparator, this.annotationRevSeparator, this.buildSeparator ); + public Version setDigits(List newDigits) { + return new Version( + newDigits, + this.annotation, + this.annotationRevision, + this.buildSpecifier, + this.annotationSeparator, + this.annotationRevSeparator, + this.buildSeparator); } - + /** *

Setter for the field annotationRevision.

* * @param newAnnotationRevision the new annotation revision * @return a new instance of Version */ - public Version setAnnotationRevision( String newAnnotationRevision ) - { - return new Version( this.digits, this.annotation, newAnnotationRevision, this.buildSpecifier, - this.annotationSeparator, - Objects.toString( this.annotationRevSeparator, DEFAULT_ANNOTATION_REV_SEPARATOR ), - this.buildSeparator ); + public Version setAnnotationRevision(String newAnnotationRevision) { + return new Version( + this.digits, + this.annotation, + newAnnotationRevision, + this.buildSpecifier, + this.annotationSeparator, + Objects.toString(this.annotationRevSeparator, DEFAULT_ANNOTATION_REV_SEPARATOR), + this.buildSeparator); } - + /** *

Setter for the field buildSpecifier.

* * @param newBuildSpecifier the new build specifier * @return a new instance of Version */ - public Version setBuildSpecifier( String newBuildSpecifier ) - { - return new Version( this.digits, this.annotation, this.annotationRevision, newBuildSpecifier, - this.annotationSeparator, this.annotationRevSeparator, - Objects.toString( this.buildSeparator, DEFAULT_BUILD_SEPARATOR ) ); + public Version setBuildSpecifier(String newBuildSpecifier) { + return new Version( + this.digits, + this.annotation, + this.annotationRevision, + newBuildSpecifier, + this.annotationSeparator, + this.annotationRevSeparator, + Objects.toString(this.buildSeparator, DEFAULT_BUILD_SEPARATOR)); } /** @@ -373,29 +357,19 @@ public Version setBuildSpecifier( String newBuildSpecifier ) * @param other a {@link org.apache.maven.shared.release.versions.Version} object * @return a int */ - public int compareTo( Version other ) - throws VersionComparisonConflictException - { - int aetherComparisonResult = this.aetherVersion.compareTo( other.aetherVersion ); - int mavenComparisonResult = this.mavenArtifactVersion.compareTo( other.mavenArtifactVersion ); - - if ( aetherComparisonResult < 0 && mavenComparisonResult < 0 ) - { + public int compareTo(Version other) throws VersionComparisonConflictException { + int aetherComparisonResult = this.aetherVersion.compareTo(other.aetherVersion); + int mavenComparisonResult = this.mavenArtifactVersion.compareTo(other.mavenArtifactVersion); + + if (aetherComparisonResult < 0 && mavenComparisonResult < 0) { return -1; - } - else if ( aetherComparisonResult == 0 && mavenComparisonResult == 0 ) - { + } else if (aetherComparisonResult == 0 && mavenComparisonResult == 0) { return 0; - } - else if ( aetherComparisonResult > 0 && mavenComparisonResult > 0 ) - { + } else if (aetherComparisonResult > 0 && mavenComparisonResult > 0) { return 1; - } - else - { - throw new VersionComparisonConflictException( this.strVersion, other.strVersion, aetherComparisonResult, - mavenComparisonResult ); + } else { + throw new VersionComparisonConflictException( + this.strVersion, other.strVersion, aetherComparisonResult, mavenComparisonResult); } } - } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionComparisonConflictException.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionComparisonConflictException.java index 80011ac90..9dc2c0102 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionComparisonConflictException.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionComparisonConflictException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,13 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; /** *

VersionComparisonConflictException class.

*/ -public class VersionComparisonConflictException - extends RuntimeException -{ +public class VersionComparisonConflictException extends RuntimeException { private final String lhsVersion; @@ -42,9 +39,8 @@ public class VersionComparisonConflictException * @param aetherComparisonResult a int * @param mavenComparisonResult a int */ - public VersionComparisonConflictException( String lhsVersion, String rhsVersion, int aetherComparisonResult, - int mavenComparisonResult ) - { + public VersionComparisonConflictException( + String lhsVersion, String rhsVersion, int aetherComparisonResult, int mavenComparisonResult) { this.lhsVersion = lhsVersion; this.rhsVersion = rhsVersion; this.aetherComparisonResult = aetherComparisonResult; @@ -52,10 +48,8 @@ public VersionComparisonConflictException( String lhsVersion, String rhsVersion, } @Override - public String getMessage() - { + public String getMessage() { return "Conflict when comparing " + lhsVersion + " with " + rhsVersion + "; Aether: " + aetherComparisonResult - + "; Maven: " + mavenComparisonResult; + + "; Maven: " + mavenComparisonResult; } - } diff --git a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionParseException.java b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionParseException.java index ec8ed5d4c..5ca0f6f4f 100644 --- a/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionParseException.java +++ b/maven-release-api/src/main/java/org/apache/maven/shared/release/versions/VersionParseException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,21 +16,19 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; /** *

VersionParseException class.

*/ -public class VersionParseException - extends Exception -{ +public class VersionParseException extends Exception { /** *

Constructor for VersionParseException.

* * @param message a {@link java.lang.String} object */ - public VersionParseException( String message ) - { - super( message ); + public VersionParseException(String message) { + super(message); } /** @@ -40,8 +36,7 @@ public VersionParseException( String message ) * * @param message a {@link java.lang.String} object */ - public VersionParseException( String message, Throwable e ) - { - super( message, e ); + public VersionParseException(String message, Throwable e) { + super(message, e); } } diff --git a/maven-release-manager/pom.xml b/maven-release-manager/pom.xml index 7488a60dc..c68edcd67 100644 --- a/maven-release-manager/pom.xml +++ b/maven-release-manager/pom.xml @@ -1,5 +1,5 @@ - - 4.0.0 @@ -240,13 +239,6 @@ org.codehaus.modello modello-maven-plugin - - - - java - - - 3.0.0 false @@ -254,6 +246,13 @@ src/main/mdo/release-descriptor.mdo + + + + java + + + org.apache.maven.plugins diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/AbstractReleaseRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/AbstractReleaseRequest.java index d1314c2a2..6184016f6 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/AbstractReleaseRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/AbstractReleaseRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.util.List; @@ -30,8 +29,7 @@ * @author Robert Scholte * @since 2.3 */ -public abstract class AbstractReleaseRequest -{ +public abstract class AbstractReleaseRequest { private ReleaseDescriptorBuilder releaseDescriptorBuilder; private List reactorProjects; @@ -43,8 +41,7 @@ public abstract class AbstractReleaseRequest * * @return the releaseDescriptor */ - public ReleaseDescriptorBuilder getReleaseDescriptorBuilder() - { + public ReleaseDescriptorBuilder getReleaseDescriptorBuilder() { return releaseDescriptorBuilder; } @@ -53,8 +50,7 @@ public ReleaseDescriptorBuilder getReleaseDescriptorBuilder() * * @param releaseDescriptor the releaseDescriptor to set */ - public void setReleaseDescriptorBuilder( ReleaseDescriptorBuilder releaseDescriptor ) - { + public void setReleaseDescriptorBuilder(ReleaseDescriptorBuilder releaseDescriptor) { this.releaseDescriptorBuilder = releaseDescriptor; } @@ -63,8 +59,7 @@ public void setReleaseDescriptorBuilder( ReleaseDescriptorBuilder releaseDescrip * * @return the reactorProjects */ - public List getReactorProjects() - { + public List getReactorProjects() { return reactorProjects; } @@ -73,8 +68,7 @@ public List getReactorProjects() * * @param reactorProjects the reactorProjects to set */ - public void setReactorProjects( List reactorProjects ) - { + public void setReactorProjects(List reactorProjects) { this.reactorProjects = reactorProjects; } @@ -83,8 +77,7 @@ public void setReactorProjects( List reactorProjects ) * * @return the releaseManagerListener */ - public ReleaseManagerListener getReleaseManagerListener() - { + public ReleaseManagerListener getReleaseManagerListener() { return releaseManagerListener; } @@ -93,8 +86,7 @@ public ReleaseManagerListener getReleaseManagerListener() * * @param releaseManagerListener the releaseManagerListener to set */ - public void setReleaseManagerListener( ReleaseManagerListener releaseManagerListener ) - { + public void setReleaseManagerListener(ReleaseManagerListener releaseManagerListener) { this.releaseManagerListener = releaseManagerListener; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManager.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManager.java index 3ad03bd7f..6358f2410 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManager.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManager.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import javax.inject.Inject; import javax.inject.Named; @@ -55,10 +54,8 @@ */ @Singleton @Named -public class DefaultReleaseManager - implements ReleaseManager -{ - private final Logger logger = LoggerFactory.getLogger( getClass() ); +public class DefaultReleaseManager implements ReleaseManager { + private final Logger logger = LoggerFactory.getLogger(getClass()); private final Map strategies; @@ -73,464 +70,382 @@ public class DefaultReleaseManager private final AtomicReference configStore; @Inject - public DefaultReleaseManager( Map strategies, - Map releasePhases, - @Named( "properties" ) ReleaseDescriptorStore configStore ) - { - this.strategies = requireNonNull( strategies ); - this.releasePhases = requireNonNull( releasePhases ); - this.configStore = new AtomicReference<>( requireNonNull( configStore ) ); + public DefaultReleaseManager( + Map strategies, + Map releasePhases, + @Named("properties") ReleaseDescriptorStore configStore) { + this.strategies = requireNonNull(strategies); + this.releasePhases = requireNonNull(releasePhases); + this.configStore = new AtomicReference<>(requireNonNull(configStore)); } /** * For easier testing only! */ - public void setConfigStore( ReleaseDescriptorStore configStore ) - { - this.configStore.set( configStore ); + public void setConfigStore(ReleaseDescriptorStore configStore) { + this.configStore.set(configStore); } @Override - public ReleaseResult prepareWithResult( ReleasePrepareRequest prepareRequest ) - { + public ReleaseResult prepareWithResult(ReleasePrepareRequest prepareRequest) { ReleaseResult result = new ReleaseResult(); - result.setStartTime( System.currentTimeMillis() ); + result.setStartTime(System.currentTimeMillis()); - try - { - prepare( prepareRequest, result ); + try { + prepare(prepareRequest, result); - result.setResultCode( ReleaseResult.SUCCESS ); - } - catch ( ReleaseExecutionException | ReleaseFailureException e ) - { - captureException( result, prepareRequest.getReleaseManagerListener(), e ); - } - finally - { - result.setEndTime( System.currentTimeMillis() ); + result.setResultCode(ReleaseResult.SUCCESS); + } catch (ReleaseExecutionException | ReleaseFailureException e) { + captureException(result, prepareRequest.getReleaseManagerListener(), e); + } finally { + result.setEndTime(System.currentTimeMillis()); } return result; } @Override - public void prepare( ReleasePrepareRequest prepareRequest ) - throws ReleaseExecutionException, ReleaseFailureException - { - prepare( prepareRequest, new ReleaseResult() ); + public void prepare(ReleasePrepareRequest prepareRequest) + throws ReleaseExecutionException, ReleaseFailureException { + prepare(prepareRequest, new ReleaseResult()); } - private void prepare( ReleasePrepareRequest prepareRequest, ReleaseResult result ) - throws ReleaseExecutionException, ReleaseFailureException - { + private void prepare(ReleasePrepareRequest prepareRequest, ReleaseResult result) + throws ReleaseExecutionException, ReleaseFailureException { final ReleaseDescriptorBuilder builder = prepareRequest.getReleaseDescriptorBuilder(); // Create a config containing values from the session properties (ie command line properties with cli). - ReleaseUtils.copyPropertiesToReleaseDescriptor( prepareRequest.getUserProperties(), - new ReleaseDescriptorBuilder() - { - public ReleaseDescriptorBuilder addDevelopmentVersion( String key, - String value ) - { - builder.addDevelopmentVersion( key, value ); + ReleaseUtils.copyPropertiesToReleaseDescriptor( + prepareRequest.getUserProperties(), new ReleaseDescriptorBuilder() { + public ReleaseDescriptorBuilder addDevelopmentVersion(String key, String value) { + builder.addDevelopmentVersion(key, value); return this; } - public ReleaseDescriptorBuilder addReleaseVersion( String key, - String value ) - { - builder.addReleaseVersion( key, value ); + public ReleaseDescriptorBuilder addReleaseVersion(String key, String value) { + builder.addReleaseVersion(key, value); return this; } - public ReleaseDescriptorBuilder addDependencyReleaseVersion( String dependencyKey, - String version ) - { - builder.addDependencyReleaseVersion( dependencyKey, version ); + public ReleaseDescriptorBuilder addDependencyReleaseVersion(String dependencyKey, String version) { + builder.addDependencyReleaseVersion(dependencyKey, version); return this; } - public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependencyKey, - String version ) - { - builder.addDependencyDevelopmentVersion( dependencyKey, version ); + public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( + String dependencyKey, String version) { + builder.addDependencyDevelopmentVersion(dependencyKey, version); return this; } - } ); + }); BuilderReleaseDescriptor config; - if ( BooleanUtils.isNotFalse( prepareRequest.getResume() ) ) - { - config = loadReleaseDescriptor( builder, prepareRequest.getReleaseManagerListener() ); - } - else - { - config = ReleaseUtils.buildReleaseDescriptor( builder ); + if (BooleanUtils.isNotFalse(prepareRequest.getResume())) { + config = loadReleaseDescriptor(builder, prepareRequest.getReleaseManagerListener()); + } else { + config = ReleaseUtils.buildReleaseDescriptor(builder); } - Strategy releaseStrategy = getStrategy( config.getReleaseStrategyId() ); + Strategy releaseStrategy = getStrategy(config.getReleaseStrategyId()); - List preparePhases = getGoalPhases( releaseStrategy, "prepare" ); + List preparePhases = getGoalPhases(releaseStrategy, "prepare"); - goalStart( prepareRequest.getReleaseManagerListener(), "prepare", preparePhases ); + goalStart(prepareRequest.getReleaseManagerListener(), "prepare", preparePhases); // Later, it would be a good idea to introduce a proper workflow tool so that the release can be made up of a // more flexible set of steps. String completedPhase = config.getCompletedPhase(); - int index = preparePhases.indexOf( completedPhase ); + int index = preparePhases.indexOf(completedPhase); - for ( int idx = 0; idx <= index; idx++ ) - { - phaseSkip( prepareRequest.getReleaseManagerListener(), preparePhases.get( idx ) ); + for (int idx = 0; idx <= index; idx++) { + phaseSkip(prepareRequest.getReleaseManagerListener(), preparePhases.get(idx)); } - if ( index == preparePhases.size() - 1 ) - { - logInfo( result, "Release preparation already completed. You can now continue with release:perform, " - + "or start again using the -Dresume=false flag" ); - } - else if ( index >= 0 ) - { - logInfo( result, "Resuming release from phase '" + preparePhases.get( index + 1 ) + "'" ); + if (index == preparePhases.size() - 1) { + logInfo( + result, + "Release preparation already completed. You can now continue with release:perform, " + + "or start again using the -Dresume=false flag"); + } else if (index >= 0) { + logInfo(result, "Resuming release from phase '" + preparePhases.get(index + 1) + "'"); } // start from next phase - for ( int i = index + 1; i < preparePhases.size(); i++ ) - { - String name = preparePhases.get( i ); + for (int i = index + 1; i < preparePhases.size(); i++) { + String name = preparePhases.get(i); - ReleasePhase phase = releasePhases.get( name ); + ReleasePhase phase = releasePhases.get(name); - if ( phase == null ) - { - throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" ); + if (phase == null) { + throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); } - phaseStart( prepareRequest.getReleaseManagerListener(), name ); + phaseStart(prepareRequest.getReleaseManagerListener(), name); ReleaseResult phaseResult = null; - try - { - if ( BooleanUtils.isTrue( prepareRequest.getDryRun() ) ) - { - phaseResult = phase.simulate( config, - prepareRequest.getReleaseEnvironment(), - prepareRequest.getReactorProjects() ); - } - else - { - phaseResult = phase.execute( config, - prepareRequest.getReleaseEnvironment(), - prepareRequest.getReactorProjects() ); + try { + if (BooleanUtils.isTrue(prepareRequest.getDryRun())) { + phaseResult = phase.simulate( + config, prepareRequest.getReleaseEnvironment(), prepareRequest.getReactorProjects()); + } else { + phaseResult = phase.execute( + config, prepareRequest.getReleaseEnvironment(), prepareRequest.getReactorProjects()); } - } - finally - { - if ( result != null && phaseResult != null ) - { - result.appendOutput( phaseResult.getOutput() ); + } finally { + if (result != null && phaseResult != null) { + result.appendOutput(phaseResult.getOutput()); } } - config.setCompletedPhase( name ); - try - { - configStore.get().write( config ); - } - catch ( ReleaseDescriptorStoreException e ) - { + config.setCompletedPhase(name); + try { + configStore.get().write(config); + } catch (ReleaseDescriptorStoreException e) { // TODO: rollback? - throw new ReleaseExecutionException( "Error writing release properties after completing phase", e ); + throw new ReleaseExecutionException("Error writing release properties after completing phase", e); } - phaseEnd( prepareRequest.getReleaseManagerListener() ); + phaseEnd(prepareRequest.getReleaseManagerListener()); } - goalEnd( prepareRequest.getReleaseManagerListener() ); + goalEnd(prepareRequest.getReleaseManagerListener()); } @Override - public void rollback( ReleaseRollbackRequest rollbackRequest ) - throws ReleaseExecutionException, ReleaseFailureException - { + public void rollback(ReleaseRollbackRequest rollbackRequest) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseDescriptor releaseDescriptor = - loadReleaseDescriptor( rollbackRequest.getReleaseDescriptorBuilder(), null ); + loadReleaseDescriptor(rollbackRequest.getReleaseDescriptorBuilder(), null); - Strategy releaseStrategy = getStrategy( releaseDescriptor.getReleaseStrategyId() ); + Strategy releaseStrategy = getStrategy(releaseDescriptor.getReleaseStrategyId()); - List rollbackPhases = getGoalPhases( releaseStrategy, "rollback" ); + List rollbackPhases = getGoalPhases(releaseStrategy, "rollback"); - goalStart( rollbackRequest.getReleaseManagerListener(), "rollback", rollbackPhases ); + goalStart(rollbackRequest.getReleaseManagerListener(), "rollback", rollbackPhases); - for ( String name : rollbackPhases ) - { - ReleasePhase phase = releasePhases.get( name ); + for (String name : rollbackPhases) { + ReleasePhase phase = releasePhases.get(name); - if ( phase == null ) - { - throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" ); + if (phase == null) { + throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); } - phaseStart( rollbackRequest.getReleaseManagerListener(), name ); - phase.execute( releaseDescriptor, - rollbackRequest.getReleaseEnvironment(), - rollbackRequest.getReactorProjects() ); - phaseEnd( rollbackRequest.getReleaseManagerListener() ); + phaseStart(rollbackRequest.getReleaseManagerListener(), name); + phase.execute( + releaseDescriptor, rollbackRequest.getReleaseEnvironment(), rollbackRequest.getReactorProjects()); + phaseEnd(rollbackRequest.getReleaseManagerListener()); } - //call release:clean so that resume will not be possible anymore after a rollback - clean( rollbackRequest ); - goalEnd( rollbackRequest.getReleaseManagerListener() ); + // call release:clean so that resume will not be possible anymore after a rollback + clean(rollbackRequest); + goalEnd(rollbackRequest.getReleaseManagerListener()); } @Override - public ReleaseResult performWithResult( ReleasePerformRequest performRequest ) - { + public ReleaseResult performWithResult(ReleasePerformRequest performRequest) { ReleaseResult result = new ReleaseResult(); - try - { - result.setStartTime( System.currentTimeMillis() ); + try { + result.setStartTime(System.currentTimeMillis()); - perform( performRequest, result ); + perform(performRequest, result); - result.setResultCode( ReleaseResult.SUCCESS ); - } - catch ( ReleaseExecutionException | ReleaseFailureException e ) - { - captureException( result, performRequest.getReleaseManagerListener(), e ); - } - finally - { - result.setEndTime( System.currentTimeMillis() ); + result.setResultCode(ReleaseResult.SUCCESS); + } catch (ReleaseExecutionException | ReleaseFailureException e) { + captureException(result, performRequest.getReleaseManagerListener(), e); + } finally { + result.setEndTime(System.currentTimeMillis()); } return result; } @Override - public void perform( ReleasePerformRequest performRequest ) - throws ReleaseExecutionException, ReleaseFailureException - { - perform( performRequest, new ReleaseResult() ); + public void perform(ReleasePerformRequest performRequest) + throws ReleaseExecutionException, ReleaseFailureException { + perform(performRequest, new ReleaseResult()); } - private void perform( ReleasePerformRequest performRequest, ReleaseResult result ) - throws ReleaseExecutionException, ReleaseFailureException - { + private void perform(ReleasePerformRequest performRequest, ReleaseResult result) + throws ReleaseExecutionException, ReleaseFailureException { // https://issues.apache.org/jira/browse/MRELEASE-1104 because stageRepository is an additional arg // and only adding at perform stage it's not available during prepare and so not save the not available // when reloading. save this then change again after load - String additionalArguments = performRequest.getReleaseDescriptorBuilder().build().getAdditionalArguments(); - - List specificProfiles = - ReleaseUtils.buildReleaseDescriptor( performRequest.getReleaseDescriptorBuilder() ) - .getActivateProfiles(); + String additionalArguments = + performRequest.getReleaseDescriptorBuilder().build().getAdditionalArguments(); - ReleaseDescriptorBuilder builder = - loadReleaseDescriptorBuilder( performRequest.getReleaseDescriptorBuilder(), - performRequest.getReleaseManagerListener() ); + List specificProfiles = ReleaseUtils.buildReleaseDescriptor( + performRequest.getReleaseDescriptorBuilder()) + .getActivateProfiles(); + ReleaseDescriptorBuilder builder = loadReleaseDescriptorBuilder( + performRequest.getReleaseDescriptorBuilder(), performRequest.getReleaseManagerListener()); - builder.setAdditionalArguments( additionalArguments ); + builder.setAdditionalArguments(additionalArguments); - if ( specificProfiles != null && !specificProfiles.isEmpty() ) - { + if (specificProfiles != null && !specificProfiles.isEmpty()) { List allProfiles = - new ArrayList<>( ReleaseUtils.buildReleaseDescriptor( builder ).getActivateProfiles() ); - for ( String specificProfile : specificProfiles ) - { - if ( !allProfiles.contains( specificProfile ) ) - { - allProfiles.add( specificProfile ); + new ArrayList<>(ReleaseUtils.buildReleaseDescriptor(builder).getActivateProfiles()); + for (String specificProfile : specificProfiles) { + if (!allProfiles.contains(specificProfile)) { + allProfiles.add(specificProfile); } } - builder.setActivateProfiles( allProfiles ); + builder.setActivateProfiles(allProfiles); } - ReleaseDescriptor releaseDescriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor releaseDescriptor = ReleaseUtils.buildReleaseDescriptor(builder); - Strategy releaseStrategy = getStrategy( releaseDescriptor.getReleaseStrategyId() ); + Strategy releaseStrategy = getStrategy(releaseDescriptor.getReleaseStrategyId()); - List performPhases = getGoalPhases( releaseStrategy, "perform" ); + List performPhases = getGoalPhases(releaseStrategy, "perform"); - goalStart( performRequest.getReleaseManagerListener(), "perform", performPhases ); + goalStart(performRequest.getReleaseManagerListener(), "perform", performPhases); - for ( String name : performPhases ) - { - ReleasePhase phase = releasePhases.get( name ); + for (String name : performPhases) { + ReleasePhase phase = releasePhases.get(name); - if ( phase == null ) - { - throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" ); + if (phase == null) { + throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); } - phaseStart( performRequest.getReleaseManagerListener(), name ); + phaseStart(performRequest.getReleaseManagerListener(), name); ReleaseResult phaseResult = null; - try - { - if ( BooleanUtils.isTrue( performRequest.getDryRun() ) ) - { - phaseResult = phase.simulate( releaseDescriptor, - performRequest.getReleaseEnvironment(), - performRequest.getReactorProjects() ); + try { + if (BooleanUtils.isTrue(performRequest.getDryRun())) { + phaseResult = phase.simulate( + releaseDescriptor, + performRequest.getReleaseEnvironment(), + performRequest.getReactorProjects()); + } else { + phaseResult = phase.execute( + releaseDescriptor, + performRequest.getReleaseEnvironment(), + performRequest.getReactorProjects()); } - else - { - phaseResult = phase.execute( releaseDescriptor, - performRequest.getReleaseEnvironment(), - performRequest.getReactorProjects() ); - } - } - finally - { - if ( result != null && phaseResult != null ) - { - result.appendOutput( phaseResult.getOutput() ); + } finally { + if (result != null && phaseResult != null) { + result.appendOutput(phaseResult.getOutput()); } } - phaseEnd( performRequest.getReleaseManagerListener() ); + phaseEnd(performRequest.getReleaseManagerListener()); } - if ( BooleanUtils.isNotFalse( performRequest.getClean() ) ) - { + if (BooleanUtils.isNotFalse(performRequest.getClean())) { // call release:clean so that resume will not be possible anymore after a perform - clean( performRequest ); + clean(performRequest); } - goalEnd( performRequest.getReleaseManagerListener() ); + goalEnd(performRequest.getReleaseManagerListener()); } @Override - public void branch( ReleaseBranchRequest branchRequest ) - throws ReleaseExecutionException, ReleaseFailureException - { + public void branch(ReleaseBranchRequest branchRequest) throws ReleaseExecutionException, ReleaseFailureException { final ReleaseDescriptorBuilder builder = branchRequest.getReleaseDescriptorBuilder(); - - ReleaseUtils.copyPropertiesToReleaseDescriptor( branchRequest.getUserProperties(), - new ReleaseDescriptorBuilder() - { - public ReleaseDescriptorBuilder addDevelopmentVersion( String key, - String value ) - { - builder.addDevelopmentVersion( key, value ); - return this; - } - - public ReleaseDescriptorBuilder addReleaseVersion( String key, - String value ) - { - builder.addReleaseVersion( key, value ); - return this; - } - } ); - - ReleaseDescriptor releaseDescriptor = - loadReleaseDescriptor( builder, branchRequest.getReleaseManagerListener() ); - boolean dryRun = BooleanUtils.isTrue( branchRequest.getDryRun() ); + ReleaseUtils.copyPropertiesToReleaseDescriptor( + branchRequest.getUserProperties(), new ReleaseDescriptorBuilder() { + public ReleaseDescriptorBuilder addDevelopmentVersion(String key, String value) { + builder.addDevelopmentVersion(key, value); + return this; + } + + public ReleaseDescriptorBuilder addReleaseVersion(String key, String value) { + builder.addReleaseVersion(key, value); + return this; + } + }); - Strategy releaseStrategy = getStrategy( releaseDescriptor.getReleaseStrategyId() ); + ReleaseDescriptor releaseDescriptor = loadReleaseDescriptor(builder, branchRequest.getReleaseManagerListener()); - List branchPhases = getGoalPhases( releaseStrategy, "branch" ); + boolean dryRun = BooleanUtils.isTrue(branchRequest.getDryRun()); - goalStart( branchRequest.getReleaseManagerListener(), "branch", branchPhases ); + Strategy releaseStrategy = getStrategy(releaseDescriptor.getReleaseStrategyId()); - for ( String name : branchPhases ) - { - ReleasePhase phase = releasePhases.get( name ); + List branchPhases = getGoalPhases(releaseStrategy, "branch"); - if ( phase == null ) - { - throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" ); - } + goalStart(branchRequest.getReleaseManagerListener(), "branch", branchPhases); - phaseStart( branchRequest.getReleaseManagerListener(), name ); + for (String name : branchPhases) { + ReleasePhase phase = releasePhases.get(name); - if ( dryRun ) - { - phase.simulate( releaseDescriptor, - branchRequest.getReleaseEnvironment(), - branchRequest.getReactorProjects() ); + if (phase == null) { + throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); } - else // getDryRun is null or FALSE + + phaseStart(branchRequest.getReleaseManagerListener(), name); + + if (dryRun) { + phase.simulate( + releaseDescriptor, branchRequest.getReleaseEnvironment(), branchRequest.getReactorProjects()); + } else // getDryRun is null or FALSE { - phase.execute( releaseDescriptor, - branchRequest.getReleaseEnvironment(), - branchRequest.getReactorProjects() ); + phase.execute( + releaseDescriptor, branchRequest.getReleaseEnvironment(), branchRequest.getReactorProjects()); } - phaseEnd( branchRequest.getReleaseManagerListener() ); + phaseEnd(branchRequest.getReleaseManagerListener()); } - if ( !dryRun ) - { - clean( branchRequest ); + if (!dryRun) { + clean(branchRequest); } - goalEnd( branchRequest.getReleaseManagerListener() ); + goalEnd(branchRequest.getReleaseManagerListener()); } @Override - public void updateVersions( ReleaseUpdateVersionsRequest updateVersionsRequest ) - throws ReleaseExecutionException, ReleaseFailureException - { + public void updateVersions(ReleaseUpdateVersionsRequest updateVersionsRequest) + throws ReleaseExecutionException, ReleaseFailureException { final ReleaseDescriptorBuilder builder = updateVersionsRequest.getReleaseDescriptorBuilder(); - + // Create a config containing values from the session properties (ie command line properties with cli). - ReleaseUtils.copyPropertiesToReleaseDescriptor( updateVersionsRequest.getUserProperties(), - new ReleaseDescriptorBuilder() - { - public ReleaseDescriptorBuilder addDevelopmentVersion( String key, - String value ) - { - builder.addDevelopmentVersion( key, value ); - return this; - } - - public ReleaseDescriptorBuilder addReleaseVersion( String key, - String value ) - { - builder.addReleaseVersion( key, value ); - return this; - } - } ); + ReleaseUtils.copyPropertiesToReleaseDescriptor( + updateVersionsRequest.getUserProperties(), new ReleaseDescriptorBuilder() { + public ReleaseDescriptorBuilder addDevelopmentVersion(String key, String value) { + builder.addDevelopmentVersion(key, value); + return this; + } + + public ReleaseDescriptorBuilder addReleaseVersion(String key, String value) { + builder.addReleaseVersion(key, value); + return this; + } + }); ReleaseDescriptor releaseDescriptor = - loadReleaseDescriptor( builder, updateVersionsRequest.getReleaseManagerListener() ); + loadReleaseDescriptor(builder, updateVersionsRequest.getReleaseManagerListener()); - Strategy releaseStrategy = getStrategy( releaseDescriptor.getReleaseStrategyId() ); + Strategy releaseStrategy = getStrategy(releaseDescriptor.getReleaseStrategyId()); - List updateVersionsPhases = getGoalPhases( releaseStrategy, "updateVersions" ); + List updateVersionsPhases = getGoalPhases(releaseStrategy, "updateVersions"); - goalStart( updateVersionsRequest.getReleaseManagerListener(), "updateVersions", updateVersionsPhases ); + goalStart(updateVersionsRequest.getReleaseManagerListener(), "updateVersions", updateVersionsPhases); - for ( String name : updateVersionsPhases ) - { - ReleasePhase phase = releasePhases.get( name ); + for (String name : updateVersionsPhases) { + ReleasePhase phase = releasePhases.get(name); - if ( phase == null ) - { - throw new ReleaseExecutionException( "Unable to find phase '" + name + "' to execute" ); + if (phase == null) { + throw new ReleaseExecutionException("Unable to find phase '" + name + "' to execute"); } - phaseStart( updateVersionsRequest.getReleaseManagerListener(), name ); - phase.execute( releaseDescriptor, - updateVersionsRequest.getReleaseEnvironment(), - updateVersionsRequest.getReactorProjects() ); - phaseEnd( updateVersionsRequest.getReleaseManagerListener() ); + phaseStart(updateVersionsRequest.getReleaseManagerListener(), name); + phase.execute( + releaseDescriptor, + updateVersionsRequest.getReleaseEnvironment(), + updateVersionsRequest.getReactorProjects()); + phaseEnd(updateVersionsRequest.getReleaseManagerListener()); } - clean( updateVersionsRequest ); + clean(updateVersionsRequest); - goalEnd( updateVersionsRequest.getReleaseManagerListener() ); + goalEnd(updateVersionsRequest.getReleaseManagerListener()); } /** @@ -543,36 +458,25 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key, * directory or "" * @return The working directory */ - protected File determineWorkingDirectory( File checkoutDirectory, String relativePathProjectDirectory ) - { - if ( StringUtils.isNotEmpty( relativePathProjectDirectory ) ) - { - return new File( checkoutDirectory, relativePathProjectDirectory ); - } - else - { + protected File determineWorkingDirectory(File checkoutDirectory, String relativePathProjectDirectory) { + if (StringUtils.isNotEmpty(relativePathProjectDirectory)) { + return new File(checkoutDirectory, relativePathProjectDirectory); + } else { return checkoutDirectory; } } - private BuilderReleaseDescriptor loadReleaseDescriptor( ReleaseDescriptorBuilder builder, - ReleaseManagerListener listener ) - throws ReleaseExecutionException - { - return ReleaseUtils.buildReleaseDescriptor( loadReleaseDescriptorBuilder( builder, listener ) ); + private BuilderReleaseDescriptor loadReleaseDescriptor( + ReleaseDescriptorBuilder builder, ReleaseManagerListener listener) throws ReleaseExecutionException { + return ReleaseUtils.buildReleaseDescriptor(loadReleaseDescriptorBuilder(builder, listener)); } - private ReleaseDescriptorBuilder loadReleaseDescriptorBuilder( ReleaseDescriptorBuilder builder, - ReleaseManagerListener listener ) - throws ReleaseExecutionException - { - try - { - return configStore.get().read( builder ); - } - catch ( ReleaseDescriptorStoreException e ) - { - throw new ReleaseExecutionException( "Error reading stored configuration: " + e.getMessage(), e ); + private ReleaseDescriptorBuilder loadReleaseDescriptorBuilder( + ReleaseDescriptorBuilder builder, ReleaseManagerListener listener) throws ReleaseExecutionException { + try { + return configStore.get().read(builder); + } catch (ReleaseDescriptorStoreException e) { + throw new ReleaseExecutionException("Error reading stored configuration: " + e.getMessage(), e); } } @@ -582,172 +486,133 @@ private ReleaseDescriptorBuilder loadReleaseDescriptorBuilder( ReleaseDescriptor * @param releaseRequest a {@link org.apache.maven.shared.release.AbstractReleaseRequest} object * @throws org.apache.maven.shared.release.ReleaseFailureException if any. */ - protected void clean( AbstractReleaseRequest releaseRequest ) throws ReleaseFailureException - { + protected void clean(AbstractReleaseRequest releaseRequest) throws ReleaseFailureException { ReleaseCleanRequest cleanRequest = new ReleaseCleanRequest(); - cleanRequest.setReleaseDescriptorBuilder( releaseRequest.getReleaseDescriptorBuilder() ); - cleanRequest.setReleaseManagerListener( releaseRequest.getReleaseManagerListener() ); - cleanRequest.setReactorProjects( releaseRequest.getReactorProjects() ); + cleanRequest.setReleaseDescriptorBuilder(releaseRequest.getReleaseDescriptorBuilder()); + cleanRequest.setReleaseManagerListener(releaseRequest.getReleaseManagerListener()); + cleanRequest.setReactorProjects(releaseRequest.getReactorProjects()); - clean( cleanRequest ); + clean(cleanRequest); } @Override - public void clean( ReleaseCleanRequest cleanRequest ) throws ReleaseFailureException - { - logger.info( "Cleaning up after release..." ); + public void clean(ReleaseCleanRequest cleanRequest) throws ReleaseFailureException { + logger.info("Cleaning up after release..."); ReleaseDescriptor releaseDescriptor = - ReleaseUtils.buildReleaseDescriptor( cleanRequest.getReleaseDescriptorBuilder() ); + ReleaseUtils.buildReleaseDescriptor(cleanRequest.getReleaseDescriptorBuilder()); - configStore.get().delete( releaseDescriptor ); + configStore.get().delete(releaseDescriptor); - Strategy releaseStrategy = getStrategy( releaseDescriptor.getReleaseStrategyId() ); + Strategy releaseStrategy = getStrategy(releaseDescriptor.getReleaseStrategyId()); Set phases = new LinkedHashSet<>(); - phases.addAll( getGoalPhases( releaseStrategy, "prepare" ) ); - phases.addAll( getGoalPhases( releaseStrategy, "branch" ) ); - - for ( String name : phases ) - { - ReleasePhase phase = releasePhases.get( name ); - - if ( phase instanceof ResourceGenerator ) - { - ( (ResourceGenerator) phase ).clean( cleanRequest.getReactorProjects() ); + phases.addAll(getGoalPhases(releaseStrategy, "prepare")); + phases.addAll(getGoalPhases(releaseStrategy, "branch")); + + for (String name : phases) { + ReleasePhase phase = releasePhases.get(name); + + if (phase instanceof ResourceGenerator) { + ((ResourceGenerator) phase).clean(cleanRequest.getReactorProjects()); } } } - void goalStart( ReleaseManagerListener listener, String goal, List phases ) - { - if ( listener != null ) - { - listener.goalStart( goal, phases ); + void goalStart(ReleaseManagerListener listener, String goal, List phases) { + if (listener != null) { + listener.goalStart(goal, phases); } } - void goalEnd( ReleaseManagerListener listener ) - { - if ( listener != null ) - { + void goalEnd(ReleaseManagerListener listener) { + if (listener != null) { listener.goalEnd(); } } - void phaseSkip( ReleaseManagerListener listener, String name ) - { - if ( listener != null ) - { - listener.phaseSkip( name ); + 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 phaseStart(ReleaseManagerListener listener, String name) { + if (listener != null) { + listener.phaseStart(name); } } - void phaseEnd( ReleaseManagerListener listener ) - { - if ( listener != null ) - { + void phaseEnd(ReleaseManagerListener listener) { + if (listener != null) { listener.phaseEnd(); } } - void error( ReleaseManagerListener listener, String name ) - { - if ( listener != null ) - { - listener.error( name ); + void error(ReleaseManagerListener listener, String name) { + if (listener != null) { + listener.error(name); } } - private Strategy getStrategy( String strategyId ) throws ReleaseFailureException - { - Strategy strategy = strategies.get( strategyId ); - if ( strategy == null ) - { - throw new ReleaseFailureException( "Unknown strategy: " + strategyId ); + private Strategy getStrategy(String strategyId) throws ReleaseFailureException { + Strategy strategy = strategies.get(strategyId); + if (strategy == null) { + throw new ReleaseFailureException("Unknown strategy: " + strategyId); } return strategy; } - private List getGoalPhases( Strategy strategy, String goal ) - { + private List getGoalPhases(Strategy strategy, String goal) { List phases; - if ( "prepare".equals( goal ) ) - { + if ("prepare".equals(goal)) { phases = strategy.getPreparePhases(); - if ( phases == null ) - { - phases = strategies.get( "default" ).getPreparePhases(); + if (phases == null) { + phases = strategies.get("default").getPreparePhases(); } - } - else if ( "perform".equals( goal ) ) - { + } else if ("perform".equals(goal)) { phases = strategy.getPerformPhases(); - if ( phases == null ) - { - phases = strategies.get( "default" ).getPerformPhases(); + if (phases == null) { + phases = strategies.get("default").getPerformPhases(); } - } - else if ( "rollback".equals( goal ) ) - { + } else if ("rollback".equals(goal)) { phases = strategy.getRollbackPhases(); - if ( phases == null ) - { - phases = strategies.get( "default" ).getRollbackPhases(); + if (phases == null) { + phases = strategies.get("default").getRollbackPhases(); } - } - else if ( "branch".equals( goal ) ) - { + } else if ("branch".equals(goal)) { phases = strategy.getBranchPhases(); - if ( phases == null ) - { - phases = strategies.get( "default" ).getBranchPhases(); + if (phases == null) { + phases = strategies.get("default").getBranchPhases(); } - } - else if ( "updateVersions".equals( goal ) ) - { + } else if ("updateVersions".equals(goal)) { phases = strategy.getUpdateVersionsPhases(); - if ( phases == null ) - { - phases = strategies.get( "default" ).getUpdateVersionsPhases(); + if (phases == null) { + phases = strategies.get("default").getUpdateVersionsPhases(); } - } - else - { + } else { phases = null; } - return Collections.unmodifiableList( phases ); // TODO: NPE here in phases=null above! + return Collections.unmodifiableList(phases); // TODO: NPE here in phases=null above! } - private void logInfo( ReleaseResult result, String message ) - { - if ( result != null ) - { - result.appendInfo( message ); + private void logInfo(ReleaseResult result, String message) { + if (result != null) { + result.appendInfo(message); } - logger.info( message ); + logger.info(message); } - private void captureException( ReleaseResult result, ReleaseManagerListener listener, Exception e ) - { - if ( listener != null ) - { - listener.error( e.getMessage() ); + private void captureException(ReleaseResult result, ReleaseManagerListener listener, Exception e) { + if (listener != null) { + listener.error(e.getMessage()); } - result.appendError( e ); + result.appendError(e); - result.setResultCode( ReleaseResult.ERROR ); + result.setResultCode(ReleaseResult.ERROR); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java index d177879ea..4a5044214 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/DefaultReleaseManagerListener.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.util.List; @@ -31,9 +30,7 @@ * * @author Hervé Boutemy */ -public class DefaultReleaseManagerListener - implements ReleaseManagerListener -{ +public class DefaultReleaseManagerListener implements ReleaseManagerListener { private final Log log; private final boolean dryRun; @@ -49,9 +46,8 @@ public class DefaultReleaseManagerListener * * @param log a {@link org.apache.maven.plugin.logging.Log} object */ - public DefaultReleaseManagerListener( Log log ) - { - this( log, false ); + public DefaultReleaseManagerListener(Log log) { + this(log, false); } /** @@ -60,62 +56,53 @@ public DefaultReleaseManagerListener( Log log ) * @param log a {@link org.apache.maven.plugin.logging.Log} object * @param dryRun a boolean */ - public DefaultReleaseManagerListener( Log log, boolean dryRun ) - { + public DefaultReleaseManagerListener(Log log, boolean dryRun) { this.log = log; this.dryRun = dryRun; } - private void nextPhase( String name ) - { + private void nextPhase(String name) { currentPhase++; - if ( !name.equals( phases.get( currentPhase ) ) ) - { - log.warn( "inconsistent phase name: expected '" + phases.get( currentPhase ) + "' but got '" + name + "'" ); + if (!name.equals(phases.get(currentPhase))) { + log.warn("inconsistent phase name: expected '" + phases.get(currentPhase) + "' but got '" + name + "'"); } } - public void goalStart( String goal, List phases ) - { - log.info( "starting " + buffer().mojo( goal ) + " goal" + ( dryRun ? " in dry-run mode" : "" ) - + ", composed of " + phases.size() + " phases: " + StringUtils.join( phases.iterator(), ", " ) ); + public void goalStart(String goal, List phases) { + 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; this.goal = goal; } - public void phaseStart( String name ) - { - nextPhase( name ); - log.info( ( currentPhase + 1 ) + "/" + phases.size() + ' ' + buffer().mojo( goal + ':' + name ) - + ( dryRun ? " dry-run" : "" ) ); + public void phaseStart(String name) { + nextPhase(name); + log.info((currentPhase + 1) + "/" + phases.size() + ' ' + buffer().mojo(goal + ':' + name) + + (dryRun ? " dry-run" : "")); } /** *

phaseEnd.

*/ - public void phaseEnd() - { + public void phaseEnd() { // NOOP } - public void phaseSkip( String name ) - { - nextPhase( name ); + public void phaseSkip(String name) { + nextPhase(name); } /** *

goalEnd.

*/ - public void goalEnd() - { + public void goalEnd() { goal = null; phases = null; } - public void error( String reason ) - { - log.error( "error during phase " + ( currentPhase + 1 ) + "/" + phases.size() + " " + phases.get( currentPhase ) - + ": " + reason ); + public void error(String reason) { + log.error("error during phase " + (currentPhase + 1) + "/" + phases.size() + " " + phases.get(currentPhase) + + ": " + reason); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseBranchRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseBranchRequest.java index 94725a0b2..9500032dd 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseBranchRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseBranchRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.util.Properties; + import org.apache.maven.shared.release.env.ReleaseEnvironment; /** @@ -28,13 +28,12 @@ * @author Robert Scholte * @since 2.3 */ -public class ReleaseBranchRequest extends AbstractReleaseRequest -{ +public class ReleaseBranchRequest extends AbstractReleaseRequest { // using Boolean to detect if has been set explicitly private Boolean dryRun; private ReleaseEnvironment releaseEnvironment; - + private Properties userProperties; /** @@ -42,8 +41,7 @@ public class ReleaseBranchRequest extends AbstractReleaseRequest * * @return the dryRun */ - public Boolean getDryRun() - { + public Boolean getDryRun() { return dryRun; } @@ -52,8 +50,7 @@ public Boolean getDryRun() * * @param dryRun the dryRun to set */ - public void setDryRun( Boolean dryRun ) - { + public void setDryRun(Boolean dryRun) { this.dryRun = dryRun; } @@ -62,8 +59,7 @@ public void setDryRun( Boolean dryRun ) * * @return the releaseEnvironment */ - public ReleaseEnvironment getReleaseEnvironment() - { + public ReleaseEnvironment getReleaseEnvironment() { return releaseEnvironment; } @@ -72,28 +68,25 @@ public ReleaseEnvironment getReleaseEnvironment() * * @param releaseEnvironment the releaseEnvironment to set */ - public void setReleaseEnvironment( ReleaseEnvironment releaseEnvironment ) - { + public void setReleaseEnvironment(ReleaseEnvironment releaseEnvironment) { this.releaseEnvironment = releaseEnvironment; } - + /** *

Getter for the field userProperties.

* * @return a {@link java.util.Properties} object */ - public Properties getUserProperties() - { + public Properties getUserProperties() { return userProperties; } - + /** *

Setter for the field userProperties.

* * @param userProperties a {@link java.util.Properties} object */ - public void setUserProperties( Properties userProperties ) - { + public void setUserProperties(Properties userProperties) { this.userProperties = userProperties; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseCleanRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseCleanRequest.java index 0aca351be..2346d95ff 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseCleanRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseCleanRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; /** *

ReleaseCleanRequest class.

@@ -25,7 +24,4 @@ * @author Robert Scholte * @since 2.3 */ -public class ReleaseCleanRequest - extends AbstractReleaseRequest -{ -} +public class ReleaseCleanRequest extends AbstractReleaseRequest {} diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManager.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManager.java index 791e70604..499528f0b 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManager.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManager.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; /** * Release management classes. * * @author Brett Porter */ -public interface ReleaseManager -{ +public interface ReleaseManager { /** * Prepare a release. * @@ -34,7 +32,7 @@ public interface ReleaseManager * @throws org.apache.maven.shared.release.ReleaseFailureException if there is a problem performing the release * @since 2.3 */ - void prepare( ReleasePrepareRequest prepareRequest ) throws ReleaseExecutionException, ReleaseFailureException; + void prepare(ReleasePrepareRequest prepareRequest) throws ReleaseExecutionException, ReleaseFailureException; /** *

prepareWithResult.

@@ -42,7 +40,7 @@ public interface ReleaseManager * @param prepareRequest a {@link org.apache.maven.shared.release.ReleasePrepareRequest} object * @return a {@link org.apache.maven.shared.release.ReleaseResult} object */ - ReleaseResult prepareWithResult( ReleasePrepareRequest prepareRequest ); + ReleaseResult prepareWithResult(ReleasePrepareRequest prepareRequest); /** *

performWithResult.

@@ -50,7 +48,7 @@ public interface ReleaseManager * @param performRequest a {@link org.apache.maven.shared.release.ReleasePerformRequest} object * @return a {@link org.apache.maven.shared.release.ReleaseResult} object */ - ReleaseResult performWithResult( ReleasePerformRequest performRequest ); + ReleaseResult performWithResult(ReleasePerformRequest performRequest); /** * Perform a release @@ -60,8 +58,7 @@ public interface ReleaseManager * @throws org.apache.maven.shared.release.ReleaseFailureException if there is a problem performing the release * @since 2.3 */ - void perform( ReleasePerformRequest performRequest ) - throws ReleaseExecutionException, ReleaseFailureException; + void perform(ReleasePerformRequest performRequest) throws ReleaseExecutionException, ReleaseFailureException; /** * Clean a release. @@ -70,7 +67,7 @@ void perform( ReleasePerformRequest performRequest ) * @throws org.apache.maven.shared.release.ReleaseFailureException if exception when releasing * @since 2.3 */ - void clean( ReleaseCleanRequest cleanRequest ) throws ReleaseFailureException; + void clean(ReleaseCleanRequest cleanRequest) throws ReleaseFailureException; /** * Rollback changes made by the previous release @@ -80,8 +77,7 @@ void perform( ReleasePerformRequest performRequest ) * @throws org.apache.maven.shared.release.ReleaseFailureException if there is a problem during release rollback * @since 2.3 */ - void rollback( ReleaseRollbackRequest rollbackRequest ) - throws ReleaseExecutionException, ReleaseFailureException; + void rollback(ReleaseRollbackRequest rollbackRequest) throws ReleaseExecutionException, ReleaseFailureException; /** * Branch a project @@ -91,7 +87,7 @@ void rollback( ReleaseRollbackRequest rollbackRequest ) * @throws org.apache.maven.shared.release.ReleaseFailureException if there is a problem during release branch * @since 2.3 */ - void branch( ReleaseBranchRequest branchRequest ) throws ReleaseExecutionException, ReleaseFailureException; + void branch(ReleaseBranchRequest branchRequest) throws ReleaseExecutionException, ReleaseFailureException; /** * Update version numbers for a project @@ -101,6 +97,6 @@ void rollback( ReleaseRollbackRequest rollbackRequest ) * @throws org.apache.maven.shared.release.ReleaseFailureException if there is a problem during update versions * @since 2.3 */ - void updateVersions( ReleaseUpdateVersionsRequest updateVersionsRequest ) - throws ReleaseExecutionException, ReleaseFailureException; + void updateVersions(ReleaseUpdateVersionsRequest updateVersionsRequest) + throws ReleaseExecutionException, ReleaseFailureException; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManagerListener.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManagerListener.java index e4292eed1..b0ea2941b 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManagerListener.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseManagerListener.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.util.List; @@ -26,22 +25,21 @@ * * @author Edwin Punzalan */ -public interface ReleaseManagerListener -{ +public interface ReleaseManagerListener { /** *

goalStart.

* * @param goal a {@link java.lang.String} object * @param phases a {@link java.util.List} object */ - void goalStart( String goal, List phases ); + void goalStart(String goal, List phases); /** *

phaseStart.

* * @param name a {@link java.lang.String} object */ - void phaseStart( String name ); + void phaseStart(String name); /** *

phaseEnd.

@@ -53,7 +51,7 @@ public interface ReleaseManagerListener * * @param name a {@link java.lang.String} object */ - void phaseSkip( String name ); + void phaseSkip(String name); /** *

goalEnd.

@@ -65,5 +63,5 @@ public interface ReleaseManagerListener * * @param reason a {@link java.lang.String} object */ - void error( String reason ); + void error(String reason); } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePerformRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePerformRequest.java index f4b37a458..c3783c057 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePerformRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePerformRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import org.apache.maven.shared.release.env.ReleaseEnvironment; @@ -27,9 +26,7 @@ * @author Robert Scholte * @since 2.3 */ -public class ReleasePerformRequest - extends AbstractReleaseRequest -{ +public class ReleasePerformRequest extends AbstractReleaseRequest { // using Boolean to detect if has been set explicitly private Boolean dryRun; @@ -43,8 +40,7 @@ public class ReleasePerformRequest * * @return the dryRun */ - public Boolean getDryRun() - { + public Boolean getDryRun() { return dryRun; } @@ -53,8 +49,7 @@ public Boolean getDryRun() * * @param dryRun the dryRun to set */ - public void setDryRun( Boolean dryRun ) - { + public void setDryRun(Boolean dryRun) { this.dryRun = dryRun; } @@ -63,8 +58,7 @@ public void setDryRun( Boolean dryRun ) * * @return the clean */ - public Boolean getClean() - { + public Boolean getClean() { return clean; } @@ -73,8 +67,7 @@ public Boolean getClean() * * @param clean the clean to set */ - public void setClean( Boolean clean ) - { + public void setClean(Boolean clean) { this.clean = clean; } @@ -83,8 +76,7 @@ public void setClean( Boolean clean ) * * @return the releaseEnvironment */ - public ReleaseEnvironment getReleaseEnvironment() - { + public ReleaseEnvironment getReleaseEnvironment() { return releaseEnvironment; } @@ -93,8 +85,7 @@ public ReleaseEnvironment getReleaseEnvironment() * * @param releaseEnvironment the releaseEnvironment to set */ - public void setReleaseEnvironment( ReleaseEnvironment releaseEnvironment ) - { + public void setReleaseEnvironment(ReleaseEnvironment releaseEnvironment) { this.releaseEnvironment = releaseEnvironment; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePrepareRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePrepareRequest.java index 992239322..4d6803671 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePrepareRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleasePrepareRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.util.Properties; @@ -29,9 +28,7 @@ * @author Robert Scholte * @since 2.3 */ -public class ReleasePrepareRequest - extends AbstractReleaseRequest -{ +public class ReleasePrepareRequest extends AbstractReleaseRequest { // using Boolean to detect if has been set explicitly private Boolean dryRun; @@ -39,7 +36,7 @@ public class ReleasePrepareRequest private Boolean resume; private ReleaseEnvironment releaseEnvironment; - + private Properties userProperties; /** @@ -47,8 +44,7 @@ public class ReleasePrepareRequest * * @return the dryRun */ - public Boolean getDryRun() - { + public Boolean getDryRun() { return dryRun; } @@ -57,8 +53,7 @@ public Boolean getDryRun() * * @param dryRun the dryRun to set */ - public void setDryRun( Boolean dryRun ) - { + public void setDryRun(Boolean dryRun) { this.dryRun = dryRun; } @@ -67,8 +62,7 @@ public void setDryRun( Boolean dryRun ) * * @return the resume */ - public Boolean getResume() - { + public Boolean getResume() { return resume; } @@ -77,8 +71,7 @@ public Boolean getResume() * * @param resume the resume to set */ - public void setResume( Boolean resume ) - { + public void setResume(Boolean resume) { this.resume = resume; } @@ -87,8 +80,7 @@ public void setResume( Boolean resume ) * * @return the releaseEnvironment */ - public ReleaseEnvironment getReleaseEnvironment() - { + public ReleaseEnvironment getReleaseEnvironment() { return releaseEnvironment; } @@ -97,28 +89,25 @@ public ReleaseEnvironment getReleaseEnvironment() * * @param releaseEnvironment the releaseEnvironment to set */ - public void setReleaseEnvironment( ReleaseEnvironment releaseEnvironment ) - { + public void setReleaseEnvironment(ReleaseEnvironment releaseEnvironment) { this.releaseEnvironment = releaseEnvironment; } - + /** *

Getter for the field userProperties.

* * @return a {@link java.util.Properties} object */ - public Properties getUserProperties() - { + public Properties getUserProperties() { return userProperties; } - + /** *

Setter for the field userProperties.

* * @param userProperties a {@link java.util.Properties} object */ - public void setUserProperties( Properties userProperties ) - { + public void setUserProperties(Properties userProperties) { this.userProperties = userProperties; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseRollbackRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseRollbackRequest.java index 45d24de88..126f4c5e2 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseRollbackRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseRollbackRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import org.apache.maven.shared.release.env.ReleaseEnvironment; @@ -27,9 +26,7 @@ * @author Robert Scholte * @since 2.3 */ -public class ReleaseRollbackRequest - extends AbstractReleaseRequest -{ +public class ReleaseRollbackRequest extends AbstractReleaseRequest { private ReleaseEnvironment releaseEnvironment; /** @@ -37,8 +34,7 @@ public class ReleaseRollbackRequest * * @return the releaseEnvironment */ - public ReleaseEnvironment getReleaseEnvironment() - { + public ReleaseEnvironment getReleaseEnvironment() { return releaseEnvironment; } @@ -47,8 +43,7 @@ public ReleaseEnvironment getReleaseEnvironment() * * @param releaseEnvironment the releaseEnvironment to set */ - public void setReleaseEnvironment( ReleaseEnvironment releaseEnvironment ) - { + public void setReleaseEnvironment(ReleaseEnvironment releaseEnvironment) { this.releaseEnvironment = releaseEnvironment; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseUpdateVersionsRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseUpdateVersionsRequest.java index 3412fc465..434f2ba6d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseUpdateVersionsRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/ReleaseUpdateVersionsRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import java.util.Properties; @@ -29,11 +28,9 @@ * @author Robert Scholte * @since 2.3 */ -public class ReleaseUpdateVersionsRequest - extends AbstractReleaseRequest -{ +public class ReleaseUpdateVersionsRequest extends AbstractReleaseRequest { private ReleaseEnvironment releaseEnvironment; - + private Properties userProperties; /** @@ -41,8 +38,7 @@ public class ReleaseUpdateVersionsRequest * * @return the releaseEnvironment */ - public ReleaseEnvironment getReleaseEnvironment() - { + public ReleaseEnvironment getReleaseEnvironment() { return releaseEnvironment; } @@ -51,28 +47,25 @@ public ReleaseEnvironment getReleaseEnvironment() * * @param releaseEnvironment the releaseEnvironment to set */ - public void setReleaseEnvironment( ReleaseEnvironment releaseEnvironment ) - { + public void setReleaseEnvironment(ReleaseEnvironment releaseEnvironment) { this.releaseEnvironment = releaseEnvironment; } - + /** *

Getter for the field userProperties.

* * @return a {@link java.util.Properties} object */ - public Properties getUserProperties() - { + public Properties getUserProperties() { return userProperties; } - + /** *

Setter for the field userProperties.

* * @param userProperties a {@link java.util.Properties} object */ - public void setUserProperties( Properties userProperties ) - { + public void setUserProperties(Properties userProperties) { this.userProperties = userProperties; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java index 9d3246c00..2ebb584d9 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStore.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; import javax.inject.Inject; import javax.inject.Named; @@ -50,25 +49,21 @@ * @author Brett Porter */ @Singleton -@Named( "properties" ) -public class PropertiesReleaseDescriptorStore - implements ReleaseDescriptorStore -{ - private final Logger logger = LoggerFactory.getLogger( getClass() ); +@Named("properties") +public class PropertiesReleaseDescriptorStore implements ReleaseDescriptorStore { + private final Logger logger = LoggerFactory.getLogger(getClass()); private final MavenCrypto mavenCrypto; @Inject - public PropertiesReleaseDescriptorStore( MavenCrypto mavenCrypto ) - { - this.mavenCrypto = requireNonNull( mavenCrypto ); + public PropertiesReleaseDescriptorStore(MavenCrypto mavenCrypto) { + this.mavenCrypto = requireNonNull(mavenCrypto); } @Override - public ReleaseDescriptorBuilder read( ReleaseDescriptorBuilder mergeDescriptor ) - throws ReleaseDescriptorStoreException - { - return read( mergeDescriptor, getDefaultReleasePropertiesFile( mergeDescriptor.build() ) ); + public ReleaseDescriptorBuilder read(ReleaseDescriptorBuilder mergeDescriptor) + throws ReleaseDescriptorStoreException { + return read(mergeDescriptor, getDefaultReleasePropertiesFile(mergeDescriptor.build())); } /** @@ -78,10 +73,8 @@ public ReleaseDescriptorBuilder read( ReleaseDescriptorBuilder mergeDescriptor ) * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @throws org.apache.maven.shared.release.config.ReleaseDescriptorStoreException if any. */ - public ReleaseDescriptorBuilder read( File file ) - throws ReleaseDescriptorStoreException - { - return read( null, file ); + public ReleaseDescriptorBuilder read(File file) throws ReleaseDescriptorStoreException { + return read(null, file); } /** @@ -92,62 +85,46 @@ public ReleaseDescriptorBuilder read( File file ) * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @throws org.apache.maven.shared.release.config.ReleaseDescriptorStoreException if any. */ - public ReleaseDescriptorBuilder read( ReleaseDescriptorBuilder mergeDescriptor, File file ) - throws ReleaseDescriptorStoreException - { + public ReleaseDescriptorBuilder read(ReleaseDescriptorBuilder mergeDescriptor, File file) + throws ReleaseDescriptorStoreException { Properties properties = new Properties(); - try ( InputStream inStream = new FileInputStream( file ) ) - { - properties.load( inStream ); - } - catch ( FileNotFoundException e ) - { - logger.debug( file.getName() + " not found - using empty properties" ); - } - catch ( IOException e ) - { + try (InputStream inStream = new FileInputStream(file)) { + properties.load(inStream); + } catch (FileNotFoundException e) { + logger.debug(file.getName() + " not found - using empty properties"); + } catch (IOException e) { throw new ReleaseDescriptorStoreException( - "Error reading properties file '" + file.getName() + "': " + e.getMessage(), e ); + "Error reading properties file '" + file.getName() + "': " + e.getMessage(), e); } - try - { - mavenCrypto.decryptProperties( properties ); - } - catch ( MavenCryptoException e ) - { - logger.debug( e.getMessage() ); + try { + mavenCrypto.decryptProperties(properties); + } catch (MavenCryptoException e) { + logger.debug(e.getMessage()); } ReleaseDescriptorBuilder builder; - if ( mergeDescriptor != null ) - { + if (mergeDescriptor != null) { builder = mergeDescriptor; - } - else - { + } else { builder = new ReleaseDescriptorBuilder(); } - ReleaseUtils.copyPropertiesToReleaseDescriptor( properties, builder ); + ReleaseUtils.copyPropertiesToReleaseDescriptor(properties, builder); return builder; } @Override - public void write( ReleaseDescriptor config ) - throws ReleaseDescriptorStoreException - { - write( (BuilderReleaseDescriptor) config, getDefaultReleasePropertiesFile( config ) ); + public void write(ReleaseDescriptor config) throws ReleaseDescriptorStoreException { + write((BuilderReleaseDescriptor) config, getDefaultReleasePropertiesFile(config)); } @Override - public void delete( ReleaseDescriptor config ) - { - File file = getDefaultReleasePropertiesFile( config ); - if ( file.exists() ) - { + public void delete(ReleaseDescriptor config) { + File file = getDefaultReleasePropertiesFile(config); + if (file.exists()) { file.delete(); } } @@ -160,232 +137,182 @@ public void delete( ReleaseDescriptor config ) * @param file a {@link java.io.File} object * @throws org.apache.maven.shared.release.config.ReleaseDescriptorStoreException if any. */ - public void write( BuilderReleaseDescriptor config, File file ) - throws ReleaseDescriptorStoreException - { + public void write(BuilderReleaseDescriptor config, File file) throws ReleaseDescriptorStoreException { Properties properties = new Properties(); - properties.setProperty( "completedPhase", config.getCompletedPhase() ); - if ( config.isCommitByProject() ) //default is false + properties.setProperty("completedPhase", config.getCompletedPhase()); + if (config.isCommitByProject()) // default is false { - properties.setProperty( "commitByProject", "true" ); + properties.setProperty("commitByProject", "true"); } - properties.setProperty( "scm.url", config.getScmSourceUrl() ); - if ( config.getScmId() != null ) - { - properties.setProperty( "scm.id", config.getScmId() ); + properties.setProperty("scm.url", config.getScmSourceUrl()); + if (config.getScmId() != null) { + properties.setProperty("scm.id", config.getScmId()); } - if ( config.getScmUsername() != null ) - { - properties.setProperty( "scm.username", config.getScmUsername() ); + if (config.getScmUsername() != null) { + properties.setProperty("scm.username", config.getScmUsername()); } - if ( config.getScmPassword() != null ) - { + if (config.getScmPassword() != null) { String password = config.getScmPassword(); - try - { - password = mavenCrypto.encryptAndDecorate( password ); - } - catch ( MavenCryptoException e ) - { - logger.debug( e.getMessage() ); + try { + password = mavenCrypto.encryptAndDecorate(password); + } catch (MavenCryptoException e) { + logger.debug(e.getMessage()); } - properties.setProperty( "scm.password", password ); + properties.setProperty("scm.password", password); } - if ( config.getScmPrivateKey() != null ) - { - properties.setProperty( "scm.privateKey", config.getScmPrivateKey() ); + if (config.getScmPrivateKey() != null) { + properties.setProperty("scm.privateKey", config.getScmPrivateKey()); } - if ( config.getScmPrivateKeyPassPhrase() != null ) - { + if (config.getScmPrivateKeyPassPhrase() != null) { String passPhrase = config.getScmPrivateKeyPassPhrase(); - try - { - passPhrase = mavenCrypto.encryptAndDecorate( passPhrase ); - } - catch ( MavenCryptoException e ) - { - logger.debug( e.getMessage() ); + try { + passPhrase = mavenCrypto.encryptAndDecorate(passPhrase); + } catch (MavenCryptoException e) { + logger.debug(e.getMessage()); } - properties.setProperty( "scm.passphrase", passPhrase ); + properties.setProperty("scm.passphrase", passPhrase); } - if ( config.getScmTagBase() != null ) - { - properties.setProperty( "scm.tagBase", config.getScmTagBase() ); + if (config.getScmTagBase() != null) { + properties.setProperty("scm.tagBase", config.getScmTagBase()); } - if ( config.getScmBranchBase() != null ) - { - properties.setProperty( "scm.branchBase", config.getScmBranchBase() ); + if (config.getScmBranchBase() != null) { + properties.setProperty("scm.branchBase", config.getScmBranchBase()); } - if ( config.getScmReleaseLabel() != null ) - { - properties.setProperty( "scm.tag", config.getScmReleaseLabel() ); + if (config.getScmReleaseLabel() != null) { + properties.setProperty("scm.tag", config.getScmReleaseLabel()); } - if ( config.getScmTagNameFormat() != null ) - { - properties.setProperty( "scm.tagNameFormat", config.getScmTagNameFormat() ); + if (config.getScmTagNameFormat() != null) { + properties.setProperty("scm.tagNameFormat", config.getScmTagNameFormat()); } - if ( config.getScmCommentPrefix() != null ) - { - properties.setProperty( "scm.commentPrefix", config.getScmCommentPrefix() ); + if (config.getScmCommentPrefix() != null) { + properties.setProperty("scm.commentPrefix", config.getScmCommentPrefix()); } - if ( config.getScmDevelopmentCommitComment() != null ) - { - properties.setProperty( "scm.developmentCommitComment", config.getScmDevelopmentCommitComment() ); + if (config.getScmDevelopmentCommitComment() != null) { + properties.setProperty("scm.developmentCommitComment", config.getScmDevelopmentCommitComment()); } - if ( config.getScmReleaseCommitComment() != null ) - { - properties.setProperty( "scm.releaseCommitComment", config.getScmReleaseCommitComment() ); + if (config.getScmReleaseCommitComment() != null) { + properties.setProperty("scm.releaseCommitComment", config.getScmReleaseCommitComment()); } - if ( config.getScmBranchCommitComment() != null ) - { - properties.setProperty( "scm.branchCommitComment", config.getScmBranchCommitComment() ); + if (config.getScmBranchCommitComment() != null) { + properties.setProperty("scm.branchCommitComment", config.getScmBranchCommitComment()); } - if ( config.getScmRollbackCommitComment() != null ) - { - properties.setProperty( "scm.rollbackCommitComment", config.getScmRollbackCommitComment() ); + if (config.getScmRollbackCommitComment() != null) { + properties.setProperty("scm.rollbackCommitComment", config.getScmRollbackCommitComment()); } - if ( config.getAdditionalArguments() != null ) - { - properties.setProperty( "exec.additionalArguments", config.getAdditionalArguments() ); + if (config.getAdditionalArguments() != null) { + properties.setProperty("exec.additionalArguments", config.getAdditionalArguments()); } - if ( config.getPomFileName() != null ) - { - properties.setProperty( "exec.pomFileName", config.getPomFileName() ); + if (config.getPomFileName() != null) { + properties.setProperty("exec.pomFileName", config.getPomFileName()); } - if ( !config.getActivateProfiles().isEmpty() ) - { - properties.setProperty( "exec.activateProfiles", - StringUtils.join( config.getActivateProfiles().iterator(), "," ) ); + if (!config.getActivateProfiles().isEmpty()) { + properties.setProperty( + "exec.activateProfiles", + StringUtils.join(config.getActivateProfiles().iterator(), ",")); } - if ( config.getPreparationGoals() != null ) - { - properties.setProperty( "preparationGoals", config.getPreparationGoals() ); + if (config.getPreparationGoals() != null) { + properties.setProperty("preparationGoals", config.getPreparationGoals()); } - if ( config.getCompletionGoals() != null ) - { - properties.setProperty( "completionGoals", config.getCompletionGoals() ); + if (config.getCompletionGoals() != null) { + properties.setProperty("completionGoals", config.getCompletionGoals()); } - if ( config.getProjectVersionPolicyId() != null ) - { - properties.setProperty( "projectVersionPolicyId", config.getProjectVersionPolicyId() ); + if (config.getProjectVersionPolicyId() != null) { + properties.setProperty("projectVersionPolicyId", config.getProjectVersionPolicyId()); } - if ( config.getProjectVersionPolicyConfig() != null ) - { - properties.setProperty( "projectVersionPolicyConfig", config.getProjectVersionPolicyConfig().toString() ); + if (config.getProjectVersionPolicyConfig() != null) { + properties.setProperty( + "projectVersionPolicyConfig", + config.getProjectVersionPolicyConfig().toString()); } - if ( config.getProjectNamingPolicyId() != null ) - { - properties.setProperty( "projectNamingPolicyId", config.getProjectNamingPolicyId() ); + if (config.getProjectNamingPolicyId() != null) { + properties.setProperty("projectNamingPolicyId", config.getProjectNamingPolicyId()); } - if ( config.getReleaseStrategyId() != null ) - { - properties.setProperty( "releaseStrategyId", config.getReleaseStrategyId() ); + if (config.getReleaseStrategyId() != null) { + properties.setProperty("releaseStrategyId", config.getReleaseStrategyId()); } - properties.setProperty( "exec.snapshotReleasePluginAllowed", - Boolean.toString( config.isSnapshotReleasePluginAllowed() ) ); + properties.setProperty( + "exec.snapshotReleasePluginAllowed", Boolean.toString(config.isSnapshotReleasePluginAllowed())); - properties.setProperty( "remoteTagging", Boolean.toString( config.isRemoteTagging() ) ); + properties.setProperty("remoteTagging", Boolean.toString(config.isRemoteTagging())); - properties.setProperty( "pinExternals", Boolean.toString( config.isPinExternals() ) ); + properties.setProperty("pinExternals", Boolean.toString(config.isPinExternals())); - properties.setProperty( "pushChanges", Boolean.toString( config.isPushChanges() ) ); + properties.setProperty("pushChanges", Boolean.toString(config.isPushChanges())); - if ( config.getWorkItem() != null ) - { - properties.setProperty( "workItem", config.getWorkItem() ); + if (config.getWorkItem() != null) { + properties.setProperty("workItem", config.getWorkItem()); } - if ( config.getAutoResolveSnapshots() != null ) - { - properties.setProperty( "autoResolveSnapshots", config.getAutoResolveSnapshots() ); + if (config.getAutoResolveSnapshots() != null) { + properties.setProperty("autoResolveSnapshots", config.getAutoResolveSnapshots()); } // others boolean properties are not written to the properties file because the value from the caller is always // used - - for ( Map.Entry entry : config.getProjectVersions().entrySet() ) - { - if ( entry.getValue().getRelease() != null ) - { - properties.setProperty( "project.rel." + entry.getKey(), entry.getValue().getRelease() ); + for (Map.Entry entry : + config.getProjectVersions().entrySet()) { + if (entry.getValue().getRelease() != null) { + properties.setProperty( + "project.rel." + entry.getKey(), entry.getValue().getRelease()); } - if ( entry.getValue().getDevelopment() != null ) - { - properties.setProperty( "project.dev." + entry.getKey(), entry.getValue().getDevelopment() ); + if (entry.getValue().getDevelopment() != null) { + properties.setProperty( + "project.dev." + entry.getKey(), entry.getValue().getDevelopment()); } } - for ( Map.Entry entry : config.getOriginalScmInfo().entrySet() ) - { + for (Map.Entry entry : config.getOriginalScmInfo().entrySet()) { Scm scm = entry.getValue(); String prefix = "project.scm." + entry.getKey(); - if ( scm != null ) - { - if ( scm.getConnection() != null ) - { - properties.setProperty( prefix + ".connection", scm.getConnection() ); + if (scm != null) { + if (scm.getConnection() != null) { + properties.setProperty(prefix + ".connection", scm.getConnection()); } - if ( scm.getDeveloperConnection() != null ) - { - properties.setProperty( prefix + ".developerConnection", scm.getDeveloperConnection() ); + if (scm.getDeveloperConnection() != null) { + properties.setProperty(prefix + ".developerConnection", scm.getDeveloperConnection()); } - if ( scm.getUrl() != null ) - { - properties.setProperty( prefix + ".url", scm.getUrl() ); + if (scm.getUrl() != null) { + properties.setProperty(prefix + ".url", scm.getUrl()); } - if ( scm.getTag() != null ) - { - properties.setProperty( prefix + ".tag", scm.getTag() ); + if (scm.getTag() != null) { + properties.setProperty(prefix + ".tag", scm.getTag()); } - if ( scm instanceof IdentifiedScm ) - { + if (scm instanceof IdentifiedScm) { IdentifiedScm identifiedScm = (IdentifiedScm) scm; - if ( identifiedScm.getId() != null ) - { - properties.setProperty( prefix + ".id", identifiedScm.getId() ); + if (identifiedScm.getId() != null) { + properties.setProperty(prefix + ".id", identifiedScm.getId()); } } - } - else - { - properties.setProperty( prefix + ".empty", "true" ); + } else { + properties.setProperty(prefix + ".empty", "true"); } } - if ( ( config.getResolvedSnapshotDependencies() != null ) - && ( config.getResolvedSnapshotDependencies().size() > 0 ) ) - { - processResolvedDependencies( properties, config.getResolvedSnapshotDependencies() ); + if ((config.getResolvedSnapshotDependencies() != null) + && (config.getResolvedSnapshotDependencies().size() > 0)) { + processResolvedDependencies(properties, config.getResolvedSnapshotDependencies()); } - try ( OutputStream outStream = new FileOutputStream( file ) ) - { - properties.store( outStream, "release configuration" ); - } - catch ( IOException e ) - { + try (OutputStream outStream = new FileOutputStream(file)) { + properties.store(outStream, "release configuration"); + } catch (IOException e) { throw new ReleaseDescriptorStoreException( - "Error writing properties file '" + file.getName() + "': " + e.getMessage(), e ); + "Error writing properties file '" + file.getName() + "': " + e.getMessage(), e); } } - private void processResolvedDependencies( Properties prop, Map resolvedDependencies ) - { - for ( Map.Entry currentEntry : resolvedDependencies.entrySet() ) - { + private void processResolvedDependencies(Properties prop, Map resolvedDependencies) { + for (Map.Entry currentEntry : resolvedDependencies.entrySet()) { ReleaseStageVersions versionMap = currentEntry.getValue(); - prop.setProperty( "dependency." + currentEntry.getKey() + ".release", - versionMap.getRelease() ); - prop.setProperty( "dependency." + currentEntry.getKey() + ".development", - versionMap.getDevelopment() ); + prop.setProperty("dependency." + currentEntry.getKey() + ".release", versionMap.getRelease()); + prop.setProperty("dependency." + currentEntry.getKey() + ".development", versionMap.getDevelopment()); } } - private static File getDefaultReleasePropertiesFile( ReleaseDescriptor mergeDescriptor ) - { - return new File( mergeDescriptor.getWorkingDirectory(), "release.properties" ); + private static File getDefaultReleasePropertiesFile(ReleaseDescriptor mergeDescriptor) { + return new File(mergeDescriptor.getWorkingDirectory(), "release.properties"); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java index 5b81f7032..a2afc729d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; import java.util.List; import java.util.regex.Matcher; @@ -34,9 +33,8 @@ * @author Robert Scholte * @since 3.0.0-M5 */ -public class ReleaseDescriptorBuilder -{ - private static final Pattern PROPERTY_PATTERN = Pattern.compile( "\\$\\{[^}]+}" ); +public class ReleaseDescriptorBuilder { + private static final Pattern PROPERTY_PATTERN = Pattern.compile("\\$\\{[^}]+}"); private final Logger logger; @@ -45,11 +43,8 @@ public class ReleaseDescriptorBuilder * * @author Robert Scholte */ - public static final class BuilderReleaseDescriptor extends ModelloReleaseDescriptor implements ReleaseDescriptor - { - private BuilderReleaseDescriptor() - { - } + public static final class BuilderReleaseDescriptor extends ModelloReleaseDescriptor implements ReleaseDescriptor { + private BuilderReleaseDescriptor() {} } private final BuilderReleaseDescriptor releaseDescriptor; @@ -57,18 +52,16 @@ private BuilderReleaseDescriptor() /** *

Constructor for ReleaseDescriptorBuilder.

*/ - public ReleaseDescriptorBuilder() - { - this( LoggerFactory.getLogger( ReleaseDescriptorBuilder.class ) ); + public ReleaseDescriptorBuilder() { + this(LoggerFactory.getLogger(ReleaseDescriptorBuilder.class)); } /** * Constructor for testing purpose. */ - ReleaseDescriptorBuilder( Logger logger ) - { + ReleaseDescriptorBuilder(Logger logger) { this.releaseDescriptor = new BuilderReleaseDescriptor(); - this.releaseDescriptor.setLineSeparator( ReleaseUtil.LS ); + this.releaseDescriptor.setLineSeparator(ReleaseUtil.LS); this.logger = logger; } @@ -78,9 +71,8 @@ public ReleaseDescriptorBuilder() * @param string a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addCheckModificationExclude( String string ) - { - releaseDescriptor.addCheckModificationExclude( string ); + public ReleaseDescriptorBuilder addCheckModificationExclude(String string) { + releaseDescriptor.addCheckModificationExclude(string); return this; } @@ -90,9 +82,8 @@ public ReleaseDescriptorBuilder addCheckModificationExclude( String string ) * @param profiles a {@link java.util.List} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setActivateProfiles( List profiles ) - { - releaseDescriptor.setActivateProfiles( profiles ); + public ReleaseDescriptorBuilder setActivateProfiles(List profiles) { + releaseDescriptor.setActivateProfiles(profiles); return this; } @@ -102,9 +93,8 @@ public ReleaseDescriptorBuilder setActivateProfiles( List profiles ) * @param addSchema a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setAddSchema( boolean addSchema ) - { - releaseDescriptor.setAddSchema( addSchema ); + public ReleaseDescriptorBuilder setAddSchema(boolean addSchema) { + releaseDescriptor.setAddSchema(addSchema); return this; } @@ -114,25 +104,19 @@ public ReleaseDescriptorBuilder setAddSchema( boolean addSchema ) * @param additionalArguments a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setAdditionalArguments( String additionalArguments ) - { - if ( additionalArguments != null ) - { - Matcher matcher = PROPERTY_PATTERN.matcher( additionalArguments ); + public ReleaseDescriptorBuilder setAdditionalArguments(String additionalArguments) { + if (additionalArguments != null) { + Matcher matcher = PROPERTY_PATTERN.matcher(additionalArguments); StringBuffer buf = new StringBuffer(); - while ( matcher.find() ) - { - matcher.appendReplacement( buf, "" ); - logger.warn( "arguments parameter contains unresolved property: '{}'", - matcher.group() ); + while (matcher.find()) { + matcher.appendReplacement(buf, ""); + logger.warn("arguments parameter contains unresolved property: '{}'", matcher.group()); } - matcher.appendTail( buf ); + matcher.appendTail(buf); - releaseDescriptor.setAdditionalArguments( buf.toString() ); - } - else - { - releaseDescriptor.setAdditionalArguments( null ); + releaseDescriptor.setAdditionalArguments(buf.toString()); + } else { + releaseDescriptor.setAdditionalArguments(null); } return this; } @@ -143,9 +127,8 @@ public ReleaseDescriptorBuilder setAdditionalArguments( String additionalArgumen * @param allowTimestampedSnapshots a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setAllowTimestampedSnapshots( boolean allowTimestampedSnapshots ) - { - releaseDescriptor.setAllowTimestampedSnapshots( allowTimestampedSnapshots ); + public ReleaseDescriptorBuilder setAllowTimestampedSnapshots(boolean allowTimestampedSnapshots) { + releaseDescriptor.setAllowTimestampedSnapshots(allowTimestampedSnapshots); return this; } @@ -155,9 +138,8 @@ public ReleaseDescriptorBuilder setAllowTimestampedSnapshots( boolean allowTimes * @param autoVersionSubmodules a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setAutoVersionSubmodules( boolean autoVersionSubmodules ) - { - releaseDescriptor.setAutoVersionSubmodules( autoVersionSubmodules ); + public ReleaseDescriptorBuilder setAutoVersionSubmodules(boolean autoVersionSubmodules) { + releaseDescriptor.setAutoVersionSubmodules(autoVersionSubmodules); return this; } @@ -167,9 +149,8 @@ public ReleaseDescriptorBuilder setAutoVersionSubmodules( boolean autoVersionSub * @param branchCreation a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setBranchCreation( boolean branchCreation ) - { - releaseDescriptor.setBranchCreation( branchCreation ); + public ReleaseDescriptorBuilder setBranchCreation(boolean branchCreation) { + releaseDescriptor.setBranchCreation(branchCreation); return this; } @@ -179,9 +160,8 @@ public ReleaseDescriptorBuilder setBranchCreation( boolean branchCreation ) * @param checkModificationExcludes a {@link java.util.List} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setCheckModificationExcludes( List checkModificationExcludes ) - { - releaseDescriptor.setCheckModificationExcludes( checkModificationExcludes ); + public ReleaseDescriptorBuilder setCheckModificationExcludes(List checkModificationExcludes) { + releaseDescriptor.setCheckModificationExcludes(checkModificationExcludes); return this; } @@ -191,9 +171,8 @@ public ReleaseDescriptorBuilder setCheckModificationExcludes( List check * @param checkoutDirectory a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setCheckoutDirectory( String checkoutDirectory ) - { - releaseDescriptor.setCheckoutDirectory( checkoutDirectory ); + public ReleaseDescriptorBuilder setCheckoutDirectory(String checkoutDirectory) { + releaseDescriptor.setCheckoutDirectory(checkoutDirectory); return this; } @@ -203,9 +182,8 @@ public ReleaseDescriptorBuilder setCheckoutDirectory( String checkoutDirectory ) * @param commitByProject a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setCommitByProject( boolean commitByProject ) - { - releaseDescriptor.setCommitByProject( commitByProject ); + public ReleaseDescriptorBuilder setCommitByProject(boolean commitByProject) { + releaseDescriptor.setCommitByProject(commitByProject); return this; } @@ -215,9 +193,8 @@ public ReleaseDescriptorBuilder setCommitByProject( boolean commitByProject ) * @param completedPhase a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setCompletedPhase( String completedPhase ) - { - releaseDescriptor.setCompletedPhase( completedPhase ); + public ReleaseDescriptorBuilder setCompletedPhase(String completedPhase) { + releaseDescriptor.setCompletedPhase(completedPhase); return this; } @@ -227,9 +204,8 @@ public ReleaseDescriptorBuilder setCompletedPhase( String completedPhase ) * @param completionGoals a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setCompletionGoals( String completionGoals ) - { - releaseDescriptor.setCompletionGoals( completionGoals ); + public ReleaseDescriptorBuilder setCompletionGoals(String completionGoals) { + releaseDescriptor.setCompletionGoals(completionGoals); return this; } @@ -239,9 +215,8 @@ public ReleaseDescriptorBuilder setCompletionGoals( String completionGoals ) * @param defaultDevelopmentVersion a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setDefaultDevelopmentVersion( String defaultDevelopmentVersion ) - { - releaseDescriptor.setDefaultDevelopmentVersion( defaultDevelopmentVersion ); + public ReleaseDescriptorBuilder setDefaultDevelopmentVersion(String defaultDevelopmentVersion) { + releaseDescriptor.setDefaultDevelopmentVersion(defaultDevelopmentVersion); return this; } @@ -251,9 +226,8 @@ public ReleaseDescriptorBuilder setDefaultDevelopmentVersion( String defaultDeve * @param defaultReleaseVersion a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setDefaultReleaseVersion( String defaultReleaseVersion ) - { - releaseDescriptor.setDefaultReleaseVersion( defaultReleaseVersion ); + public ReleaseDescriptorBuilder setDefaultReleaseVersion(String defaultReleaseVersion) { + releaseDescriptor.setDefaultReleaseVersion(defaultReleaseVersion); return this; } @@ -263,9 +237,8 @@ public ReleaseDescriptorBuilder setDefaultReleaseVersion( String defaultReleaseV * @param description a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setDescription( String description ) - { - releaseDescriptor.setDescription( description ); + public ReleaseDescriptorBuilder setDescription(String description) { + releaseDescriptor.setDescription(description); return this; } @@ -275,9 +248,8 @@ public ReleaseDescriptorBuilder setDescription( String description ) * @param generateReleasePoms a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setGenerateReleasePoms( boolean generateReleasePoms ) - { - releaseDescriptor.setGenerateReleasePoms( generateReleasePoms ); + public ReleaseDescriptorBuilder setGenerateReleasePoms(boolean generateReleasePoms) { + releaseDescriptor.setGenerateReleasePoms(generateReleasePoms); return this; } @@ -287,9 +259,8 @@ public ReleaseDescriptorBuilder setGenerateReleasePoms( boolean generateReleaseP * @param interactive a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setInteractive( boolean interactive ) - { - releaseDescriptor.setInteractive( interactive ); + public ReleaseDescriptorBuilder setInteractive(boolean interactive) { + releaseDescriptor.setInteractive(interactive); return this; } @@ -299,9 +270,8 @@ public ReleaseDescriptorBuilder setInteractive( boolean interactive ) * @param ls a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setLineSeparator( String ls ) - { - releaseDescriptor.setLineSeparator( ls ); + public ReleaseDescriptorBuilder setLineSeparator(String ls) { + releaseDescriptor.setLineSeparator(ls); return this; } @@ -311,9 +281,8 @@ public ReleaseDescriptorBuilder setLineSeparator( String ls ) * @param localCheckout a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setLocalCheckout( boolean localCheckout ) - { - releaseDescriptor.setLocalCheckout( localCheckout ); + public ReleaseDescriptorBuilder setLocalCheckout(boolean localCheckout) { + releaseDescriptor.setLocalCheckout(localCheckout); return this; } @@ -323,9 +292,8 @@ public ReleaseDescriptorBuilder setLocalCheckout( boolean localCheckout ) * @param modelEncoding a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setModelEncoding( String modelEncoding ) - { - releaseDescriptor.setModelEncoding( modelEncoding ); + public ReleaseDescriptorBuilder setModelEncoding(String modelEncoding) { + releaseDescriptor.setModelEncoding(modelEncoding); return this; } @@ -335,9 +303,8 @@ public ReleaseDescriptorBuilder setModelEncoding( String modelEncoding ) * @param name a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setName( String name ) - { - releaseDescriptor.setName( name ); + public ReleaseDescriptorBuilder setName(String name) { + releaseDescriptor.setName(name); return this; } @@ -347,9 +314,8 @@ public ReleaseDescriptorBuilder setName( String name ) * @param performGoals a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setPerformGoals( String performGoals ) - { - releaseDescriptor.setPerformGoals( performGoals ); + public ReleaseDescriptorBuilder setPerformGoals(String performGoals) { + releaseDescriptor.setPerformGoals(performGoals); return this; } @@ -359,9 +325,8 @@ public ReleaseDescriptorBuilder setPerformGoals( String performGoals ) * @param pomFileName a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setPomFileName( String pomFileName ) - { - releaseDescriptor.setPomFileName( pomFileName ); + public ReleaseDescriptorBuilder setPomFileName(String pomFileName) { + releaseDescriptor.setPomFileName(pomFileName); return this; } @@ -371,9 +336,8 @@ public ReleaseDescriptorBuilder setPomFileName( String pomFileName ) * @param preparationGoals a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setPreparationGoals( String preparationGoals ) - { - releaseDescriptor.setPreparationGoals( preparationGoals ); + public ReleaseDescriptorBuilder setPreparationGoals(String preparationGoals) { + releaseDescriptor.setPreparationGoals(preparationGoals); return this; } @@ -383,9 +347,8 @@ public ReleaseDescriptorBuilder setPreparationGoals( String preparationGoals ) * @param projectNamingPolicyId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setProjectNamingPolicyId( String projectNamingPolicyId ) - { - releaseDescriptor.setProjectNamingPolicyId( projectNamingPolicyId ); + public ReleaseDescriptorBuilder setProjectNamingPolicyId(String projectNamingPolicyId) { + releaseDescriptor.setProjectNamingPolicyId(projectNamingPolicyId); return this; } @@ -395,9 +358,8 @@ public ReleaseDescriptorBuilder setProjectNamingPolicyId( String projectNamingPo * @param projectVersionPolicyId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setProjectVersionPolicyId( String projectVersionPolicyId ) - { - releaseDescriptor.setProjectVersionPolicyId( projectVersionPolicyId ); + public ReleaseDescriptorBuilder setProjectVersionPolicyId(String projectVersionPolicyId) { + releaseDescriptor.setProjectVersionPolicyId(projectVersionPolicyId); return this; } @@ -407,9 +369,8 @@ public ReleaseDescriptorBuilder setProjectVersionPolicyId( String projectVersion * @param setProjectVersionPolicyConfig a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setProjectVersionPolicyConfig( String setProjectVersionPolicyConfig ) - { - releaseDescriptor.setProjectVersionPolicyConfig( setProjectVersionPolicyConfig ); + public ReleaseDescriptorBuilder setProjectVersionPolicyConfig(String setProjectVersionPolicyConfig) { + releaseDescriptor.setProjectVersionPolicyConfig(setProjectVersionPolicyConfig); return this; } @@ -419,9 +380,8 @@ public ReleaseDescriptorBuilder setProjectVersionPolicyConfig( String setProject * @param pushChanges a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setPushChanges( boolean pushChanges ) - { - releaseDescriptor.setPushChanges( pushChanges ); + public ReleaseDescriptorBuilder setPushChanges(boolean pushChanges) { + releaseDescriptor.setPushChanges(pushChanges); return this; } @@ -431,9 +391,8 @@ public ReleaseDescriptorBuilder setPushChanges( boolean pushChanges ) * @param workItem a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setWorkItem( String workItem ) - { - releaseDescriptor.setWorkItem( workItem ); + public ReleaseDescriptorBuilder setWorkItem(String workItem) { + releaseDescriptor.setWorkItem(workItem); return this; } @@ -443,9 +402,8 @@ public ReleaseDescriptorBuilder setWorkItem( String workItem ) * @param releaseStrategyId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setReleaseStrategyId( String releaseStrategyId ) - { - releaseDescriptor.setReleaseStrategyId( releaseStrategyId ); + public ReleaseDescriptorBuilder setReleaseStrategyId(String releaseStrategyId) { + releaseDescriptor.setReleaseStrategyId(releaseStrategyId); return this; } @@ -455,9 +413,8 @@ public ReleaseDescriptorBuilder setReleaseStrategyId( String releaseStrategyId ) * @param remoteTagging a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setRemoteTagging( boolean remoteTagging ) - { - releaseDescriptor.setRemoteTagging( remoteTagging ); + public ReleaseDescriptorBuilder setRemoteTagging(boolean remoteTagging) { + releaseDescriptor.setRemoteTagging(remoteTagging); return this; } @@ -467,9 +424,8 @@ public ReleaseDescriptorBuilder setRemoteTagging( boolean remoteTagging ) * @param scmBranchBase a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmBranchBase( String scmBranchBase ) - { - releaseDescriptor.setScmBranchBase( scmBranchBase ); + public ReleaseDescriptorBuilder setScmBranchBase(String scmBranchBase) { + releaseDescriptor.setScmBranchBase(scmBranchBase); return this; } @@ -479,9 +435,8 @@ public ReleaseDescriptorBuilder setScmBranchBase( String scmBranchBase ) * @param scmCommentPrefix a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmCommentPrefix( String scmCommentPrefix ) - { - releaseDescriptor.setScmCommentPrefix( scmCommentPrefix ); + public ReleaseDescriptorBuilder setScmCommentPrefix(String scmCommentPrefix) { + releaseDescriptor.setScmCommentPrefix(scmCommentPrefix); return this; } @@ -492,9 +447,8 @@ public ReleaseDescriptorBuilder setScmCommentPrefix( String scmCommentPrefix ) * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @since 3.0.0-M6 */ - public ReleaseDescriptorBuilder setScmShallowClone( boolean scmShallowClone ) - { - releaseDescriptor.setScmShallowClone( scmShallowClone ); + public ReleaseDescriptorBuilder setScmShallowClone(boolean scmShallowClone) { + releaseDescriptor.setScmShallowClone(scmShallowClone); return this; } @@ -505,9 +459,8 @@ public ReleaseDescriptorBuilder setScmShallowClone( boolean scmShallowClone ) * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @since 3.0.0-M1 */ - public ReleaseDescriptorBuilder setScmReleaseCommitComment( String scmReleaseCommitComment ) - { - releaseDescriptor.setScmReleaseCommitComment( scmReleaseCommitComment ); + public ReleaseDescriptorBuilder setScmReleaseCommitComment(String scmReleaseCommitComment) { + releaseDescriptor.setScmReleaseCommitComment(scmReleaseCommitComment); return this; } @@ -518,9 +471,8 @@ public ReleaseDescriptorBuilder setScmReleaseCommitComment( String scmReleaseCom * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @since 3.0.0-M1 */ - public ReleaseDescriptorBuilder setScmDevelopmentCommitComment( String scmDevelopmentCommitComment ) - { - releaseDescriptor.setScmDevelopmentCommitComment( scmDevelopmentCommitComment ); + public ReleaseDescriptorBuilder setScmDevelopmentCommitComment(String scmDevelopmentCommitComment) { + releaseDescriptor.setScmDevelopmentCommitComment(scmDevelopmentCommitComment); return this; } @@ -531,9 +483,8 @@ public ReleaseDescriptorBuilder setScmDevelopmentCommitComment( String scmDevelo * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @since 3.0.0-M1 */ - public ReleaseDescriptorBuilder setScmBranchCommitComment( String scmBranchCommitComment ) - { - releaseDescriptor.setScmBranchCommitComment( scmBranchCommitComment ); + public ReleaseDescriptorBuilder setScmBranchCommitComment(String scmBranchCommitComment) { + releaseDescriptor.setScmBranchCommitComment(scmBranchCommitComment); return this; } @@ -544,9 +495,8 @@ public ReleaseDescriptorBuilder setScmBranchCommitComment( String scmBranchCommi * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @since 3.0.0-M1 */ - public ReleaseDescriptorBuilder setScmRollbackCommitComment( String scmRollbackCommitComment ) - { - releaseDescriptor.setScmRollbackCommitComment( scmRollbackCommitComment ); + public ReleaseDescriptorBuilder setScmRollbackCommitComment(String scmRollbackCommitComment) { + releaseDescriptor.setScmRollbackCommitComment(scmRollbackCommitComment); return this; } @@ -556,9 +506,8 @@ public ReleaseDescriptorBuilder setScmRollbackCommitComment( String scmRollbackC * @param scmId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmId( String scmId ) - { - releaseDescriptor.setScmId( scmId ); + public ReleaseDescriptorBuilder setScmId(String scmId) { + releaseDescriptor.setScmId(scmId); return this; } @@ -568,9 +517,8 @@ public ReleaseDescriptorBuilder setScmId( String scmId ) * @param scmPassword a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmPassword( String scmPassword ) - { - releaseDescriptor.setScmPassword( scmPassword ); + public ReleaseDescriptorBuilder setScmPassword(String scmPassword) { + releaseDescriptor.setScmPassword(scmPassword); return this; } @@ -580,9 +528,8 @@ public ReleaseDescriptorBuilder setScmPassword( String scmPassword ) * @param scmPrivateKey a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmPrivateKey( String scmPrivateKey ) - { - releaseDescriptor.setScmPrivateKey( scmPrivateKey ); + public ReleaseDescriptorBuilder setScmPrivateKey(String scmPrivateKey) { + releaseDescriptor.setScmPrivateKey(scmPrivateKey); return this; } @@ -592,9 +539,8 @@ public ReleaseDescriptorBuilder setScmPrivateKey( String scmPrivateKey ) * @param scmPrivateKeyPassPhrase a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmPrivateKeyPassPhrase( String scmPrivateKeyPassPhrase ) - { - releaseDescriptor.setScmPrivateKeyPassPhrase( scmPrivateKeyPassPhrase ); + public ReleaseDescriptorBuilder setScmPrivateKeyPassPhrase(String scmPrivateKeyPassPhrase) { + releaseDescriptor.setScmPrivateKeyPassPhrase(scmPrivateKeyPassPhrase); return this; } @@ -604,9 +550,8 @@ public ReleaseDescriptorBuilder setScmPrivateKeyPassPhrase( String scmPrivateKey * @param scmRelativePathProjectDirectory a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmRelativePathProjectDirectory( String scmRelativePathProjectDirectory ) - { - releaseDescriptor.setScmRelativePathProjectDirectory( scmRelativePathProjectDirectory ); + public ReleaseDescriptorBuilder setScmRelativePathProjectDirectory(String scmRelativePathProjectDirectory) { + releaseDescriptor.setScmRelativePathProjectDirectory(scmRelativePathProjectDirectory); return this; } @@ -616,9 +561,8 @@ public ReleaseDescriptorBuilder setScmRelativePathProjectDirectory( String scmRe * @param scmReleaseLabel a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmReleaseLabel( String scmReleaseLabel ) - { - releaseDescriptor.setScmReleaseLabel( scmReleaseLabel ); + public ReleaseDescriptorBuilder setScmReleaseLabel(String scmReleaseLabel) { + releaseDescriptor.setScmReleaseLabel(scmReleaseLabel); return this; } @@ -628,9 +572,8 @@ public ReleaseDescriptorBuilder setScmReleaseLabel( String scmReleaseLabel ) * @param scmReleasedPomRevision a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmReleasedPomRevision( String scmReleasedPomRevision ) - { - releaseDescriptor.setScmReleasedPomRevision( scmReleasedPomRevision ); + public ReleaseDescriptorBuilder setScmReleasedPomRevision(String scmReleasedPomRevision) { + releaseDescriptor.setScmReleasedPomRevision(scmReleasedPomRevision); return this; } @@ -640,9 +583,8 @@ public ReleaseDescriptorBuilder setScmReleasedPomRevision( String scmReleasedPom * @param scmSourceUrl a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmSourceUrl( String scmSourceUrl ) - { - releaseDescriptor.setScmSourceUrl( scmSourceUrl ); + public ReleaseDescriptorBuilder setScmSourceUrl(String scmSourceUrl) { + releaseDescriptor.setScmSourceUrl(scmSourceUrl); return this; } @@ -652,9 +594,8 @@ public ReleaseDescriptorBuilder setScmSourceUrl( String scmSourceUrl ) * @param scmTagBase a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmTagBase( String scmTagBase ) - { - releaseDescriptor.setScmTagBase( scmTagBase ); + public ReleaseDescriptorBuilder setScmTagBase(String scmTagBase) { + releaseDescriptor.setScmTagBase(scmTagBase); return this; } @@ -664,9 +605,8 @@ public ReleaseDescriptorBuilder setScmTagBase( String scmTagBase ) * @param scmTagNameFormat a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmTagNameFormat( String scmTagNameFormat ) - { - releaseDescriptor.setScmTagNameFormat( scmTagNameFormat ); + public ReleaseDescriptorBuilder setScmTagNameFormat(String scmTagNameFormat) { + releaseDescriptor.setScmTagNameFormat(scmTagNameFormat); return this; } @@ -676,9 +616,8 @@ public ReleaseDescriptorBuilder setScmTagNameFormat( String scmTagNameFormat ) * @param signTags a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmSignTags( boolean signTags ) - { - releaseDescriptor.setScmSignTags( signTags ); + public ReleaseDescriptorBuilder setScmSignTags(boolean signTags) { + releaseDescriptor.setScmSignTags(signTags); return this; } @@ -688,9 +627,8 @@ public ReleaseDescriptorBuilder setScmSignTags( boolean signTags ) * @param scmUseEditMode a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmUseEditMode( boolean scmUseEditMode ) - { - releaseDescriptor.setScmUseEditMode( scmUseEditMode ); + public ReleaseDescriptorBuilder setScmUseEditMode(boolean scmUseEditMode) { + releaseDescriptor.setScmUseEditMode(scmUseEditMode); return this; } @@ -700,9 +638,8 @@ public ReleaseDescriptorBuilder setScmUseEditMode( boolean scmUseEditMode ) * @param scmUsername a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setScmUsername( String scmUsername ) - { - releaseDescriptor.setScmUsername( scmUsername ); + public ReleaseDescriptorBuilder setScmUsername(String scmUsername) { + releaseDescriptor.setScmUsername(scmUsername); return this; } @@ -712,9 +649,8 @@ public ReleaseDescriptorBuilder setScmUsername( String scmUsername ) * @param snapshotReleasePluginAllowed a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setSnapshotReleasePluginAllowed( boolean snapshotReleasePluginAllowed ) - { - releaseDescriptor.setSnapshotReleasePluginAllowed( snapshotReleasePluginAllowed ); + public ReleaseDescriptorBuilder setSnapshotReleasePluginAllowed(boolean snapshotReleasePluginAllowed) { + releaseDescriptor.setSnapshotReleasePluginAllowed(snapshotReleasePluginAllowed); return this; } @@ -724,9 +660,8 @@ public ReleaseDescriptorBuilder setSnapshotReleasePluginAllowed( boolean snapsho * @param suppressCommitBeforeTagOrBranch a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setSuppressCommitBeforeTagOrBranch( boolean suppressCommitBeforeTagOrBranch ) - { - releaseDescriptor.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTagOrBranch ); + public ReleaseDescriptorBuilder setSuppressCommitBeforeTagOrBranch(boolean suppressCommitBeforeTagOrBranch) { + releaseDescriptor.setSuppressCommitBeforeTagOrBranch(suppressCommitBeforeTagOrBranch); return this; } @@ -736,9 +671,8 @@ public ReleaseDescriptorBuilder setSuppressCommitBeforeTagOrBranch( boolean supp * @param updateBranchVersions a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setUpdateBranchVersions( boolean updateBranchVersions ) - { - releaseDescriptor.setUpdateBranchVersions( updateBranchVersions ); + public ReleaseDescriptorBuilder setUpdateBranchVersions(boolean updateBranchVersions) { + releaseDescriptor.setUpdateBranchVersions(updateBranchVersions); return this; } @@ -748,9 +682,8 @@ public ReleaseDescriptorBuilder setUpdateBranchVersions( boolean updateBranchVer * @param updateDependencies a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setUpdateDependencies( boolean updateDependencies ) - { - releaseDescriptor.setUpdateDependencies( updateDependencies ); + public ReleaseDescriptorBuilder setUpdateDependencies(boolean updateDependencies) { + releaseDescriptor.setUpdateDependencies(updateDependencies); return this; } @@ -760,9 +693,8 @@ public ReleaseDescriptorBuilder setUpdateDependencies( boolean updateDependencie * @param updateVersionsToSnapshot a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setUpdateVersionsToSnapshot( boolean updateVersionsToSnapshot ) - { - releaseDescriptor.setUpdateVersionsToSnapshot( updateVersionsToSnapshot ); + public ReleaseDescriptorBuilder setUpdateVersionsToSnapshot(boolean updateVersionsToSnapshot) { + releaseDescriptor.setUpdateVersionsToSnapshot(updateVersionsToSnapshot); return this; } @@ -772,9 +704,8 @@ public ReleaseDescriptorBuilder setUpdateVersionsToSnapshot( boolean updateVersi * @param updateWorkingCopyVersions a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setUpdateWorkingCopyVersions( boolean updateWorkingCopyVersions ) - { - releaseDescriptor.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); + public ReleaseDescriptorBuilder setUpdateWorkingCopyVersions(boolean updateWorkingCopyVersions) { + releaseDescriptor.setUpdateWorkingCopyVersions(updateWorkingCopyVersions); return this; } @@ -784,9 +715,8 @@ public ReleaseDescriptorBuilder setUpdateWorkingCopyVersions( boolean updateWork * @param useReleaseProfile a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setUseReleaseProfile( boolean useReleaseProfile ) - { - releaseDescriptor.setUseReleaseProfile( useReleaseProfile ); + public ReleaseDescriptorBuilder setUseReleaseProfile(boolean useReleaseProfile) { + releaseDescriptor.setUseReleaseProfile(useReleaseProfile); return this; } @@ -796,9 +726,8 @@ public ReleaseDescriptorBuilder setUseReleaseProfile( boolean useReleaseProfile * @param waitBeforeTagging a int * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setWaitBeforeTagging( int waitBeforeTagging ) - { - releaseDescriptor.setWaitBeforeTagging( waitBeforeTagging ); + public ReleaseDescriptorBuilder setWaitBeforeTagging(int waitBeforeTagging) { + releaseDescriptor.setWaitBeforeTagging(waitBeforeTagging); return this; } @@ -808,9 +737,8 @@ public ReleaseDescriptorBuilder setWaitBeforeTagging( int waitBeforeTagging ) * @param workingDirectory a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setWorkingDirectory( String workingDirectory ) - { - releaseDescriptor.setWorkingDirectory( workingDirectory ); + public ReleaseDescriptorBuilder setWorkingDirectory(String workingDirectory) { + releaseDescriptor.setWorkingDirectory(workingDirectory); return this; } @@ -821,9 +749,8 @@ public ReleaseDescriptorBuilder setWorkingDirectory( String workingDirectory ) * @param value a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addReleaseVersion( String key, String value ) - { - releaseDescriptor.addReleaseVersion( key, value ); + public ReleaseDescriptorBuilder addReleaseVersion(String key, String value) { + releaseDescriptor.addReleaseVersion(key, value); return this; } @@ -834,9 +761,8 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key, String value ) * @param value a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addDevelopmentVersion( String key, String value ) - { - releaseDescriptor.addDevelopmentVersion( key, value ); + public ReleaseDescriptorBuilder addDevelopmentVersion(String key, String value) { + releaseDescriptor.addDevelopmentVersion(key, value); return this; } @@ -847,9 +773,8 @@ public ReleaseDescriptorBuilder addDevelopmentVersion( String key, String value * @param value a {@link org.apache.maven.model.Scm} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addOriginalScmInfo( String key, Scm value ) - { - releaseDescriptor.addOriginalScmInfo( key, value ); + public ReleaseDescriptorBuilder addOriginalScmInfo(String key, Scm value) { + releaseDescriptor.addOriginalScmInfo(key, value); return this; } @@ -859,9 +784,8 @@ public ReleaseDescriptorBuilder addOriginalScmInfo( String key, Scm value ) * @param projectKey a {@link java.lang.String} object * @param version a {@link java.lang.String} object */ - public void putOriginalVersion( String projectKey, String version ) - { - releaseDescriptor.addOriginalVersion( projectKey, version ); + public void putOriginalVersion(String projectKey, String version) { + releaseDescriptor.addOriginalVersion(projectKey, version); } /** @@ -871,11 +795,9 @@ public void putOriginalVersion( String projectKey, String version ) * @param version a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addDependencyOriginalVersion( String dependencyKey, String version ) - { - releaseDescriptor.addDependencyOriginalVersion( dependencyKey, version ); + public ReleaseDescriptorBuilder addDependencyOriginalVersion(String dependencyKey, String version) { + releaseDescriptor.addDependencyOriginalVersion(dependencyKey, version); return this; - } /** @@ -885,9 +807,8 @@ public ReleaseDescriptorBuilder addDependencyOriginalVersion( String dependencyK * @param version a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addDependencyReleaseVersion( String dependencyKey, String version ) - { - releaseDescriptor.addDependencyReleaseVersion( dependencyKey, version ); + public ReleaseDescriptorBuilder addDependencyReleaseVersion(String dependencyKey, String version) { + releaseDescriptor.addDependencyReleaseVersion(dependencyKey, version); return this; } @@ -898,9 +819,8 @@ public ReleaseDescriptorBuilder addDependencyReleaseVersion( String dependencyKe * @param version a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependencyKey, String version ) - { - releaseDescriptor.addDependencyDevelopmentVersion( dependencyKey, version ); + public ReleaseDescriptorBuilder addDependencyDevelopmentVersion(String dependencyKey, String version) { + releaseDescriptor.addDependencyDevelopmentVersion(dependencyKey, version); return this; } @@ -910,9 +830,8 @@ public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependen * @param autoResolveSnapshots a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setAutoResolveSnapshots( String autoResolveSnapshots ) - { - releaseDescriptor.setAutoResolveSnapshots( autoResolveSnapshots ); + public ReleaseDescriptorBuilder setAutoResolveSnapshots(String autoResolveSnapshots) { + releaseDescriptor.setAutoResolveSnapshots(autoResolveSnapshots); return this; } @@ -922,14 +841,12 @@ public ReleaseDescriptorBuilder setAutoResolveSnapshots( String autoResolveSnaps * @param pinExternals a boolean * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public ReleaseDescriptorBuilder setPinExternals( boolean pinExternals ) - { - releaseDescriptor.setPinExternals( pinExternals ); + public ReleaseDescriptorBuilder setPinExternals(boolean pinExternals) { + releaseDescriptor.setPinExternals(pinExternals); return this; } - public BuilderReleaseDescriptor build() - { + public BuilderReleaseDescriptor build() { return releaseDescriptor; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStore.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStore.java index 86b1f5a84..d82eba3aa 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStore.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStore.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; /** * Storage for reading and writing release configuration. * * @author Brett Porter */ -public interface ReleaseDescriptorStore -{ +public interface ReleaseDescriptorStore { /** * Read a configuration. * @@ -34,8 +32,7 @@ public interface ReleaseDescriptorStore * @return the configuration * @throws org.apache.maven.shared.release.config.ReleaseDescriptorStoreException if any. */ - ReleaseDescriptorBuilder read( ReleaseDescriptorBuilder mergeDescriptor ) - throws ReleaseDescriptorStoreException; + ReleaseDescriptorBuilder read(ReleaseDescriptorBuilder mergeDescriptor) throws ReleaseDescriptorStoreException; /** * Save a configuration. @@ -43,13 +40,12 @@ ReleaseDescriptorBuilder read( ReleaseDescriptorBuilder mergeDescriptor ) * @param config the configuration * @throws org.apache.maven.shared.release.config.ReleaseDescriptorStoreException if any. */ - void write( ReleaseDescriptor config ) - throws ReleaseDescriptorStoreException; + void write(ReleaseDescriptor config) throws ReleaseDescriptorStoreException; /** * Remove a configuration. * * @param config the location of the configuration */ - void delete( ReleaseDescriptor config ); + void delete(ReleaseDescriptor config); } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreException.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreException.java index 75eccb449..fb7631aa1 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreException.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,23 +16,21 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; /** * Exception occurring within the configuration store. * * @author Brett Porter */ -public class ReleaseDescriptorStoreException - extends Exception -{ +public class ReleaseDescriptorStoreException extends Exception { /** *

Constructor for ReleaseDescriptorStoreException.

* * @param message a {@link java.lang.String} object * @param t a {@link java.lang.Throwable} object */ - public ReleaseDescriptorStoreException( String message, Throwable t ) - { - super( message, t ); + public ReleaseDescriptorStoreException(String message, Throwable t) { + super(message, t); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseUtils.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseUtils.java index 2d24e35c2..100fd02db 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseUtils.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/config/ReleaseUtils.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; import java.util.Arrays; import java.util.Iterator; @@ -33,14 +32,12 @@ * * @author Jeremy Whitlock */ -public class ReleaseUtils -{ +public class ReleaseUtils { private static final String DEVELOPMENT_KEY = "dev"; private static final String RELEASE_KEY = "rel"; - private ReleaseUtils() - { + private ReleaseUtils() { // nothing to see here } @@ -50,8 +47,7 @@ private ReleaseUtils() * @param builder a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder.BuilderReleaseDescriptor} object */ - public static BuilderReleaseDescriptor buildReleaseDescriptor( ReleaseDescriptorBuilder builder ) - { + public static BuilderReleaseDescriptor buildReleaseDescriptor(ReleaseDescriptorBuilder builder) { return builder.build(); } @@ -61,194 +57,146 @@ public static BuilderReleaseDescriptor buildReleaseDescriptor( ReleaseDescriptor * @param properties a {@link java.util.Properties} object * @param builder a {@link org.apache.maven.shared.release.config.ReleaseDescriptorBuilder} object */ - public static void copyPropertiesToReleaseDescriptor( Properties properties, ReleaseDescriptorBuilder builder ) - { - if ( properties.containsKey( "completedPhase" ) ) - { - builder.setCompletedPhase( properties.getProperty( "completedPhase" ) ); - } - if ( properties.containsKey( "commitByProject" ) ) - { - builder.setCommitByProject( Boolean.parseBoolean( properties.getProperty( "commitByProject" ) ) ); - } - if ( properties.containsKey( "scm.id" ) ) - { - builder.setScmId( properties.getProperty( "scm.id" ) ); - } - if ( properties.containsKey( "scm.url" ) ) - { - builder.setScmSourceUrl( properties.getProperty( "scm.url" ) ); - } - if ( properties.containsKey( "scm.username" ) ) - { - builder.setScmUsername( properties.getProperty( "scm.username" ) ); - } - if ( properties.containsKey( "scm.password" ) ) - { - builder.setScmPassword( properties.getProperty( "scm.password" ) ); - } - if ( properties.containsKey( "scm.privateKey" ) ) - { - builder.setScmPrivateKey( properties.getProperty( "scm.privateKey" ) ); - } - if ( properties.containsKey( "scm.passphrase" ) ) - { - builder.setScmPrivateKeyPassPhrase( properties.getProperty( "scm.passphrase" ) ); - } - if ( properties.containsKey( "scm.tagBase" ) ) - { - builder.setScmTagBase( properties.getProperty( "scm.tagBase" ) ); - } - if ( properties.containsKey( "scm.tagNameFormat" ) ) - { - builder.setScmTagNameFormat( properties.getProperty( "scm.tagNameFormat" ) ); - } - if ( properties.containsKey( "scm.branchBase" ) ) - { - builder.setScmBranchBase( properties.getProperty( "scm.branchBase" ) ); - } - if ( properties.containsKey( "scm.tag" ) ) - { - builder.setScmReleaseLabel( properties.getProperty( "scm.tag" ) ); - } - if ( properties.containsKey( "scm.commentPrefix" ) ) - { - builder.setScmCommentPrefix( properties.getProperty( "scm.commentPrefix" ) ); - } - if ( properties.containsKey( "scm.developmentCommitComment" ) ) - { - builder.setScmDevelopmentCommitComment( properties.getProperty( "scm.developmentCommitComment" ) ); - } - if ( properties.containsKey( "scm.releaseCommitComment" ) ) - { - builder.setScmReleaseCommitComment( properties.getProperty( "scm.releaseCommitComment" ) ); - } - if ( properties.containsKey( "scm.branchCommitComment" ) ) - { - builder.setScmBranchCommitComment( properties.getProperty( "scm.branchCommitComment" ) ); - } - if ( properties.containsKey( "scm.rollbackCommitComment" ) ) - { - builder.setScmRollbackCommitComment( properties.getProperty( "scm.rollbackCommitComment" ) ); - } - if ( properties.containsKey( "exec.additionalArguments" ) ) - { - builder.setAdditionalArguments( properties.getProperty( "exec.additionalArguments" ) ); - } - if ( properties.containsKey( "exec.pomFileName" ) ) - { - builder.setPomFileName( properties.getProperty( "exec.pomFileName" ) ); - } - if ( properties.containsKey( "exec.activateProfiles" ) ) - { - builder.setActivateProfiles( - Arrays.asList( properties.getProperty( "exec.activateProfiles" ).split( "," ) ) ); - } - if ( properties.containsKey( "preparationGoals" ) ) - { - builder.setPreparationGoals( properties.getProperty( "preparationGoals" ) ); - } - if ( properties.containsKey( "completionGoals" ) ) - { - builder.setCompletionGoals( properties.getProperty( "completionGoals" ) ); - } - if ( properties.containsKey( "projectVersionPolicyId" ) ) - { - builder.setProjectVersionPolicyId( properties.getProperty( "projectVersionPolicyId" ) ); - } - if ( properties.containsKey( "projectVersionPolicyConfig" ) ) - { - builder.setProjectVersionPolicyConfig( properties.getProperty( "projectVersionPolicyConfig" ) ); - } - if ( properties.containsKey( "projectNamingPolicyId" ) ) - { - builder.setProjectNamingPolicyId( properties.getProperty( "projectNamingPolicyId" ) ); - } - if ( properties.containsKey( "releaseStrategyId" ) ) - { - builder.setReleaseStrategyId( properties.getProperty( "releaseStrategyId" ) ); - } - if ( properties.containsKey( "exec.snapshotReleasePluginAllowed" ) ) - { - String snapshotReleasePluginAllowedStr = properties.getProperty( "exec.snapshotReleasePluginAllowed" ); - builder.setSnapshotReleasePluginAllowed( Boolean.parseBoolean( snapshotReleasePluginAllowedStr ) ); - } - if ( properties.containsKey( "remoteTagging" ) ) - { - String remoteTaggingStr = properties.getProperty( "remoteTagging" ); - builder.setRemoteTagging( Boolean.parseBoolean( remoteTaggingStr ) ); - } - if ( properties.containsKey( "pinExternals" ) ) - { - String pinExternals = properties.getProperty( "pinExternals" ); - builder.setPinExternals( Boolean.parseBoolean( pinExternals ) ); + public static void copyPropertiesToReleaseDescriptor(Properties properties, ReleaseDescriptorBuilder builder) { + if (properties.containsKey("completedPhase")) { + builder.setCompletedPhase(properties.getProperty("completedPhase")); + } + if (properties.containsKey("commitByProject")) { + builder.setCommitByProject(Boolean.parseBoolean(properties.getProperty("commitByProject"))); + } + if (properties.containsKey("scm.id")) { + builder.setScmId(properties.getProperty("scm.id")); + } + if (properties.containsKey("scm.url")) { + builder.setScmSourceUrl(properties.getProperty("scm.url")); + } + if (properties.containsKey("scm.username")) { + builder.setScmUsername(properties.getProperty("scm.username")); + } + if (properties.containsKey("scm.password")) { + builder.setScmPassword(properties.getProperty("scm.password")); + } + if (properties.containsKey("scm.privateKey")) { + builder.setScmPrivateKey(properties.getProperty("scm.privateKey")); + } + if (properties.containsKey("scm.passphrase")) { + builder.setScmPrivateKeyPassPhrase(properties.getProperty("scm.passphrase")); + } + if (properties.containsKey("scm.tagBase")) { + builder.setScmTagBase(properties.getProperty("scm.tagBase")); + } + if (properties.containsKey("scm.tagNameFormat")) { + builder.setScmTagNameFormat(properties.getProperty("scm.tagNameFormat")); + } + if (properties.containsKey("scm.branchBase")) { + builder.setScmBranchBase(properties.getProperty("scm.branchBase")); + } + if (properties.containsKey("scm.tag")) { + builder.setScmReleaseLabel(properties.getProperty("scm.tag")); + } + if (properties.containsKey("scm.commentPrefix")) { + builder.setScmCommentPrefix(properties.getProperty("scm.commentPrefix")); + } + if (properties.containsKey("scm.developmentCommitComment")) { + builder.setScmDevelopmentCommitComment(properties.getProperty("scm.developmentCommitComment")); + } + if (properties.containsKey("scm.releaseCommitComment")) { + builder.setScmReleaseCommitComment(properties.getProperty("scm.releaseCommitComment")); + } + if (properties.containsKey("scm.branchCommitComment")) { + builder.setScmBranchCommitComment(properties.getProperty("scm.branchCommitComment")); + } + if (properties.containsKey("scm.rollbackCommitComment")) { + builder.setScmRollbackCommitComment(properties.getProperty("scm.rollbackCommitComment")); + } + if (properties.containsKey("exec.additionalArguments")) { + builder.setAdditionalArguments(properties.getProperty("exec.additionalArguments")); + } + if (properties.containsKey("exec.pomFileName")) { + builder.setPomFileName(properties.getProperty("exec.pomFileName")); + } + if (properties.containsKey("exec.activateProfiles")) { + builder.setActivateProfiles(Arrays.asList( + properties.getProperty("exec.activateProfiles").split(","))); } - if ( properties.containsKey( "pushChanges" ) ) - { - String pushChanges = properties.getProperty( "pushChanges" ); - builder.setPushChanges( Boolean.parseBoolean( pushChanges ) ); - } - if ( properties.containsKey( "workItem" ) ) - { - builder.setWorkItem( properties.getProperty( "workItem" ) ); - } - if ( properties.containsKey( "autoResolveSnapshots" ) ) - { - String resolve = properties.getProperty( "autoResolveSnapshots" ); - builder.setAutoResolveSnapshots( resolve ); + if (properties.containsKey("preparationGoals")) { + builder.setPreparationGoals(properties.getProperty("preparationGoals")); + } + if (properties.containsKey("completionGoals")) { + builder.setCompletionGoals(properties.getProperty("completionGoals")); + } + if (properties.containsKey("projectVersionPolicyId")) { + builder.setProjectVersionPolicyId(properties.getProperty("projectVersionPolicyId")); + } + if (properties.containsKey("projectVersionPolicyConfig")) { + builder.setProjectVersionPolicyConfig(properties.getProperty("projectVersionPolicyConfig")); + } + if (properties.containsKey("projectNamingPolicyId")) { + builder.setProjectNamingPolicyId(properties.getProperty("projectNamingPolicyId")); + } + if (properties.containsKey("releaseStrategyId")) { + builder.setReleaseStrategyId(properties.getProperty("releaseStrategyId")); + } + if (properties.containsKey("exec.snapshotReleasePluginAllowed")) { + String snapshotReleasePluginAllowedStr = properties.getProperty("exec.snapshotReleasePluginAllowed"); + builder.setSnapshotReleasePluginAllowed(Boolean.parseBoolean(snapshotReleasePluginAllowedStr)); + } + if (properties.containsKey("remoteTagging")) { + String remoteTaggingStr = properties.getProperty("remoteTagging"); + builder.setRemoteTagging(Boolean.parseBoolean(remoteTaggingStr)); + } + if (properties.containsKey("pinExternals")) { + String pinExternals = properties.getProperty("pinExternals"); + builder.setPinExternals(Boolean.parseBoolean(pinExternals)); + } + if (properties.containsKey("pushChanges")) { + String pushChanges = properties.getProperty("pushChanges"); + builder.setPushChanges(Boolean.parseBoolean(pushChanges)); + } + if (properties.containsKey("workItem")) { + builder.setWorkItem(properties.getProperty("workItem")); + } + if (properties.containsKey("autoResolveSnapshots")) { + String resolve = properties.getProperty("autoResolveSnapshots"); + builder.setAutoResolveSnapshots(resolve); } - loadResolvedDependencies( properties, builder ); + loadResolvedDependencies(properties, builder); // boolean properties are not written to the properties file because the value from the caller is always used - for ( Object o : properties.keySet() ) - { + for (Object o : properties.keySet()) { String property = (String) o; - if ( property.startsWith( "project.rel." ) ) - { - builder.addReleaseVersion( property.substring( "project.rel.".length() ), - properties.getProperty( property ) ); - } - else if ( property.startsWith( "project.dev." ) ) - { - builder.addDevelopmentVersion( property.substring( "project.dev.".length() ), - properties.getProperty( property ) ); - } - else if ( property.startsWith( "dependency.rel." ) ) - { - builder.addDependencyReleaseVersion( property.substring( "dependency.rel.".length() ), - properties.getProperty( property ) ); - } - else if ( property.startsWith( "dependency.dev." ) ) - { - builder.addDependencyDevelopmentVersion( property.substring( "dependency.dev.".length() ), - properties.getProperty( property ) ); - } - else if ( property.startsWith( "project.scm." ) ) - { - int index = property.lastIndexOf( '.' ); - if ( index > "project.scm.".length() ) - { - String key = property.substring( "project.scm.".length(), index ); - - if ( builder.build().getOriginalScmInfo( key ) == null ) - { - if ( properties.getProperty( "project.scm." + key + ".empty" ) != null ) - { - builder.addOriginalScmInfo( key, null ); - } - else - { + if (property.startsWith("project.rel.")) { + builder.addReleaseVersion( + property.substring("project.rel.".length()), properties.getProperty(property)); + } else if (property.startsWith("project.dev.")) { + builder.addDevelopmentVersion( + property.substring("project.dev.".length()), properties.getProperty(property)); + } else if (property.startsWith("dependency.rel.")) { + builder.addDependencyReleaseVersion( + property.substring("dependency.rel.".length()), properties.getProperty(property)); + } else if (property.startsWith("dependency.dev.")) { + builder.addDependencyDevelopmentVersion( + property.substring("dependency.dev.".length()), properties.getProperty(property)); + } else if (property.startsWith("project.scm.")) { + int index = property.lastIndexOf('.'); + if (index > "project.scm.".length()) { + String key = property.substring("project.scm.".length(), index); + + if (builder.build().getOriginalScmInfo(key) == null) { + if (properties.getProperty("project.scm." + key + ".empty") != null) { + builder.addOriginalScmInfo(key, null); + } else { IdentifiedScm scm = new IdentifiedScm(); - scm.setConnection( properties.getProperty( "project.scm." + key + ".connection" ) ); + scm.setConnection(properties.getProperty("project.scm." + key + ".connection")); scm.setDeveloperConnection( - properties.getProperty( "project.scm." + key + ".developerConnection" ) ); - scm.setUrl( properties.getProperty( "project.scm." + key + ".url" ) ); - scm.setTag( properties.getProperty( "project.scm." + key + ".tag" ) ); - scm.setId( properties.getProperty( "project.scm." + key + ".id" ) ); + properties.getProperty("project.scm." + key + ".developerConnection")); + scm.setUrl(properties.getProperty("project.scm." + key + ".url")); + scm.setTag(properties.getProperty("project.scm." + key + ".tag")); + scm.setId(properties.getProperty("project.scm." + key + ".id")); - builder.addOriginalScmInfo( key, scm ); + builder.addOriginalScmInfo(key, scm); } } } @@ -256,53 +204,41 @@ else if ( property.startsWith( "project.scm." ) ) } } - private static void loadResolvedDependencies( Properties prop, ReleaseDescriptorBuilder builder ) - { + private static void loadResolvedDependencies(Properties prop, ReleaseDescriptorBuilder builder) { Set entries = prop.entrySet(); Iterator> iterator = entries.iterator(); String propertyName; Entry currentEntry; - while ( iterator.hasNext() ) - { + while (iterator.hasNext()) { currentEntry = iterator.next(); propertyName = currentEntry.getKey(); - if ( propertyName.startsWith( "dependency." ) ) - { + if (propertyName.startsWith("dependency.")) { String artifactVersionlessKey; int startIndex = "dependency.".length(); int endIndex; String versionType; - if ( propertyName.contains( ".development" ) ) - { - endIndex = propertyName.lastIndexOf( ".development" ); + if (propertyName.contains(".development")) { + endIndex = propertyName.lastIndexOf(".development"); versionType = DEVELOPMENT_KEY; - } - else if ( propertyName.contains( ".release" ) ) - { - endIndex = propertyName.lastIndexOf( ".release" ); + } else if (propertyName.contains(".release")) { + endIndex = propertyName.lastIndexOf(".release"); versionType = RELEASE_KEY; - } - else - { + } else { // MRELEASE-834, probably a maven-dependency-plugin property continue; } - artifactVersionlessKey = propertyName.substring( startIndex, endIndex ); + artifactVersionlessKey = propertyName.substring(startIndex, endIndex); - if ( RELEASE_KEY.equals( versionType ) ) - { - builder.addDependencyReleaseVersion( artifactVersionlessKey, currentEntry.getValue() ); - } - else if ( DEVELOPMENT_KEY.equals( versionType ) ) - { - builder.addDependencyDevelopmentVersion( artifactVersionlessKey, currentEntry.getValue() ); + if (RELEASE_KEY.equals(versionType)) { + builder.addDependencyReleaseVersion(artifactVersionlessKey, currentEntry.getValue()); + } else if (DEVELOPMENT_KEY.equals(versionType)) { + builder.addDependencyDevelopmentVersion(artifactVersionlessKey, currentEntry.getValue()); } } } } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/env/DefaultReleaseEnvironment.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/env/DefaultReleaseEnvironment.java index b9a393f3a..787e1abbd 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/env/DefaultReleaseEnvironment.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/env/DefaultReleaseEnvironment.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.env; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.env; import java.io.File; @@ -26,9 +25,7 @@ /** *

DefaultReleaseEnvironment class.

*/ -public class DefaultReleaseEnvironment - implements ReleaseEnvironment -{ +public class DefaultReleaseEnvironment implements ReleaseEnvironment { private File mavenHome; private File javaHome; @@ -40,14 +37,12 @@ public class DefaultReleaseEnvironment private String mavenExecutorId = DEFAULT_MAVEN_EXECUTOR_ID; @Override - public File getMavenHome() - { + public File getMavenHome() { return mavenHome; } @Override - public Settings getSettings() - { + public Settings getSettings() { return settings; } @@ -57,8 +52,7 @@ public Settings getSettings() * @param mavenHome a {@link java.io.File} object * @return a {@link org.apache.maven.shared.release.env.DefaultReleaseEnvironment} object */ - public DefaultReleaseEnvironment setMavenHome( File mavenHome ) - { + public DefaultReleaseEnvironment setMavenHome(File mavenHome) { this.mavenHome = mavenHome; return this; } @@ -69,15 +63,13 @@ public DefaultReleaseEnvironment setMavenHome( File mavenHome ) * @param settings a {@link org.apache.maven.settings.Settings} object * @return a {@link org.apache.maven.shared.release.env.DefaultReleaseEnvironment} object */ - public DefaultReleaseEnvironment setSettings( Settings settings ) - { + public DefaultReleaseEnvironment setSettings(Settings settings) { this.settings = settings; return this; } @Override - public String getMavenExecutorId() - { + public String getMavenExecutorId() { return mavenExecutorId; } @@ -87,15 +79,13 @@ public String getMavenExecutorId() * @param mavenExecutorId a {@link java.lang.String} object * @return a {@link org.apache.maven.shared.release.env.DefaultReleaseEnvironment} object */ - public DefaultReleaseEnvironment setMavenExecutorId( String mavenExecutorId ) - { + public DefaultReleaseEnvironment setMavenExecutorId(String mavenExecutorId) { this.mavenExecutorId = mavenExecutorId; return this; } @Override - public File getJavaHome() - { + public File getJavaHome() { return javaHome; } @@ -105,20 +95,17 @@ public File getJavaHome() * @param javaHome a {@link java.io.File} object * @return a {@link org.apache.maven.shared.release.env.DefaultReleaseEnvironment} object */ - public DefaultReleaseEnvironment setJavaHome( File javaHome ) - { + public DefaultReleaseEnvironment setJavaHome(File javaHome) { this.javaHome = javaHome; return this; } @Override - public File getLocalRepositoryDirectory() - { + public File getLocalRepositoryDirectory() { File localRepo = localRepositoryDirectory; - if ( localRepo == null && settings != null && settings.getLocalRepository() != null ) - { - localRepo = new File( settings.getLocalRepository() ).getAbsoluteFile(); + if (localRepo == null && settings != null && settings.getLocalRepository() != null) { + localRepo = new File(settings.getLocalRepository()).getAbsoluteFile(); } return localRepo; @@ -130,8 +117,7 @@ public File getLocalRepositoryDirectory() * @param localRepositoryDirectory a {@link java.io.File} object * @return a {@link org.apache.maven.shared.release.env.DefaultReleaseEnvironment} object */ - public DefaultReleaseEnvironment setLocalRepositoryDirectory( File localRepositoryDirectory ) - { + public DefaultReleaseEnvironment setLocalRepositoryDirectory(File localRepositoryDirectory) { this.localRepositoryDirectory = localRepositoryDirectory; return this; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/AbstractMavenExecutor.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/AbstractMavenExecutor.java index f63d2bf68..980929a1f 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/AbstractMavenExecutor.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/AbstractMavenExecutor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.File; import java.util.ArrayList; @@ -42,39 +41,44 @@ /** *

Abstract AbstractMavenExecutor class.

*/ -public abstract class AbstractMavenExecutor - implements MavenExecutor -{ - private final Logger logger = LoggerFactory.getLogger( getClass() ); +public abstract class AbstractMavenExecutor implements MavenExecutor { + private final Logger logger = LoggerFactory.getLogger(getClass()); private final MavenCrypto mavenCrypto; - protected AbstractMavenExecutor( MavenCrypto mavenCrypto ) - { - this.mavenCrypto = requireNonNull( mavenCrypto ); + protected AbstractMavenExecutor(MavenCrypto mavenCrypto) { + this.mavenCrypto = requireNonNull(mavenCrypto); } @Override - public void executeGoals( File workingDirectory, String goals, ReleaseEnvironment releaseEnvironment, - boolean interactive, String additionalArguments, String pomFileName, - ReleaseResult result ) - throws MavenExecutorException - { + public void executeGoals( + File workingDirectory, + String goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult result) + throws MavenExecutorException { List goalsList = new ArrayList<>(); - if ( goals != null ) - { + if (goals != null) { // accept both space and comma, so the old way still work // also accept line separators, so that goal lists can be spread // across multiple lines in the POM. - Collections.addAll( goalsList, StringUtils.split( goals, ", \n\r\t" ) ); + Collections.addAll(goalsList, StringUtils.split(goals, ", \n\r\t")); } - executeGoals( workingDirectory, goalsList, releaseEnvironment, interactive, additionalArguments, pomFileName, - result ); + executeGoals( + workingDirectory, goalsList, releaseEnvironment, interactive, additionalArguments, pomFileName, result); } - protected abstract void executeGoals( File workingDirectory, List goals, - ReleaseEnvironment releaseEnvironment, boolean interactive, - String additionalArguments, String pomFileName, ReleaseResult result ) + protected abstract void executeGoals( + File workingDirectory, + List goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult result) throws MavenExecutorException; /** @@ -82,8 +86,7 @@ protected abstract void executeGoals( File workingDirectory, List goals, * * @return a {@link Logger} object */ - protected final Logger getLogger() - { + protected final Logger getLogger() { return logger; } @@ -93,50 +96,35 @@ protected final Logger getLogger() * @param settings a {@link org.apache.maven.settings.Settings} object * @return a {@link org.apache.maven.settings.Settings} object */ - protected Settings encryptSettings( Settings settings ) - { - Settings encryptedSettings = SettingsUtils.copySettings( settings ); + protected Settings encryptSettings(Settings settings) { + Settings encryptedSettings = SettingsUtils.copySettings(settings); - for ( Server server : encryptedSettings.getServers() ) - { + for (Server server : encryptedSettings.getServers()) { String password = server.getPassword(); - if ( password != null && !mavenCrypto.isEncryptedString( password ) ) - { - try - { - server.setPassword( mavenCrypto.encryptAndDecorate( password ) ); - } - catch ( MavenCryptoException e ) - { + if (password != null && !mavenCrypto.isEncryptedString(password)) { + try { + server.setPassword(mavenCrypto.encryptAndDecorate(password)); + } catch (MavenCryptoException e) { // ignore } } String passphrase = server.getPassphrase(); - if ( passphrase != null && !mavenCrypto.isEncryptedString( passphrase ) ) - { - try - { - server.setPassphrase( mavenCrypto.encryptAndDecorate( passphrase ) ); - } - catch ( MavenCryptoException e ) - { + if (passphrase != null && !mavenCrypto.isEncryptedString(passphrase)) { + try { + server.setPassphrase(mavenCrypto.encryptAndDecorate(passphrase)); + } catch (MavenCryptoException e) { // ignore } } } - for ( Proxy proxy : encryptedSettings.getProxies() ) - { + for (Proxy proxy : encryptedSettings.getProxies()) { String password = proxy.getPassword(); - if ( password != null && !mavenCrypto.isEncryptedString( password ) ) - { - try - { - proxy.setPassword( mavenCrypto.encryptAndDecorate( password ) ); - } - catch ( MavenCryptoException e ) - { + if (password != null && !mavenCrypto.isEncryptedString(password)) { + try { + proxy.setPassword(mavenCrypto.encryptAndDecorate(password)); + } catch (MavenCryptoException e) { // ignore } } @@ -150,8 +138,7 @@ protected Settings encryptSettings( Settings settings ) * * @return a {@link org.apache.maven.settings.io.xpp3.SettingsXpp3Writer} object */ - protected SettingsXpp3Writer getSettingsWriter() - { + protected SettingsXpp3Writer getSettingsWriter() { return new SettingsXpp3Writer(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/CommandLineFactory.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/CommandLineFactory.java index 50e7a12ed..90c6b598a 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/CommandLineFactory.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/CommandLineFactory.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import org.codehaus.plexus.util.cli.Commandline; @@ -26,8 +25,7 @@ * * @author Brett Porter */ -public interface CommandLineFactory -{ +public interface CommandLineFactory { /** * Create a command line object with default environment for the given executable. * @@ -36,6 +34,5 @@ public interface CommandLineFactory * @throws org.apache.maven.shared.release.exec.MavenExecutorException if there was a problem creating * the command line */ - Commandline createCommandLine( String executable ) - throws MavenExecutorException; + Commandline createCommandLine(String executable) throws MavenExecutorException; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/DefaultCommandLineFactory.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/DefaultCommandLineFactory.java index cdf8a1914..7b857cd19 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/DefaultCommandLineFactory.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/DefaultCommandLineFactory.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import javax.inject.Named; import javax.inject.Singleton; @@ -31,23 +30,16 @@ */ @Singleton @Named -public class DefaultCommandLineFactory - implements CommandLineFactory -{ +public class DefaultCommandLineFactory implements CommandLineFactory { @Override - public Commandline createCommandLine( String executable ) - throws MavenExecutorException - { + public Commandline createCommandLine(String executable) throws MavenExecutorException { Commandline commandline = new Commandline(); - commandline.setExecutable( executable ); + commandline.setExecutable(executable); - try - { + try { commandline.addSystemEnvironment(); - } - catch ( Exception e ) - { - throw new MavenExecutorException( e.getMessage(), e ); + } catch (Exception e) { + throw new MavenExecutorException(e.getMessage(), e); } return commandline; diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java index 1c5c36209..947424b0d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/ForkedMavenExecutor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import javax.inject.Inject; import javax.inject.Named; @@ -46,131 +45,108 @@ * @author Brett Porter */ @Singleton -@Named( "forked-path" ) -public class ForkedMavenExecutor - extends AbstractMavenExecutor -{ +@Named("forked-path") +public class ForkedMavenExecutor extends AbstractMavenExecutor { /** * Command line factory. */ private final CommandLineFactory commandLineFactory; @Inject - public ForkedMavenExecutor( MavenCrypto mavenCrypto, - CommandLineFactory commandLineFactory ) - { - super( mavenCrypto ); - this.commandLineFactory = requireNonNull( commandLineFactory ); + public ForkedMavenExecutor(MavenCrypto mavenCrypto, CommandLineFactory commandLineFactory) { + super(mavenCrypto); + this.commandLineFactory = requireNonNull(commandLineFactory); } /* * @noinspection UseOfSystemOutOrSystemErr */ @Override - public void executeGoals( File workingDirectory, List goals, ReleaseEnvironment releaseEnvironment, - boolean interactive, String additionalArguments, String pomFileName, - ReleaseResult relResult ) - throws MavenExecutorException - { + public void executeGoals( + File workingDirectory, + List goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult relResult) + throws MavenExecutorException { String mavenPath; // if null we use the current one - if ( releaseEnvironment.getMavenHome() != null ) - { + if (releaseEnvironment.getMavenHome() != null) { mavenPath = releaseEnvironment.getMavenHome().getAbsolutePath(); - } - else - { - mavenPath = System.getProperty( "maven.home" ); + } else { + mavenPath = System.getProperty("maven.home"); } File settingsFile = null; - if ( releaseEnvironment.getSettings() != null ) - { + if (releaseEnvironment.getSettings() != null) { // Have to serialize to a file as if Maven is embedded, there may not actually be a settings.xml on disk - try - { - settingsFile = File.createTempFile( "release-settings", ".xml" ); + try { + settingsFile = File.createTempFile("release-settings", ".xml"); SettingsXpp3Writer writer = getSettingsWriter(); - try ( FileWriter fileWriter = new FileWriter( settingsFile ) ) - { - writer.write( fileWriter, encryptSettings( releaseEnvironment.getSettings() ) ); + try (FileWriter fileWriter = new FileWriter(settingsFile)) { + writer.write(fileWriter, encryptSettings(releaseEnvironment.getSettings())); } - } - catch ( IOException e ) - { - throw new MavenExecutorException( "Could not create temporary file for release settings.xml", e ); + } catch (IOException e) { + throw new MavenExecutorException("Could not create temporary file for release settings.xml", e); } } - try - { + try { Commandline cl = - commandLineFactory.createCommandLine( mavenPath + File.separator + "bin" + File.separator + "mvn" ); + commandLineFactory.createCommandLine(mavenPath + File.separator + "bin" + File.separator + "mvn"); - cl.setWorkingDirectory( workingDirectory.getAbsolutePath() ); + cl.setWorkingDirectory(workingDirectory.getAbsolutePath()); // FIX for MRELEASE-1105 - //cl.addEnvironment( "MAVEN_DEBUG_OPTS", "" ); + // cl.addEnvironment( "MAVEN_DEBUG_OPTS", "" ); - cl.addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); + cl.addEnvironment("MAVEN_TERMINATE_CMD", "on"); - if ( settingsFile != null ) - { - cl.createArg().setValue( "-s" ); - cl.createArg().setFile( settingsFile ); + if (settingsFile != null) { + cl.createArg().setValue("-s"); + cl.createArg().setFile(settingsFile); } - if ( pomFileName != null ) - { - cl.createArg().setValue( "-f" ); - cl.createArg().setValue( pomFileName ); + if (pomFileName != null) { + cl.createArg().setValue("-f"); + cl.createArg().setValue(pomFileName); } - for ( String goal : goals ) - { - cl.createArg().setValue( goal ); + for (String goal : goals) { + cl.createArg().setValue(goal); } - if ( !interactive ) - { - cl.createArg().setValue( "--batch-mode" ); + if (!interactive) { + cl.createArg().setValue("--batch-mode"); } - if ( !StringUtils.isEmpty( additionalArguments ) ) - { - cl.createArg().setLine( additionalArguments ); + if (!StringUtils.isEmpty(additionalArguments)) { + cl.createArg().setLine(additionalArguments); } - TeeOutputStream stdOut = new TeeOutputStream( System.out ); + TeeOutputStream stdOut = new TeeOutputStream(System.out); - TeeOutputStream stdErr = new TeeOutputStream( System.err ); + TeeOutputStream stdErr = new TeeOutputStream(System.err); - try - { - relResult.appendInfo( "Executing: " + cl ); - getLogger().info( "Executing: " + cl ); + try { + relResult.appendInfo("Executing: " + cl); + getLogger().info("Executing: " + cl); - int result = executeCommandLine( cl, System.in, stdOut, stdErr ); + int result = executeCommandLine(cl, System.in, stdOut, stdErr); - if ( result != 0 ) - { - throw new MavenExecutorException( "Maven execution failed, exit code: '" + result + "'", result ); + if (result != 0) { + throw new MavenExecutorException("Maven execution failed, exit code: '" + result + "'", result); } + } catch (CommandLineException e) { + throw new MavenExecutorException("Can't run goal " + goals, e); + } finally { + relResult.appendOutput(stdOut.toString()); } - catch ( CommandLineException e ) - { - throw new MavenExecutorException( "Can't run goal " + goals, e ); - } - finally - { - relResult.appendOutput( stdOut.toString() ); - } - } - finally - { - if ( settingsFile != null && settingsFile.exists() && !settingsFile.delete() ) - { + } finally { + if (settingsFile != null && settingsFile.exists() && !settingsFile.delete()) { settingsFile.deleteOnExit(); } } @@ -186,31 +162,27 @@ public void executeGoals( File workingDirectory, List goals, ReleaseEnvi * @return a int * @throws org.codehaus.plexus.util.cli.CommandLineException if any. */ - public static int executeCommandLine( Commandline cl, InputStream systemIn, OutputStream systemOut, - OutputStream systemErr ) - throws CommandLineException - { - if ( cl == null ) - { - throw new IllegalArgumentException( "cl cannot be null." ); + public static int executeCommandLine( + Commandline cl, InputStream systemIn, OutputStream systemOut, OutputStream systemErr) + throws CommandLineException { + if (cl == null) { + throw new IllegalArgumentException("cl cannot be null."); } Process p = cl.execute(); - //processes.put( new Long( cl.getPid() ), p ); + // processes.put( new Long( cl.getPid() ), p ); RawStreamPumper inputFeeder = null; - if ( systemIn != null ) - { - inputFeeder = new RawStreamPumper( systemIn, p.getOutputStream(), true ); + if (systemIn != null) { + inputFeeder = new RawStreamPumper(systemIn, p.getOutputStream(), true); } - RawStreamPumper outputPumper = new RawStreamPumper( p.getInputStream(), systemOut ); - RawStreamPumper errorPumper = new RawStreamPumper( p.getErrorStream(), systemErr ); + RawStreamPumper outputPumper = new RawStreamPumper(p.getInputStream(), systemOut); + RawStreamPumper errorPumper = new RawStreamPumper(p.getErrorStream(), systemErr); - if ( inputFeeder != null ) - { + if (inputFeeder != null) { inputFeeder.start(); } @@ -218,57 +190,39 @@ public static int executeCommandLine( Commandline cl, InputStream systemIn, Outp errorPumper.start(); - try - { + try { int returnValue = p.waitFor(); - if ( inputFeeder != null ) - { + if (inputFeeder != null) { inputFeeder.setDone(); } outputPumper.setDone(); errorPumper.setDone(); - //processes.remove( new Long( cl.getPid() ) ); + // processes.remove( new Long( cl.getPid() ) ); return returnValue; - } - catch ( InterruptedException ex ) - { - //killProcess( cl.getPid() ); - throw new CommandLineException( "Error while executing external command, process killed.", ex ); - } - finally - { - try - { + } catch (InterruptedException ex) { + // killProcess( cl.getPid() ); + throw new CommandLineException("Error while executing external command, process killed.", ex); + } finally { + try { errorPumper.closeInput(); + } catch (IOException e) { + // ignore } - catch ( IOException e ) - { - //ignore - } - try - { + try { outputPumper.closeInput(); + } catch (IOException e) { + // ignore } - catch ( IOException e ) - { - //ignore - } - if ( inputFeeder != null ) - { - try - { + if (inputFeeder != null) { + try { inputFeeder.closeOutput(); - } - catch ( IOException e ) - { - //ignore + } catch (IOException e) { + // ignore } } } } - - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java index 972cbc675..cc3932447 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/InvokerMavenExecutor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import javax.inject.Inject; import javax.inject.Named; @@ -46,102 +45,87 @@ * Fork Maven using the maven-invoker shared library. */ @Singleton -@Named( "invoker" ) -public class InvokerMavenExecutor - extends AbstractMavenExecutor -{ +@Named("invoker") +public class InvokerMavenExecutor extends AbstractMavenExecutor { @Inject - public InvokerMavenExecutor( MavenCrypto mavenCrypto ) - { - super( mavenCrypto ); + public InvokerMavenExecutor(MavenCrypto mavenCrypto) { + super(mavenCrypto); } @Override - public void executeGoals( File workingDirectory, List goals, ReleaseEnvironment releaseEnvironment, - boolean interactive, String additionalArguments, String pomFileName, - ReleaseResult result ) - throws MavenExecutorException - { + public void executeGoals( + File workingDirectory, + List goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult result) + throws MavenExecutorException { InvokerLogger bridge = getInvokerLogger(); Invoker invoker = new DefaultInvoker() - .setMavenHome( releaseEnvironment.getMavenHome() ) - .setLocalRepositoryDirectory( releaseEnvironment.getLocalRepositoryDirectory() ) - .setLogger( bridge ); + .setMavenHome(releaseEnvironment.getMavenHome()) + .setLocalRepositoryDirectory(releaseEnvironment.getLocalRepositoryDirectory()) + .setLogger(bridge); InvocationRequest req = new DefaultInvocationRequest() - .setDebug( getLogger().isDebugEnabled() ) - .setBaseDirectory( workingDirectory ) + .setDebug(getLogger().isDebugEnabled()) + .setBaseDirectory(workingDirectory) // fix for MRELEASE-1105 - //.addShellEnvironment( "MAVEN_DEBUG_OPTS", "" ) - .setBatchMode( true ) - .setOutputHandler( getLogger()::info ) - .setErrorHandler( getLogger()::error ); - - if ( pomFileName != null ) - { - req.setPomFileName( pomFileName ); + // .addShellEnvironment( "MAVEN_DEBUG_OPTS", "" ) + .setBatchMode(true) + .setOutputHandler(getLogger()::info) + .setErrorHandler(getLogger()::error); + + if (pomFileName != null) { + req.setPomFileName(pomFileName); } File settingsFile = null; - if ( releaseEnvironment.getSettings() != null ) - { + if (releaseEnvironment.getSettings() != null) { // Have to serialize to a file as if Maven is embedded, there may not actually be a settings.xml on disk - try - { - settingsFile = File.createTempFile( "release-settings", ".xml" ); + try { + settingsFile = File.createTempFile("release-settings", ".xml"); SettingsXpp3Writer writer = getSettingsWriter(); - try ( FileWriter fileWriter = new FileWriter( settingsFile ) ) - { - writer.write( fileWriter, encryptSettings( releaseEnvironment.getSettings() ) ); + try (FileWriter fileWriter = new FileWriter(settingsFile)) { + writer.write(fileWriter, encryptSettings(releaseEnvironment.getSettings())); } - req.setUserSettingsFile( settingsFile ); - } - catch ( IOException e ) - { - throw new MavenExecutorException( "Could not create temporary file for release settings.xml", e ); + req.setUserSettingsFile(settingsFile); + } catch (IOException e) { + throw new MavenExecutorException("Could not create temporary file for release settings.xml", e); } } - try - { - List targetGoals = new ArrayList<>( goals ); + try { + List targetGoals = new ArrayList<>(goals); - if ( additionalArguments != null && !additionalArguments.isEmpty() ) - { + if (additionalArguments != null && !additionalArguments.isEmpty()) { // additionalArguments will be parsed be MavenInvoker - targetGoals.add( additionalArguments ); + targetGoals.add(additionalArguments); } - req.setGoals( targetGoals ); + req.setGoals(targetGoals); - try - { - InvocationResult invocationResult = invoker.execute( req ); + try { + InvocationResult invocationResult = invoker.execute(req); - if ( invocationResult.getExecutionException() != null ) - { - throw new MavenExecutorException( "Error executing Maven.", - invocationResult.getExecutionException() ); + if (invocationResult.getExecutionException() != null) { + throw new MavenExecutorException( + "Error executing Maven.", invocationResult.getExecutionException()); } - if ( invocationResult.getExitCode() != 0 ) - { + if (invocationResult.getExitCode() != 0) { throw new MavenExecutorException( - "Maven execution failed, exit code: " + invocationResult.getExitCode(), - invocationResult.getExitCode() ); + "Maven execution failed, exit code: " + invocationResult.getExitCode(), + invocationResult.getExitCode()); } + } catch (MavenInvocationException e) { + throw new MavenExecutorException("Failed to invoke Maven build.", e); } - catch ( MavenInvocationException e ) - { - throw new MavenExecutorException( "Failed to invoke Maven build.", e ); - } - } - finally - { - if ( settingsFile != null && settingsFile.exists() && !settingsFile.delete() ) - { + } finally { + if (settingsFile != null && settingsFile.exists() && !settingsFile.delete()) { settingsFile.deleteOnExit(); } } @@ -152,125 +136,103 @@ public void executeGoals( File workingDirectory, List goals, ReleaseEnvi * * @return a {@link org.apache.maven.shared.invoker.InvokerLogger} object */ - protected InvokerLogger getInvokerLogger() - { - return new LoggerBridge( getLogger() ); + protected InvokerLogger getInvokerLogger() { + return new LoggerBridge(getLogger()); } - private static final class LoggerBridge - implements InvokerLogger - { + private static final class LoggerBridge implements InvokerLogger { private final Logger logger; - LoggerBridge( Logger logger ) - { + LoggerBridge(Logger logger) { this.logger = logger; } @Override - public void debug( String message, Throwable error ) - { - logger.debug( message, error ); + public void debug(String message, Throwable error) { + logger.debug(message, error); } @Override - public void debug( String message ) - { - logger.debug( message ); + public void debug(String message) { + logger.debug(message); } @Override - public void error( String message, Throwable error ) - { - logger.error( message, error ); + public void error(String message, Throwable error) { + logger.error(message, error); } @Override - public void error( String message ) - { - logger.error( message ); + public void error(String message) { + logger.error(message); } @Override - public void fatalError( String message, Throwable error ) - { - logger.error( message, error ); + public void fatalError(String message, Throwable error) { + logger.error(message, error); } @Override - public void fatalError( String message ) - { - logger.error( message ); + public void fatalError(String message) { + logger.error(message); } @Override - public int getThreshold() - { + public int getThreshold() { return InvokerLogger.DEBUG; } @Override - public void info( String message, Throwable error ) - { - logger.info( message, error ); + public void info(String message, Throwable error) { + logger.info(message, error); } @Override - public void info( String message ) - { - logger.info( message ); + public void info(String message) { + logger.info(message); } @Override - public boolean isDebugEnabled() - { + public boolean isDebugEnabled() { return logger.isDebugEnabled(); } @Override - public boolean isErrorEnabled() - { + public boolean isErrorEnabled() { return logger.isErrorEnabled(); } @Override - public boolean isFatalErrorEnabled() - { + public boolean isFatalErrorEnabled() { return logger.isErrorEnabled(); } @Override - public boolean isInfoEnabled() - { + public boolean isInfoEnabled() { return logger.isInfoEnabled(); } @Override - public boolean isWarnEnabled() - { + public boolean isWarnEnabled() { return logger.isWarnEnabled(); } @Override - public void setThreshold( int level ) - { + public void setThreshold(int level) { // NOTE: // logger.setThreshold( level ) // is not supported in plexus-container-default:1.0-alpha-9 as used in Maven 2.x } @Override - public void warn( String message, Throwable error ) - { - logger.warn( message, error ); + public void warn(String message, Throwable error) { + logger.warn(message, error); } @Override - public void warn( String message ) - { - logger.warn( message ); + public void warn(String message) { + logger.warn(message); } } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutor.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutor.java index 53475a7ed..c37532ccd 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutor.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutor.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.File; @@ -29,8 +28,7 @@ * * @author Brett Porter */ -public interface MavenExecutor -{ +public interface MavenExecutor { /** * Execute goals using Maven. * @@ -43,7 +41,13 @@ public interface MavenExecutor * @param result holds all results of the execution * @throws org.apache.maven.shared.release.exec.MavenExecutorException if an error occurred executing Maven */ - void executeGoals( File workingDirectory, String goals, ReleaseEnvironment releaseEnvironment, - boolean interactive, String additionalArguments, String pomFileName, ReleaseResult result ) + void executeGoals( + File workingDirectory, + String goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult result) throws MavenExecutorException; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutorException.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutorException.java index 7a6894930..3ce003251 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutorException.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/MavenExecutorException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; /** * Exception executing Maven. * * @author Brett Porter */ -public class MavenExecutorException - extends Exception -{ +public class MavenExecutorException extends Exception { private int exitCode; /** @@ -35,9 +32,8 @@ public class MavenExecutorException * @param message a {@link java.lang.String} object * @param exitCode a int */ - public MavenExecutorException( String message, int exitCode ) - { - super( message ); + public MavenExecutorException(String message, int exitCode) { + super(message); this.exitCode = exitCode; } @@ -48,9 +44,8 @@ public MavenExecutorException( String message, int exitCode ) * @param message a {@link java.lang.String} object * @param cause a {@link java.lang.Throwable} object */ - public MavenExecutorException( String message, Throwable cause ) - { - super( message, cause ); + public MavenExecutorException(String message, Throwable cause) { + super(message, cause); } /** @@ -58,8 +53,7 @@ public MavenExecutorException( String message, Throwable cause ) * * @return a int */ - public int getExitCode() - { + public int getExitCode() { return exitCode; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/RawStreamPumper.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/RawStreamPumper.java index 34da69704..2988b0b40 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/RawStreamPumper.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/RawStreamPumper.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.IOException; import java.io.InputStream; @@ -26,9 +25,7 @@ /** *

RawStreamPumper class.

*/ -public class RawStreamPumper - extends Thread -{ +public class RawStreamPumper extends Thread { private final InputStream in; private final OutputStream out; @@ -46,8 +43,7 @@ public class RawStreamPumper * @param out a {@link java.io.OutputStream} object * @param poll a boolean */ - public RawStreamPumper( InputStream in, OutputStream out, boolean poll ) - { + public RawStreamPumper(InputStream in, OutputStream out, boolean poll) { this.in = in; this.out = out; this.poll = poll; @@ -59,8 +55,7 @@ public RawStreamPumper( InputStream in, OutputStream out, boolean poll ) * @param in a {@link java.io.InputStream} object * @param out a {@link java.io.OutputStream} object */ - public RawStreamPumper( InputStream in, OutputStream out ) - { + public RawStreamPumper(InputStream in, OutputStream out) { this.in = in; this.out = out; this.poll = false; @@ -69,8 +64,7 @@ public RawStreamPumper( InputStream in, OutputStream out ) /** *

Setter for the field done.

*/ - public void setDone() - { + public void setDone() { done = true; } @@ -79,9 +73,7 @@ public void setDone() * * @throws java.io.IOException if any. */ - public void closeInput() - throws IOException - { + public void closeInput() throws IOException { in.close(); } @@ -90,64 +82,42 @@ public void closeInput() * * @throws java.io.IOException if any. */ - public void closeOutput() - throws IOException - { + public void closeOutput() throws IOException { out.close(); } @Override - public void run() - { - try - { - if ( poll ) - { - while ( !done ) - { - if ( in.available() > 0 ) - { - int i = in.read( buffer ); - if ( i != -1 ) - { - out.write( buffer, 0, i ); + public void run() { + try { + if (poll) { + while (!done) { + if (in.available() > 0) { + int i = in.read(buffer); + if (i != -1) { + out.write(buffer, 0, i); out.flush(); - } - else - { + } else { done = true; } - } - else - { - Thread.sleep( 1 ); + } else { + Thread.sleep(1); } } - } - else - { - int i = in.read( buffer ); - while ( i != -1 && !done ) - { - if ( i != -1 ) - { - out.write( buffer, 0, i ); + } else { + int i = in.read(buffer); + while (i != -1 && !done) { + if (i != -1) { + out.write(buffer, 0, i); out.flush(); - } - else - { + } else { done = true; } - i = in.read( buffer ); + i = in.read(buffer); } } - } - catch ( Throwable e ) - { + } catch (Throwable e) { // Caught everything - } - finally - { + } finally { done = true; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeConsumer.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeConsumer.java index c30d588ac..b6f29b7ef 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeConsumer.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeConsumer.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.PrintStream; @@ -28,9 +27,7 @@ * * @author Brett Porter */ -public class TeeConsumer - implements StreamConsumer -{ +public class TeeConsumer implements StreamConsumer { private final PrintStream stream; /** @@ -38,7 +35,7 @@ public class TeeConsumer */ private final StringBuffer content = new StringBuffer(); - private static final String LS = System.getProperty( "line.separator" ); + private static final String LS = System.getProperty("line.separator"); private final String indent; @@ -47,9 +44,8 @@ public class TeeConsumer * * @param stream a {@link java.io.PrintStream} object */ - public TeeConsumer( PrintStream stream ) - { - this( stream, " " ); + public TeeConsumer(PrintStream stream) { + this(stream, " "); } /** @@ -58,19 +54,17 @@ public TeeConsumer( PrintStream stream ) * @param stream a {@link java.io.PrintStream} object * @param indent a {@link java.lang.String} object */ - public TeeConsumer( PrintStream stream, String indent ) - { + public TeeConsumer(PrintStream stream, String indent) { this.stream = stream; this.indent = indent; } @Override - public void consumeLine( String line ) - { - stream.println( indent + line ); + public void consumeLine(String line) { + stream.println(indent + line); - content.append( line ); - content.append( LS ); + content.append(line); + content.append(LS); } /** @@ -78,14 +72,12 @@ public void consumeLine( String line ) * * @return a {@link java.lang.String} object */ - public String getContent() - { + public String getContent() { return content.toString(); } @Override - public String toString() - { + public String toString() { return getContent(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java index 363e76ad7..f5737a5fd 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/exec/TeeOutputStream.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; @@ -27,10 +26,8 @@ /** *

TeeOutputStream class.

*/ -public class TeeOutputStream - extends FilterOutputStream -{ - private final ByteArrayOutputStream bout = new ByteArrayOutputStream( 1024 * 8 ); +public class TeeOutputStream extends FilterOutputStream { + private final ByteArrayOutputStream bout = new ByteArrayOutputStream(1024 * 8); private final byte[] indent; private int last = '\n'; @@ -39,9 +36,8 @@ public class TeeOutputStream * * @param out a {@link java.io.OutputStream} object */ - public TeeOutputStream( OutputStream out ) - { - this( out, " " ); + public TeeOutputStream(OutputStream out) { + this(out, " "); } /** @@ -50,50 +46,41 @@ public TeeOutputStream( OutputStream out ) * @param out a {@link java.io.OutputStream} object * @param i a {@link java.lang.String} object */ - public TeeOutputStream( OutputStream out, String i ) - { - super( out ); + public TeeOutputStream(OutputStream out, String i) { + super(out); indent = i.getBytes(); } @Override - public void write( byte[] b, int off, int len ) - throws IOException - { - for ( int x = 0; x < len; x++ ) - { + public void write(byte[] b, int off, int len) throws IOException { + for (int x = 0; x < len; x++) { int c = b[off + x]; - if ( last == '\n' || ( last == '\r' && c != '\n' ) ) - { - out.write( b, off, x ); - bout.write( b, off, x ); - out.write( indent ); + if (last == '\n' || (last == '\r' && c != '\n')) { + out.write(b, off, x); + bout.write(b, off, x); + out.write(indent); off += x; len -= x; x = 0; } last = c; } - out.write( b, off, len ); - bout.write( b, off, len ); + out.write(b, off, len); + bout.write(b, off, len); } @Override - public void write( int b ) - throws IOException - { - if ( last == '\n' || ( last == '\r' && b != '\n' ) ) - { - out.write( indent ); + public void write(int b) throws IOException { + if (last == '\n' || (last == '\r' && b != '\n')) { + out.write(indent); } - out.write( b ); - bout.write( b ); + out.write(b); + bout.write(b); last = b; } @Override - public String toString() - { + public String toString() { return bout.toString(); } @@ -102,9 +89,7 @@ public String toString() * * @return a {@link java.lang.String} object */ - public String getContent() - { + public String getContent() { return bout.toString(); } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhase.java index c0fe0d181..ab5cc566f 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.io.File; @@ -29,9 +28,7 @@ * * @author Edwin Punzalan */ -public abstract class AbstractBackupPomsPhase - extends AbstractReleasePhase -{ +public abstract class AbstractBackupPomsPhase extends AbstractReleasePhase { protected static final String BACKUP_SUFFIX = ".releaseBackup"; /** @@ -40,16 +37,12 @@ public abstract class AbstractBackupPomsPhase * @param project a {@link org.apache.maven.project.MavenProject} object * @return a {@link java.io.File} object */ - protected File getPomBackup( MavenProject project ) - { - File pomFile = ReleaseUtil.getStandardPom( project ); + protected File getPomBackup(MavenProject project) { + File pomFile = ReleaseUtil.getStandardPom(project); - if ( pomFile != null ) - { - return new File( pomFile.getAbsolutePath() + BACKUP_SUFFIX ); - } - else - { + if (pomFile != null) { + return new File(pomFile.getAbsolutePath() + BACKUP_SUFFIX); + } else { return null; } } @@ -59,12 +52,10 @@ protected File getPomBackup( MavenProject project ) * * @param project a {@link org.apache.maven.project.MavenProject} object */ - protected void deletePomBackup( MavenProject project ) - { - File pomBackup = getPomBackup( project ); + protected void deletePomBackup(MavenProject project) { + File pomBackup = getPomBackup(project); - if ( pomBackup != null && pomBackup.exists() ) - { + if (pomBackup != null && pomBackup.exists()) { pomBackup.delete(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java index 37c5e4c6c..fed385048 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractCheckPomPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.util.List; @@ -41,9 +40,7 @@ * * @author Brett Porter */ -public abstract class AbstractCheckPomPhase - extends AbstractReleasePhase -{ +public abstract class AbstractCheckPomPhase extends AbstractReleasePhase { private final ScmRepositoryConfigurator scmRepositoryConfigurator; @@ -57,74 +54,64 @@ public abstract class AbstractCheckPomPhase */ private final boolean snapshotsRequired; - public AbstractCheckPomPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, boolean scmRequired, - boolean snapshotsRequired ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); + public AbstractCheckPomPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, boolean scmRequired, boolean snapshotsRequired) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); this.scmRequired = scmRequired; this.snapshotsRequired = snapshotsRequired; } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); // Currently, we don't deal with multiple SCM locations in a multiproject - if ( scmRequired ) - { - if ( StringUtils.isEmpty( releaseDescriptor.getScmSourceUrl() ) ) - { + if (scmRequired) { + if (StringUtils.isEmpty(releaseDescriptor.getScmSourceUrl())) { throw new ReleaseFailureException( - "Missing required setting: scm connection or developerConnection must be specified." ); + "Missing required setting: scm connection or developerConnection must be specified."); } - try - { - scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { + try { + scmRepositoryConfigurator.getConfiguredRepository(releaseDescriptor, releaseEnvironment.getSettings()); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { throw new ReleaseFailureException( - "The provider given in the SCM URL could not be found: " + e.getMessage() ); + "The provider given in the SCM URL could not be found: " + e.getMessage()); } } boolean containsSnapshotProjects = false; - for ( MavenProject project : reactorProjects ) - { - if ( ArtifactUtils.isSnapshot( project.getVersion() ) ) - { + for (MavenProject project : reactorProjects) { + if (ArtifactUtils.isSnapshot(project.getVersion())) { containsSnapshotProjects = true; break; } } - if ( snapshotsRequired && !containsSnapshotProjects && !releaseDescriptor.isBranchCreation() ) - { - throw new ReleaseFailureException( "You don't have a SNAPSHOT project in the reactor projects list." ); + if (snapshotsRequired && !containsSnapshotProjects && !releaseDescriptor.isBranchCreation()) { + throw new ReleaseFailureException("You don't have a SNAPSHOT project in the reactor projects list."); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { // It makes no modifications, so simulate is the same as execute - return execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + return execute(releaseDescriptor, releaseEnvironment, reactorProjects); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractInputVariablesPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractInputVariablesPhase.java index 7a00671c7..c97728501 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractInputVariablesPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractInputVariablesPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.util.Arrays; import java.util.List; @@ -59,9 +58,7 @@ * * @author Brett Porter */ -public abstract class AbstractInputVariablesPhase - extends AbstractReleasePhase -{ +public abstract class AbstractInputVariablesPhase extends AbstractReleasePhase { /** * Component used to prompt for input. */ @@ -87,13 +84,15 @@ public abstract class AbstractInputVariablesPhase */ private final String defaultNamingPolicy; - protected AbstractInputVariablesPhase( Prompter prompter, ScmRepositoryConfigurator scmRepositoryConfigurator, - Map namingPolicies, boolean branchOperation, - String defaultNamingPolicy ) - { - this.prompter = new AtomicReference<>( requireNonNull( prompter ) ); - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); - this.namingPolicies = requireNonNull( namingPolicies ); + protected AbstractInputVariablesPhase( + Prompter prompter, + ScmRepositoryConfigurator scmRepositoryConfigurator, + Map namingPolicies, + boolean branchOperation, + String defaultNamingPolicy) { + this.prompter = new AtomicReference<>(requireNonNull(prompter)); + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); + this.namingPolicies = requireNonNull(namingPolicies); this.branchOperation = branchOperation; this.defaultNamingPolicy = defaultNamingPolicy; } @@ -101,13 +100,11 @@ protected AbstractInputVariablesPhase( Prompter prompter, ScmRepositoryConfigura /** * For easier testing only! */ - public void setPrompter( Prompter prompter ) - { - this.prompter.set( prompter ); + public void setPrompter(Prompter prompter) { + this.prompter.set(prompter); } - boolean isBranchOperation() - { + boolean isBranchOperation() { return branchOperation; } @@ -120,194 +117,151 @@ boolean isBranchOperation() * @throws ReleaseScmRepositoryException if any. * @throws ReleaseExecutionException if any. */ - protected ScmProvider getScmProvider( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment ) - throws ReleaseScmRepositoryException, ReleaseExecutionException - { - try - { - ScmRepository repository = - scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); + protected ScmProvider getScmProvider(ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment) + throws ReleaseScmRepositoryException, ReleaseExecutionException { + try { + ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); - return scmRepositoryConfigurator.getRepositoryProvider( repository ); - } - catch ( ScmRepositoryException e ) - { + return scmRepositoryConfigurator.getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { throw new ReleaseScmRepositoryException( - e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); // get the root project - MavenProject project = ReleaseUtil.getRootProject( reactorProjects ); + MavenProject project = ReleaseUtil.getRootProject(reactorProjects); String tag = releaseDescriptor.getScmReleaseLabel(); - if ( tag == null ) - { + if (tag == null) { // Must get default version from mapped versions, as the project will be the incorrect snapshot - String key = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); - String releaseVersion = releaseDescriptor.getProjectReleaseVersion( key ); - if ( releaseVersion == null ) - { - throw new ReleaseExecutionException( "Project tag cannot be selected if version is not yet mapped" ); + String key = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); + String releaseVersion = releaseDescriptor.getProjectReleaseVersion(key); + if (releaseVersion == null) { + throw new ReleaseExecutionException("Project tag cannot be selected if version is not yet mapped"); } String suggestedName; String scmTagNameFormat = releaseDescriptor.getScmTagNameFormat(); - if ( releaseDescriptor.getProjectNamingPolicyId() != null ) - { - try - { + if (releaseDescriptor.getProjectNamingPolicyId() != null) { + try { suggestedName = - resolveSuggestedName( releaseDescriptor.getProjectNamingPolicyId(), releaseVersion, - project ); + resolveSuggestedName(releaseDescriptor.getProjectNamingPolicyId(), releaseVersion, project); + } catch (PolicyException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } - catch ( PolicyException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); - } - } - else if ( scmTagNameFormat != null ) - { - Interpolator interpolator = new StringSearchInterpolator( "@{", "}" ); - List possiblePrefixes = Arrays.asList( "project", "pom" ); + } else if (scmTagNameFormat != null) { + Interpolator interpolator = new StringSearchInterpolator("@{", "}"); + List possiblePrefixes = Arrays.asList("project", "pom"); Properties values = new Properties(); - values.setProperty( "artifactId", project.getArtifactId() ); - values.setProperty( "groupId", project.getGroupId() ); - values.setProperty( "version", releaseVersion ); - interpolator.addValueSource( new PrefixedPropertiesValueSource( possiblePrefixes, values, true ) ); - RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( possiblePrefixes ); - try - { - suggestedName = interpolator.interpolate( scmTagNameFormat, recursionInterceptor ); - } - catch ( InterpolationException e ) - { + values.setProperty("artifactId", project.getArtifactId()); + values.setProperty("groupId", project.getGroupId()); + values.setProperty("version", releaseVersion); + interpolator.addValueSource(new PrefixedPropertiesValueSource(possiblePrefixes, values, true)); + RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor(possiblePrefixes); + try { + suggestedName = interpolator.interpolate(scmTagNameFormat, recursionInterceptor); + } catch (InterpolationException e) { throw new ReleaseExecutionException( - "Could not interpolate specified tag name format: " + scmTagNameFormat, e ); + "Could not interpolate specified tag name format: " + scmTagNameFormat, e); } - } - else - { - try - { - suggestedName = resolveSuggestedName( defaultNamingPolicy, releaseVersion, project ); - } - catch ( PolicyException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } else { + try { + suggestedName = resolveSuggestedName(defaultNamingPolicy, releaseVersion, project); + } catch (PolicyException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } } ScmProvider provider; - try - { - provider = getScmProvider( releaseDescriptor, releaseEnvironment ); - } - catch ( ReleaseScmRepositoryException e ) - { + try { + provider = getScmProvider(releaseDescriptor, releaseEnvironment); + } catch (ReleaseScmRepositoryException e) { throw new ReleaseExecutionException( - "No scm provider can be found for url: " + releaseDescriptor.getScmSourceUrl(), e ); + "No scm provider can be found for url: " + releaseDescriptor.getScmSourceUrl(), e); } - suggestedName = provider.sanitizeTagName( suggestedName ); + suggestedName = provider.sanitizeTagName(suggestedName); - if ( releaseDescriptor.isInteractive() ) - { - try - { - if ( branchOperation ) - { - tag = prompter.get().prompt( "What is the branch name for \"" + project.getName() + "\"? (" - + buffer().project( project.getArtifactId() ) + ")" ); - if ( StringUtils.isEmpty( tag ) ) - { - throw new ReleaseExecutionException( "No branch name was given." ); + if (releaseDescriptor.isInteractive()) { + try { + if (branchOperation) { + tag = prompter.get() + .prompt("What is the branch name for \"" + project.getName() + "\"? (" + + 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() + "\"? (" + + buffer().project(project.getArtifactId()) + ")", + suggestedName); } - else - { - tag = prompter.get().prompt( - "What is the SCM release tag or label for \"" + project.getName() - + "\"? (" + buffer().project( project.getArtifactId() ) + ")", - suggestedName ); - } - } - catch ( PrompterException e ) - { - throw new ReleaseExecutionException( "Error reading version from input handler: " + e.getMessage(), - e ); - } - } - else if ( suggestedName == null ) - { - if ( isBranchOperation() ) - { - throw new ReleaseExecutionException( "No branch name was given." ); + } catch (PrompterException e) { + throw new ReleaseExecutionException( + "Error reading version from input handler: " + e.getMessage(), e); } - else - { - throw new ReleaseExecutionException( "No tag name was given." ); + } else if (suggestedName == null) { + if (isBranchOperation()) { + throw new ReleaseExecutionException("No branch name was given."); + } else { + throw new ReleaseExecutionException("No tag name was given."); } - } - else - { + } else { tag = suggestedName; } - releaseDescriptor.setScmReleaseLabel( tag ); + releaseDescriptor.setScmReleaseLabel(tag); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); // It makes no modifications, so simulate is the same as execute - execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + execute(releaseDescriptor, releaseEnvironment, reactorProjects); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private String resolveSuggestedName( String policyId, String version, MavenProject project ) - throws PolicyException - { - if ( policyId == null ) - { + private String resolveSuggestedName(String policyId, String version, MavenProject project) throws PolicyException { + if (policyId == null) { return null; } - NamingPolicy policy = namingPolicies.get( policyId ); - if ( policy == null ) - { - throw new PolicyException( "Policy '" + policyId + "' is unknown, available: " - + namingPolicies.keySet() ); + NamingPolicy policy = namingPolicies.get(policyId); + if (policy == null) { + throw new PolicyException("Policy '" + policyId + "' is unknown, available: " + namingPolicies.keySet()); } NamingPolicyRequest request = new NamingPolicyRequest() - .setGroupId( project.getGroupId() ) - .setArtifactId( project.getArtifactId() ) - .setVersion( version ); - return policy.getName( request ).getName(); + .setGroupId(project.getGroupId()) + .setArtifactId(project.getArtifactId()) + .setVersion(version); + return policy.getName(request).getName(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java index 53e20efab..c2b0a6fef 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractMapVersionsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.util.List; import java.util.Map; @@ -73,9 +72,7 @@ * @author Brett Porter * @author Robert Scholte */ -public abstract class AbstractMapVersionsPhase - extends AbstractReleasePhase -{ +public abstract class AbstractMapVersionsPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ @@ -101,348 +98,263 @@ public abstract class AbstractMapVersionsPhase */ private final boolean convertToBranch; - public AbstractMapVersionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Prompter prompter, Map versionPolicies, - boolean convertToSnapshot, boolean convertToBranch ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); - this.prompter = requireNonNull( prompter ); - this.versionPolicies = requireNonNull( versionPolicies ); + public AbstractMapVersionsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, + Prompter prompter, + Map versionPolicies, + boolean convertToSnapshot, + boolean convertToBranch) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); + this.prompter = requireNonNull(prompter); + this.versionPolicies = requireNonNull(versionPolicies); this.convertToSnapshot = convertToSnapshot; this.convertToBranch = convertToBranch; - } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); - if ( releaseDescriptor.isAutoVersionSubmodules() && ArtifactUtils.isSnapshot( rootProject.getVersion() ) ) - { + if (releaseDescriptor.isAutoVersionSubmodules() && ArtifactUtils.isSnapshot(rootProject.getVersion())) { // get the root project MavenProject project = rootProject; - String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); + String projectId = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); - String nextVersion = resolveNextVersion( project, projectId, releaseDescriptor, releaseEnvironment ); + String nextVersion = resolveNextVersion(project, projectId, releaseDescriptor, releaseEnvironment); - if ( !convertToSnapshot ) - { - releaseDescriptor.addReleaseVersion( projectId, nextVersion ); - } - else if ( releaseDescriptor.isBranchCreation() && convertToBranch ) - { - releaseDescriptor.addReleaseVersion( projectId, nextVersion ); - } - else - { - releaseDescriptor.addDevelopmentVersion( projectId, nextVersion ); + if (!convertToSnapshot) { + releaseDescriptor.addReleaseVersion(projectId, nextVersion); + } else if (releaseDescriptor.isBranchCreation() && convertToBranch) { + releaseDescriptor.addReleaseVersion(projectId, nextVersion); + } else { + releaseDescriptor.addDevelopmentVersion(projectId, nextVersion); } - for ( MavenProject subProject : reactorProjects ) - { - String subProjectId = - ArtifactUtils.versionlessKey( subProject.getGroupId(), subProject.getArtifactId() ); + for (MavenProject subProject : reactorProjects) { + String subProjectId = ArtifactUtils.versionlessKey(subProject.getGroupId(), subProject.getArtifactId()); - if ( convertToSnapshot ) - { - String subProjectNextVersion = releaseDescriptor.getProjectDevelopmentVersion( subProjectId ); + if (convertToSnapshot) { + String subProjectNextVersion = releaseDescriptor.getProjectDevelopmentVersion(subProjectId); String v; - if ( subProjectNextVersion != null ) - { + if (subProjectNextVersion != null) { v = subProjectNextVersion; - } - else if ( ArtifactUtils.isSnapshot( subProject.getVersion() ) ) - { + } else if (ArtifactUtils.isSnapshot(subProject.getVersion())) { v = nextVersion; - } - else - { + } else { v = subProject.getVersion(); } - if ( releaseDescriptor.isBranchCreation() && convertToBranch ) - { - releaseDescriptor.addReleaseVersion( subProjectId, v ); - } - else - { - releaseDescriptor.addDevelopmentVersion( subProjectId, v ); - } - } - else - { - String subProjectNextVersion = releaseDescriptor.getProjectReleaseVersion( subProjectId ); - if ( subProjectNextVersion != null ) - { - releaseDescriptor.addReleaseVersion( subProjectId, subProjectNextVersion ); + if (releaseDescriptor.isBranchCreation() && convertToBranch) { + releaseDescriptor.addReleaseVersion(subProjectId, v); + } else { + releaseDescriptor.addDevelopmentVersion(subProjectId, v); } - else - { - releaseDescriptor.addReleaseVersion( subProjectId, nextVersion ); + } else { + String subProjectNextVersion = releaseDescriptor.getProjectReleaseVersion(subProjectId); + if (subProjectNextVersion != null) { + releaseDescriptor.addReleaseVersion(subProjectId, subProjectNextVersion); + } else { + releaseDescriptor.addReleaseVersion(subProjectId, nextVersion); } } } - } - else - { - for ( MavenProject project : reactorProjects ) - { - String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); - - String nextVersion = resolveNextVersion( project, projectId, releaseDescriptor, releaseEnvironment ); - - if ( !convertToSnapshot ) - { - releaseDescriptor.addReleaseVersion( projectId, nextVersion ); - } - else if ( releaseDescriptor.isBranchCreation() && convertToBranch ) - { - releaseDescriptor.addReleaseVersion( projectId, nextVersion ); - } - else - { - releaseDescriptor.addDevelopmentVersion( projectId, nextVersion ); + } else { + for (MavenProject project : reactorProjects) { + String projectId = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); + + String nextVersion = resolveNextVersion(project, projectId, releaseDescriptor, releaseEnvironment); + + if (!convertToSnapshot) { + releaseDescriptor.addReleaseVersion(projectId, nextVersion); + } else if (releaseDescriptor.isBranchCreation() && convertToBranch) { + releaseDescriptor.addReleaseVersion(projectId, nextVersion); + } else { + releaseDescriptor.addDevelopmentVersion(projectId, nextVersion); } } } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private String resolveNextVersion( MavenProject project, - String projectId, - ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment ) - throws ReleaseExecutionException - { + private String resolveNextVersion( + MavenProject project, + String projectId, + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment) + throws ReleaseExecutionException { String defaultVersion; - if ( convertToBranch ) - { + if (convertToBranch) { // no branch modification - if ( !( releaseDescriptor.isUpdateBranchVersions() - && ( ArtifactUtils.isSnapshot( project.getVersion() ) - || releaseDescriptor.isUpdateVersionsToSnapshot() ) ) ) - { + if (!(releaseDescriptor.isUpdateBranchVersions() + && (ArtifactUtils.isSnapshot(project.getVersion()) + || releaseDescriptor.isUpdateVersionsToSnapshot()))) { return project.getVersion(); } - defaultVersion = getReleaseVersion( projectId, releaseDescriptor ); - } - else if ( !convertToSnapshot ) // map-release-version - { - defaultVersion = getReleaseVersion( projectId, releaseDescriptor ); - } - else if ( releaseDescriptor.isBranchCreation() ) + defaultVersion = getReleaseVersion(projectId, releaseDescriptor); + } else if (!convertToSnapshot) // map-release-version { + defaultVersion = getReleaseVersion(projectId, releaseDescriptor); + } else if (releaseDescriptor.isBranchCreation()) { // no working copy modification - if ( !( ArtifactUtils.isSnapshot( project.getVersion() ) - && releaseDescriptor.isUpdateWorkingCopyVersions() ) ) - { + if (!(ArtifactUtils.isSnapshot(project.getVersion()) && releaseDescriptor.isUpdateWorkingCopyVersions())) { return project.getVersion(); } - defaultVersion = getDevelopmentVersion( projectId, releaseDescriptor ); - } - else - { + defaultVersion = getDevelopmentVersion(projectId, releaseDescriptor); + } else { // no working copy modification - if ( !( releaseDescriptor.isUpdateWorkingCopyVersions() ) ) - { + if (!(releaseDescriptor.isUpdateWorkingCopyVersions())) { return project.getVersion(); } - defaultVersion = getDevelopmentVersion( projectId, releaseDescriptor ); + defaultVersion = getDevelopmentVersion(projectId, releaseDescriptor); } - //@todo validate default version, maybe with DefaultArtifactVersion + // @todo validate default version, maybe with DefaultArtifactVersion String suggestedVersion = null; String nextVersion = defaultVersion; String messageFormat = null; - try - { - while ( nextVersion == null || ArtifactUtils.isSnapshot( nextVersion ) != convertToSnapshot ) - { - if ( suggestedVersion == null ) - { + try { + while (nextVersion == null || ArtifactUtils.isSnapshot(nextVersion) != convertToSnapshot) { + if (suggestedVersion == null) { String baseVersion = null; - if ( convertToSnapshot ) - { - baseVersion = getReleaseVersion( projectId, releaseDescriptor ); + if (convertToSnapshot) { + baseVersion = getReleaseVersion(projectId, releaseDescriptor); } // unspecified and unmapped version, so use project version - if ( baseVersion == null ) - { + if (baseVersion == null) { baseVersion = project.getVersion(); } - try - { - try - { + try { + try { suggestedVersion = - resolveSuggestedVersion( baseVersion, - releaseDescriptor, - releaseEnvironment ); - } - catch ( VersionParseException e ) - { - if ( releaseDescriptor.isInteractive() ) - { + resolveSuggestedVersion(baseVersion, releaseDescriptor, releaseEnvironment); + } catch (VersionParseException e) { + if (releaseDescriptor.isInteractive()) { suggestedVersion = - resolveSuggestedVersion( "1.0", releaseDescriptor, releaseEnvironment ); - } - else - { - throw new ReleaseExecutionException( "Error parsing version, cannot determine next " - + "version: " + e.getMessage(), e ); + resolveSuggestedVersion("1.0", releaseDescriptor, releaseEnvironment); + } else { + throw new ReleaseExecutionException( + "Error parsing version, cannot determine next " + "version: " + e.getMessage(), + e); } } - } - catch ( PolicyException | VersionParseException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } catch (PolicyException | VersionParseException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } } - if ( releaseDescriptor.isInteractive() ) - { - if ( messageFormat == null ) - { - messageFormat = "What is the " + getContextString( releaseDescriptor ) - + " version for \"%s\"? (" + buffer().project( "%s" ) + ")"; + if (releaseDescriptor.isInteractive()) { + if (messageFormat == null) { + messageFormat = "What is the " + getContextString(releaseDescriptor) + " version for \"%s\"? (" + + buffer().project("%s") + ")"; } - String message = String.format( messageFormat, project.getName(), project.getArtifactId() ); - nextVersion = prompter.prompt( message, suggestedVersion ); + String message = String.format(messageFormat, project.getName(), project.getArtifactId()); + nextVersion = prompter.prompt(message, suggestedVersion); - //@todo validate next version, maybe with DefaultArtifactVersion - } - else if ( defaultVersion == null ) - { + // @todo validate next version, maybe with DefaultArtifactVersion + } else if (defaultVersion == null) { nextVersion = suggestedVersion; - } - else if ( convertToSnapshot ) - { - throw new ReleaseExecutionException( defaultVersion + " is invalid, expected a snapshot" ); - } - else - { - throw new ReleaseExecutionException( defaultVersion + " is invalid, expected a non-snapshot" ); + } else if (convertToSnapshot) { + throw new ReleaseExecutionException(defaultVersion + " is invalid, expected a snapshot"); + } else { + throw new ReleaseExecutionException(defaultVersion + " is invalid, expected a non-snapshot"); } } - } - catch ( PrompterException e ) - { - throw new ReleaseExecutionException( "Error reading version from input handler: " + e.getMessage(), e ); + } catch (PrompterException e) { + throw new ReleaseExecutionException("Error reading version from input handler: " + e.getMessage(), e); } return nextVersion; } - private String getContextString( ReleaseDescriptor releaseDescriptor ) - { - if ( convertToBranch ) - { + private String getContextString(ReleaseDescriptor releaseDescriptor) { + if (convertToBranch) { return "branch"; } - if ( !convertToSnapshot ) - { + if (!convertToSnapshot) { return "release"; } - if ( releaseDescriptor.isBranchCreation() ) - { + if (releaseDescriptor.isBranchCreation()) { return "new working copy"; } return "new development"; } - private String resolveSuggestedVersion( String baseVersion, - ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment ) - throws PolicyException, VersionParseException - { + private String resolveSuggestedVersion( + String baseVersion, ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment) + throws PolicyException, VersionParseException { String policyId = releaseDescriptor.getProjectVersionPolicyId(); - VersionPolicy policy = versionPolicies.get( policyId ); - if ( policy == null ) - { - throw new PolicyException( "Policy '" + policyId + "' is unknown, available: " + versionPolicies.keySet() ); + VersionPolicy policy = versionPolicies.get(policyId); + if (policy == null) { + throw new PolicyException("Policy '" + policyId + "' is unknown, available: " + versionPolicies.keySet()); } - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( baseVersion ); + VersionPolicyRequest request = new VersionPolicyRequest().setVersion(baseVersion); - if ( releaseDescriptor.getProjectVersionPolicyConfig() != null ) - { - request.setConfig( releaseDescriptor.getProjectVersionPolicyConfig().toString() ); + if (releaseDescriptor.getProjectVersionPolicyConfig() != null) { + request.setConfig(releaseDescriptor.getProjectVersionPolicyConfig().toString()); } - request.setWorkingDirectory( releaseDescriptor.getWorkingDirectory() ); + request.setWorkingDirectory(releaseDescriptor.getWorkingDirectory()); - if ( scmRepositoryConfigurator != null && releaseDescriptor.getScmSourceUrl() != null ) - { - try - { - ScmRepository repository = scmRepositoryConfigurator - .getConfiguredRepository( releaseDescriptor, releaseEnvironment.getSettings() ); + if (scmRepositoryConfigurator != null && releaseDescriptor.getScmSourceUrl() != null) { + try { + ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); - ScmProvider provider = scmRepositoryConfigurator - .getRepositoryProvider( repository ); + ScmProvider provider = scmRepositoryConfigurator.getRepositoryProvider(repository); - request.setScmRepository( repository ); - request.setScmProvider( provider ); - } - catch ( ScmRepositoryException | NoSuchScmProviderException e ) - { + request.setScmRepository(repository); + request.setScmProvider(provider); + } catch (ScmRepositoryException | NoSuchScmProviderException e) { Logger logger = getLogger(); - if ( logger.isWarnEnabled() ) - { - logger.warn( "Next Version will NOT be based on the version control: {}", e.getMessage() ); - } - else - { - if ( logger.isDebugEnabled() ) - { - logger.warn( "Next Version will NOT be based on the version control", e ); + if (logger.isWarnEnabled()) { + logger.warn("Next Version will NOT be based on the version control: {}", e.getMessage()); + } else { + if (logger.isDebugEnabled()) { + logger.warn("Next Version will NOT be based on the version control", e); } } } } - return convertToSnapshot ? policy.getDevelopmentVersion( request ).getVersion() - : policy.getReleaseVersion( request ).getVersion(); + return convertToSnapshot + ? policy.getDevelopmentVersion(request).getVersion() + : policy.getReleaseVersion(request).getVersion(); } - private String getDevelopmentVersion( String projectId, ReleaseDescriptor releaseDescriptor ) - { - String projectVersion = releaseDescriptor.getProjectDevelopmentVersion( projectId ); + private String getDevelopmentVersion(String projectId, ReleaseDescriptor releaseDescriptor) { + String projectVersion = releaseDescriptor.getProjectDevelopmentVersion(projectId); - if ( StringUtils.isEmpty( projectVersion ) ) - { + if (StringUtils.isEmpty(projectVersion)) { projectVersion = releaseDescriptor.getDefaultDevelopmentVersion(); } - if ( StringUtils.isEmpty( projectVersion ) ) - { + if (StringUtils.isEmpty(projectVersion)) { return null; } return projectVersion; } - private String getReleaseVersion( String projectId, ReleaseDescriptor releaseDescriptor ) - { - String projectVersion = releaseDescriptor.getProjectReleaseVersion( projectId ); + private String getReleaseVersion(String projectId, ReleaseDescriptor releaseDescriptor) { + String projectVersion = releaseDescriptor.getProjectReleaseVersion(projectId); - if ( StringUtils.isEmpty( projectVersion ) ) - { + if (StringUtils.isEmpty(projectVersion)) { projectVersion = releaseDescriptor.getDefaultReleaseVersion(); } - if ( StringUtils.isEmpty( projectVersion ) ) - { + if (StringUtils.isEmpty(projectVersion)) { return null; } @@ -450,16 +362,17 @@ private String getReleaseVersion( String projectId, ReleaseDescriptor releaseDes } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); // It makes no modifications, so simulate is the same as execute - execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + execute(releaseDescriptor, releaseEnvironment, reactorProjects); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePomsPhase.java index 5794501b3..3199d8408 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractReleasePomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.scm.manager.NoSuchScmProviderException; import org.apache.maven.scm.provider.ScmProvider; @@ -35,49 +34,35 @@ * * @author Mark Hobson */ -public abstract class AbstractReleasePomsPhase extends AbstractReleasePhase -{ +public abstract class AbstractReleasePomsPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ private final ScmRepositoryConfigurator scmRepositoryConfigurator; - protected AbstractReleasePomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { + protected AbstractReleasePomsPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { this.scmRepositoryConfigurator = scmRepositoryConfigurator; } - protected ScmRepository getScmRepository( ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment ) - throws ReleaseFailureException, ReleaseExecutionException - { - try - { - return scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); - } - catch ( ScmRepositoryException exception ) - { - throw new ReleaseScmRepositoryException( exception.getMessage(), exception.getValidationMessages() ); - } - catch ( NoSuchScmProviderException exception ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + exception.getMessage(), - exception ); + protected ScmRepository getScmRepository(ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment) + throws ReleaseFailureException, ReleaseExecutionException { + try { + return scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); + } catch (ScmRepositoryException exception) { + throw new ReleaseScmRepositoryException(exception.getMessage(), exception.getValidationMessages()); + } catch (NoSuchScmProviderException exception) { + throw new ReleaseExecutionException( + "Unable to configure SCM repository: " + exception.getMessage(), exception); } } - protected ScmProvider getScmProvider( ScmRepository scmRepository ) - throws ReleaseExecutionException - { - try - { - return scmRepositoryConfigurator.getRepositoryProvider( scmRepository ); - } - catch ( NoSuchScmProviderException exception ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + exception.getMessage(), - exception ); + protected ScmProvider getScmProvider(ScmRepository scmRepository) throws ReleaseExecutionException { + try { + return scmRepositoryConfigurator.getRepositoryProvider(scmRepository); + } catch (NoSuchScmProviderException exception) { + throw new ReleaseExecutionException( + "Unable to configure SCM repository: " + exception.getMessage(), exception); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java index 9fc6b0564..17f0c578c 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRewritePomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.io.File; import java.net.URI; @@ -72,9 +71,7 @@ * * @author Brett Porter */ -public abstract class AbstractRewritePomsPhase - extends AbstractReleasePhase implements ResourceGenerator -{ +public abstract class AbstractRewritePomsPhase extends AbstractReleasePhase implements ResourceGenerator { /** * Tool that gets a configured SCM repository from release configuration. */ @@ -94,13 +91,13 @@ public abstract class AbstractRewritePomsPhase private long startTime = -1 * 1000; - protected AbstractRewritePomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Map modelETLFactories, - Map scmTranslators ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); - this.modelETLFactories = requireNonNull( modelETLFactories ); - this.scmTranslators = requireNonNull( scmTranslators ); + protected AbstractRewritePomsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, + Map modelETLFactories, + Map scmTranslators) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); + this.modelETLFactories = requireNonNull(modelETLFactories); + this.scmTranslators = requireNonNull(scmTranslators); } /** @@ -108,8 +105,7 @@ protected AbstractRewritePomsPhase( ScmRepositoryConfigurator scmRepositoryConfi * * @return a {@link java.util.Map} object */ - protected final Map getScmTranslators() - { + protected final Map getScmTranslators() { return scmTranslators; } @@ -118,8 +114,7 @@ protected final Map getScmTranslators() * * @param modelETL a {@link java.lang.String} object */ - public void setModelETL( String modelETL ) - { + public void setModelETL(String modelETL) { this.modelETL = modelETL; } @@ -128,8 +123,7 @@ public void setModelETL( String modelETL ) * * @param startTime a long */ - public void setStartTime( long startTime ) - { + public void setStartTime(long startTime) { this.startTime = startTime; } @@ -141,485 +135,475 @@ public void setStartTime( long startTime ) protected abstract String getPomSuffix(); @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - transform( releaseDescriptor, releaseEnvironment, reactorProjects, false, result ); + transform(releaseDescriptor, releaseEnvironment, reactorProjects, false, result); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - transform( releaseDescriptor, releaseEnvironment, reactorProjects, true, result ); + transform(releaseDescriptor, releaseEnvironment, reactorProjects, true, result); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult clean( List reactorProjects ) - { + public ReleaseResult clean(List reactorProjects) { ReleaseResult result = new ReleaseResult(); - if ( reactorProjects != null ) - { - for ( MavenProject project : reactorProjects ) - { - File pomFile = ReleaseUtil.getStandardPom( project ); + if (reactorProjects != null) { + for (MavenProject project : reactorProjects) { + File pomFile = ReleaseUtil.getStandardPom(project); // MRELEASE-273 : if no pom - if ( pomFile != null ) - { - File file = new File( pomFile.getParentFile(), pomFile.getName() + "." + getPomSuffix() ); - if ( file.exists() ) - { + if (pomFile != null) { + File file = new File(pomFile.getParentFile(), pomFile.getName() + "." + getPomSuffix()); + if (file.exists()) { file.delete(); } } } } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private void transform( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, boolean simulate, ReleaseResult result ) - throws ReleaseExecutionException, ReleaseFailureException - { - result.setStartTime( ( startTime >= 0 ) ? startTime : System.currentTimeMillis() ); + private void transform( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + boolean simulate, + ReleaseResult result) + throws ReleaseExecutionException, ReleaseFailureException { + result.setStartTime((startTime >= 0) ? startTime : System.currentTimeMillis()); - URI root = ReleaseUtil.getRootProject( reactorProjects ).getBasedir().toURI(); + URI root = ReleaseUtil.getRootProject(reactorProjects).getBasedir().toURI(); - for ( MavenProject project : reactorProjects ) - { + for (MavenProject project : reactorProjects) { URI pom = project.getFile().toURI(); - logInfo( result, - "Transforming " + root.relativize( pom ).getPath() + ' ' - + buffer().project( project.getArtifactId() ) + " '" + project.getName() + "'" - + ( simulate ? " with ." + getPomSuffix() + " suffix" : "" ) + "..." ); + logInfo( + result, + "Transforming " + root.relativize(pom).getPath() + ' ' + + buffer().project(project.getArtifactId()) + " '" + project.getName() + "'" + + (simulate ? " with ." + getPomSuffix() + " suffix" : "") + "..."); - transformProject( project, releaseDescriptor, releaseEnvironment, simulate, result ); + transformProject(project, releaseDescriptor, releaseEnvironment, simulate, result); } } - private void transformProject( MavenProject project, ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment, boolean simulate, - ReleaseResult result ) - throws ReleaseExecutionException, ReleaseFailureException - { - File pomFile = ReleaseUtil.getStandardPom( project ); + private void transformProject( + MavenProject project, + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + boolean simulate, + ReleaseResult result) + throws ReleaseExecutionException, ReleaseFailureException { + File pomFile = ReleaseUtil.getStandardPom(project); ModelETLRequest request = new ModelETLRequest(); - request.setProject( project ); - request.setReleaseDescriptor( releaseDescriptor ); + request.setProject(project); + request.setReleaseDescriptor(releaseDescriptor); - ModelETL etl = modelETLFactories.get( modelETL ).newInstance( request ); + ModelETL etl = modelETLFactories.get(modelETL).newInstance(request); - etl.extract( pomFile ); + etl.extract(pomFile); ScmRepository scmRepository = null; ScmProvider provider = null; - if ( isUpdateScm() ) - { - try - { - scmRepository = scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); + if (isUpdateScm()) { + try { + scmRepository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); - provider = scmRepositoryConfigurator.getRepositoryProvider( scmRepository ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + provider = scmRepositoryConfigurator.getRepositoryProvider(scmRepository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } } - transformDocument( project, etl.getModel(), releaseDescriptor, scmRepository, result, - simulate ); + transformDocument(project, etl.getModel(), releaseDescriptor, scmRepository, result, simulate); File outputFile; - if ( simulate ) - { - outputFile = new File( pomFile.getParentFile(), pomFile.getName() + "." + getPomSuffix() ); - } - else - { + if (simulate) { + outputFile = new File(pomFile.getParentFile(), pomFile.getName() + "." + getPomSuffix()); + } else { outputFile = pomFile; - prepareScm( pomFile, releaseDescriptor, scmRepository, provider ); + prepareScm(pomFile, releaseDescriptor, scmRepository, provider); } - etl.load( outputFile ); - + etl.load(outputFile); } - private void transformDocument( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor, - ScmRepository scmRepository, ReleaseResult result, - boolean simulate ) - throws ReleaseExecutionException, ReleaseFailureException - { + private void transformDocument( + MavenProject project, + Model modelTarget, + ReleaseDescriptor releaseDescriptor, + ScmRepository scmRepository, + ReleaseResult result, + boolean simulate) + throws ReleaseExecutionException, ReleaseFailureException { Model model = project.getModel(); Properties properties = modelTarget.getProperties(); - String parentVersion = rewriteParent( project, modelTarget, releaseDescriptor, simulate ); + String parentVersion = rewriteParent(project, modelTarget, releaseDescriptor, simulate); - String projectId = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); + String projectId = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); - rewriteVersion( modelTarget, releaseDescriptor, projectId, project ); + rewriteVersion(modelTarget, releaseDescriptor, projectId, project); Build buildTarget = modelTarget.getBuild(); - if ( buildTarget != null ) - { + if (buildTarget != null) { // profile.build.extensions doesn't exist, so only rewrite project.build.extensions - rewriteArtifactVersions( toMavenCoordinates( buildTarget.getExtensions() ), - model, properties, result, releaseDescriptor, simulate ); - - rewriteArtifactVersions( toMavenCoordinates( buildTarget.getPlugins() ), - model, properties, result, releaseDescriptor, simulate ); - - for ( Plugin plugin : buildTarget.getPlugins() ) - { - rewriteArtifactVersions( toMavenCoordinates( plugin.getDependencies() ), - model, properties, - result, releaseDescriptor, simulate ); + rewriteArtifactVersions( + toMavenCoordinates(buildTarget.getExtensions()), + model, + properties, + result, + releaseDescriptor, + simulate); + + rewriteArtifactVersions( + toMavenCoordinates(buildTarget.getPlugins()), + model, + properties, + result, + releaseDescriptor, + simulate); + + for (Plugin plugin : buildTarget.getPlugins()) { + rewriteArtifactVersions( + toMavenCoordinates(plugin.getDependencies()), + model, + properties, + result, + releaseDescriptor, + simulate); } - if ( buildTarget.getPluginManagement() != null ) - { - rewriteArtifactVersions( toMavenCoordinates( buildTarget.getPluginManagement().getPlugins() ), model, - properties, result, releaseDescriptor, simulate ); - - for ( Plugin plugin : buildTarget.getPluginManagement().getPlugins() ) - { - rewriteArtifactVersions( toMavenCoordinates( plugin.getDependencies() ), model, properties, result, - releaseDescriptor, simulate ); + if (buildTarget.getPluginManagement() != null) { + rewriteArtifactVersions( + toMavenCoordinates(buildTarget.getPluginManagement().getPlugins()), + model, + properties, + result, + releaseDescriptor, + simulate); + + for (Plugin plugin : buildTarget.getPluginManagement().getPlugins()) { + rewriteArtifactVersions( + toMavenCoordinates(plugin.getDependencies()), + model, + properties, + result, + releaseDescriptor, + simulate); } } } - for ( Profile profile : modelTarget.getProfiles() ) - { + for (Profile profile : modelTarget.getProfiles()) { BuildBase profileBuild = profile.getBuild(); - if ( profileBuild != null ) - { - rewriteArtifactVersions( toMavenCoordinates( profileBuild.getPlugins() ), model, properties, result, - releaseDescriptor, simulate ); - - for ( Plugin plugin : profileBuild.getPlugins() ) - { - rewriteArtifactVersions( toMavenCoordinates( plugin.getDependencies() ), model, properties, result, - releaseDescriptor, simulate ); + if (profileBuild != null) { + rewriteArtifactVersions( + toMavenCoordinates(profileBuild.getPlugins()), + model, + properties, + result, + releaseDescriptor, + simulate); + + for (Plugin plugin : profileBuild.getPlugins()) { + rewriteArtifactVersions( + toMavenCoordinates(plugin.getDependencies()), + model, + properties, + result, + releaseDescriptor, + simulate); } - if ( profileBuild.getPluginManagement() != null ) - { - rewriteArtifactVersions( toMavenCoordinates( profileBuild.getPluginManagement().getPlugins() ), - model, properties, result, releaseDescriptor, simulate ); - - for ( Plugin plugin : profileBuild.getPluginManagement().getPlugins() ) - { - rewriteArtifactVersions( toMavenCoordinates( plugin.getDependencies() ), model, properties, - result, releaseDescriptor, simulate ); + if (profileBuild.getPluginManagement() != null) { + rewriteArtifactVersions( + toMavenCoordinates( + profileBuild.getPluginManagement().getPlugins()), + model, + properties, + result, + releaseDescriptor, + simulate); + + for (Plugin plugin : profileBuild.getPluginManagement().getPlugins()) { + rewriteArtifactVersions( + toMavenCoordinates(plugin.getDependencies()), + model, + properties, + result, + releaseDescriptor, + simulate); } } } } List modelBases = new ArrayList<>(); - modelBases.add( modelTarget ); - modelBases.addAll( modelTarget.getProfiles() ); - - for ( ModelBase modelBase : modelBases ) - { - rewriteArtifactVersions( toMavenCoordinates( modelBase.getDependencies() ), model, properties, result, - releaseDescriptor, simulate ); - - if ( modelBase.getDependencyManagement() != null ) - { - rewriteArtifactVersions( toMavenCoordinates( modelBase.getDependencyManagement().getDependencies() ), - model, properties, result, releaseDescriptor, simulate ); + modelBases.add(modelTarget); + modelBases.addAll(modelTarget.getProfiles()); + + for (ModelBase modelBase : modelBases) { + rewriteArtifactVersions( + toMavenCoordinates(modelBase.getDependencies()), + model, + properties, + result, + releaseDescriptor, + simulate); + + if (modelBase.getDependencyManagement() != null) { + rewriteArtifactVersions( + toMavenCoordinates(modelBase.getDependencyManagement().getDependencies()), + model, + properties, + result, + releaseDescriptor, + simulate); } - if ( modelBase.getReporting() != null ) - { - rewriteArtifactVersions( toMavenCoordinates( modelBase.getReporting().getPlugins() ), model, properties, - result, releaseDescriptor, simulate ); + if (modelBase.getReporting() != null) { + rewriteArtifactVersions( + toMavenCoordinates(modelBase.getReporting().getPlugins()), + model, + properties, + result, + releaseDescriptor, + simulate); } } - transformScm( project, modelTarget, releaseDescriptor, projectId, scmRepository, result ); + transformScm(project, modelTarget, releaseDescriptor, projectId, scmRepository, result); - if ( properties != null ) - { - rewriteBuildOutputTimestampProperty( properties, result ); + if (properties != null) { + rewriteBuildOutputTimestampProperty(properties, result); } } - private void rewriteBuildOutputTimestampProperty( Properties properties, ReleaseResult result ) - { - String buildOutputTimestamp = properties.getProperty( "project.build.outputTimestamp" ); - if ( buildOutputTimestamp == null || StringUtils.isEmpty( buildOutputTimestamp ) ) - { + private void rewriteBuildOutputTimestampProperty(Properties properties, ReleaseResult result) { + String buildOutputTimestamp = properties.getProperty("project.build.outputTimestamp"); + if (buildOutputTimestamp == null || StringUtils.isEmpty(buildOutputTimestamp)) { // no Reproducible Builds output timestamp defined return; } - if ( StringUtils.isNumeric( buildOutputTimestamp ) ) - { + if (StringUtils.isNumeric(buildOutputTimestamp)) { // int representing seconds since the epoch, like SOURCE_DATE_EPOCH - buildOutputTimestamp = String.valueOf( result.getStartTime() / 1000 ); - } - else if ( buildOutputTimestamp.length() <= 1 ) - { + buildOutputTimestamp = String.valueOf(result.getStartTime() / 1000); + } else if (buildOutputTimestamp.length() <= 1) { // value length == 1 means disable Reproducible Builds return; - } - else - { + } else { // ISO-8601 - DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'" ); - df.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); - buildOutputTimestamp = df.format( new Date( result.getStartTime() ) ); + DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + df.setTimeZone(TimeZone.getTimeZone("UTC")); + buildOutputTimestamp = df.format(new Date(result.getStartTime())); } - properties.setProperty( "project.build.outputTimestamp", buildOutputTimestamp ); + properties.setProperty("project.build.outputTimestamp", buildOutputTimestamp); } - private void rewriteVersion( Model modelTarget, ReleaseDescriptor releaseDescriptor, String projectId, - MavenProject project ) - throws ReleaseFailureException - { - String version = getNextVersion( releaseDescriptor, projectId ); - if ( version == null ) - { - throw new ReleaseFailureException( "Version for '" + project.getName() + "' was not mapped" ); + private void rewriteVersion( + Model modelTarget, ReleaseDescriptor releaseDescriptor, String projectId, MavenProject project) + throws ReleaseFailureException { + String version = getNextVersion(releaseDescriptor, projectId); + if (version == null) { + throw new ReleaseFailureException("Version for '" + project.getName() + "' was not mapped"); } - modelTarget.setVersion( version ); + modelTarget.setVersion(version); } - private String rewriteParent( MavenProject project, Model targetModel, - ReleaseDescriptor releaseDescriptor, boolean simulate ) - throws ReleaseFailureException - { + private String rewriteParent( + MavenProject project, Model targetModel, ReleaseDescriptor releaseDescriptor, boolean simulate) + throws ReleaseFailureException { String parentVersion = null; - if ( project.hasParent() ) - { + if (project.hasParent()) { MavenProject parent = project.getParent(); - String key = ArtifactUtils.versionlessKey( parent.getGroupId(), parent.getArtifactId() ); - parentVersion = getNextVersion( releaseDescriptor, key ); - if ( parentVersion == null ) - { - //MRELEASE-317 - parentVersion = getResolvedSnapshotVersion( key, releaseDescriptor ); + String key = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId()); + parentVersion = getNextVersion(releaseDescriptor, key); + if (parentVersion == null) { + // MRELEASE-317 + parentVersion = getResolvedSnapshotVersion(key, releaseDescriptor); } - if ( parentVersion == null ) - { - String original = getOriginalVersion( releaseDescriptor, key, simulate ); - if ( parent.getVersion().equals( original ) ) - { - throw new ReleaseFailureException( "Version for parent '" + parent.getName() + "' was not mapped" ); + if (parentVersion == null) { + String original = getOriginalVersion(releaseDescriptor, key, simulate); + if (parent.getVersion().equals(original)) { + throw new ReleaseFailureException("Version for parent '" + parent.getName() + "' was not mapped"); } - } - else - { - targetModel.getParent().setVersion( parentVersion ); + } else { + targetModel.getParent().setVersion(parentVersion); } } return parentVersion; } - private void rewriteArtifactVersions( Collection elements, Model projectModel, - Properties properties, ReleaseResult result, - ReleaseDescriptor releaseDescriptor, boolean simulate ) - throws ReleaseExecutionException, ReleaseFailureException - { - if ( elements == null ) - { + private void rewriteArtifactVersions( + Collection elements, + Model projectModel, + Properties properties, + ReleaseResult result, + ReleaseDescriptor releaseDescriptor, + boolean simulate) + throws ReleaseExecutionException, ReleaseFailureException { + if (elements == null) { return; } - String projectId = ArtifactUtils.versionlessKey( projectModel.getGroupId(), projectModel.getArtifactId() ); - for ( MavenCoordinate coordinate : elements ) - { + String projectId = ArtifactUtils.versionlessKey(projectModel.getGroupId(), projectModel.getArtifactId()); + for (MavenCoordinate coordinate : elements) { String rawVersion = coordinate.getVersion(); - if ( rawVersion == null ) - { + if (rawVersion == null) { // managed dependency or unversioned plugin continue; } String rawGroupId = coordinate.getGroupId(); - if ( rawGroupId == null ) - { - if ( "plugin".equals( coordinate.getName() ) ) - { + if (rawGroupId == null) { + if ("plugin".equals(coordinate.getName())) { rawGroupId = "org.apache.maven.plugins"; - } - else - { + } else { // incomplete dependency continue; } } - String groupId = ReleaseUtil.interpolate( rawGroupId, projectModel ); + String groupId = ReleaseUtil.interpolate(rawGroupId, projectModel); String rawArtifactId = coordinate.getArtifactId(); - if ( rawArtifactId == null ) - { + if (rawArtifactId == null) { // incomplete element continue; } - String artifactId = ReleaseUtil.interpolate( rawArtifactId, projectModel ); - - String key = ArtifactUtils.versionlessKey( groupId, artifactId ); - String resolvedSnapshotVersion = getResolvedSnapshotVersion( key, releaseDescriptor ); - String mappedVersion = getNextVersion( releaseDescriptor, key ); - String originalVersion = getOriginalVersion( releaseDescriptor, key, simulate ); - if ( originalVersion == null ) - { - originalVersion = getOriginalResolvedSnapshotVersion( key, releaseDescriptor ); + String artifactId = ReleaseUtil.interpolate(rawArtifactId, projectModel); + + String key = ArtifactUtils.versionlessKey(groupId, artifactId); + String resolvedSnapshotVersion = getResolvedSnapshotVersion(key, releaseDescriptor); + String mappedVersion = getNextVersion(releaseDescriptor, key); + String originalVersion = getOriginalVersion(releaseDescriptor, key, simulate); + if (originalVersion == null) { + originalVersion = getOriginalResolvedSnapshotVersion(key, releaseDescriptor); } // MRELEASE-220 - if ( mappedVersion != null && mappedVersion.endsWith( Artifact.SNAPSHOT_VERSION ) - && !rawVersion.endsWith( Artifact.SNAPSHOT_VERSION ) && !releaseDescriptor.isUpdateDependencies() ) - { + if (mappedVersion != null + && mappedVersion.endsWith(Artifact.SNAPSHOT_VERSION) + && !rawVersion.endsWith(Artifact.SNAPSHOT_VERSION) + && !releaseDescriptor.isUpdateDependencies()) { continue; } - if ( mappedVersion != null ) - { - if ( rawVersion.equals( originalVersion ) ) - { - logInfo( result, " Updating " + artifactId + " to " + mappedVersion ); - coordinate.setVersion( mappedVersion ); - } - else if ( rawVersion.matches( "\\$\\{.+\\}" ) ) - { - String expression = rawVersion.substring( 2, rawVersion.length() - 1 ); - - if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) - || "version".equals( expression ) ) - { - if ( !mappedVersion.equals( getNextVersion( releaseDescriptor, projectId ) ) ) - { - logInfo( result, " Updating " + artifactId + " to " + mappedVersion ); - coordinate.setVersion( mappedVersion ); + if (mappedVersion != null) { + if (rawVersion.equals(originalVersion)) { + logInfo(result, " Updating " + artifactId + " to " + mappedVersion); + coordinate.setVersion(mappedVersion); + } else if (rawVersion.matches("\\$\\{.+\\}")) { + String expression = rawVersion.substring(2, rawVersion.length() - 1); + + if (expression.startsWith("project.") + || expression.startsWith("pom.") + || "version".equals(expression)) { + if (!mappedVersion.equals(getNextVersion(releaseDescriptor, projectId))) { + logInfo(result, " Updating " + artifactId + " to " + mappedVersion); + coordinate.setVersion(mappedVersion); + } else { + logInfo(result, " Ignoring artifact version update for expression " + rawVersion); } - else - { - logInfo( result, " Ignoring artifact version update for expression " + rawVersion ); - } - } - else if ( properties != null ) - { + } else if (properties != null) { // version is an expression, check for properties to update instead - String propertyValue = properties.getProperty( expression ); + String propertyValue = properties.getProperty(expression); - if ( propertyValue != null ) - { - if ( propertyValue.equals( originalVersion ) ) - { - logInfo( result, " Updating " + rawVersion + " to " + mappedVersion ); + if (propertyValue != null) { + if (propertyValue.equals(originalVersion)) { + logInfo(result, " Updating " + rawVersion + " to " + mappedVersion); // change the property only if the property is the same as what's in the reactor - properties.setProperty( expression, mappedVersion ); - } - else if ( mappedVersion.equals( propertyValue ) ) - { + properties.setProperty(expression, mappedVersion); + } else if (mappedVersion.equals(propertyValue)) { // this property may have been updated during processing a sibling. - logInfo( result, " Ignoring artifact version update for expression " + rawVersion - + " because it is already updated" ); - } - else if ( !mappedVersion.equals( rawVersion ) ) - { + logInfo( + result, + " Ignoring artifact version update for expression " + rawVersion + + " because it is already updated"); + } else if (!mappedVersion.equals(rawVersion)) { // WARNING: ${pom.*} prefix support and ${version} is about to be dropped in mvn4! // https://issues.apache.org/jira/browse/MNG-7404 // https://issues.apache.org/jira/browse/MNG-7244 - if ( mappedVersion.matches( "\\$\\{project.+\\}" ) - || mappedVersion.matches( "\\$\\{pom.+\\}" ) - || "${version}".equals( mappedVersion ) ) - { - logInfo( result, " Ignoring artifact version update for expression " - + mappedVersion ); + if (mappedVersion.matches("\\$\\{project.+\\}") + || mappedVersion.matches("\\$\\{pom.+\\}") + || "${version}".equals(mappedVersion)) { + logInfo( + result, + " Ignoring artifact version update for expression " + mappedVersion); // ignore... we cannot update this expression - } - else - { + } else { // the value of the expression conflicts with what the user wanted to release - throw new ReleaseFailureException( "The artifact (" + key + ") requires a " + throw new ReleaseFailureException("The artifact (" + key + ") requires a " + "different version (" + mappedVersion + ") than what is found (" + propertyValue + ") for the expression (" + expression + ") in the " - + "project (" + projectId + ")." ); + + "project (" + projectId + ")."); } } - } - else - { + } else { // the expression used to define the version of this artifact may be inherited // TODO needs a better error message, what pom? what dependency? - throw new ReleaseFailureException( "The version could not be updated: " + rawVersion ); + throw new ReleaseFailureException("The version could not be updated: " + rawVersion); } } - } - else - { + } else { // different/previous version not related to current release } - } - else if ( resolvedSnapshotVersion != null ) - { - logInfo( result, " Updating " + artifactId + " to " + resolvedSnapshotVersion ); + } else if (resolvedSnapshotVersion != null) { + logInfo(result, " Updating " + artifactId + " to " + resolvedSnapshotVersion); - coordinate.setVersion( resolvedSnapshotVersion ); - } - else - { + coordinate.setVersion(resolvedSnapshotVersion); + } else { // artifact not related to current release } } } - private void prepareScm( File pomFile, ReleaseDescriptor releaseDescriptor, ScmRepository repository, - ScmProvider provider ) - throws ReleaseExecutionException, ReleaseScmCommandException - { - try - { - if ( isUpdateScm() && ( releaseDescriptor.isScmUseEditMode() || provider.requiresEditMode() ) ) - { - EditScmResult result = provider.edit( repository, new ScmFileSet( - new File( releaseDescriptor.getWorkingDirectory() ), pomFile ) ); - - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to enable editing on the POM", result ); + private void prepareScm( + File pomFile, ReleaseDescriptor releaseDescriptor, ScmRepository repository, ScmProvider provider) + throws ReleaseExecutionException, ReleaseScmCommandException { + try { + if (isUpdateScm() && (releaseDescriptor.isScmUseEditMode() || provider.requiresEditMode())) { + EditScmResult result = provider.edit( + repository, new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()), pomFile)); + + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to enable editing on the POM", result); } } - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error occurred enabling edit mode: " + e.getMessage(), e ); + } catch (ScmException e) { + throw new ReleaseExecutionException("An error occurred enabling edit mode: " + e.getMessage(), e); } } - /** *

getResolvedSnapshotVersion.

* @@ -627,8 +611,8 @@ private void prepareScm( File pomFile, ReleaseDescriptor releaseDescriptor, ScmR * @param releaseDscriptor a {@link org.apache.maven.shared.release.config.ReleaseDescriptor} object * @return a {@link java.lang.String} object */ - protected abstract String getResolvedSnapshotVersion( String artifactVersionlessKey, - ReleaseDescriptor releaseDscriptor ); + protected abstract String getResolvedSnapshotVersion( + String artifactVersionlessKey, ReleaseDescriptor releaseDscriptor); /** *

getOriginalVersion.

@@ -638,8 +622,8 @@ protected abstract String getResolvedSnapshotVersion( String artifactVersionless * @param simulate a boolean * @return a {@link java.lang.String} object */ - protected abstract String getOriginalVersion( ReleaseDescriptor releaseDescriptor, String projectKey, - boolean simulate ); + protected abstract String getOriginalVersion( + ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate); /** *

getNextVersion.

@@ -648,7 +632,7 @@ protected abstract String getOriginalVersion( ReleaseDescriptor releaseDescripto * @param key a {@link java.lang.String} object * @return a {@link java.lang.String} object */ - protected abstract String getNextVersion( ReleaseDescriptor releaseDescriptor, String key ); + protected abstract String getNextVersion(ReleaseDescriptor releaseDescriptor, String key); /** *

transformScm.

@@ -661,9 +645,13 @@ protected abstract String getOriginalVersion( ReleaseDescriptor releaseDescripto * @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, + Model modelTarget, + ReleaseDescriptor releaseDescriptor, + String projectId, + ScmRepository scmRepository, + ReleaseResult result) throws ReleaseExecutionException; /** @@ -672,8 +660,7 @@ protected abstract void transformScm( MavenProject project, Model modelTarget, R * @return {@code true} if the SCM-section should be updated, otherwise {@code false} * @since 2.4 */ - protected boolean isUpdateScm() - { + protected boolean isUpdateScm() { return true; } @@ -684,10 +671,9 @@ protected boolean isUpdateScm() * @param releaseDescriptor a {@link org.apache.maven.shared.release.config.ReleaseDescriptor} object * @return a {@link java.lang.String} object */ - protected String getOriginalResolvedSnapshotVersion( String artifactVersionlessKey, - ReleaseDescriptor releaseDescriptor ) - { - return releaseDescriptor.getDependencyOriginalVersion( artifactVersionlessKey ); + protected String getOriginalResolvedSnapshotVersion( + String artifactVersionlessKey, ReleaseDescriptor releaseDescriptor) { + return releaseDescriptor.getDependencyOriginalVersion(artifactVersionlessKey); } /** @@ -699,55 +685,41 @@ protected String getOriginalResolvedSnapshotVersion( String artifactVersionlessK * @param urlPath - scm.url or scm.connection * @return The url path for the tag. */ - protected static String translateUrlPath( String trunkPath, String tagPath, String urlPath ) - { + protected static String translateUrlPath(String trunkPath, String tagPath, String urlPath) { trunkPath = trunkPath.trim(); tagPath = tagPath.trim(); - //Strip the slash at the end if one is present - if ( trunkPath.endsWith( "/" ) ) - { - trunkPath = trunkPath.substring( 0, trunkPath.length() - 1 ); + // Strip the slash at the end if one is present + if (trunkPath.endsWith("/")) { + trunkPath = trunkPath.substring(0, trunkPath.length() - 1); } - if ( tagPath.endsWith( "/" ) ) - { - tagPath = tagPath.substring( 0, tagPath.length() - 1 ); + if (tagPath.endsWith("/")) { + tagPath = tagPath.substring(0, tagPath.length() - 1); } char[] tagPathChars = trunkPath.toCharArray(); char[] trunkPathChars = tagPath.toCharArray(); // Find the common path between trunk and tags int i = 0; - while ( ( i < tagPathChars.length ) && ( i < trunkPathChars.length ) && tagPathChars[i] == trunkPathChars[i] ) - { + while ((i < tagPathChars.length) && (i < trunkPathChars.length) && tagPathChars[i] == trunkPathChars[i]) { ++i; } // If there is nothing common between trunk and tags, or the relative // path does not exist in the url, then just return the tag. - if ( i == 0 || urlPath.indexOf( trunkPath.substring( i ) ) < 0 ) - { + if (i == 0 || urlPath.indexOf(trunkPath.substring(i)) < 0) { return tagPath; - } - else - { - return StringUtils.replace( urlPath, trunkPath.substring( i ), tagPath.substring( i ) ); + } else { + return StringUtils.replace(urlPath, trunkPath.substring(i), tagPath.substring(i)); } } - private Collection toMavenCoordinates( List objects ) - { - Collection coordinates = new ArrayList<>( objects.size() ); - for ( Object object : objects ) - { - if ( object instanceof MavenCoordinate ) - { - coordinates.add( (MavenCoordinate) object ); - } - else - { + private Collection toMavenCoordinates(List objects) { + Collection coordinates = new ArrayList<>(objects.size()); + for (Object object : objects) { + if (object instanceof MavenCoordinate) { + coordinates.add((MavenCoordinate) object); + } else { throw new UnsupportedOperationException(); } } return coordinates; } - - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java index 9b8bdcac1..ff30e4d1a 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractRunGoalsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.List; @@ -40,98 +39,100 @@ * * @author Brett Porter */ -public abstract class AbstractRunGoalsPhase - extends AbstractReleasePhase -{ +public abstract class AbstractRunGoalsPhase extends AbstractReleasePhase { /** * Component to assist in executing Maven. */ private final Map mavenExecutors; - protected AbstractRunGoalsPhase( Map mavenExecutors ) - { - this.mavenExecutors = requireNonNull( mavenExecutors ); + protected AbstractRunGoalsPhase(Map mavenExecutors) { + this.mavenExecutors = requireNonNull(mavenExecutors); } - protected ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, boolean logArguments ) - throws ReleaseExecutionException - { - return execute( releaseDescriptor, releaseEnvironment, new File( releaseDescriptor.getWorkingDirectory() ), - getAdditionalArguments( releaseDescriptor ), logArguments ); + protected ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + boolean logArguments) + throws ReleaseExecutionException { + return execute( + releaseDescriptor, + releaseEnvironment, + new File(releaseDescriptor.getWorkingDirectory()), + getAdditionalArguments(releaseDescriptor), + logArguments); } - protected ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - File workingDirectory, String additionalArguments, boolean logArguments ) - throws ReleaseExecutionException - { + protected ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + File workingDirectory, + String additionalArguments, + boolean logArguments) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); - try - { - String goals = getGoals( releaseDescriptor ); - if ( !StringUtils.isEmpty( goals ) ) - { - logInfo( result, "Executing goals '" + buffer().strong( goals ) + "'..." ); - if ( logArguments ) - { + try { + String goals = getGoals(releaseDescriptor); + if (!StringUtils.isEmpty(goals)) { + logInfo(result, "Executing goals '" + buffer().strong(goals) + "'..."); + if (logArguments) { // logging arguments may log secrets: should be activated only on dryRun - logInfo( result, " with additional arguments: " - + ( additionalArguments == null ? "(none)" : additionalArguments ) ); + logInfo( + result, + " with additional arguments: " + + (additionalArguments == null ? "(none)" : additionalArguments)); } - MavenExecutor mavenExecutor = mavenExecutors.get( releaseEnvironment.getMavenExecutorId() ); + MavenExecutor mavenExecutor = mavenExecutors.get(releaseEnvironment.getMavenExecutorId()); - if ( mavenExecutor == null ) - { + if (mavenExecutor == null) { throw new ReleaseExecutionException( - "Cannot find Maven executor with id: " + releaseEnvironment.getMavenExecutorId() ); + "Cannot find Maven executor with id: " + releaseEnvironment.getMavenExecutorId()); } File executionRoot; String pomFileName; - if ( releaseDescriptor.getPomFileName() != null ) - { - File rootPom = new File( workingDirectory, releaseDescriptor.getPomFileName() ); + if (releaseDescriptor.getPomFileName() != null) { + File rootPom = new File(workingDirectory, releaseDescriptor.getPomFileName()); executionRoot = rootPom.getParentFile(); pomFileName = rootPom.getName(); - } - else - { + } else { executionRoot = workingDirectory; pomFileName = null; } - mavenExecutor.executeGoals( executionRoot, goals, releaseEnvironment, - releaseDescriptor.isInteractive(), additionalArguments, - pomFileName, result ); + mavenExecutor.executeGoals( + executionRoot, + goals, + releaseEnvironment, + releaseDescriptor.isInteractive(), + additionalArguments, + pomFileName, + result); } - } - catch ( MavenExecutorException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } catch (MavenExecutorException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - protected abstract String getGoals( ReleaseDescriptor releaseDescriptor ); + protected abstract String getGoals(ReleaseDescriptor releaseDescriptor); - protected String getAdditionalArguments( ReleaseDescriptor releaseDescriptor ) - { + protected String getAdditionalArguments(ReleaseDescriptor releaseDescriptor) { StringBuilder builder = new StringBuilder(); - if ( releaseDescriptor.getAdditionalArguments() != null ) - { - builder.append( releaseDescriptor.getAdditionalArguments() ); + if (releaseDescriptor.getAdditionalArguments() != null) { + builder.append(releaseDescriptor.getAdditionalArguments()); } - if ( !releaseDescriptor.getActivateProfiles().isEmpty() ) - { - builder.append( " -P " ) - .append( StringUtils.join( releaseDescriptor.getActivateProfiles().iterator(), "," ) ); + if (!releaseDescriptor.getActivateProfiles().isEmpty()) { + builder.append(" -P ") + .append(StringUtils.join( + releaseDescriptor.getActivateProfiles().iterator(), ",")); } return builder.length() > 0 ? builder.toString().trim() : null; @@ -147,13 +148,11 @@ protected String getAdditionalArguments( ReleaseDescriptor releaseDescriptor ) * directory or "" * @return The working directory */ - protected File determineWorkingDirectory( File checkoutDirectory, String relativePathProjectDirectory ) - { + protected File determineWorkingDirectory(File checkoutDirectory, String relativePathProjectDirectory) { File workingDirectory = checkoutDirectory; - if ( StringUtils.isNotEmpty( relativePathProjectDirectory ) ) - { - workingDirectory = new File( checkoutDirectory, relativePathProjectDirectory ); + if (StringUtils.isNotEmpty(relativePathProjectDirectory)) { + workingDirectory = new File(checkoutDirectory, relativePathProjectDirectory); } return workingDirectory; diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitDevelopmentPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitDevelopmentPhase.java index 15ea93914..4badb570f 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitDevelopmentPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitDevelopmentPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.io.File; import java.text.MessageFormat; @@ -38,9 +37,7 @@ * * @author Brett Porter */ -public abstract class AbstractScmCommitDevelopmentPhase - extends AbstractScmCommitPhase -{ +public abstract class AbstractScmCommitDevelopmentPhase extends AbstractScmCommitPhase { /** * The format for the */ @@ -48,64 +45,54 @@ public abstract class AbstractScmCommitDevelopmentPhase protected AbstractScmCommitDevelopmentPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - String descriptorCommentGetter, String rollbackMessageFormat ) - { - super( scmRepositoryConfigurator, descriptorCommentGetter ); + String descriptorCommentGetter, + String rollbackMessageFormat) { + super(scmRepositoryConfigurator, descriptorCommentGetter); this.rollbackMessageFormat = rollbackMessageFormat; } @Override - protected void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, ReleaseResult result, boolean simulating ) - throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException - { + protected void runLogic( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + ReleaseResult result, + boolean simulating) + throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException { // no rollback required if ( - // was there no commit that has to be rolled back by a new one - releaseDescriptor.isSuppressCommitBeforeTagOrBranch() - // and working copy should not be touched - && !releaseDescriptor.isUpdateWorkingCopyVersions() ) - { - if ( simulating ) - { - logInfo( result, "Full run would not commit changes, because updateWorkingCopyVersions is false." ); - } - else - { - logInfo( result, "Modified POMs are not committed because updateWorkingCopyVersions is set to false." ); + // was there no commit that has to be rolled back by a new one + releaseDescriptor.isSuppressCommitBeforeTagOrBranch() + // and working copy should not be touched + && !releaseDescriptor.isUpdateWorkingCopyVersions()) { + if (simulating) { + logInfo(result, "Full run would not commit changes, because updateWorkingCopyVersions is false."); + } else { + logInfo(result, "Modified POMs are not committed because updateWorkingCopyVersions is set to false."); } } // rollback or commit development versions required - else - { + else { String message; - if ( !releaseDescriptor.isUpdateWorkingCopyVersions() ) - { + if (!releaseDescriptor.isUpdateWorkingCopyVersions()) { // the commit is a rollback - message = createRollbackMessage( releaseDescriptor ); - } - else - { + message = createRollbackMessage(releaseDescriptor); + } else { // a normal commit - message = createMessage( reactorProjects, releaseDescriptor ); - } - if ( simulating ) - { - Collection pomFiles = createPomFiles( releaseDescriptor, reactorProjects ); - logInfo( result, - "Full run would commit " + pomFiles.size() + " files with message: '" + message + "'" ); + message = createMessage(reactorProjects, releaseDescriptor); } - else - { - performCheckins( releaseDescriptor, releaseEnvironment, reactorProjects, message ); + if (simulating) { + Collection pomFiles = createPomFiles(releaseDescriptor, reactorProjects); + logInfo(result, "Full run would commit " + pomFiles.size() + " files with message: '" + message + "'"); + } else { + performCheckins(releaseDescriptor, releaseEnvironment, reactorProjects, message); } } } - private String createRollbackMessage( ReleaseDescriptor releaseDescriptor ) - { - return MessageFormat.format( releaseDescriptor.getScmCommentPrefix() + rollbackMessageFormat, - releaseDescriptor.getScmReleaseLabel() ); + private String createRollbackMessage(ReleaseDescriptor releaseDescriptor) { + return MessageFormat.format( + releaseDescriptor.getScmCommentPrefix() + rollbackMessageFormat, + releaseDescriptor.getScmReleaseLabel()); } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java index a5a61eac8..a479cbb9a 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.ArrayList; @@ -51,9 +50,7 @@ * @author Brett Porter * @author Lars Corneliussen */ -public abstract class AbstractScmCommitPhase - extends AbstractReleasePhase -{ +public abstract class AbstractScmCommitPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ @@ -64,41 +61,42 @@ public abstract class AbstractScmCommitPhase */ protected final String descriptorCommentGetter; - protected AbstractScmCommitPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - String descriptorCommentGetter ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); - this.descriptorCommentGetter = requireNonNull( descriptorCommentGetter ); + protected AbstractScmCommitPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, String descriptorCommentGetter) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); + this.descriptorCommentGetter = requireNonNull(descriptorCommentGetter); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult relResult = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); - runLogic( releaseDescriptor, releaseEnvironment, reactorProjects, relResult, false ); + runLogic(releaseDescriptor, releaseEnvironment, reactorProjects, relResult, false); - relResult.setResultCode( ReleaseResult.SUCCESS ); + relResult.setResultCode(ReleaseResult.SUCCESS); return relResult; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); - runLogic( releaseDescriptor, releaseEnvironment, reactorProjects, result, true ); + runLogic(releaseDescriptor, releaseEnvironment, reactorProjects, result, true); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @@ -114,8 +112,12 @@ public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvir * @throws org.apache.maven.shared.release.ReleaseExecutionException if any. * @throws org.apache.maven.shared.release.scm.ReleaseScmRepositoryException if any. */ - protected abstract void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, ReleaseResult result, boolean simulating ) + protected abstract void runLogic( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + ReleaseResult result, + boolean simulating) throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException; /** @@ -129,75 +131,66 @@ protected abstract void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEn * @throws org.apache.maven.shared.release.ReleaseExecutionException if any. * @throws org.apache.maven.shared.release.scm.ReleaseScmCommandException if any. */ - protected void performCheckins( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, String message ) - throws ReleaseScmRepositoryException, ReleaseExecutionException, ReleaseScmCommandException - { + protected void performCheckins( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + String message) + throws ReleaseScmRepositoryException, ReleaseExecutionException, ReleaseScmCommandException { - getLogger().info( "Checking in modified POMs..." ); + getLogger().info("Checking in modified POMs..."); ScmRepository repository; ScmProvider provider; - try - { - repository = scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); + try { + repository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); - repository.getProviderRepository().setPushChanges( releaseDescriptor.isPushChanges() ); + repository.getProviderRepository().setPushChanges(releaseDescriptor.isPushChanges()); - repository.getProviderRepository().setWorkItem( releaseDescriptor.getWorkItem() ); + repository.getProviderRepository().setWorkItem(releaseDescriptor.getWorkItem()); - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + provider = scmRepositoryConfigurator.getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } - if ( releaseDescriptor.isCommitByProject() ) - { - for ( MavenProject project : reactorProjects ) - { - List pomFiles = createPomFiles( releaseDescriptor, project ); - ScmFileSet fileSet = new ScmFileSet( project.getFile().getParentFile(), pomFiles ); + if (releaseDescriptor.isCommitByProject()) { + for (MavenProject project : reactorProjects) { + List pomFiles = createPomFiles(releaseDescriptor, project); + ScmFileSet fileSet = new ScmFileSet(project.getFile().getParentFile(), pomFiles); - checkin( provider, repository, fileSet, releaseDescriptor, message ); + checkin(provider, repository, fileSet, releaseDescriptor, message); } - } - else - { - List pomFiles = createPomFiles( releaseDescriptor, reactorProjects ); - ScmFileSet fileSet = new ScmFileSet( new File( releaseDescriptor.getWorkingDirectory() ), pomFiles ); + } else { + List pomFiles = createPomFiles(releaseDescriptor, reactorProjects); + ScmFileSet fileSet = new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()), pomFiles); - checkin( provider, repository, fileSet, releaseDescriptor, message ); + checkin(provider, repository, fileSet, releaseDescriptor, message); } } - private void checkin( ScmProvider provider, ScmRepository repository, ScmFileSet fileSet, - ReleaseDescriptor releaseDescriptor, String message ) - throws ReleaseExecutionException, ReleaseScmCommandException - { + private void checkin( + ScmProvider provider, + ScmRepository repository, + ScmFileSet fileSet, + ReleaseDescriptor releaseDescriptor, + String message) + throws ReleaseExecutionException, ReleaseScmCommandException { CheckInScmResult result; - try - { - result = provider.checkIn( repository, fileSet, (ScmVersion) null, message ); - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error is occurred in the checkin process: " + e.getMessage(), e ); + try { + result = provider.checkIn(repository, fileSet, (ScmVersion) null, message); + } catch (ScmException e) { + throw new ReleaseExecutionException("An error is occurred in the checkin process: " + e.getMessage(), e); } - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to commit files", result ); + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to commit files", result); } - if ( releaseDescriptor.isRemoteTagging() ) - { - releaseDescriptor.setScmReleasedPomRevision( result.getScmRevision() ); + if (releaseDescriptor.isRemoteTagging()) { + releaseDescriptor.setScmReleasedPomRevision(result.getScmRevision()); } } @@ -209,11 +202,13 @@ private void checkin( ScmProvider provider, ScmRepository repository, ScmFileSet * @param result a {@link org.apache.maven.shared.release.ReleaseResult} object * @param message a {@link java.lang.String} object */ - protected void simulateCheckins( ReleaseDescriptor releaseDescriptor, List reactorProjects, - ReleaseResult result, String message ) - { - Collection pomFiles = createPomFiles( releaseDescriptor, reactorProjects ); - logInfo( result, "Full run would be commit " + pomFiles.size() + " files with message: '" + message + "'" ); + protected void simulateCheckins( + ReleaseDescriptor releaseDescriptor, + List reactorProjects, + ReleaseResult result, + String message) { + Collection pomFiles = createPomFiles(releaseDescriptor, reactorProjects); + logInfo(result, "Full run would be commit " + pomFiles.size() + " files with message: '" + message + "'"); } /** @@ -222,12 +217,9 @@ protected void simulateCheckins( ReleaseDescriptor releaseDescriptor, List reactorProjects, - ReleaseDescriptor releaseDescriptor ) - throws ReleaseExecutionException - { + protected String createMessage(List reactorProjects, ReleaseDescriptor releaseDescriptor) + throws ReleaseExecutionException { String comment; boolean branch = false; - if ( "getScmReleaseCommitComment".equals( descriptorCommentGetter ) ) - { + if ("getScmReleaseCommitComment".equals(descriptorCommentGetter)) { comment = releaseDescriptor.getScmReleaseCommitComment(); - } - else if ( "getScmDevelopmentCommitComment".equals( descriptorCommentGetter ) ) - { + } else if ("getScmDevelopmentCommitComment".equals(descriptorCommentGetter)) { comment = releaseDescriptor.getScmDevelopmentCommitComment(); - } - else if ( "getScmBranchCommitComment".equals( descriptorCommentGetter ) ) - { + } else if ("getScmBranchCommitComment".equals(descriptorCommentGetter)) { comment = releaseDescriptor.getScmBranchCommitComment(); branch = true; - } - else if ( "getScmRollbackCommitComment".equals( descriptorCommentGetter ) ) - { + } else if ("getScmRollbackCommitComment".equals(descriptorCommentGetter)) { comment = releaseDescriptor.getScmRollbackCommitComment(); - } - else - { + } else { throw new ReleaseExecutionException( - "Invalid configuration of descriptorCommentGetter='" + descriptorCommentGetter + "'" ); + "Invalid configuration of descriptorCommentGetter='" + descriptorCommentGetter + "'"); } - MavenProject project = ReleaseUtil.getRootProject( reactorProjects ); - comment = comment.replace( "@{prefix}", releaseDescriptor.getScmCommentPrefix().trim() ); - comment = comment.replace( "@{groupId}", project.getGroupId() ); - comment = comment.replace( "@{artifactId}", project.getArtifactId() ); - if ( branch ) - { - comment = comment.replace( "@{branchName}", releaseDescriptor.getScmReleaseLabel() ); - } - else - { - comment = comment.replace( "@{releaseLabel}", releaseDescriptor.getScmReleaseLabel() ); + MavenProject project = ReleaseUtil.getRootProject(reactorProjects); + comment = comment.replace( + "@{prefix}", releaseDescriptor.getScmCommentPrefix().trim()); + comment = comment.replace("@{groupId}", project.getGroupId()); + comment = comment.replace("@{artifactId}", project.getArtifactId()); + if (branch) { + comment = comment.replace("@{branchName}", releaseDescriptor.getScmReleaseLabel()); + } else { + comment = comment.replace("@{releaseLabel}", releaseDescriptor.getScmReleaseLabel()); } return comment; } @@ -290,15 +269,13 @@ else if ( "getScmRollbackCommitComment".equals( descriptorCommentGetter ) ) * @param project a {@link org.apache.maven.project.MavenProject} object * @return a {@link java.util.List} object */ - protected static List createPomFiles( ReleaseDescriptor releaseDescriptor, MavenProject project ) - { + protected static List createPomFiles(ReleaseDescriptor releaseDescriptor, MavenProject project) { List pomFiles = new ArrayList<>(); - pomFiles.add( ReleaseUtil.getStandardPom( project ) ); + pomFiles.add(ReleaseUtil.getStandardPom(project)); - if ( releaseDescriptor.isGenerateReleasePoms() && !releaseDescriptor.isSuppressCommitBeforeTagOrBranch() ) - { - pomFiles.add( ReleaseUtil.getReleasePom( project ) ); + if (releaseDescriptor.isGenerateReleasePoms() && !releaseDescriptor.isSuppressCommitBeforeTagOrBranch()) { + pomFiles.add(ReleaseUtil.getReleasePom(project)); } return pomFiles; @@ -311,13 +288,11 @@ protected static List createPomFiles( ReleaseDescriptor releaseDescriptor, * @param reactorProjects a {@link java.util.List} object * @return a {@link java.util.List} object */ - protected static List createPomFiles( ReleaseDescriptor releaseDescriptor, - List reactorProjects ) - { + protected static List createPomFiles( + ReleaseDescriptor releaseDescriptor, List reactorProjects) { List pomFiles = new ArrayList<>(); - for ( MavenProject project : reactorProjects ) - { - pomFiles.addAll( createPomFiles( releaseDescriptor, project ) ); + for (MavenProject project : reactorProjects) { + pomFiles.addAll(createPomFiles(releaseDescriptor, project)); } return pomFiles; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPreparationPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPreparationPhase.java index 5c36a2f5f..84d8d6ed4 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPreparationPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/AbstractScmCommitPreparationPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.util.List; @@ -36,69 +35,54 @@ * * @author Brett Porter */ -public abstract class AbstractScmCommitPreparationPhase - extends AbstractScmCommitPhase -{ +public abstract class AbstractScmCommitPreparationPhase extends AbstractScmCommitPhase { protected AbstractScmCommitPreparationPhase( - ScmRepositoryConfigurator scmRepositoryConfigurator, - String descriptorCommentGetter ) - { - super( scmRepositoryConfigurator, descriptorCommentGetter ); + ScmRepositoryConfigurator scmRepositoryConfigurator, String descriptorCommentGetter) { + super(scmRepositoryConfigurator, descriptorCommentGetter); } @Override - protected void runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, ReleaseResult result, boolean simulating ) - throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException - { + protected void runLogic( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + ReleaseResult result, + boolean simulating) + throws ReleaseScmCommandException, ReleaseExecutionException, ReleaseScmRepositoryException { // no prepare-commit required - if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() ) - { + if (releaseDescriptor.isSuppressCommitBeforeTagOrBranch()) { String parameterName; - if ( releaseDescriptor.isBranchCreation() ) - { + if (releaseDescriptor.isBranchCreation()) { parameterName = "suppressCommitBeforeBranch"; - } - else - { + } else { parameterName = "suppressCommitBeforeTag"; } - if ( simulating ) - { - logInfo( result, - "Full run would not commit changes, " + "because " + parameterName + " is set to true." ); - } - else - { - logInfo( result, - "Modified POMs are not committed because " + parameterName + " is set to true." ); + if (simulating) { + logInfo( + result, + "Full run would not commit changes, " + "because " + parameterName + " is set to true."); + } else { + logInfo(result, "Modified POMs are not committed because " + parameterName + " is set to true."); } } // commit development versions required - else - { - String message = createMessage( reactorProjects, releaseDescriptor ); - if ( simulating ) - { - simulateCheckins( releaseDescriptor, reactorProjects, result, message ); - } - else - { - performCheckins( releaseDescriptor, releaseEnvironment, reactorProjects, message ); + else { + String message = createMessage(reactorProjects, releaseDescriptor); + if (simulating) { + simulateCheckins(releaseDescriptor, reactorProjects, result, message); + } else { + performCheckins(releaseDescriptor, releaseEnvironment, reactorProjects, message); } } } - protected void validateConfiguration( ReleaseDescriptor releaseDescriptor ) - throws ReleaseFailureException - { - super.validateConfiguration( releaseDescriptor ); + protected void validateConfiguration(ReleaseDescriptor releaseDescriptor) throws ReleaseFailureException { + super.validateConfiguration(releaseDescriptor); - if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() && releaseDescriptor.isRemoteTagging() ) - { + if (releaseDescriptor.isSuppressCommitBeforeTagOrBranch() && releaseDescriptor.isRemoteTagging()) { throw new ReleaseFailureException( - "Cannot perform a remote tag or branch without committing the working copy first." ); + "Cannot perform a remote tag or branch without committing the working copy first."); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhase.java index c0ca7f540..a218cb938 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -35,14 +34,13 @@ * @author Brett Porter */ @Singleton -@Named( "branch-input-variables" ) -public class BranchInputVariablesPhase - extends AbstractInputVariablesPhase -{ +@Named("branch-input-variables") +public class BranchInputVariablesPhase extends AbstractInputVariablesPhase { @Inject - public BranchInputVariablesPhase( Prompter prompter, ScmRepositoryConfigurator scmRepositoryConfigurator, - Map namingPolicies ) - { - super( prompter, scmRepositoryConfigurator, namingPolicies, true, null ); + public BranchInputVariablesPhase( + Prompter prompter, + ScmRepositoryConfigurator scmRepositoryConfigurator, + Map namingPolicies) { + super(prompter, scmRepositoryConfigurator, namingPolicies, true, null); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckCompletedPreparePhasesPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckCompletedPreparePhasesPhase.java index 15bc7a0f9..4b59920b8 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckCompletedPreparePhasesPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckCompletedPreparePhasesPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Named; import javax.inject.Singleton; @@ -35,54 +34,50 @@ * @author Emmanuel Venisse */ @Singleton -@Named( "verify-completed-prepare-phases" ) -public class CheckCompletedPreparePhasesPhase - extends AbstractReleasePhase -{ +@Named("verify-completed-prepare-phases") +public class CheckCompletedPreparePhasesPhase extends AbstractReleasePhase { @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); // if we stopped mid-way through preparation - don't perform - if ( releaseDescriptor.getCompletedPhase() != null - && !"end-release".equals( releaseDescriptor.getCompletedPhase() ) ) - { + if (releaseDescriptor.getCompletedPhase() != null + && !"end-release".equals(releaseDescriptor.getCompletedPhase())) { String message = "Cannot perform release - the preparation step was stopped mid-way. Please re-run " + "release:prepare to continue, or perform the release from an SCM tag."; - result.setResultCode( ReleaseResult.ERROR ); + result.setResultCode(ReleaseResult.ERROR); - logError( result, message ); + logError(result, message); - throw new ReleaseFailureException( message ); + throw new ReleaseFailureException(message); } - if ( releaseDescriptor.getScmSourceUrl() == null ) - { + if (releaseDescriptor.getScmSourceUrl() == null) { String message = "No SCM URL was provided to perform the release from"; - result.setResultCode( ReleaseResult.ERROR ); + result.setResultCode(ReleaseResult.ERROR); - logError( result, message ); + logError(result, message); - throw new ReleaseFailureException( message ); + throw new ReleaseFailureException(message); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java index bc278ca7a..0a29ea3e1 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -55,13 +54,14 @@ * * @author Brett Porter */ -// TODO plugins with no version will be resolved to RELEASE which is not a snapshot, but remains unresolved to this point. This is a potential hole in the check, and should be revisited after the release pom writing is done and resolving versions to verify whether it is. -// TODO plugins injected by the lifecycle are not tested here. They will be injected with a RELEASE version so are covered under the above point. +// TODO plugins with no version will be resolved to RELEASE which is not a snapshot, but remains unresolved to this +// point. This is a potential hole in the check, and should be revisited after the release pom writing is done and +// resolving versions to verify whether it is. +// TODO plugins injected by the lifecycle are not tested here. They will be injected with a RELEASE version so are +// covered under the above point. @Singleton -@Named( "check-dependency-snapshots" ) -public class CheckDependencySnapshotsPhase - extends AbstractReleasePhase -{ +@Named("check-dependency-snapshots") +public class CheckDependencySnapshotsPhase extends AbstractReleasePhase { public static final String RESOLVE_SNAPSHOT_MESSAGE = "There are still some remaining snapshot dependencies.\n"; public static final String RESOLVE_SNAPSHOT_PROMPT = "Do you want to resolve them now?"; @@ -80,7 +80,8 @@ public class CheckDependencySnapshotsPhase // UsedSnapshots end up on the classpath. // SpecifiedSnapshots are defined anywhere in the pom. // We'll probably need to introduce specifiedSnapshots as well. - // @TODO MRELEASE-378: verify custom dependencies in plugins. Be aware of deprecated/removed Components in M3, such as PluginCollector + // @TODO MRELEASE-378: verify custom dependencies in plugins. Be aware of deprecated/removed Components in M3, such + // as PluginCollector // @TODO MRELEASE-763: verify all dependencies in inactive profiles // Don't prompt for every project in reactor, remember state of questions @@ -89,455 +90,382 @@ public class CheckDependencySnapshotsPhase private String resolveSnapshotType; @Inject - public CheckDependencySnapshotsPhase( Prompter prompter ) - { - this.prompter = new AtomicReference<>( requireNonNull( prompter ) ); + public CheckDependencySnapshotsPhase(Prompter prompter) { + this.prompter = new AtomicReference<>(requireNonNull(prompter)); } /** * For easier testing only! */ - public void setPrompter( Prompter prompter ) - { - this.prompter.set( prompter ); + public void setPrompter(Prompter prompter) { + this.prompter.set(prompter); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - if ( !releaseDescriptor.isAllowTimestampedSnapshots() ) - { - logInfo( result, "Checking dependencies and plugins for snapshots ..." ); + if (!releaseDescriptor.isAllowTimestampedSnapshots()) { + logInfo(result, "Checking dependencies and plugins for snapshots ..."); - for ( MavenProject project : reactorProjects ) - { - checkProject( project, releaseDescriptor ); + for (MavenProject project : reactorProjects) { + checkProject(project, releaseDescriptor); } + } else { + logInfo(result, "Ignoring SNAPSHOT dependencies and plugins ..."); } - else - { - logInfo( result, "Ignoring SNAPSHOT dependencies and plugins ..." ); - } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private void checkProject( MavenProject project, ReleaseDescriptor releaseDescriptor ) - throws ReleaseFailureException, ReleaseExecutionException - { - Map artifactMap = ArtifactUtils.artifactMapByVersionlessId( project.getArtifacts() ); + private void checkProject(MavenProject project, ReleaseDescriptor releaseDescriptor) + throws ReleaseFailureException, ReleaseExecutionException { + Map artifactMap = ArtifactUtils.artifactMapByVersionlessId(project.getArtifacts()); Set usedSnapshotDependencies = new HashSet<>(); - if ( project.getParentArtifact() != null ) - { - if ( checkArtifact( project.getParentArtifact(), artifactMap, releaseDescriptor ) ) - { - usedSnapshotDependencies.add( project.getParentArtifact() ); + if (project.getParentArtifact() != null) { + if (checkArtifact(project.getParentArtifact(), artifactMap, releaseDescriptor)) { + usedSnapshotDependencies.add(project.getParentArtifact()); } } Set dependencyArtifacts = project.getDependencyArtifacts(); - usedSnapshotDependencies.addAll( checkDependencies( releaseDescriptor, artifactMap, dependencyArtifacts ) ); + usedSnapshotDependencies.addAll(checkDependencies(releaseDescriptor, artifactMap, dependencyArtifacts)); - //@todo check dependencyManagement + // @todo check dependencyManagement Set pluginArtifacts = project.getPluginArtifacts(); - Set usedSnapshotPlugins = checkPlugins( releaseDescriptor, artifactMap, pluginArtifacts ); + Set usedSnapshotPlugins = checkPlugins(releaseDescriptor, artifactMap, pluginArtifacts); - //@todo check pluginManagement + // @todo check pluginManagement Set reportArtifacts = project.getReportArtifacts(); - Set usedSnapshotReports = checkReports( releaseDescriptor, artifactMap, reportArtifacts ); + Set usedSnapshotReports = checkReports(releaseDescriptor, artifactMap, reportArtifacts); Set extensionArtifacts = project.getExtensionArtifacts(); - Set usedSnapshotExtensions = checkExtensions( releaseDescriptor, artifactMap, extensionArtifacts ); - - //@todo check profiles - - if ( !usedSnapshotDependencies.isEmpty() || !usedSnapshotReports.isEmpty() - || !usedSnapshotExtensions.isEmpty() || !usedSnapshotPlugins.isEmpty() ) - { - if ( releaseDescriptor.isInteractive() || null != releaseDescriptor.getAutoResolveSnapshots() ) - { - resolveSnapshots( usedSnapshotDependencies, usedSnapshotReports, usedSnapshotExtensions, - usedSnapshotPlugins, releaseDescriptor ); + Set usedSnapshotExtensions = checkExtensions(releaseDescriptor, artifactMap, extensionArtifacts); + + // @todo check profiles + + if (!usedSnapshotDependencies.isEmpty() + || !usedSnapshotReports.isEmpty() + || !usedSnapshotExtensions.isEmpty() + || !usedSnapshotPlugins.isEmpty()) { + if (releaseDescriptor.isInteractive() || null != releaseDescriptor.getAutoResolveSnapshots()) { + resolveSnapshots( + usedSnapshotDependencies, + usedSnapshotReports, + usedSnapshotExtensions, + usedSnapshotPlugins, + releaseDescriptor); } - if ( !usedSnapshotDependencies.isEmpty() || !usedSnapshotReports.isEmpty() - || !usedSnapshotExtensions.isEmpty() || !usedSnapshotPlugins.isEmpty() ) - { + if (!usedSnapshotDependencies.isEmpty() + || !usedSnapshotReports.isEmpty() + || !usedSnapshotExtensions.isEmpty() + || !usedSnapshotPlugins.isEmpty()) { StringBuilder message = new StringBuilder(); - printSnapshotDependencies( usedSnapshotDependencies, message ); - printSnapshotDependencies( usedSnapshotReports, message ); - printSnapshotDependencies( usedSnapshotExtensions, message ); - printSnapshotDependencies( usedSnapshotPlugins, message ); - message.append( "in project '" + project.getName() + "' (" + project.getId() + ")" ); + printSnapshotDependencies(usedSnapshotDependencies, message); + printSnapshotDependencies(usedSnapshotReports, message); + printSnapshotDependencies(usedSnapshotExtensions, message); + printSnapshotDependencies(usedSnapshotPlugins, message); + message.append("in project '" + project.getName() + "' (" + project.getId() + ")"); throw new ReleaseFailureException( - "Can't release project due to non released dependencies :\n" + message ); + "Can't release project due to non released dependencies :\n" + message); } } } - private Set checkPlugins( ReleaseDescriptor releaseDescriptor, - Map artifactMap, Set pluginArtifacts ) - throws ReleaseExecutionException - { + private Set checkPlugins( + ReleaseDescriptor releaseDescriptor, Map artifactMap, Set pluginArtifacts) + throws ReleaseExecutionException { Set usedSnapshotPlugins = new HashSet<>(); - for ( Artifact artifact : pluginArtifacts ) - { - if ( checkArtifact( artifact, artifactMap, releaseDescriptor ) ) - { + for (Artifact artifact : pluginArtifacts) { + if (checkArtifact(artifact, artifactMap, releaseDescriptor)) { boolean addToFailures; - if ( "org.apache.maven.plugins".equals( artifact.getGroupId() ) && "maven-release-plugin".equals( - artifact.getArtifactId() ) ) - { + if ("org.apache.maven.plugins".equals(artifact.getGroupId()) + && "maven-release-plugin".equals(artifact.getArtifactId())) { // It's a snapshot of the release plugin. Maybe just testing - ask // By default, we fail as for any other plugin - if ( releaseDescriptor.isSnapshotReleasePluginAllowed() ) - { + if (releaseDescriptor.isSnapshotReleasePluginAllowed()) { addToFailures = false; - } - else if ( releaseDescriptor.isInteractive() ) - { - try - { + } else if (releaseDescriptor.isInteractive()) { + try { String result; - if ( !releaseDescriptor.isSnapshotReleasePluginAllowed() ) - { - prompter.get().showMessage( "This project relies on a SNAPSHOT of the release plugin. " - + "This may be necessary during testing.\n" ); - result = prompter.get().prompt( "Do you want to continue with the release?", - Arrays.asList( "yes", "no" ), "no" ); - } - else - { + if (!releaseDescriptor.isSnapshotReleasePluginAllowed()) { + prompter.get() + .showMessage("This project relies on a SNAPSHOT of the release plugin. " + + "This may be necessary during testing.\n"); + result = prompter.get() + .prompt( + "Do you want to continue with the release?", + Arrays.asList("yes", "no"), + "no"); + } else { result = "yes"; } - addToFailures = !result.toLowerCase( Locale.ENGLISH ).startsWith( "y" ); - } - catch ( PrompterException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + addToFailures = !result.toLowerCase(Locale.ENGLISH).startsWith("y"); + } catch (PrompterException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } - } - else - { + } else { addToFailures = true; } - } - else - { + } else { addToFailures = true; } - if ( addToFailures ) - { - usedSnapshotPlugins.add( artifact ); + if (addToFailures) { + usedSnapshotPlugins.add(artifact); } } } return usedSnapshotPlugins; } - private Set checkDependencies( ReleaseDescriptor releaseDescriptor, - Map artifactMap, - Set dependencyArtifacts ) - { + private Set checkDependencies( + ReleaseDescriptor releaseDescriptor, Map artifactMap, Set dependencyArtifacts) { Set usedSnapshotDependencies = new HashSet<>(); - for ( Artifact artifact : dependencyArtifacts ) - { - if ( checkArtifact( artifact, artifactMap, releaseDescriptor ) ) - { - usedSnapshotDependencies.add( getArtifactFromMap( artifact, artifactMap ) ); + for (Artifact artifact : dependencyArtifacts) { + if (checkArtifact(artifact, artifactMap, releaseDescriptor)) { + usedSnapshotDependencies.add(getArtifactFromMap(artifact, artifactMap)); } } return usedSnapshotDependencies; } - private Set checkReports( ReleaseDescriptor releaseDescriptor, - Map artifactMap, Set reportArtifacts ) - { + private Set checkReports( + ReleaseDescriptor releaseDescriptor, Map artifactMap, Set reportArtifacts) { Set usedSnapshotReports = new HashSet<>(); - for ( Artifact artifact : reportArtifacts ) - { - if ( checkArtifact( artifact, artifactMap, releaseDescriptor ) ) - { - //snapshotDependencies.add( artifact ); - usedSnapshotReports.add( artifact ); + for (Artifact artifact : reportArtifacts) { + if (checkArtifact(artifact, artifactMap, releaseDescriptor)) { + // snapshotDependencies.add( artifact ); + usedSnapshotReports.add(artifact); } } return usedSnapshotReports; } - private Set checkExtensions( ReleaseDescriptor releaseDescriptor, - Map artifactMap, Set extensionArtifacts ) - { + private Set checkExtensions( + ReleaseDescriptor releaseDescriptor, Map artifactMap, Set extensionArtifacts) { Set usedSnapshotExtensions = new HashSet<>(); - for ( Artifact artifact : extensionArtifacts ) - { - if ( checkArtifact( artifact, artifactMap, releaseDescriptor ) ) - { - usedSnapshotExtensions.add( artifact ); + for (Artifact artifact : extensionArtifacts) { + if (checkArtifact(artifact, artifactMap, releaseDescriptor)) { + usedSnapshotExtensions.add(artifact); } } return usedSnapshotExtensions; } - private static boolean checkArtifact( Artifact artifact, - Map artifactMapByVersionlessId, - ReleaseDescriptor releaseDescriptor ) - { - Artifact checkArtifact = getArtifactFromMap( artifact, artifactMapByVersionlessId ); + private static boolean checkArtifact( + Artifact artifact, Map artifactMapByVersionlessId, ReleaseDescriptor releaseDescriptor) { + Artifact checkArtifact = getArtifactFromMap(artifact, artifactMapByVersionlessId); - return checkArtifact( checkArtifact, releaseDescriptor ); + return checkArtifact(checkArtifact, releaseDescriptor); } - private static Artifact getArtifactFromMap( Artifact artifact, Map artifactMapByVersionlessId ) - { - String versionlessId = ArtifactUtils.versionlessKey( artifact ); - Artifact checkArtifact = artifactMapByVersionlessId.get( versionlessId ); + private static Artifact getArtifactFromMap(Artifact artifact, Map artifactMapByVersionlessId) { + String versionlessId = ArtifactUtils.versionlessKey(artifact); + Artifact checkArtifact = artifactMapByVersionlessId.get(versionlessId); - if ( checkArtifact == null ) - { + if (checkArtifact == null) { checkArtifact = artifact; } return checkArtifact; } - private static boolean checkArtifact( Artifact artifact, ReleaseDescriptor releaseDescriptor ) - { - String versionlessKey = ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); - String releaseDescriptorResolvedVersion = releaseDescriptor.getDependencyReleaseVersion( versionlessKey ); + private static boolean checkArtifact(Artifact artifact, ReleaseDescriptor releaseDescriptor) { + String versionlessKey = ArtifactUtils.versionlessKey(artifact.getGroupId(), artifact.getArtifactId()); + String releaseDescriptorResolvedVersion = releaseDescriptor.getDependencyReleaseVersion(versionlessKey); boolean releaseDescriptorResolvedVersionIsSnapshot = releaseDescriptorResolvedVersion == null - || releaseDescriptorResolvedVersion.contains( Artifact.SNAPSHOT_VERSION ); + || releaseDescriptorResolvedVersion.contains(Artifact.SNAPSHOT_VERSION); // We are only looking at dependencies external to the project - ignore anything found in the reactor as // it's version will be updated boolean bannedVersion = artifact.isSnapshot() - && !artifact.getBaseVersion().equals( releaseDescriptor.getProjectOriginalVersion( versionlessKey ) ) + && !artifact.getBaseVersion().equals(releaseDescriptor.getProjectOriginalVersion(versionlessKey)) && releaseDescriptorResolvedVersionIsSnapshot; // If we have a snapshot but allowTimestampedSnapshots is true, accept the artifact if the version // indicates that it is a timestamped snapshot. - if ( bannedVersion && releaseDescriptor.isAllowTimestampedSnapshots() ) - { - bannedVersion = artifact.getVersion().contains( Artifact.SNAPSHOT_VERSION ); + if (bannedVersion && releaseDescriptor.isAllowTimestampedSnapshots()) { + bannedVersion = artifact.getVersion().contains(Artifact.SNAPSHOT_VERSION); } return bannedVersion; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { // It makes no modifications, so simulate is the same as execute - return execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + return execute(releaseDescriptor, releaseEnvironment, reactorProjects); } - private void printSnapshotDependencies( Set snapshotsSet, StringBuilder message ) - { - List snapshotsList = new ArrayList<>( snapshotsSet ); + private void printSnapshotDependencies(Set snapshotsSet, StringBuilder message) { + List snapshotsList = new ArrayList<>(snapshotsSet); - Collections.sort( snapshotsList ); + Collections.sort(snapshotsList); - for ( Artifact artifact : snapshotsList ) - { - message.append( " " ); + for (Artifact artifact : snapshotsList) { + message.append(" "); - message.append( artifact ); + message.append(artifact); - message.append( "\n" ); + message.append("\n"); } } - private void resolveSnapshots( Set projectDependencies, Set reportDependencies, - Set extensionDependencies, Set pluginDependencies, - ReleaseDescriptor releaseDescriptor ) - throws ReleaseExecutionException - { - try - { + private void resolveSnapshots( + Set projectDependencies, + Set reportDependencies, + Set extensionDependencies, + Set pluginDependencies, + ReleaseDescriptor releaseDescriptor) + throws ReleaseExecutionException { + try { String autoResolveSnapshots = releaseDescriptor.getAutoResolveSnapshots(); - if ( resolveSnapshot == null ) - { - prompter.get().showMessage( RESOLVE_SNAPSHOT_MESSAGE ); - if ( autoResolveSnapshots != null ) - { + if (resolveSnapshot == null) { + prompter.get().showMessage(RESOLVE_SNAPSHOT_MESSAGE); + if (autoResolveSnapshots != null) { resolveSnapshot = "yes"; - prompter.get().showMessage( RESOLVE_SNAPSHOT_PROMPT + " " + resolveSnapshot ); - } - else - { - resolveSnapshot = - prompter.get().prompt( RESOLVE_SNAPSHOT_PROMPT, Arrays.asList( "yes", "no" ), "no" ); + prompter.get().showMessage(RESOLVE_SNAPSHOT_PROMPT + " " + resolveSnapshot); + } else { + resolveSnapshot = prompter.get().prompt(RESOLVE_SNAPSHOT_PROMPT, Arrays.asList("yes", "no"), "no"); } } - if ( resolveSnapshot.toLowerCase( Locale.ENGLISH ).startsWith( "y" ) ) - { - if ( resolveSnapshotType == null ) - { - prompter.get().showMessage( RESOLVE_SNAPSHOT_TYPE_MESSAGE ); + if (resolveSnapshot.toLowerCase(Locale.ENGLISH).startsWith("y")) { + if (resolveSnapshotType == null) { + prompter.get().showMessage(RESOLVE_SNAPSHOT_TYPE_MESSAGE); int defaultAnswer = -1; - if ( autoResolveSnapshots != null ) - { - if ( "all".equalsIgnoreCase( autoResolveSnapshots ) ) - { + if (autoResolveSnapshots != null) { + if ("all".equalsIgnoreCase(autoResolveSnapshots)) { defaultAnswer = 0; - } - else if ( "dependencies".equalsIgnoreCase( autoResolveSnapshots ) ) - { + } else if ("dependencies".equalsIgnoreCase(autoResolveSnapshots)) { defaultAnswer = 1; - } - else if ( "plugins".equalsIgnoreCase( autoResolveSnapshots ) ) - { + } else if ("plugins".equalsIgnoreCase(autoResolveSnapshots)) { defaultAnswer = 2; - } - else if ( "reports".equalsIgnoreCase( autoResolveSnapshots ) ) - { + } else if ("reports".equalsIgnoreCase(autoResolveSnapshots)) { defaultAnswer = 3; - } - else if ( "extensions".equalsIgnoreCase( autoResolveSnapshots ) ) - { + } else if ("extensions".equalsIgnoreCase(autoResolveSnapshots)) { defaultAnswer = 4; - } - else - { - try - { - defaultAnswer = Integer.parseInt( autoResolveSnapshots ); - } - catch ( NumberFormatException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } else { + try { + defaultAnswer = Integer.parseInt(autoResolveSnapshots); + } catch (NumberFormatException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } } } - if ( defaultAnswer >= 0 && defaultAnswer <= 4 ) - { - prompter.get().showMessage( RESOLVE_SNAPSHOT_TYPE_PROMPT + " " + autoResolveSnapshots ); - resolveSnapshotType = Integer.toString( defaultAnswer ); - } - else - { - resolveSnapshotType = - prompter.get() - .prompt( RESOLVE_SNAPSHOT_TYPE_PROMPT, Arrays.asList( "0", "1", "2", "3" ), - "1" ); + if (defaultAnswer >= 0 && defaultAnswer <= 4) { + prompter.get().showMessage(RESOLVE_SNAPSHOT_TYPE_PROMPT + " " + autoResolveSnapshots); + resolveSnapshotType = Integer.toString(defaultAnswer); + } else { + resolveSnapshotType = prompter.get() + .prompt(RESOLVE_SNAPSHOT_TYPE_PROMPT, Arrays.asList("0", "1", "2", "3"), "1"); } } - switch ( Integer.parseInt( resolveSnapshotType.toLowerCase( Locale.ENGLISH ) ) ) - { - // all + switch (Integer.parseInt(resolveSnapshotType.toLowerCase(Locale.ENGLISH))) { + // all case 0: - processSnapshot( projectDependencies, releaseDescriptor, autoResolveSnapshots ); - processSnapshot( pluginDependencies, releaseDescriptor, autoResolveSnapshots ); - processSnapshot( reportDependencies, releaseDescriptor, autoResolveSnapshots ); - processSnapshot( extensionDependencies, releaseDescriptor, autoResolveSnapshots ); + processSnapshot(projectDependencies, releaseDescriptor, autoResolveSnapshots); + processSnapshot(pluginDependencies, releaseDescriptor, autoResolveSnapshots); + processSnapshot(reportDependencies, releaseDescriptor, autoResolveSnapshots); + processSnapshot(extensionDependencies, releaseDescriptor, autoResolveSnapshots); break; - // project dependencies + // project dependencies case 1: - processSnapshot( projectDependencies, releaseDescriptor, autoResolveSnapshots ); + processSnapshot(projectDependencies, releaseDescriptor, autoResolveSnapshots); break; - // plugins + // plugins case 2: - processSnapshot( pluginDependencies, releaseDescriptor, autoResolveSnapshots ); + processSnapshot(pluginDependencies, releaseDescriptor, autoResolveSnapshots); break; - // reports + // reports case 3: - processSnapshot( reportDependencies, releaseDescriptor, autoResolveSnapshots ); + processSnapshot(reportDependencies, releaseDescriptor, autoResolveSnapshots); break; - // extensions + // extensions case 4: - processSnapshot( extensionDependencies, releaseDescriptor, autoResolveSnapshots ); + processSnapshot(extensionDependencies, releaseDescriptor, autoResolveSnapshots); break; default: } } - } - catch ( PrompterException | VersionParseException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } catch (PrompterException | VersionParseException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } } - private void processSnapshot( Set snapshotSet, ReleaseDescriptor releaseDescriptor, - String autoResolveSnapshots ) - throws PrompterException, VersionParseException - { + private void processSnapshot( + Set snapshotSet, ReleaseDescriptor releaseDescriptor, String autoResolveSnapshots) + throws PrompterException, VersionParseException { Iterator iterator = snapshotSet.iterator(); - while ( iterator.hasNext() ) - { + while (iterator.hasNext()) { Artifact currentArtifact = iterator.next(); - String versionlessKey = ArtifactUtils.versionlessKey( currentArtifact ); + String versionlessKey = ArtifactUtils.versionlessKey(currentArtifact); - VersionInfo versionInfo = new DefaultVersionInfo( currentArtifact.getBaseVersion() ); - releaseDescriptor.addDependencyOriginalVersion( versionlessKey, versionInfo.toString() ); + VersionInfo versionInfo = new DefaultVersionInfo(currentArtifact.getBaseVersion()); + releaseDescriptor.addDependencyOriginalVersion(versionlessKey, versionInfo.toString()); - prompter.get().showMessage( - "Dependency '" + versionlessKey + "' is a snapshot (" + currentArtifact.getVersion() + ")\n" ); + prompter.get() + .showMessage("Dependency '" + versionlessKey + "' is a snapshot (" + currentArtifact.getVersion() + + ")\n"); String message = "Which release version should it be set to?"; String result; - if ( null != autoResolveSnapshots ) - { + if (null != autoResolveSnapshots) { result = versionInfo.getReleaseVersionString(); - prompter.get().showMessage( message + " " + result ); - } - else - { - result = prompter.get().prompt( message, versionInfo.getReleaseVersionString() ); + prompter.get().showMessage(message + " " + result); + } else { + result = prompter.get().prompt(message, versionInfo.getReleaseVersionString()); } - releaseDescriptor.addDependencyReleaseVersion( versionlessKey, result ); + releaseDescriptor.addDependencyReleaseVersion(versionlessKey, result); iterator.remove(); // by default, keep the same version for the dependency after release, unless it was previously newer // the user may opt to type in something different - VersionInfo nextVersionInfo = new DefaultVersionInfo( result ); + VersionInfo nextVersionInfo = new DefaultVersionInfo(result); String nextVersion; - if ( nextVersionInfo.compareTo( versionInfo ) > 0 ) - { + if (nextVersionInfo.compareTo(versionInfo) > 0) { nextVersion = nextVersionInfo.toString(); - } - else - { + } else { nextVersion = versionInfo.toString(); } message = "What version should the dependency be reset to for development?"; - if ( null != autoResolveSnapshots ) - { + if (null != autoResolveSnapshots) { result = nextVersion; - prompter.get().showMessage( message + " " + result ); - } - else - { - result = prompter.get().prompt( message, nextVersion ); + prompter.get().showMessage(message + " " + result); + } else { + result = prompter.get().prompt(message, nextVersion); } - releaseDescriptor.addDependencyDevelopmentVersion( versionlessKey, result ); + releaseDescriptor.addDependencyDevelopmentVersion(versionlessKey, result); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsPhase.java index f1f15c6b6..736cc213b 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -31,13 +30,10 @@ * @author Brett Porter */ @Singleton -@Named( "check-poms" ) -public class CheckPomsPhase - extends AbstractCheckPomPhase -{ +@Named("check-poms") +public class CheckPomsPhase extends AbstractCheckPomPhase { @Inject - public CheckPomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator, true, true ); + public CheckPomsPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super(scmRepositoryConfigurator, true, true); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsUpdateversionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsUpdateversionsPhase.java index 108e5ba0a..d27976a31 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsUpdateversionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckPomsUpdateversionsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -31,13 +30,10 @@ * @author Brett Porter */ @Singleton -@Named( "check-poms-updateversions" ) -public class CheckPomsUpdateversionsPhase - extends AbstractCheckPomPhase -{ +@Named("check-poms-updateversions") +public class CheckPomsUpdateversionsPhase extends AbstractCheckPomPhase { @Inject - public CheckPomsUpdateversionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator, false, false ); + public CheckPomsUpdateversionsPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super(scmRepositoryConfigurator, false, false); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java index 719610d72..b233c60b1 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScm.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -60,234 +59,206 @@ * @author Emmanuel Venisse */ @Singleton -@Named( "checkout-project-from-scm" ) -public class CheckoutProjectFromScm - extends AbstractReleasePhase -{ +@Named("checkout-project-from-scm") +public class CheckoutProjectFromScm extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ private final ScmRepositoryConfigurator scmRepositoryConfigurator; @Inject - public CheckoutProjectFromScm( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); + public CheckoutProjectFromScm(ScmRepositoryConfigurator scmRepositoryConfigurator) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult releaseResult; - if ( releaseDescriptor.isLocalCheckout() ) - { + if (releaseDescriptor.isLocalCheckout()) { // in the release phase we have to change the checkout URL // to do a local checkout instead of going over the network. // the first step is a bit tricky, we need to know which provider! like e.g. "scm:jgit:http://" // the offset of 4 is because 'scm:' has 4 characters... - String providerPart = releaseDescriptor.getScmSourceUrl() - .substring( 0, releaseDescriptor.getScmSourceUrl().indexOf( ':', 4 ) ); + String providerPart = releaseDescriptor + .getScmSourceUrl() + .substring(0, releaseDescriptor.getScmSourceUrl().indexOf(':', 4)); String scmPath = releaseDescriptor.getWorkingDirectory(); // now we iteratively try to checkout. // if the local checkout fails, then we might be in a subdirectory // and need to walk a few directories up. - do - { - try - { - if ( scmPath.startsWith( "/" ) ) - { + do { + try { + if (scmPath.startsWith("/")) { // cut off the first '/' - scmPath = scmPath.substring( 1 ); + scmPath = scmPath.substring(1); } String scmUrl = providerPart + ":file:///" + scmPath; - releaseDescriptor.setScmSourceUrl( scmUrl ); - getLogger().info( "Performing a LOCAL checkout from " + releaseDescriptor.getScmSourceUrl() ); + releaseDescriptor.setScmSourceUrl(scmUrl); + getLogger().info("Performing a LOCAL checkout from " + releaseDescriptor.getScmSourceUrl()); - releaseResult = performCheckout( releaseDescriptor, releaseEnvironment, reactorProjects ); - } - catch ( ScmException scmEx ) - { + releaseResult = performCheckout(releaseDescriptor, releaseEnvironment, reactorProjects); + } catch (ScmException scmEx) { // the checkout from _this_ directory failed releaseResult = null; } - if ( releaseResult == null || releaseResult.getResultCode() == ReleaseResult.ERROR ) - { + if (releaseResult == null || releaseResult.getResultCode() == ReleaseResult.ERROR) { // this means that there is no SCM repo in this directory // thus we try to step one directory up releaseResult = null; // remove last sub-directory path - int lastSlashPos = scmPath.lastIndexOf( File.separator ); - if ( lastSlashPos > 0 ) - { - scmPath = scmPath.substring( 0, lastSlashPos ); - } - else - { - throw new ReleaseExecutionException( "could not perform a local checkout" ); + int lastSlashPos = scmPath.lastIndexOf(File.separator); + if (lastSlashPos > 0) { + scmPath = scmPath.substring(0, lastSlashPos); + } else { + throw new ReleaseExecutionException("could not perform a local checkout"); } } - } - while ( releaseResult == null ); - } - else - { + } while (releaseResult == null); + } else { // when there is no localCheckout, then we just do a standard SCM checkout. - try - { - releaseResult = performCheckout( releaseDescriptor, releaseEnvironment, reactorProjects ); - } - catch ( ScmException e ) - { + try { + releaseResult = performCheckout(releaseDescriptor, releaseEnvironment, reactorProjects); + } catch (ScmException e) { releaseResult = new ReleaseResult(); - releaseResult.setResultCode( ReleaseResult.ERROR ); - logError( releaseResult, e.getMessage() ); + releaseResult.setResultCode(ReleaseResult.ERROR); + logError(releaseResult, e.getMessage()); - throw new ReleaseExecutionException( "An error is occurred in the checkout process: " - + e.getMessage(), e ); + throw new ReleaseExecutionException( + "An error is occurred in the checkout process: " + e.getMessage(), e); } - } return releaseResult; } - - private ReleaseResult performCheckout( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException, ScmException - { + private ReleaseResult performCheckout( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException, ScmException { ReleaseResult result = new ReleaseResult(); - logInfo( result, "Checking out the project to perform the release ..." ); + logInfo(result, "Checking out the project to perform the release ..."); ScmRepository repository; ScmProvider provider; - try - { - repository = scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); + try { + repository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); - } - catch ( ScmRepositoryException e ) - { - result.setResultCode( ReleaseResult.ERROR ); - logError( result, e.getMessage() ); + provider = scmRepositoryConfigurator.getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { + result.setResultCode(ReleaseResult.ERROR); + logError(result, e.getMessage()); - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - result.setResultCode( ReleaseResult.ERROR ); - logError( result, e.getMessage() ); + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + result.setResultCode(ReleaseResult.ERROR); + logError(result, e.getMessage()); - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); // TODO: sanity check that it is not . or .. or lower File checkoutDirectory = - FileUtils.resolveFile( rootProject.getBasedir(), releaseDescriptor.getCheckoutDirectory() ); + FileUtils.resolveFile(rootProject.getBasedir(), releaseDescriptor.getCheckoutDirectory()); - if ( checkoutDirectory.exists() ) - { - try - { - FileUtils.deleteDirectory( checkoutDirectory ); - } - catch ( IOException e ) - { - result.setResultCode( ReleaseResult.ERROR ); - logError( result, e.getMessage() ); + if (checkoutDirectory.exists()) { + try { + FileUtils.deleteDirectory(checkoutDirectory); + } catch (IOException e) { + result.setResultCode(ReleaseResult.ERROR); + logError(result, e.getMessage()); - throw new ReleaseExecutionException( "Unable to remove old checkout directory: " + e.getMessage(), e ); + throw new ReleaseExecutionException("Unable to remove old checkout directory: " + e.getMessage(), e); } } checkoutDirectory.mkdirs(); CommandParameters commandParameters = new CommandParameters(); - commandParameters.setString( CommandParameter.SHALLOW, - Boolean.valueOf( releaseDescriptor.isScmShallowClone() ).toString() ); + commandParameters.setString( + CommandParameter.SHALLOW, + Boolean.valueOf(releaseDescriptor.isScmShallowClone()).toString()); - CheckOutScmResult scmResult = provider.checkOut( repository, new ScmFileSet( checkoutDirectory ), - new ScmTag( releaseDescriptor.getScmReleaseLabel() ), commandParameters ); + CheckOutScmResult scmResult = provider.checkOut( + repository, + new ScmFileSet(checkoutDirectory), + new ScmTag(releaseDescriptor.getScmReleaseLabel()), + commandParameters); - if ( releaseDescriptor.isLocalCheckout() && !scmResult.isSuccess() ) - { + if (releaseDescriptor.isLocalCheckout() && !scmResult.isSuccess()) { // this is not beautiful but needed to indicate that the execute() method // should continue in the parent directory return null; } String scmRelativePathProjectDirectory = scmResult.getRelativePathProjectDirectory(); - if ( StringUtils.isEmpty( scmRelativePathProjectDirectory ) ) - { - Path workingDirectory = Paths.get( releaseDescriptor.getWorkingDirectory() ); + if (StringUtils.isEmpty(scmRelativePathProjectDirectory)) { + Path workingDirectory = Paths.get(releaseDescriptor.getWorkingDirectory()); Path rootProjectBasedir; - try - { - rootProjectBasedir = rootProject.getBasedir().toPath().toRealPath( LinkOption.NOFOLLOW_LINKS ); - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + try { + rootProjectBasedir = rootProject.getBasedir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); + } catch (IOException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } - scmRelativePathProjectDirectory = workingDirectory.relativize( rootProjectBasedir ).toString(); + scmRelativePathProjectDirectory = + workingDirectory.relativize(rootProjectBasedir).toString(); } - releaseDescriptor.setScmRelativePathProjectDirectory( scmRelativePathProjectDirectory ); + releaseDescriptor.setScmRelativePathProjectDirectory(scmRelativePathProjectDirectory); - if ( !scmResult.isSuccess() ) - { - result.setResultCode( ReleaseResult.ERROR ); - logError( result, scmResult.getProviderMessage() ); + if (!scmResult.isSuccess()) { + result.setResultCode(ReleaseResult.ERROR); + logError(result, scmResult.getProviderMessage()); - throw new ReleaseScmCommandException( "Unable to checkout from SCM", scmResult ); + throw new ReleaseScmCommandException("Unable to checkout from SCM", scmResult); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); File checkoutDirectory = - FileUtils.resolveFile( rootProject.getBasedir(), releaseDescriptor.getCheckoutDirectory() ); - - if ( releaseDescriptor.isLocalCheckout() ) - { - logInfo( result, - "The project would have a " + buffer().strong( "local" ) - + " check out to perform the release from " + checkoutDirectory + "..." ); - } - else - { - logInfo( result, - "The project would be checked out to perform the release from " + checkoutDirectory + "..." ); + FileUtils.resolveFile(rootProject.getBasedir(), releaseDescriptor.getCheckoutDirectory()); + + if (releaseDescriptor.isLocalCheckout()) { + logInfo( + result, + "The project would have a " + buffer().strong("local") + " check out to perform the release from " + + checkoutDirectory + "..."); + } else { + logInfo( + result, + "The project would be checked out to perform the release from " + checkoutDirectory + "..."); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhase.java index 3a9ba41be..7e9ad94ea 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Named; import javax.inject.Singleton; @@ -38,68 +37,60 @@ * @author Edwin Punzalan */ @Singleton -@Named( "create-backup-poms" ) -public class CreateBackupPomsPhase - extends AbstractBackupPomsPhase implements ResourceGenerator -{ +@Named("create-backup-poms") +public class CreateBackupPomsPhase extends AbstractBackupPomsPhase implements ResourceGenerator { @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); // remove previous backups, if any - clean( reactorProjects ); + clean(reactorProjects); - logInfo( result, "Creating pom.xml backup with " + BACKUP_SUFFIX + " suffix" ); + logInfo(result, "Creating pom.xml backup with " + BACKUP_SUFFIX + " suffix"); - for ( MavenProject project : reactorProjects ) - { - createPomBackup( project ); + for (MavenProject project : reactorProjects) { + createPomBackup(project); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult clean( List reactorProjects ) - { + public ReleaseResult clean(List reactorProjects) { ReleaseResult result = new ReleaseResult(); - for ( MavenProject project : reactorProjects ) - { - deletePomBackup( project ); + for (MavenProject project : reactorProjects) { + deletePomBackup(project); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects); } - private void createPomBackup( MavenProject project ) - throws ReleaseExecutionException - { + private void createPomBackup(MavenProject project) throws ReleaseExecutionException { // delete any existing backup first - deletePomBackup( project ); + deletePomBackup(project); - try - { - FileUtils.copyFile( ReleaseUtil.getStandardPom( project ), getPomBackup( project ) ); - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( "Error creating backup POM: " + e.getMessage(), e ); + try { + FileUtils.copyFile(ReleaseUtil.getStandardPom(project), getPomBackup(project)); + } catch (IOException e) { + throw new ReleaseExecutionException("Error creating backup POM: " + e.getMessage(), e); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/EndReleasePhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/EndReleasePhase.java index b55cf2f93..cea0082f5 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/EndReleasePhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/EndReleasePhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Named; import javax.inject.Singleton; @@ -37,34 +36,34 @@ * @author Brett Porter */ @Singleton -@Named( "end-release" ) -public class EndReleasePhase - extends AbstractReleasePhase -{ +@Named("end-release") +public class EndReleasePhase extends AbstractReleasePhase { @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - logInfo( result, "Release preparation complete." ); + logInfo(result, "Release preparation complete."); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - logInfo( result, "Release preparation simulation complete." ); + logInfo(result, "Release preparation simulation complete."); - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java index 9a2ec0f9e..af4dd4624 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -77,10 +76,8 @@ * @author Mark Hobson */ @Singleton -@Named( "generate-release-poms" ) -public class GenerateReleasePomsPhase - extends AbstractReleasePomsPhase implements ResourceGenerator -{ +@Named("generate-release-poms") +public class GenerateReleasePomsPhase extends AbstractReleasePomsPhase implements ResourceGenerator { private static final String FINALNAME_EXPRESSION = "${project.artifactId}-${project.version}"; private final SuperPomProvider superPomProvider; @@ -95,13 +92,13 @@ public class GenerateReleasePomsPhase @Inject public GenerateReleasePomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - SuperPomProvider superPomProvider, ModelInterpolator modelInterpolator, - Map scmTranslators ) - { - super( scmRepositoryConfigurator ); - this.superPomProvider = requireNonNull( superPomProvider ); - this.modelInterpolator = requireNonNull( modelInterpolator ); - this.scmTranslators = requireNonNull( scmTranslators ); + SuperPomProvider superPomProvider, + ModelInterpolator modelInterpolator, + Map scmTranslators) { + super(scmRepositoryConfigurator); + this.superPomProvider = requireNonNull(superPomProvider); + this.modelInterpolator = requireNonNull(modelInterpolator); + this.scmTranslators = requireNonNull(scmTranslators); } /* @@ -109,347 +106,327 @@ public GenerateReleasePomsPhase( * org.apache.maven.settings.Settings, java.util.List) */ @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects, false ); + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects, false); } - private ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, boolean simulate ) - throws ReleaseExecutionException, ReleaseFailureException - { + private ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + boolean simulate) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - if ( releaseDescriptor.isGenerateReleasePoms() ) - { - logInfo( result, "Generating release POMs..." ); + if (releaseDescriptor.isGenerateReleasePoms()) { + logInfo(result, "Generating release POMs..."); - generateReleasePoms( releaseDescriptor, releaseEnvironment, reactorProjects, simulate, result ); - } - else - { - logInfo( result, "Not generating release POMs" ); + generateReleasePoms(releaseDescriptor, releaseEnvironment, reactorProjects, simulate, result); + } else { + logInfo(result, "Not generating release POMs"); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private void generateReleasePoms( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, boolean simulate, ReleaseResult result ) - throws ReleaseExecutionException, ReleaseFailureException - { + private void generateReleasePoms( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + boolean simulate, + ReleaseResult result) + throws ReleaseExecutionException, ReleaseFailureException { List releasePoms = new ArrayList<>(); - for ( MavenProject project : reactorProjects ) - { - logInfo( result, "Generating release POM for '" + project.getName() + "'..." ); + for (MavenProject project : reactorProjects) { + logInfo(result, "Generating release POM for '" + project.getName() + "'..."); - releasePoms.add( generateReleasePom( project, releaseDescriptor, releaseEnvironment, result ) ); + releasePoms.add(generateReleasePom(project, releaseDescriptor, releaseEnvironment, result)); } - addReleasePomsToScm( releaseDescriptor, releaseEnvironment, reactorProjects, simulate, result, releasePoms ); + addReleasePomsToScm(releaseDescriptor, releaseEnvironment, reactorProjects, simulate, result, releasePoms); } - private File generateReleasePom( MavenProject project, ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment, - ReleaseResult result ) - throws ReleaseExecutionException, ReleaseFailureException - { + private File generateReleasePom( + MavenProject project, + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + ReleaseResult result) + throws ReleaseExecutionException, ReleaseFailureException { // create release pom - Model releasePom = createReleaseModel( project, releaseDescriptor, releaseEnvironment, result ); + Model releasePom = createReleaseModel(project, releaseDescriptor, releaseEnvironment, result); // write release pom to file MavenXpp3Writer pomWriter = new MavenXpp3Writer(); - File releasePomFile = ReleaseUtil.getReleasePom( project ); + File releasePomFile = ReleaseUtil.getReleasePom(project); // MRELEASE-273 : A release pom can be null - if ( releasePomFile == null ) - { - throw new ReleaseExecutionException( "Cannot generate release POM : pom file is null" ); + if (releasePomFile == null) { + throw new ReleaseExecutionException("Cannot generate release POM : pom file is null"); } - - try ( Writer fileWriter = WriterFactory.newXmlWriter( releasePomFile ) ) - { - pomWriter.write( fileWriter, releasePom ); - } - catch ( IOException exception ) - { - throw new ReleaseExecutionException( "Cannot generate release POM", exception ); + try (Writer fileWriter = WriterFactory.newXmlWriter(releasePomFile)) { + pomWriter.write(fileWriter, releasePom); + } catch (IOException exception) { + throw new ReleaseExecutionException("Cannot generate release POM", exception); } return releasePomFile; } - private void addReleasePomsToScm( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, boolean simulate, ReleaseResult result, - List releasePoms ) - throws ReleaseFailureException, ReleaseExecutionException - { - if ( simulate ) - { - logInfo( result, "Full run would be adding " + releasePoms ); - } - else - { - ScmRepository scmRepository = getScmRepository( releaseDescriptor, releaseEnvironment ); - ScmProvider scmProvider = getScmProvider( scmRepository ); - - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - ScmFileSet scmFileSet = new ScmFileSet( rootProject.getFile().getParentFile(), releasePoms ); - - try - { - AddScmResult scmResult = scmProvider.add( scmRepository, scmFileSet ); - - if ( !scmResult.isSuccess() ) - { - throw new ReleaseScmCommandException( "Cannot add release POM to SCM", scmResult ); + private void addReleasePomsToScm( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + boolean simulate, + ReleaseResult result, + List releasePoms) + throws ReleaseFailureException, ReleaseExecutionException { + if (simulate) { + logInfo(result, "Full run would be adding " + releasePoms); + } else { + ScmRepository scmRepository = getScmRepository(releaseDescriptor, releaseEnvironment); + ScmProvider scmProvider = getScmProvider(scmRepository); + + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + ScmFileSet scmFileSet = new ScmFileSet(rootProject.getFile().getParentFile(), releasePoms); + + try { + AddScmResult scmResult = scmProvider.add(scmRepository, scmFileSet); + + if (!scmResult.isSuccess()) { + throw new ReleaseScmCommandException("Cannot add release POM to SCM", scmResult); } - } - catch ( ScmException exception ) - { - throw new ReleaseExecutionException( "Cannot add release POM to SCM: " + exception.getMessage(), - exception ); + } catch (ScmException exception) { + throw new ReleaseExecutionException( + "Cannot add release POM to SCM: " + exception.getMessage(), exception); } } } - private Model createReleaseModel( MavenProject project, ReleaseDescriptor releaseDescriptor, - ReleaseEnvironment releaseEnvironment, - ReleaseResult result ) - throws ReleaseFailureException, ReleaseExecutionException - { + private Model createReleaseModel( + MavenProject project, + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + ReleaseResult result) + throws ReleaseFailureException, ReleaseExecutionException { MavenProject releaseProject = project.clone(); Model releaseModel = releaseProject.getModel(); // the release POM should reflect bits of these which were injected at build time... // we don't need these polluting the POM. - releaseModel.setParent( null ); - releaseModel.setProfiles( Collections.emptyList() ); - releaseModel.setDependencyManagement( null ); - releaseProject.getBuild().setPluginManagement( null ); + releaseModel.setParent(null); + releaseModel.setProfiles(Collections.emptyList()); + releaseModel.setDependencyManagement(null); + releaseProject.getBuild().setPluginManagement(null); // update project version String projectVersion = releaseModel.getVersion(); - String releaseVersion = - getNextVersion( releaseDescriptor, project.getGroupId(), project.getArtifactId() ); - releaseModel.setVersion( releaseVersion ); + String releaseVersion = getNextVersion(releaseDescriptor, project.getGroupId(), project.getArtifactId()); + releaseModel.setVersion(releaseVersion); String originalFinalName = releaseModel.getBuild().getFinalName(); // update final name if implicit - if ( !FINALNAME_EXPRESSION.equals( originalFinalName ) ) - { - originalFinalName = findOriginalFinalName( project ); + if (!FINALNAME_EXPRESSION.equals(originalFinalName)) { + originalFinalName = findOriginalFinalName(project); - if ( originalFinalName == null ) - { + if (originalFinalName == null) { // as defined in super-pom originalFinalName = FINALNAME_EXPRESSION; } } // make finalName always explicit - String finalName = ReleaseUtil.interpolate( originalFinalName, releaseModel ); + String finalName = ReleaseUtil.interpolate(originalFinalName, releaseModel); // still required? - if ( finalName.contains( Artifact.SNAPSHOT_VERSION ) ) - { - throw new ReleaseFailureException( "Cannot reliably adjust the finalName of project: " - + releaseProject.getId() ); + if (finalName.contains(Artifact.SNAPSHOT_VERSION)) { + throw new ReleaseFailureException( + "Cannot reliably adjust the finalName of project: " + releaseProject.getId()); } - releaseModel.getBuild().setFinalName( finalName ); - + releaseModel.getBuild().setFinalName(finalName); // update scm Scm scm = releaseModel.getScm(); - if ( scm != null ) - { - ScmRepository scmRepository = getScmRepository( releaseDescriptor, releaseEnvironment ); - ScmTranslator scmTranslator = getScmTranslator( scmRepository ); + if (scm != null) { + ScmRepository scmRepository = getScmRepository(releaseDescriptor, releaseEnvironment); + ScmTranslator scmTranslator = getScmTranslator(scmRepository); - if ( scmTranslator != null ) - { - releaseModel.setScm( createReleaseScm( releaseModel.getScm(), scmTranslator, releaseDescriptor ) ); - } - else - { + if (scmTranslator != null) { + releaseModel.setScm(createReleaseScm(releaseModel.getScm(), scmTranslator, releaseDescriptor)); + } else { String message = "No SCM translator found - skipping rewrite"; - result.appendDebug( message ); + result.appendDebug(message); - getLogger().debug( message ); + getLogger().debug(message); } } // rewrite dependencies - releaseModel.setDependencies( createReleaseDependencies( releaseDescriptor, releaseProject ) ); + releaseModel.setDependencies(createReleaseDependencies(releaseDescriptor, releaseProject)); // rewrite plugins - releaseModel.getBuild().setPlugins( createReleasePlugins( releaseDescriptor, releaseProject ) ); + releaseModel.getBuild().setPlugins(createReleasePlugins(releaseDescriptor, releaseProject)); // rewrite reports - releaseModel.getReporting().setPlugins( createReleaseReportPlugins( releaseDescriptor, - releaseProject ) ); + releaseModel.getReporting().setPlugins(createReleaseReportPlugins(releaseDescriptor, releaseProject)); // rewrite extensions - releaseModel.getBuild().setExtensions( createReleaseExtensions( releaseDescriptor, - releaseProject ) ); + releaseModel.getBuild().setExtensions(createReleaseExtensions(releaseDescriptor, releaseProject)); - unalignFromBaseDirectory( releaseModel, project.getBasedir() ); + unalignFromBaseDirectory(releaseModel, project.getBasedir()); return releaseModel; } - - private void unalignFromBaseDirectory( Model releaseModel, File basedir ) - { - Model rawSuperModel = superPomProvider.getSuperModel( releaseModel.getModelVersion() ); + private void unalignFromBaseDirectory(Model releaseModel, File basedir) { + Model rawSuperModel = superPomProvider.getSuperModel(releaseModel.getModelVersion()); ModelBuildingRequest buildingRequest = new DefaultModelBuildingRequest(); - buildingRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); + buildingRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT); // inject proper values used by project.build.finalName Properties properties = new Properties(); - properties.put( "project.version", releaseModel.getVersion() ); - properties.put( "project.artifactId", releaseModel.getArtifactId() ); - buildingRequest.setUserProperties( properties ); + properties.put("project.version", releaseModel.getVersion()); + properties.put("project.artifactId", releaseModel.getArtifactId()); + buildingRequest.setUserProperties(properties); Model interpolatedSuperModel = - modelInterpolator.interpolateModel( rawSuperModel.clone(), basedir, buildingRequest, null ); + modelInterpolator.interpolateModel(rawSuperModel.clone(), basedir, buildingRequest, null); Build currentBuild = releaseModel.getBuild(); Build interpolatedSuperBuild = interpolatedSuperModel.getBuild(); Build rawSuperBuild = rawSuperModel.getBuild(); - currentBuild.setSourceDirectory( resolvePath( basedir.toPath(), currentBuild.getSourceDirectory(), + currentBuild.setSourceDirectory(resolvePath( + basedir.toPath(), + currentBuild.getSourceDirectory(), interpolatedSuperBuild.getSourceDirectory(), - rawSuperBuild.getSourceDirectory() ) ); - currentBuild.setScriptSourceDirectory( resolvePath( basedir.toPath(), currentBuild.getScriptSourceDirectory(), + rawSuperBuild.getSourceDirectory())); + currentBuild.setScriptSourceDirectory(resolvePath( + basedir.toPath(), + currentBuild.getScriptSourceDirectory(), interpolatedSuperBuild.getScriptSourceDirectory(), - rawSuperBuild.getScriptSourceDirectory() ) ); - currentBuild.setTestSourceDirectory( resolvePath( basedir.toPath(), currentBuild.getTestSourceDirectory(), + rawSuperBuild.getScriptSourceDirectory())); + currentBuild.setTestSourceDirectory(resolvePath( + basedir.toPath(), + currentBuild.getTestSourceDirectory(), interpolatedSuperBuild.getTestSourceDirectory(), - rawSuperBuild.getTestSourceDirectory() ) ); - currentBuild.setOutputDirectory( resolvePath( basedir.toPath(), currentBuild.getOutputDirectory(), + rawSuperBuild.getTestSourceDirectory())); + currentBuild.setOutputDirectory(resolvePath( + basedir.toPath(), + currentBuild.getOutputDirectory(), interpolatedSuperBuild.getOutputDirectory(), - rawSuperBuild.getOutputDirectory() ) ); - currentBuild.setTestOutputDirectory( resolvePath( basedir.toPath(), currentBuild.getTestOutputDirectory(), + rawSuperBuild.getOutputDirectory())); + currentBuild.setTestOutputDirectory(resolvePath( + basedir.toPath(), + currentBuild.getTestOutputDirectory(), interpolatedSuperBuild.getTestOutputDirectory(), - rawSuperBuild.getTestOutputDirectory() ) ); - currentBuild.setDirectory( resolvePath( basedir.toPath(), currentBuild.getDirectory(), + rawSuperBuild.getTestOutputDirectory())); + currentBuild.setDirectory(resolvePath( + basedir.toPath(), + currentBuild.getDirectory(), interpolatedSuperBuild.getDirectory(), - rawSuperBuild.getDirectory() ) ); + rawSuperBuild.getDirectory())); - for ( Resource currentResource : currentBuild.getResources() ) - { + for (Resource currentResource : currentBuild.getResources()) { Map superResourceDirectories = - new LinkedHashMap<>( interpolatedSuperBuild.getResources().size() ); - for ( int i = 0; i < interpolatedSuperBuild.getResources().size(); i++ ) - { - superResourceDirectories.put( interpolatedSuperBuild.getResources().get( i ).getDirectory(), - rawSuperBuild.getResources().get( i ).getDirectory() ); + new LinkedHashMap<>(interpolatedSuperBuild.getResources().size()); + for (int i = 0; i < interpolatedSuperBuild.getResources().size(); i++) { + superResourceDirectories.put( + interpolatedSuperBuild.getResources().get(i).getDirectory(), + rawSuperBuild.getResources().get(i).getDirectory()); } - currentResource.setDirectory( resolvePath( basedir.toPath(), currentResource.getDirectory(), - superResourceDirectories ) ); + currentResource.setDirectory( + resolvePath(basedir.toPath(), currentResource.getDirectory(), superResourceDirectories)); } - for ( Resource currentResource : currentBuild.getTestResources() ) - { - Map superResourceDirectories = - new LinkedHashMap<>( interpolatedSuperBuild.getTestResources().size() ); - for ( int i = 0; i < interpolatedSuperBuild.getTestResources().size(); i++ ) - { - superResourceDirectories.put( interpolatedSuperBuild.getTestResources().get( i ).getDirectory(), - rawSuperBuild.getTestResources().get( i ).getDirectory() ); + for (Resource currentResource : currentBuild.getTestResources()) { + Map superResourceDirectories = new LinkedHashMap<>( + interpolatedSuperBuild.getTestResources().size()); + for (int i = 0; i < interpolatedSuperBuild.getTestResources().size(); i++) { + superResourceDirectories.put( + interpolatedSuperBuild.getTestResources().get(i).getDirectory(), + rawSuperBuild.getTestResources().get(i).getDirectory()); } - currentResource.setDirectory( resolvePath( basedir.toPath(), currentResource.getDirectory(), - superResourceDirectories ) ); + currentResource.setDirectory( + resolvePath(basedir.toPath(), currentResource.getDirectory(), superResourceDirectories)); } - - releaseModel.getReporting().setOutputDirectory( resolvePath( basedir.toPath(), - releaseModel.getReporting().getOutputDirectory(), - interpolatedSuperModel.getReporting().getOutputDirectory(), - rawSuperModel.getReporting().getOutputDirectory() ) ); + releaseModel + .getReporting() + .setOutputDirectory(resolvePath( + basedir.toPath(), + releaseModel.getReporting().getOutputDirectory(), + interpolatedSuperModel.getReporting().getOutputDirectory(), + rawSuperModel.getReporting().getOutputDirectory())); } - private String resolvePath( Path basedir, String current, String superInterpolated, String superRaw ) - { - return basedir.resolve( current ).equals( basedir.resolve( superInterpolated ) ) ? superRaw : current; + private String resolvePath(Path basedir, String current, String superInterpolated, String superRaw) { + return basedir.resolve(current).equals(basedir.resolve(superInterpolated)) ? superRaw : current; } - private String resolvePath( Path basedir, - String current, - Map superValues ) - { - for ( Map.Entry superValue : superValues.entrySet() ) - { - if ( basedir.resolve( current ).equals( basedir.resolve( superValue.getKey() ) ) ) - { + private String resolvePath( + Path basedir, String current, Map superValues) { + for (Map.Entry superValue : superValues.entrySet()) { + if (basedir.resolve(current).equals(basedir.resolve(superValue.getKey()))) { return superValue.getValue(); } } return current; } - private String findOriginalFinalName( MavenProject project ) - { - if ( project.getOriginalModel().getBuild() != null - && project.getOriginalModel().getBuild().getFinalName() != null ) - { + private String findOriginalFinalName(MavenProject project) { + if (project.getOriginalModel().getBuild() != null + && project.getOriginalModel().getBuild().getFinalName() != null) { return project.getOriginalModel().getBuild().getFinalName(); - } - else if ( project.hasParent() ) - { - return findOriginalFinalName( project.getParent() ); - } - else - { + } else if (project.hasParent()) { + return findOriginalFinalName(project.getParent()); + } else { return null; } } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects, true ); + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects, true); } - private String getNextVersion( ReleaseDescriptor releaseDescriptor, String groupId, String artifactId ) - throws ReleaseFailureException - { + private String getNextVersion(ReleaseDescriptor releaseDescriptor, String groupId, String artifactId) + throws ReleaseFailureException { // TODO: share with RewritePomsForReleasePhase.rewriteVersion - String id = ArtifactUtils.versionlessKey( groupId, artifactId ); + String id = ArtifactUtils.versionlessKey(groupId, artifactId); - String nextVersion = releaseDescriptor.getProjectReleaseVersion( id ); + String nextVersion = releaseDescriptor.getProjectReleaseVersion(id); - if ( nextVersion == null ) - { - throw new ReleaseFailureException( "Version for '" + id + "' was not mapped" ); + if (nextVersion == null) { + throw new ReleaseFailureException("Version for '" + id + "' was not mapped"); } return nextVersion; } - private ScmTranslator getScmTranslator( ScmRepository scmRepository ) - { - return scmTranslators.get( scmRepository.getProvider() ); + private ScmTranslator getScmTranslator(ScmRepository scmRepository) { + return scmTranslators.get(scmRepository.getProvider()); } - private Scm createReleaseScm( Scm scm, ScmTranslator scmTranslator, ReleaseDescriptor releaseDescriptor ) - { + private Scm createReleaseScm(Scm scm, ScmTranslator scmTranslator, ReleaseDescriptor releaseDescriptor) { // TODO: share with RewritePomsForReleasePhase.translateScm String tag = releaseDescriptor.getScmReleaseLabel(); @@ -457,96 +434,79 @@ private Scm createReleaseScm( Scm scm, ScmTranslator scmTranslator, ReleaseDescr Scm releaseScm = new Scm(); - if ( scm.getConnection() != null ) - { - String value = scmTranslator.translateTagUrl( scm.getConnection(), tag, tagBase ); - releaseScm.setConnection( value ); + if (scm.getConnection() != null) { + String value = scmTranslator.translateTagUrl(scm.getConnection(), tag, tagBase); + releaseScm.setConnection(value); } - if ( scm.getDeveloperConnection() != null ) - { - String value = scmTranslator.translateTagUrl( scm.getDeveloperConnection(), tag, tagBase ); - releaseScm.setDeveloperConnection( value ); + if (scm.getDeveloperConnection() != null) { + String value = scmTranslator.translateTagUrl(scm.getDeveloperConnection(), tag, tagBase); + releaseScm.setDeveloperConnection(value); } - if ( scm.getUrl() != null ) - { - String value = scmTranslator.translateTagUrl( scm.getUrl(), tag, tagBase ); - releaseScm.setUrl( value ); + if (scm.getUrl() != null) { + String value = scmTranslator.translateTagUrl(scm.getUrl(), tag, tagBase); + releaseScm.setUrl(value); } - if ( scm.getTag() != null ) - { - String value = scmTranslator.resolveTag( scm.getTag() ); - releaseScm.setTag( value ); + if (scm.getTag() != null) { + String value = scmTranslator.resolveTag(scm.getTag()); + releaseScm.setTag(value); } return releaseScm; } - private List createReleaseDependencies( ReleaseDescriptor releaseDescriptor, - MavenProject project ) - throws ReleaseFailureException - { + private List createReleaseDependencies(ReleaseDescriptor releaseDescriptor, MavenProject project) + throws ReleaseFailureException { Set artifacts = project.getArtifacts(); List releaseDependencies = null; - if ( artifacts != null ) - { + if (artifacts != null) { // make dependency order deterministic for tests (related to MNG-1412) - List orderedArtifacts = new ArrayList<>( artifacts ); - Collections.sort( orderedArtifacts ); + List orderedArtifacts = new ArrayList<>(artifacts); + Collections.sort(orderedArtifacts); releaseDependencies = new ArrayList<>(); - for ( Artifact artifact : orderedArtifacts ) - { + for (Artifact artifact : orderedArtifacts) { Dependency releaseDependency = new Dependency(); - releaseDependency.setGroupId( artifact.getGroupId() ); - releaseDependency.setArtifactId( artifact.getArtifactId() ); + releaseDependency.setGroupId(artifact.getGroupId()); + releaseDependency.setArtifactId(artifact.getArtifactId()); - String version = getReleaseVersion( releaseDescriptor, artifact ); + String version = getReleaseVersion(releaseDescriptor, artifact); - releaseDependency.setVersion( version ); - releaseDependency.setType( artifact.getType() ); - releaseDependency.setScope( artifact.getScope() ); - releaseDependency.setClassifier( artifact.getClassifier() ); + releaseDependency.setVersion(version); + releaseDependency.setType(artifact.getType()); + releaseDependency.setScope(artifact.getScope()); + releaseDependency.setClassifier(artifact.getClassifier()); - releaseDependencies.add( releaseDependency ); + releaseDependencies.add(releaseDependency); } } return releaseDependencies; } - private String getReleaseVersion( ReleaseDescriptor releaseDescriptor, - Artifact artifact ) - throws ReleaseFailureException - { - String key = ArtifactUtils.versionlessKey( artifact ); + private String getReleaseVersion(ReleaseDescriptor releaseDescriptor, Artifact artifact) + throws ReleaseFailureException { + String key = ArtifactUtils.versionlessKey(artifact); - String originalVersion = releaseDescriptor.getProjectOriginalVersion( key ); - String mappedVersion = releaseDescriptor.getProjectReleaseVersion( key ); + String originalVersion = releaseDescriptor.getProjectOriginalVersion(key); + String mappedVersion = releaseDescriptor.getProjectReleaseVersion(key); String version = artifact.getVersion(); - if ( version.equals( originalVersion ) ) - { - if ( mappedVersion != null ) - { + if (version.equals(originalVersion)) { + if (mappedVersion != null) { version = mappedVersion; + } else { + throw new ReleaseFailureException("Version '" + version + "' for '" + key + "' was not mapped"); } - else - { - throw new ReleaseFailureException( "Version '" + version + "' for '" + key + "' was not mapped" ); - } - } - else - { - if ( !ArtifactUtils.isSnapshot( version ) ) - { + } else { + if (!ArtifactUtils.isSnapshot(version)) { version = artifact.getBaseVersion(); } } @@ -554,46 +514,40 @@ private String getReleaseVersion( ReleaseDescriptor releaseDescriptor, return version; } - private List createReleasePlugins( ReleaseDescriptor releaseDescriptor, - MavenProject project ) - throws ReleaseFailureException - { + private List createReleasePlugins(ReleaseDescriptor releaseDescriptor, MavenProject project) + throws ReleaseFailureException { List releasePlugins = null; // Use original - don't want the lifecycle introduced ones Build build = project.getOriginalModel().getBuild(); - if ( build != null ) - { + if (build != null) { List plugins = build.getPlugins(); - if ( plugins != null ) - { + if (plugins != null) { Map artifactsById = project.getPluginArtifactMap(); releasePlugins = new ArrayList<>(); - for ( Plugin plugin : plugins ) - { - String id = ArtifactUtils.versionlessKey( plugin.getGroupId(), plugin.getArtifactId() ); - Artifact artifact = artifactsById.get( id ); - String version = getReleaseVersion( releaseDescriptor, artifact ); + for (Plugin plugin : plugins) { + String id = ArtifactUtils.versionlessKey(plugin.getGroupId(), plugin.getArtifactId()); + Artifact artifact = artifactsById.get(id); + String version = getReleaseVersion(releaseDescriptor, artifact); Plugin releasePlugin = new Plugin(); - releasePlugin.setGroupId( plugin.getGroupId() ); - releasePlugin.setArtifactId( plugin.getArtifactId() ); - releasePlugin.setVersion( version ); - if ( plugin.getExtensions() != null ) - { - releasePlugin.setExtensions( plugin.isExtensions() ); + releasePlugin.setGroupId(plugin.getGroupId()); + releasePlugin.setArtifactId(plugin.getArtifactId()); + releasePlugin.setVersion(version); + if (plugin.getExtensions() != null) { + releasePlugin.setExtensions(plugin.isExtensions()); } - releasePlugin.setExecutions( plugin.getExecutions() ); - releasePlugin.setDependencies( plugin.getDependencies() ); - releasePlugin.setGoals( plugin.getGoals() ); - releasePlugin.setInherited( plugin.getInherited() ); - releasePlugin.setConfiguration( plugin.getConfiguration() ); + releasePlugin.setExecutions(plugin.getExecutions()); + releasePlugin.setDependencies(plugin.getDependencies()); + releasePlugin.setGoals(plugin.getGoals()); + releasePlugin.setInherited(plugin.getInherited()); + releasePlugin.setConfiguration(plugin.getConfiguration()); - releasePlugins.add( releasePlugin ); + releasePlugins.add(releasePlugin); } } } @@ -601,39 +555,34 @@ private List createReleasePlugins( ReleaseDescriptor releaseDescriptor, return releasePlugins; } - private List createReleaseReportPlugins( ReleaseDescriptor releaseDescriptor, - MavenProject project ) - throws ReleaseFailureException - { + private List createReleaseReportPlugins(ReleaseDescriptor releaseDescriptor, MavenProject project) + throws ReleaseFailureException { List releaseReportPlugins = null; Reporting reporting = project.getModel().getReporting(); - if ( reporting != null ) - { + if (reporting != null) { List reportPlugins = reporting.getPlugins(); - if ( reportPlugins != null ) - { + if (reportPlugins != null) { Map artifactsById = project.getReportArtifactMap(); releaseReportPlugins = new ArrayList<>(); - for ( ReportPlugin reportPlugin : reportPlugins ) - { - String id = ArtifactUtils.versionlessKey( reportPlugin.getGroupId(), reportPlugin.getArtifactId() ); - Artifact artifact = artifactsById.get( id ); - String version = getReleaseVersion( releaseDescriptor, artifact ); + for (ReportPlugin reportPlugin : reportPlugins) { + String id = ArtifactUtils.versionlessKey(reportPlugin.getGroupId(), reportPlugin.getArtifactId()); + Artifact artifact = artifactsById.get(id); + String version = getReleaseVersion(releaseDescriptor, artifact); ReportPlugin releaseReportPlugin = new ReportPlugin(); - releaseReportPlugin.setGroupId( reportPlugin.getGroupId() ); - releaseReportPlugin.setArtifactId( reportPlugin.getArtifactId() ); - releaseReportPlugin.setVersion( version ); - releaseReportPlugin.setInherited( reportPlugin.getInherited() ); - releaseReportPlugin.setConfiguration( reportPlugin.getConfiguration() ); - releaseReportPlugin.setReportSets( reportPlugin.getReportSets() ); - - releaseReportPlugins.add( releaseReportPlugin ); + releaseReportPlugin.setGroupId(reportPlugin.getGroupId()); + releaseReportPlugin.setArtifactId(reportPlugin.getArtifactId()); + releaseReportPlugin.setVersion(version); + releaseReportPlugin.setInherited(reportPlugin.getInherited()); + releaseReportPlugin.setConfiguration(reportPlugin.getConfiguration()); + releaseReportPlugin.setReportSets(reportPlugin.getReportSets()); + + releaseReportPlugins.add(releaseReportPlugin); } } } @@ -641,35 +590,30 @@ private List createReleaseReportPlugins( ReleaseDescriptor release return releaseReportPlugins; } - private List createReleaseExtensions( ReleaseDescriptor releaseDescriptor, - MavenProject project ) - throws ReleaseFailureException - { + private List createReleaseExtensions(ReleaseDescriptor releaseDescriptor, MavenProject project) + throws ReleaseFailureException { List releaseExtensions = null; // Use original - don't want the lifecycle introduced ones Build build = project.getOriginalModel().getBuild(); - if ( build != null ) - { + if (build != null) { List extensions = build.getExtensions(); - if ( extensions != null ) - { + if (extensions != null) { releaseExtensions = new ArrayList<>(); - for ( Extension extension : extensions ) - { - String id = ArtifactUtils.versionlessKey( extension.getGroupId(), extension.getArtifactId() ); - Artifact artifact = project.getExtensionArtifactMap().get( id ); - String version = getReleaseVersion( releaseDescriptor, artifact ); + for (Extension extension : extensions) { + String id = ArtifactUtils.versionlessKey(extension.getGroupId(), extension.getArtifactId()); + Artifact artifact = project.getExtensionArtifactMap().get(id); + String version = getReleaseVersion(releaseDescriptor, artifact); Extension releaseExtension = new Extension(); - releaseExtension.setGroupId( extension.getGroupId() ); - releaseExtension.setArtifactId( extension.getArtifactId() ); - releaseExtension.setVersion( version ); + releaseExtension.setGroupId(extension.getGroupId()); + releaseExtension.setArtifactId(extension.getArtifactId()); + releaseExtension.setVersion(version); - releaseExtensions.add( releaseExtension ); + releaseExtensions.add(releaseExtension); } } } @@ -681,27 +625,23 @@ private List createReleaseExtensions( ReleaseDescriptor releaseDescri * @see org.apache.maven.shared.release.phase.AbstractReleasePhase#clean(java.util.List) */ @Override - public ReleaseResult clean( List reactorProjects ) - { + public ReleaseResult clean(List reactorProjects) { ReleaseResult result = new ReleaseResult(); - for ( MavenProject project : reactorProjects ) - { - File releasePom = ReleaseUtil.getReleasePom( project ); + for (MavenProject project : reactorProjects) { + File releasePom = ReleaseUtil.getReleasePom(project); // MRELEASE-273 : A release pom can be null - if ( releasePom != null && releasePom.exists() ) - { - logInfo( result, "Deleting release POM for '" + project.getName() + "'..." ); + if (releasePom != null && releasePom.exists()) { + logInfo(result, "Deleting release POM for '" + project.getName() + "'..."); - if ( !releasePom.delete() ) - { - logWarn( result, "Cannot delete release POM: " + releasePom ); + if (!releasePom.delete()) { + logWarn(result, "Cannot delete release POM: " + releasePom); } } } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java index 4460b7b93..3798eac3b 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -35,14 +34,13 @@ * @author Brett Porter */ @Singleton -@Named( "input-variables" ) -public class InputVariablesPhase - extends AbstractInputVariablesPhase -{ +@Named("input-variables") +public class InputVariablesPhase extends AbstractInputVariablesPhase { @Inject - public InputVariablesPhase( Prompter prompter, ScmRepositoryConfigurator scmRepositoryConfigurator, - Map namingPolicies ) - { - super( prompter, scmRepositoryConfigurator, namingPolicies, false, "default" ); + public InputVariablesPhase( + Prompter prompter, + ScmRepositoryConfigurator scmRepositoryConfigurator, + Map namingPolicies) { + super(prompter, scmRepositoryConfigurator, namingPolicies, false, "default"); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapBranchVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapBranchVersionsPhase.java index c3a3cb92a..cd8a959ec 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapBranchVersionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapBranchVersionsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -57,14 +56,13 @@ * @author Robert Scholte */ @Singleton -@Named( "map-branch-versions" ) -public class MapBranchVersionsPhase - extends AbstractMapVersionsPhase -{ +@Named("map-branch-versions") +public class MapBranchVersionsPhase extends AbstractMapVersionsPhase { @Inject - public MapBranchVersionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Prompter prompter, Map versionPolicies ) - { - super( scmRepositoryConfigurator, prompter, versionPolicies, true, true ); + public MapBranchVersionsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, + Prompter prompter, + Map versionPolicies) { + super(scmRepositoryConfigurator, prompter, versionPolicies, true, true); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionsPhase.java index 76c2efc17..af665df02 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -57,14 +56,13 @@ * @author Robert Scholte */ @Singleton -@Named( "map-development-versions" ) -public class MapDevelopmentVersionsPhase - extends AbstractMapVersionsPhase -{ +@Named("map-development-versions") +public class MapDevelopmentVersionsPhase extends AbstractMapVersionsPhase { @Inject - public MapDevelopmentVersionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Prompter prompter, Map versionPolicies ) - { - super( scmRepositoryConfigurator, prompter, versionPolicies, true, false ); + public MapDevelopmentVersionsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, + Prompter prompter, + Map versionPolicies) { + super(scmRepositoryConfigurator, prompter, versionPolicies, true, false); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapReleaseVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapReleaseVersionsPhase.java index 9627c3a0b..5162f1f0d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapReleaseVersionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/MapReleaseVersionsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -57,14 +56,13 @@ * @author Robert Scholte */ @Singleton -@Named( "map-release-versions" ) -public class MapReleaseVersionsPhase - extends AbstractMapVersionsPhase -{ +@Named("map-release-versions") +public class MapReleaseVersionsPhase extends AbstractMapVersionsPhase { @Inject - public MapReleaseVersionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Prompter prompter, Map versionPolicies ) - { - super( scmRepositoryConfigurator, prompter, versionPolicies, false, false ); + public MapReleaseVersionsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, + Prompter prompter, + Map versionPolicies) { + super(scmRepositoryConfigurator, prompter, versionPolicies, false, false); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhase.java index 839889edb..3a845a6b0 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -49,119 +48,107 @@ * @author Mark Hobson */ @Singleton -@Named( "remove-release-poms" ) -public class RemoveReleasePomsPhase - extends AbstractReleasePomsPhase -{ +@Named("remove-release-poms") +public class RemoveReleasePomsPhase extends AbstractReleasePomsPhase { @Inject - public RemoveReleasePomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator ); + public RemoveReleasePomsPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super(scmRepositoryConfigurator); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseFailureException, ReleaseExecutionException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects, false ); + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseFailureException, ReleaseExecutionException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects, false); } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseFailureException, ReleaseExecutionException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects, true ); + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseFailureException, ReleaseExecutionException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects, true); } - private ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects, boolean simulate ) - throws ReleaseFailureException, ReleaseExecutionException - { + private ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects, + boolean simulate) + throws ReleaseFailureException, ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); - if ( releaseDescriptor.isGenerateReleasePoms() ) - { - removeReleasePoms( releaseDescriptor, releaseEnvironment, simulate, result, reactorProjects ); - } - else - { - logInfo( result, "Not removing release POMs" ); + if (releaseDescriptor.isGenerateReleasePoms()) { + removeReleasePoms(releaseDescriptor, releaseEnvironment, simulate, result, reactorProjects); + } else { + logInfo(result, "Not removing release POMs"); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private void removeReleasePoms( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - boolean simulate, ReleaseResult result, List projects ) - throws ReleaseFailureException, ReleaseExecutionException - { + private void removeReleasePoms( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + boolean simulate, + ReleaseResult result, + List projects) + throws ReleaseFailureException, ReleaseExecutionException { List releasePoms = new ArrayList<>(); - for ( MavenProject project : projects ) - { - logInfo( result, "Removing release POM for '" + project.getName() + "'..." ); + for (MavenProject project : projects) { + logInfo(result, "Removing release POM for '" + project.getName() + "'..."); - releasePoms.add( ReleaseUtil.getReleasePom( project ) ); + releasePoms.add(ReleaseUtil.getReleasePom(project)); } - if ( releaseDescriptor.isSuppressCommitBeforeTagOrBranch() ) - { - removeReleasePomsFromFilesystem( simulate, result, releasePoms ); - } - else - { - 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 releasePoms ) - { - if ( simulate ) - { - logInfo( result, "Full run would be removing " + releasePoms ); - } - else - { - for ( File releasePom : releasePoms ) - { + private void removeReleasePomsFromFilesystem(boolean simulate, ReleaseResult result, List 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, - boolean simulate, ReleaseResult result, List releasePoms ) - throws ReleaseFailureException, ReleaseExecutionException - { - if ( simulate ) - { - logInfo( result, "Full run would be removing " + releasePoms ); - } - else - { - ScmRepository scmRepository = getScmRepository( releaseDescriptor, releaseEnvironment ); - ScmProvider scmProvider = getScmProvider( scmRepository ); - - ScmFileSet scmFileSet = new ScmFileSet( new File( releaseDescriptor.getWorkingDirectory() ), releasePoms ); - - try - { + private void removeReleasePomsFromScm( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + boolean simulate, + ReleaseResult result, + List releasePoms) + throws ReleaseFailureException, ReleaseExecutionException { + if (simulate) { + logInfo(result, "Full run would be removing " + releasePoms); + } else { + ScmRepository scmRepository = getScmRepository(releaseDescriptor, releaseEnvironment); + ScmProvider scmProvider = getScmProvider(scmRepository); + + ScmFileSet scmFileSet = new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()), releasePoms); + + try { RemoveScmResult scmResult = - scmProvider.remove( scmRepository, scmFileSet, "Removing for next development iteration." ); + scmProvider.remove(scmRepository, scmFileSet, "Removing for next development iteration."); - if ( !scmResult.isSuccess() ) - { - throw new ReleaseScmCommandException( "Cannot remove release POMs from SCM", scmResult ); + if (!scmResult.isSuccess()) { + throw new ReleaseScmCommandException("Cannot remove release POMs from SCM", scmResult); } - } - catch ( ScmException exception ) - { - throw new ReleaseExecutionException( "Cannot remove release POMs from SCM: " + exception.getMessage(), - exception ); + } catch (ScmException exception) { + throw new ReleaseExecutionException( + "Cannot remove release POMs from SCM: " + exception.getMessage(), exception); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveScmTagPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveScmTagPhase.java index 1d4299fbe..70cb86727 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveScmTagPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RemoveScmTagPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -51,121 +50,105 @@ * Remove tag from SCM repository during rollback */ @Singleton -@Named( "remove-scm-tag" ) -public class RemoveScmTagPhase - extends AbstractReleasePhase -{ +@Named("remove-scm-tag") +public class RemoveScmTagPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ private final ScmRepositoryConfigurator scmRepositoryConfigurator; @Inject - public RemoveScmTagPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); + public RemoveScmTagPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult releaseResult = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); - logInfo( releaseResult, "Removing tag with the label " + releaseDescriptor.getScmReleaseLabel() + " ..." ); + logInfo(releaseResult, "Removing tag with the label " + releaseDescriptor.getScmReleaseLabel() + " ..."); ReleaseDescriptor basedirAlignedReleaseDescriptor = - ReleaseUtil.createBasedirAlignedReleaseDescriptor( releaseDescriptor, reactorProjects ); + ReleaseUtil.createBasedirAlignedReleaseDescriptor(releaseDescriptor, reactorProjects); ScmRepository repository; ScmProvider provider; - try - { - repository = - scmRepositoryConfigurator.getConfiguredRepository( - basedirAlignedReleaseDescriptor.getScmSourceUrl(), - releaseDescriptor, - releaseEnvironment.getSettings() ); + try { + repository = scmRepositoryConfigurator.getConfiguredRepository( + basedirAlignedReleaseDescriptor.getScmSourceUrl(), + releaseDescriptor, + releaseEnvironment.getSettings()); - repository.getProviderRepository().setPushChanges( releaseDescriptor.isPushChanges() ); + repository.getProviderRepository().setPushChanges(releaseDescriptor.isPushChanges()); - repository.getProviderRepository().setWorkItem( releaseDescriptor.getWorkItem() ); + repository.getProviderRepository().setWorkItem(releaseDescriptor.getWorkItem()); - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + provider = scmRepositoryConfigurator.getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } UntagScmResult untagScmResult; - try - { - ScmFileSet fileSet = new ScmFileSet( new File( basedirAlignedReleaseDescriptor.getWorkingDirectory() ) ); + try { + ScmFileSet fileSet = new ScmFileSet(new File(basedirAlignedReleaseDescriptor.getWorkingDirectory())); String tagName = releaseDescriptor.getScmReleaseLabel(); String message = releaseDescriptor.getScmCommentPrefix() + "remove tag " + tagName; CommandParameters commandParameters = new CommandParameters(); - commandParameters.setString( CommandParameter.TAG_NAME, tagName ); - commandParameters.setString( CommandParameter.MESSAGE, message ); - if ( getLogger().isDebugEnabled() ) - { - getLogger().debug( - "RemoveScmTagPhase :: scmUntagParameters tagName " + tagName ); - getLogger().debug( - "RemoveScmTagPhase :: scmUntagParameters message " + message ); - getLogger().debug( - "RemoveScmTagPhase :: fileSet " + fileSet ); + commandParameters.setString(CommandParameter.TAG_NAME, tagName); + commandParameters.setString(CommandParameter.MESSAGE, message); + if (getLogger().isDebugEnabled()) { + getLogger().debug("RemoveScmTagPhase :: scmUntagParameters tagName " + tagName); + getLogger().debug("RemoveScmTagPhase :: scmUntagParameters message " + message); + getLogger().debug("RemoveScmTagPhase :: fileSet " + fileSet); } - untagScmResult = provider.untag( repository, fileSet, commandParameters ); - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error has occurred in the remove tag process: " - + e.getMessage(), e ); + untagScmResult = provider.untag(repository, fileSet, commandParameters); + } catch (ScmException e) { + throw new ReleaseExecutionException( + "An error has occurred in the remove tag process: " + e.getMessage(), e); } - if ( !untagScmResult.isSuccess() ) - { - getLogger().warn( String.format( "Unable to remove tag%nProvider message: %s%nCommand output: %s", - untagScmResult.getProviderMessage(), untagScmResult.getCommandOutput() ) ); + if (!untagScmResult.isSuccess()) { + getLogger() + .warn(String.format( + "Unable to remove tag%nProvider message: %s%nCommand output: %s", + untagScmResult.getProviderMessage(), untagScmResult.getCommandOutput())); } - releaseResult.setResultCode( ReleaseResult.SUCCESS ); + releaseResult.setResultCode(ReleaseResult.SUCCESS); return releaseResult; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult releaseResult = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); - logInfo( releaseResult, "Full run would remove tag with label: '" + releaseDescriptor.getScmReleaseLabel() - + "'" ); + logInfo( + releaseResult, + "Full run would remove tag with label: '" + releaseDescriptor.getScmReleaseLabel() + "'"); - releaseResult.setResultCode( ReleaseResult.SUCCESS ); + releaseResult.setResultCode(ReleaseResult.SUCCESS); return releaseResult; } - private void validateConfiguration( ReleaseDescriptor releaseDescriptor ) - throws ReleaseFailureException - { - if ( releaseDescriptor.getScmReleaseLabel() == null ) - { - throw new ReleaseFailureException( "A release label is required for removal" ); + private void validateConfiguration(ReleaseDescriptor releaseDescriptor) throws ReleaseFailureException { + if (releaseDescriptor.getScmReleaseLabel() == null) { + throw new ReleaseFailureException("A release label is required for removal"); } } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhase.java index fcf11fe85..1873ec8fc 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -52,102 +51,85 @@ * @author Edwin Punzalan */ @Singleton -@Named( "restore-backup-poms" ) -public class RestoreBackupPomsPhase - extends AbstractBackupPomsPhase -{ +@Named("restore-backup-poms") +public class RestoreBackupPomsPhase extends AbstractBackupPomsPhase { /** * Tool that gets a configured SCM repository from release configuration. */ private final ScmRepositoryConfigurator scmRepositoryConfigurator; @Inject - public RestoreBackupPomsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); + public RestoreBackupPomsPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - for ( MavenProject project : reactorProjects ) - { - restorePomBackup( releaseDescriptor, releaseEnvironment, project ); + for (MavenProject project : reactorProjects) { + restorePomBackup(releaseDescriptor, releaseEnvironment, project); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects); } - protected void restorePomBackup( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - MavenProject project ) - throws ReleaseExecutionException, ReleaseFailureException - { - File pomBackup = getPomBackup( project ); + protected void restorePomBackup( + ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, MavenProject project) + throws ReleaseExecutionException, ReleaseFailureException { + File pomBackup = getPomBackup(project); - if ( !pomBackup.exists() ) - { + if (!pomBackup.exists()) { throw new ReleaseExecutionException( - "Cannot restore from a missing backup POM: " + pomBackup.getAbsolutePath() ); + "Cannot restore from a missing backup POM: " + pomBackup.getAbsolutePath()); } - try - { + try { ScmRepository scmRepository; ScmProvider provider; - try - { - scmRepository = - scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); - - provider = scmRepositoryConfigurator.getRepositoryProvider( scmRepository ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + try { + scmRepository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); + + provider = scmRepositoryConfigurator.getRepositoryProvider(scmRepository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } - if ( releaseDescriptor.isScmUseEditMode() || provider.requiresEditMode() ) - { - EditScmResult result = provider.edit( scmRepository, new ScmFileSet( - new File( releaseDescriptor.getWorkingDirectory() ), project.getFile() ) ); + if (releaseDescriptor.isScmUseEditMode() || provider.requiresEditMode()) { + EditScmResult result = provider.edit( + scmRepository, + new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()), project.getFile())); - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to enable editing on the POM", result ); + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to enable editing on the POM", result); } } - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error occurred enabling edit mode: " + e.getMessage(), e ); + } catch (ScmException e) { + throw new ReleaseExecutionException("An error occurred enabling edit mode: " + e.getMessage(), e); } - try - { - FileUtils.copyFile( getPomBackup( project ), ReleaseUtil.getStandardPom( project ) ); - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( "Error restoring from backup POM: " + e.getMessage(), e ); + try { + FileUtils.copyFile(getPomBackup(project), ReleaseUtil.getStandardPom(project)); + } catch (IOException e) { + throw new ReleaseExecutionException("Error restoring from backup POM: " + e.getMessage(), e); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomVersionsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomVersionsPhase.java index d95ee1adb..72c574820 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomVersionsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomVersionsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -40,53 +39,49 @@ * @author Brett Porter */ @Singleton -@Named( "rewrite-pom-versions" ) -public class RewritePomVersionsPhase - extends AbstractRewritePomsPhase -{ +@Named("rewrite-pom-versions") +public class RewritePomVersionsPhase extends AbstractRewritePomsPhase { @Inject - public RewritePomVersionsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Map modelETLFactories, - Map scmTranslators ) - { - super( scmRepositoryConfigurator, modelETLFactories, scmTranslators ); + public RewritePomVersionsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, + Map modelETLFactories, + Map scmTranslators) { + super(scmRepositoryConfigurator, modelETLFactories, scmTranslators); } @Override - protected final String getPomSuffix() - { + protected final String getPomSuffix() { return "next"; } @Override - protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor, - String projectId, ScmRepository scmRepository, ReleaseResult result ) - { + protected void transformScm( + MavenProject project, + Model modelTarget, + ReleaseDescriptor releaseDescriptor, + String projectId, + ScmRepository scmRepository, + ReleaseResult result) { // We are only updating versions no mods to scm needed } @Override - protected boolean isUpdateScm() - { + protected boolean isUpdateScm() { return false; } @Override - protected String getOriginalVersion( ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate ) - { - return releaseDescriptor.getProjectOriginalVersion( projectKey ); + protected String getOriginalVersion(ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate) { + return releaseDescriptor.getProjectOriginalVersion(projectKey); } @Override - protected String getNextVersion( ReleaseDescriptor releaseDescriptor, String key ) - { - return releaseDescriptor.getProjectDevelopmentVersion( key ); + protected String getNextVersion(ReleaseDescriptor releaseDescriptor, String key) { + return releaseDescriptor.getProjectDevelopmentVersion(key); } @Override - protected String getResolvedSnapshotVersion( String artifactVersionlessKey, - ReleaseDescriptor resolvedSnapshotsMap ) - { + protected String getResolvedSnapshotVersion(String artifactVersionlessKey, ReleaseDescriptor resolvedSnapshotsMap) { // Only update the pom version, not the dependency versions return null; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhase.java index b66f685a9..59052c705 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -48,71 +47,58 @@ * @author Emmanuel Venisse */ @Singleton -@Named( "rewrite-poms-for-branch" ) -public class RewritePomsForBranchPhase - extends AbstractRewritePomsPhase -{ +@Named("rewrite-poms-for-branch") +public class RewritePomsForBranchPhase extends AbstractRewritePomsPhase { @Inject public RewritePomsForBranchPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, Map modelETLFactories, - Map scmTranslators ) - { - super( scmRepositoryConfigurator, modelETLFactories, scmTranslators ); + Map scmTranslators) { + super(scmRepositoryConfigurator, modelETLFactories, scmTranslators); } @Override - protected final String getPomSuffix() - { + protected final String getPomSuffix() { return "branch"; } @Override - protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor, - String projectId, ScmRepository scmRepository, ReleaseResult result ) - throws ReleaseExecutionException - { + protected void transformScm( + MavenProject project, + 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 ) - { + if (project.getScm() != null) { Scm scmRoot = modelTarget.getScm(); - if ( scmRoot != null ) - { - try - { - translateScm( project, releaseDescriptor, scmRoot, scmRepository, result ); - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + if (scmRoot != null) { + try { + translateScm(project, releaseDescriptor, scmRoot, scmRepository, result); + } catch (IOException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } - } - else - { + } else { MavenProject parent = project.getParent(); - if ( parent != null ) - { + if (parent != null) { // If the SCM element is not present, only add it if the parent was not mapped (ie, it's external to // the release process and so has not been modified, so the values will not be correct on the tag), - String parentId = ArtifactUtils.versionlessKey( parent.getGroupId(), parent.getArtifactId() ); - if ( !releaseDescriptor.hasOriginalScmInfo( parentId ) ) - { + String parentId = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId()); + if (!releaseDescriptor.hasOriginalScmInfo(parentId)) { // we need to add it, since it has changed from the inherited value scmRoot = new Scm(); // reset default value (HEAD) - scmRoot.setTag( null ); + scmRoot.setTag(null); - try - { - if ( translateScm( project, releaseDescriptor, scmRoot, scmRepository, result ) ) - { - modelTarget.setScm( scmRoot ); + try { + if (translateScm(project, releaseDescriptor, scmRoot, scmRepository, result)) { + modelTarget.setScm(scmRoot); } - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } catch (IOException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } } } @@ -120,17 +106,18 @@ protected void transformScm( MavenProject project, Model modelTarget, ReleaseDes } } - private boolean translateScm( MavenProject project, ReleaseDescriptor releaseDescriptor, Scm scmTarget, - ScmRepository scmRepository, ReleaseResult relResult ) - throws IOException - { - ScmTranslator translator = getScmTranslators().get( scmRepository.getProvider() ); + private boolean translateScm( + MavenProject project, + ReleaseDescriptor releaseDescriptor, + Scm scmTarget, + ScmRepository scmRepository, + ReleaseResult relResult) + throws IOException { + ScmTranslator translator = getScmTranslators().get(scmRepository.getProvider()); boolean result = false; - if ( translator != null ) - { + if (translator != null) { Scm scm = project.getOriginalModel().getScm(); - if ( scm == null ) - { + if (scm == null) { scm = project.getScm(); } @@ -138,135 +125,110 @@ private boolean translateScm( MavenProject project, ReleaseDescriptor releaseDes String branchBase = releaseDescriptor.getScmBranchBase(); // TODO: svn utils should take care of prepending this - if ( branchBase != null ) - { + if (branchBase != null) { branchBase = "scm:svn:" + branchBase; } - Path projectBasedir = project.getBasedir().toPath().toRealPath( LinkOption.NOFOLLOW_LINKS ); - Path workingDirectory = Paths.get( releaseDescriptor.getWorkingDirectory() ); + Path projectBasedir = project.getBasedir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); + Path workingDirectory = Paths.get(releaseDescriptor.getWorkingDirectory()); - int count = ReleaseUtil.getBaseWorkingDirectoryParentCount( workingDirectory, projectBasedir ); + int count = ReleaseUtil.getBaseWorkingDirectoryParentCount(workingDirectory, projectBasedir); - if ( scm.getConnection() != null ) - { - String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getConnection() ); + if (scm.getConnection() != null) { + String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getConnection()); - String subDirectoryBranch = scm.getConnection().substring( rootUrl.length() ); - if ( !subDirectoryBranch.startsWith( "/" ) ) - { + String subDirectoryBranch = scm.getConnection().substring(rootUrl.length()); + if (!subDirectoryBranch.startsWith("/")) { subDirectoryBranch = "/" + subDirectoryBranch; } String scmConnectionBranch = branchBase; - if ( scmConnectionBranch != null ) - { + if (scmConnectionBranch != null) { String trunkUrl = scm.getDeveloperConnection(); - if ( trunkUrl == null ) - { + if (trunkUrl == null) { trunkUrl = scm.getConnection(); } - scmConnectionBranch = translateUrlPath( trunkUrl, branchBase, scm.getConnection() ); + scmConnectionBranch = translateUrlPath(trunkUrl, branchBase, scm.getConnection()); } - String value = - translator.translateBranchUrl( scm.getConnection(), branchName + subDirectoryBranch, - scmConnectionBranch ); - if ( !value.equals( scm.getConnection() ) ) - { - scmTarget.setConnection( value ); + String value = translator.translateBranchUrl( + scm.getConnection(), branchName + subDirectoryBranch, scmConnectionBranch); + if (!value.equals(scm.getConnection())) { + scmTarget.setConnection(value); result = true; } } - if ( scm.getDeveloperConnection() != null ) - { - String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getDeveloperConnection() ); + if (scm.getDeveloperConnection() != null) { + String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getDeveloperConnection()); - String subDirectoryBranch = scm.getDeveloperConnection().substring( rootUrl.length() ); - if ( !subDirectoryBranch.startsWith( "/" ) ) - { + String subDirectoryBranch = scm.getDeveloperConnection().substring(rootUrl.length()); + if (!subDirectoryBranch.startsWith("/")) { subDirectoryBranch = "/" + subDirectoryBranch; } - String value = - translator.translateBranchUrl( scm.getDeveloperConnection(), branchName + subDirectoryBranch, - branchBase ); - if ( !value.equals( scm.getDeveloperConnection() ) ) - { - scmTarget.setDeveloperConnection( value ); + String value = translator.translateBranchUrl( + scm.getDeveloperConnection(), branchName + subDirectoryBranch, branchBase); + if (!value.equals(scm.getDeveloperConnection())) { + scmTarget.setDeveloperConnection(value); result = true; } } - if ( scm.getUrl() != null ) - { - String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getUrl() ); + if (scm.getUrl() != null) { + String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getUrl()); - String subDirectoryBranch = scm.getUrl().substring( rootUrl.length() ); - if ( !subDirectoryBranch.startsWith( "/" ) ) - { + String subDirectoryBranch = scm.getUrl().substring(rootUrl.length()); + if (!subDirectoryBranch.startsWith("/")) { subDirectoryBranch = "/" + subDirectoryBranch; } String tagScmUrl = branchBase; - if ( tagScmUrl != null ) - { + if (tagScmUrl != null) { String trunkUrl = scm.getDeveloperConnection(); - if ( trunkUrl == null ) - { + if (trunkUrl == null) { trunkUrl = scm.getConnection(); } - tagScmUrl = translateUrlPath( trunkUrl, branchBase, scm.getUrl() ); + tagScmUrl = translateUrlPath(trunkUrl, branchBase, scm.getUrl()); } // use original branch base without protocol - String value = translator.translateBranchUrl( scm.getUrl(), branchName + subDirectoryBranch, - tagScmUrl ); - if ( !value.equals( scm.getUrl() ) ) - { - scmTarget.setUrl( value ); + String value = translator.translateBranchUrl(scm.getUrl(), branchName + subDirectoryBranch, tagScmUrl); + if (!value.equals(scm.getUrl())) { + scmTarget.setUrl(value); result = true; } } - if ( branchName != null ) - { - String value = translator.resolveTag( branchName ); - if ( value != null && !value.equals( scm.getTag() ) ) - { - scmTarget.setTag( value ); + if (branchName != null) { + String value = translator.resolveTag(branchName); + if (value != null && !value.equals(scm.getTag())) { + scmTarget.setTag(value); result = true; } } - } - else - { + } else { String message = "No SCM translator found - skipping rewrite"; - relResult.appendDebug( message ); + relResult.appendDebug(message); - getLogger().debug( message ); + getLogger().debug(message); } return result; } @Override - protected String getOriginalVersion( ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate ) - { - return releaseDescriptor.getProjectOriginalVersion( projectKey ); + protected String getOriginalVersion(ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate) { + return releaseDescriptor.getProjectOriginalVersion(projectKey); } @Override - protected String getNextVersion( ReleaseDescriptor releaseDescriptor, String key ) - { - return releaseDescriptor.getProjectReleaseVersion( key ); + protected String getNextVersion(ReleaseDescriptor releaseDescriptor, String key) { + return releaseDescriptor.getProjectReleaseVersion(key); } @Override - protected String getResolvedSnapshotVersion( String artifactVersionlessKey, - ReleaseDescriptor releaseDescriptor ) - { - return releaseDescriptor.getDependencyReleaseVersion( artifactVersionlessKey ); + protected String getResolvedSnapshotVersion(String artifactVersionlessKey, ReleaseDescriptor releaseDescriptor) { + return releaseDescriptor.getDependencyReleaseVersion(artifactVersionlessKey); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhase.java index a18889009..954f82a48 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -41,93 +40,79 @@ * @author Brett Porter */ @Singleton -@Named( "rewrite-poms-for-development" ) -public class RewritePomsForDevelopmentPhase - extends AbstractRewritePomsPhase -{ +@Named("rewrite-poms-for-development") +public class RewritePomsForDevelopmentPhase extends AbstractRewritePomsPhase { @Inject public RewritePomsForDevelopmentPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, Map modelETLFactories, - Map scmTranslators ) - { - super( scmRepositoryConfigurator, modelETLFactories, scmTranslators ); + Map scmTranslators) { + super(scmRepositoryConfigurator, modelETLFactories, scmTranslators); } @Override - protected final String getPomSuffix() - { + protected final String getPomSuffix() { return "next"; } @Override - protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor, - String projectId, ScmRepository scmRepository, ReleaseResult result ) - { + protected void transformScm( + MavenProject project, + 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.getScm() != null) { Scm scmRoot = modelTarget.getScm(); - if ( scmRoot != null ) - { - ScmTranslator translator = getScmTranslators().get( scmRepository.getProvider() ); - if ( translator != null ) - { - Scm scm = releaseDescriptor.getOriginalScmInfo( projectId ); + if (scmRoot != null) { + ScmTranslator translator = getScmTranslators().get(scmRepository.getProvider()); + if (translator != null) { + Scm scm = releaseDescriptor.getOriginalScmInfo(projectId); - if ( scm != null ) - { - scmRoot.setConnection( scm.getConnection() ); - scmRoot.setDeveloperConnection( scm.getDeveloperConnection() ); - scmRoot.setUrl( scm.getUrl() ); - String tag = translator.resolveTag( scm.getTag() ); + if (scm != null) { + scmRoot.setConnection(scm.getConnection()); + scmRoot.setDeveloperConnection(scm.getDeveloperConnection()); + scmRoot.setUrl(scm.getUrl()); + String tag = translator.resolveTag(scm.getTag()); // reuse unresolved tag from original in case ScmTranslator does not support tags - if ( tag == null ) - { + if (tag == null) { tag = scm.getTag(); // never give out default value as there is no way to distinguish it from an the // explicitly set tag with the same value - if ( "HEAD".equals( tag ) ) - { + if ("HEAD".equals(tag)) { tag = null; } } - scmRoot.setTag( tag ); - } - else - { + scmRoot.setTag(tag); + } else { // cleanly remove the SCM element - modelTarget.setScm( null ); + modelTarget.setScm(null); } - } - else - { + } else { String message = "No SCM translator found - skipping rewrite"; - result.appendDebug( message ); - getLogger().debug( message ); + result.appendDebug(message); + getLogger().debug(message); } } } } @Override - protected String getOriginalVersion( ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate ) - { + protected String getOriginalVersion(ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate) { return simulate - ? releaseDescriptor.getProjectOriginalVersion( projectKey ) - : releaseDescriptor.getProjectReleaseVersion( projectKey ); + ? releaseDescriptor.getProjectOriginalVersion(projectKey) + : releaseDescriptor.getProjectReleaseVersion(projectKey); } @Override - protected String getNextVersion( ReleaseDescriptor releaseDescriptor, String key ) - { - return releaseDescriptor.getProjectDevelopmentVersion( key ); + protected String getNextVersion(ReleaseDescriptor releaseDescriptor, String key) { + return releaseDescriptor.getProjectDevelopmentVersion(key); } @Override - protected String getResolvedSnapshotVersion( String artifactVersionlessKey, - ReleaseDescriptor releaseDescriptor ) - { - return releaseDescriptor.getDependencyDevelopmentVersion( artifactVersionlessKey ); + protected String getResolvedSnapshotVersion(String artifactVersionlessKey, ReleaseDescriptor releaseDescriptor) { + return releaseDescriptor.getDependencyDevelopmentVersion(artifactVersionlessKey); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java index 2217d919f..67b9f18c0 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -48,70 +47,57 @@ * @author Brett Porter */ @Singleton -@Named( "rewrite-poms-for-release" ) -public class RewritePomsForReleasePhase - extends AbstractRewritePomsPhase -{ +@Named("rewrite-poms-for-release") +public class RewritePomsForReleasePhase extends AbstractRewritePomsPhase { @Inject public RewritePomsForReleasePhase( ScmRepositoryConfigurator scmRepositoryConfigurator, Map modelETLFactories, - Map scmTranslators ) - { - super( scmRepositoryConfigurator, modelETLFactories, scmTranslators ); + Map scmTranslators) { + super(scmRepositoryConfigurator, modelETLFactories, scmTranslators); } @Override - protected final String getPomSuffix() - { + protected final String getPomSuffix() { return "tag"; } @Override - protected void transformScm( MavenProject project, Model modelTarget, ReleaseDescriptor releaseDescriptor, - String projectId, ScmRepository scmRepository, ReleaseResult result ) - throws ReleaseExecutionException - { + protected void transformScm( + MavenProject project, + 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 ) - { + if (project.getScm() != null) { Scm scmRoot = modelTarget.getScm(); - if ( scmRoot != null ) - { - try - { - translateScm( project, releaseDescriptor, scmRoot, scmRepository, result ); - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + if (scmRoot != null) { + try { + translateScm(project, releaseDescriptor, scmRoot, scmRepository, result); + } catch (IOException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } - } - else - { + } else { MavenProject parent = project.getParent(); - if ( parent != null ) - { + if (parent != null) { // If the SCM element is not present, only add it if the parent was not mapped (ie, it's external to // the release process and so has not been modified, so the values will not be correct on the tag), - String parentId = ArtifactUtils.versionlessKey( parent.getGroupId(), parent.getArtifactId() ); - if ( !releaseDescriptor.hasOriginalScmInfo( parentId ) ) - { + String parentId = ArtifactUtils.versionlessKey(parent.getGroupId(), parent.getArtifactId()); + if (!releaseDescriptor.hasOriginalScmInfo(parentId)) { // we need to add it, since it has changed from the inherited value Scm scmTarget = new Scm(); // reset default value (HEAD) - scmTarget.setTag( null ); + scmTarget.setTag(null); - try - { - if ( translateScm( project, releaseDescriptor, scmTarget, scmRepository, result ) ) - { - modelTarget.setScm( scmTarget ); + try { + if (translateScm(project, releaseDescriptor, scmTarget, scmRepository, result)) { + modelTarget.setScm(scmTarget); } - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( e.getMessage(), e ); + } catch (IOException e) { + throw new ReleaseExecutionException(e.getMessage(), e); } } } @@ -119,17 +105,18 @@ protected void transformScm( MavenProject project, Model modelTarget, ReleaseDes } } - private boolean translateScm( MavenProject project, ReleaseDescriptor releaseDescriptor, Scm scmTarget, - ScmRepository scmRepository, ReleaseResult relResult ) - throws IOException - { - ScmTranslator translator = getScmTranslators().get( scmRepository.getProvider() ); + private boolean translateScm( + MavenProject project, + ReleaseDescriptor releaseDescriptor, + Scm scmTarget, + ScmRepository scmRepository, + ReleaseResult relResult) + throws IOException { + ScmTranslator translator = getScmTranslators().get(scmRepository.getProvider()); boolean result = false; - if ( translator != null ) - { + if (translator != null) { Scm scm = project.getOriginalModel().getScm(); - if ( scm == null ) - { + if (scm == null) { scm = project.getScm(); } @@ -137,132 +124,108 @@ private boolean translateScm( MavenProject project, ReleaseDescriptor releaseDes String tagBase = releaseDescriptor.getScmTagBase(); // TODO: svn utils should take care of prepending this - if ( tagBase != null ) - { + if (tagBase != null) { tagBase = "scm:svn:" + tagBase; } - Path projectBasedir = project.getBasedir().toPath().toRealPath( LinkOption.NOFOLLOW_LINKS ); - Path workingDirectory = Paths.get( releaseDescriptor.getWorkingDirectory() ); + Path projectBasedir = project.getBasedir().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); + Path workingDirectory = Paths.get(releaseDescriptor.getWorkingDirectory()); - int count = ReleaseUtil.getBaseWorkingDirectoryParentCount( workingDirectory, projectBasedir ); + int count = ReleaseUtil.getBaseWorkingDirectoryParentCount(workingDirectory, projectBasedir); - if ( scm.getConnection() != null ) - { - String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getConnection() ); + if (scm.getConnection() != null) { + String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getConnection()); - String subDirectoryTag = scm.getConnection().substring( rootUrl.length() ); - if ( !subDirectoryTag.startsWith( "/" ) ) - { + String subDirectoryTag = scm.getConnection().substring(rootUrl.length()); + if (!subDirectoryTag.startsWith("/")) { subDirectoryTag = "/" + subDirectoryTag; } String scmConnectionTag = tagBase; - if ( scmConnectionTag != null ) - { + if (scmConnectionTag != null) { String trunkUrl = scm.getDeveloperConnection(); - if ( trunkUrl == null ) - { + if (trunkUrl == null) { trunkUrl = scm.getConnection(); } - scmConnectionTag = translateUrlPath( trunkUrl, tagBase, scm.getConnection() ); + scmConnectionTag = translateUrlPath(trunkUrl, tagBase, scm.getConnection()); } - String value = - translator.translateTagUrl( scm.getConnection(), tag + subDirectoryTag, scmConnectionTag ); + String value = translator.translateTagUrl(scm.getConnection(), tag + subDirectoryTag, scmConnectionTag); - if ( !value.equals( scm.getConnection() ) ) - { - scmTarget.setConnection( value ); + if (!value.equals(scm.getConnection())) { + scmTarget.setConnection(value); result = true; } } - if ( scm.getDeveloperConnection() != null ) - { - String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getDeveloperConnection() ); + if (scm.getDeveloperConnection() != null) { + String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getDeveloperConnection()); - String subDirectoryTag = scm.getDeveloperConnection().substring( rootUrl.length() ); - if ( !subDirectoryTag.startsWith( "/" ) ) - { + String subDirectoryTag = scm.getDeveloperConnection().substring(rootUrl.length()); + if (!subDirectoryTag.startsWith("/")) { subDirectoryTag = "/" + subDirectoryTag; } - String value = - translator.translateTagUrl( scm.getDeveloperConnection(), tag + subDirectoryTag, tagBase ); + String value = translator.translateTagUrl(scm.getDeveloperConnection(), tag + subDirectoryTag, tagBase); - if ( !value.equals( scm.getDeveloperConnection() ) ) - { - scmTarget.setDeveloperConnection( value ); + if (!value.equals(scm.getDeveloperConnection())) { + scmTarget.setDeveloperConnection(value); result = true; } } - if ( scm.getUrl() != null ) - { - String rootUrl = ReleaseUtil.realignScmUrl( count, scm.getUrl() ); + if (scm.getUrl() != null) { + String rootUrl = ReleaseUtil.realignScmUrl(count, scm.getUrl()); - String subDirectoryTag = scm.getUrl().substring( rootUrl.length() ); - if ( !subDirectoryTag.startsWith( "/" ) ) - { + String subDirectoryTag = scm.getUrl().substring(rootUrl.length()); + if (!subDirectoryTag.startsWith("/")) { subDirectoryTag = "/" + subDirectoryTag; } String tagScmUrl = tagBase; - if ( tagScmUrl != null ) - { + if (tagScmUrl != null) { String trunkUrl = scm.getDeveloperConnection(); - if ( trunkUrl == null ) - { + if (trunkUrl == null) { trunkUrl = scm.getConnection(); } - tagScmUrl = translateUrlPath( trunkUrl, tagBase, scm.getUrl() ); + tagScmUrl = translateUrlPath(trunkUrl, tagBase, scm.getUrl()); } // use original tag base without protocol - String value = translator.translateTagUrl( scm.getUrl(), tag + subDirectoryTag, tagScmUrl ); - if ( !value.equals( scm.getUrl() ) ) - { - scmTarget.setUrl( value ); + String value = translator.translateTagUrl(scm.getUrl(), tag + subDirectoryTag, tagScmUrl); + if (!value.equals(scm.getUrl())) { + scmTarget.setUrl(value); result = true; } } - if ( tag != null ) - { - String value = translator.resolveTag( tag ); - if ( value != null && !value.equals( scm.getTag() ) ) - { - scmTarget.setTag( value ); + if (tag != null) { + String value = translator.resolveTag(tag); + if (value != null && !value.equals(scm.getTag())) { + scmTarget.setTag(value); result = true; } } - } - else - { + } else { String message = "No SCM translator found - skipping rewrite"; - relResult.appendDebug( message ); + relResult.appendDebug(message); - getLogger().debug( message ); + getLogger().debug(message); } return result; } @Override - protected String getOriginalVersion( ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate ) - { - return releaseDescriptor.getProjectOriginalVersion( projectKey ); + protected String getOriginalVersion(ReleaseDescriptor releaseDescriptor, String projectKey, boolean simulate) { + return releaseDescriptor.getProjectOriginalVersion(projectKey); } @Override - protected String getNextVersion( ReleaseDescriptor releaseDescriptor, String key ) - { - return releaseDescriptor.getProjectReleaseVersion( key ); + protected String getNextVersion(ReleaseDescriptor releaseDescriptor, String key) { + return releaseDescriptor.getProjectReleaseVersion(key); } @Override - protected String getResolvedSnapshotVersion( String artifactVersionlessKey, - ReleaseDescriptor releaseDescriptor ) - { - return releaseDescriptor.getDependencyReleaseVersion( artifactVersionlessKey ); + protected String getResolvedSnapshotVersion(String artifactVersionlessKey, ReleaseDescriptor releaseDescriptor) { + return releaseDescriptor.getDependencyReleaseVersion(artifactVersionlessKey); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhase.java index db481d7a9..decf0fde1 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -40,42 +39,42 @@ * @author Stephen Connolly */ @Singleton -@Named( "run-completion-goals" ) -public class RunCompleteGoalsPhase - extends AbstractRunGoalsPhase -{ +@Named("run-completion-goals") +public class RunCompleteGoalsPhase extends AbstractRunGoalsPhase { @Inject - public RunCompleteGoalsPhase( Map mavenExecutors ) - { - super( mavenExecutors ); + public RunCompleteGoalsPhase(Map mavenExecutors) { + super(mavenExecutors); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects, false ); + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects, false); } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); - logInfo( result, "Executing completion goals - since this is simulation mode it is running against the " - + "original project, not the rewritten ones" ); + logInfo( + result, + "Executing completion goals - since this is simulation mode it is running against the " + + "original project, not the rewritten ones"); - execute( releaseDescriptor, releaseEnvironment, reactorProjects, true ); + execute(releaseDescriptor, releaseEnvironment, reactorProjects, true); return result; } @Override - protected String getGoals( ReleaseDescriptor releaseDescriptor ) - { + protected String getGoals(ReleaseDescriptor releaseDescriptor) { return releaseDescriptor.getCompletionGoals(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhase.java index 32bf357cc..51dbb3c97 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,13 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; - import java.io.File; import java.util.List; import java.util.Map; @@ -38,100 +35,87 @@ import org.apache.maven.shared.release.util.PomFinder; import org.codehaus.plexus.util.StringUtils; +import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; + /** * Run the effective release build of the project and its deploy to remote repository. * * @author Brett Porter */ @Singleton -@Named( "run-perform-goals" ) -public class RunPerformGoalsPhase - extends AbstractRunGoalsPhase -{ +@Named("run-perform-goals") +public class RunPerformGoalsPhase extends AbstractRunGoalsPhase { @Inject - public RunPerformGoalsPhase( Map mavenExecutors ) - { - super( mavenExecutors ); + public RunPerformGoalsPhase(Map mavenExecutors) { + super(mavenExecutors); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { - return runLogic( releaseDescriptor, releaseEnvironment, false ); + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { + return runLogic(releaseDescriptor, releaseEnvironment, false); } - private ReleaseResult runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - boolean simulate ) - throws ReleaseExecutionException - { - String additionalArguments = getAdditionalArguments( releaseDescriptor ); + private ReleaseResult runLogic( + ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, boolean simulate) + throws ReleaseExecutionException { + String additionalArguments = getAdditionalArguments(releaseDescriptor); - if ( releaseDescriptor.isUseReleaseProfile() ) - { - if ( !StringUtils.isEmpty( additionalArguments ) ) - { + if (releaseDescriptor.isUseReleaseProfile()) { + if (!StringUtils.isEmpty(additionalArguments)) { additionalArguments = additionalArguments + " -DperformRelease=true"; - } - else - { + } else { additionalArguments = "-DperformRelease=true"; } } String pomFileName = releaseDescriptor.getPomFileName(); - if ( pomFileName == null ) - { + if (pomFileName == null) { pomFileName = "pom.xml"; } // ensure we don't use the release pom for the perform goals // ^^ paranoia? A MavenExecutor has already access to this. Probably worth refactoring. - if ( !StringUtils.isEmpty( additionalArguments ) ) - { + if (!StringUtils.isEmpty(additionalArguments)) { additionalArguments = additionalArguments + " -f " + pomFileName; - } - else - { + } else { additionalArguments = "-f " + pomFileName; } - if ( simulate ) - { + if (simulate) { ReleaseResult result = new ReleaseResult(); - logInfo( result, "Simulating perform goals '" + buffer().strong( getGoals( releaseDescriptor ) ) - + "' - since this is simulation mode these goals are skipped." ); - logInfo( result, " with additional arguments: " + additionalArguments ); + logInfo( + result, + "Simulating perform goals '" + buffer().strong(getGoals(releaseDescriptor)) + + "' - since this is simulation mode these goals are skipped."); + logInfo(result, " with additional arguments: " + additionalArguments); return result; } String workDir = releaseDescriptor.getWorkingDirectory(); - if ( workDir == null ) - { - workDir = System.getProperty( "user.dir" ); + if (workDir == null) { + workDir = System.getProperty("user.dir"); } - - File pomFile = new File( workDir, pomFileName ); - PomFinder pomFinder = new PomFinder( getLogger() ); + File pomFile = new File(workDir, pomFileName); + PomFinder pomFinder = new PomFinder(getLogger()); boolean foundPom = false; - if ( StringUtils.isEmpty( releaseDescriptor.getScmRelativePathProjectDirectory() ) ) - { - foundPom = pomFinder.parsePom( pomFile ); + if (StringUtils.isEmpty(releaseDescriptor.getScmRelativePathProjectDirectory())) { + foundPom = pomFinder.parsePom(pomFile); } - File workDirectory = new File( releaseDescriptor.getCheckoutDirectory() ); + File workDirectory = new File(releaseDescriptor.getCheckoutDirectory()); - if ( foundPom ) - { - File matchingPom = pomFinder.findMatchingPom( workDirectory ); - if ( matchingPom != null ) - { - getLogger().info( "Invoking perform goals in directory " + matchingPom.getParent() ); + if (foundPom) { + File matchingPom = pomFinder.findMatchingPom(workDirectory); + if (matchingPom != null) { + getLogger().info("Invoking perform goals in directory " + matchingPom.getParent()); // The directory of the POM in a flat project layout is not // the same directory as the SCM checkout directory! // The same is true for a sparse checkout in e.g. GIT @@ -140,20 +124,20 @@ private ReleaseResult runLogic( ReleaseDescriptor releaseDescriptor, ReleaseEnvi } } - return execute( releaseDescriptor, releaseEnvironment, workDirectory, additionalArguments, false ); + return execute(releaseDescriptor, releaseEnvironment, workDirectory, additionalArguments, false); } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { - return runLogic( releaseDescriptor, releaseEnvironment, true ); + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { + return runLogic(releaseDescriptor, releaseEnvironment, true); } @Override - protected String getGoals( ReleaseDescriptor releaseDescriptor ) - { + protected String getGoals(ReleaseDescriptor releaseDescriptor) { return releaseDescriptor.getPerformGoals(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhase.java index fa646ea39..c6da6f155 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -39,42 +38,42 @@ * @author Brett Porter */ @Singleton -@Named( "run-preparation-goals" ) -public class RunPrepareGoalsPhase - extends AbstractRunGoalsPhase -{ +@Named("run-preparation-goals") +public class RunPrepareGoalsPhase extends AbstractRunGoalsPhase { @Inject - public RunPrepareGoalsPhase( Map mavenExecutors ) - { - super( mavenExecutors ); + public RunPrepareGoalsPhase(Map mavenExecutors) { + super(mavenExecutors); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { - return execute( releaseDescriptor, releaseEnvironment, reactorProjects, false ); + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { + return execute(releaseDescriptor, releaseEnvironment, reactorProjects, false); } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException { ReleaseResult result = new ReleaseResult(); - logInfo( result, "Executing preparation goals - since this is simulation mode it is running against the " - + "original project, not the rewritten ones" ); + logInfo( + result, + "Executing preparation goals - since this is simulation mode it is running against the " + + "original project, not the rewritten ones"); - execute( releaseDescriptor, releaseEnvironment, reactorProjects, true ); + execute(releaseDescriptor, releaseEnvironment, reactorProjects, true); return result; } @Override - protected String getGoals( ReleaseDescriptor releaseDescriptor ) - { + protected String getGoals(ReleaseDescriptor releaseDescriptor) { return releaseDescriptor.getPreparationGoals(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmBranchPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmBranchPhase.java index cb3d1fb99..cf32c1d5b 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmBranchPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmBranchPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -51,123 +50,107 @@ * @author Emmanuel Venisse */ @Singleton -@Named( "scm-branch" ) -public class ScmBranchPhase - extends AbstractReleasePhase -{ +@Named("scm-branch") +public class ScmBranchPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ private final ScmRepositoryConfigurator scmRepositoryConfigurator; @Inject - public ScmBranchPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { + public ScmBranchPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { this.scmRepositoryConfigurator = scmRepositoryConfigurator; } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult relResult = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); - logInfo( relResult, "Branching release with the label " + releaseDescriptor.getScmReleaseLabel() + "..." ); + logInfo(relResult, "Branching release with the label " + releaseDescriptor.getScmReleaseLabel() + "..."); ReleaseDescriptor basedirAlignedReleaseDescriptor = - ReleaseUtil.createBasedirAlignedReleaseDescriptor( releaseDescriptor, reactorProjects ); + ReleaseUtil.createBasedirAlignedReleaseDescriptor(releaseDescriptor, reactorProjects); ScmRepository repository; ScmProvider provider; - try - { - repository = - scmRepositoryConfigurator.getConfiguredRepository( - basedirAlignedReleaseDescriptor.getScmSourceUrl(), - releaseDescriptor, - releaseEnvironment.getSettings() ); + try { + repository = scmRepositoryConfigurator.getConfiguredRepository( + basedirAlignedReleaseDescriptor.getScmSourceUrl(), + releaseDescriptor, + releaseEnvironment.getSettings()); - repository.getProviderRepository().setPushChanges( releaseDescriptor.isPushChanges() ); + repository.getProviderRepository().setPushChanges(releaseDescriptor.isPushChanges()); - repository.getProviderRepository().setWorkItem( releaseDescriptor.getWorkItem() ); + repository.getProviderRepository().setWorkItem(releaseDescriptor.getWorkItem()); - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); + provider = scmRepositoryConfigurator.getRepositoryProvider(repository); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } BranchScmResult result; - try - { - ScmFileSet fileSet = new ScmFileSet( new File( basedirAlignedReleaseDescriptor.getWorkingDirectory() ) ); + try { + ScmFileSet fileSet = new ScmFileSet(new File(basedirAlignedReleaseDescriptor.getWorkingDirectory())); String branchName = releaseDescriptor.getScmReleaseLabel(); ScmBranchParameters scmBranchParameters = new ScmBranchParameters(); - scmBranchParameters.setMessage( releaseDescriptor.getScmCommentPrefix() + "copy for branch " + branchName ); - scmBranchParameters.setRemoteBranching( releaseDescriptor.isRemoteTagging() ); - scmBranchParameters.setScmRevision( releaseDescriptor.getScmReleasedPomRevision() ); - scmBranchParameters.setPinExternals( releaseDescriptor.isPinExternals() ); - - result = provider.branch( repository, fileSet, branchName, scmBranchParameters ); - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error is occurred in the branch process: " + e.getMessage(), e ); + scmBranchParameters.setMessage(releaseDescriptor.getScmCommentPrefix() + "copy for branch " + branchName); + scmBranchParameters.setRemoteBranching(releaseDescriptor.isRemoteTagging()); + scmBranchParameters.setScmRevision(releaseDescriptor.getScmReleasedPomRevision()); + scmBranchParameters.setPinExternals(releaseDescriptor.isPinExternals()); + + result = provider.branch(repository, fileSet, branchName, scmBranchParameters); + } catch (ScmException e) { + throw new ReleaseExecutionException("An error is occurred in the branch process: " + e.getMessage(), e); } - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to branch SCM", result ); + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to branch SCM", result); } - relResult.setResultCode( ReleaseResult.SUCCESS ); + relResult.setResultCode(ReleaseResult.SUCCESS); return relResult; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); ReleaseDescriptor basedirAlignedReleaseDescriptor = - ReleaseUtil.createBasedirAlignedReleaseDescriptor( releaseDescriptor, reactorProjects ); + ReleaseUtil.createBasedirAlignedReleaseDescriptor(releaseDescriptor, reactorProjects); - logInfo( result, "Full run would branch " + basedirAlignedReleaseDescriptor.getWorkingDirectory() ); - if ( releaseDescriptor.getScmBranchBase() != null ) - { - logInfo( result, " to SCM URL " + releaseDescriptor.getScmBranchBase() ); + logInfo(result, "Full run would branch " + basedirAlignedReleaseDescriptor.getWorkingDirectory()); + if (releaseDescriptor.getScmBranchBase() != null) { + logInfo(result, " to SCM URL " + releaseDescriptor.getScmBranchBase()); } - logInfo( result, " with label '" + releaseDescriptor.getScmReleaseLabel() + "'" ); - if ( releaseDescriptor.isPinExternals() ) - { - logInfo( result, " and pinned externals" ); + logInfo(result, " with label '" + releaseDescriptor.getScmReleaseLabel() + "'"); + if (releaseDescriptor.isPinExternals()) { + logInfo(result, " and pinned externals"); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private static void validateConfiguration( ReleaseDescriptor releaseDescriptor ) - throws ReleaseFailureException - { - if ( releaseDescriptor.getScmReleaseLabel() == null ) - { - throw new ReleaseFailureException( "A release label is required for committing" ); + private static void validateConfiguration(ReleaseDescriptor releaseDescriptor) throws ReleaseFailureException { + if (releaseDescriptor.getScmReleaseLabel() == null) { + throw new ReleaseFailureException("A release label is required for committing"); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java index 4c9a8f2bc..3cc020d70 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,11 +16,20 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import java.io.File; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.maven.project.MavenProject; import org.apache.maven.scm.ScmException; import org.apache.maven.scm.ScmFile; @@ -44,14 +51,6 @@ import org.codehaus.plexus.util.SelectorUtils; import org.codehaus.plexus.util.StringUtils; -import java.io.File; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - import static java.util.Objects.requireNonNull; /** @@ -60,10 +59,8 @@ * @author Brett Porter */ @Singleton -@Named( "scm-check-modifications" ) -public class ScmCheckModificationsPhase - extends AbstractReleasePhase -{ +@Named("scm-check-modifications") +public class ScmCheckModificationsPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ @@ -79,107 +76,87 @@ public class ScmCheckModificationsPhase * * @todo proper construction of filenames, especially release properties */ - private final Set exclusionPatterns = new HashSet<>( Arrays.asList( - "**" + File.separator + "pom.xml.backup", "**" + File.separator + "pom.xml.tag", - "**" + File.separator + "pom.xml.next", "**" + File.separator + "pom.xml.branch", - "**" + File.separator + "release.properties", "**" + File.separator + "pom.xml.releaseBackup" ) ); + private final Set exclusionPatterns = new HashSet<>(Arrays.asList( + "**" + File.separator + "pom.xml.backup", "**" + File.separator + "pom.xml.tag", + "**" + File.separator + "pom.xml.next", "**" + File.separator + "pom.xml.branch", + "**" + File.separator + "release.properties", "**" + File.separator + "pom.xml.releaseBackup")); @Inject - public ScmCheckModificationsPhase( ScmRepositoryConfigurator scmRepositoryConfigurator, - Map scmTranslators ) - { - this.scmRepositoryConfigurator = requireNonNull( scmRepositoryConfigurator ); - this.scmTranslators = requireNonNull( scmTranslators ); + public ScmCheckModificationsPhase( + ScmRepositoryConfigurator scmRepositoryConfigurator, Map scmTranslators) { + this.scmRepositoryConfigurator = requireNonNull(scmRepositoryConfigurator); + this.scmTranslators = requireNonNull(scmTranslators); } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult relResult = new ReleaseResult(); List additionalExcludes = releaseDescriptor.getCheckModificationExcludes(); - if ( additionalExcludes != null ) - { + if (additionalExcludes != null) { // SelectorUtils expects OS-specific paths and patterns - for ( String additionalExclude : additionalExcludes ) - { - exclusionPatterns.add( additionalExclude.replace( "\\", File.separator ) - .replace( "/", File.separator ) ); + for (String additionalExclude : additionalExcludes) { + exclusionPatterns.add( + additionalExclude.replace("\\", File.separator).replace("/", File.separator)); } } - logInfo( relResult, "Verifying that there are no local modifications..." ); - logInfo( relResult, " ignoring changes on: " + StringUtils.join( exclusionPatterns.toArray(), ", " ) ); + logInfo(relResult, "Verifying that there are no local modifications..."); + logInfo(relResult, " ignoring changes on: " + StringUtils.join(exclusionPatterns.toArray(), ", ")); ScmRepository repository; ScmProvider provider; - try - { - repository = - scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, - releaseEnvironment.getSettings() ); - - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage() + " for URL: " - + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + try { + repository = scmRepositoryConfigurator.getConfiguredRepository( + releaseDescriptor, releaseEnvironment.getSettings()); + + provider = scmRepositoryConfigurator.getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException( + e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } StatusScmResult result; - try - { - result = - provider.status( repository, new ScmFileSet( new File( releaseDescriptor.getWorkingDirectory() ) ) ); - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error occurred during the status check process: " + e.getMessage(), - e ); + try { + result = provider.status(repository, new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()))); + } catch (ScmException e) { + throw new ReleaseExecutionException( + "An error occurred during the status check process: " + e.getMessage(), e); } - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to check for local modifications", result ); + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to check for local modifications", result); } List changedFiles = result.getChangedFiles(); - if ( !changedFiles.isEmpty() ) - { - ScmTranslator scmTranslator = scmTranslators.get( repository.getProvider() ); + if (!changedFiles.isEmpty()) { + ScmTranslator scmTranslator = scmTranslators.get(repository.getProvider()); // TODO: would be nice for SCM status command to do this for me. - for ( Iterator i = changedFiles.iterator(); i.hasNext(); ) - { + for (Iterator i = changedFiles.iterator(); i.hasNext(); ) { ScmFile f = i.next(); String path; - if ( scmTranslator != null ) - { - path = scmTranslator.toRelativePath( f.getPath() ); - } - else - { + if (scmTranslator != null) { + path = scmTranslator.toRelativePath(f.getPath()); + } else { path = f.getPath(); } // SelectorUtils expects File.separator, don't standardize! - String fileName = path.replace( "\\", File.separator ).replace( "/", File.separator ); + String fileName = path.replace("\\", File.separator).replace("/", File.separator); - for ( String exclusionPattern : exclusionPatterns ) - { - if ( SelectorUtils.matchPath( exclusionPattern, fileName ) ) - { - logDebug( relResult, "Ignoring changed file: " + fileName ); + for (String exclusionPattern : exclusionPatterns) { + if (SelectorUtils.matchPath(exclusionPattern, fileName)) { + logDebug(relResult, "Ignoring changed file: " + fileName); i.remove(); break; } @@ -187,31 +164,30 @@ public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnviro } } - if ( !changedFiles.isEmpty() ) - { + if (!changedFiles.isEmpty()) { StringBuilder message = new StringBuilder(); - for ( ScmFile file : changedFiles ) - { - message.append( file.toString() ); - message.append( "\n" ); + for (ScmFile file : changedFiles) { + message.append(file.toString()); + message.append("\n"); } - throw new ReleaseFailureException( "Cannot prepare the release because you have local modifications : \n" - + message ); + throw new ReleaseFailureException( + "Cannot prepare the release because you have local modifications : \n" + message); } - relResult.setResultCode( ReleaseResult.SUCCESS ); + relResult.setResultCode(ReleaseResult.SUCCESS); return relResult; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { // It makes no modifications, so simulate is the same as execute - return execute( releaseDescriptor, releaseEnvironment, reactorProjects ); + return execute(releaseDescriptor, releaseEnvironment, reactorProjects); } -} \ No newline at end of file +} diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitBranchPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitBranchPhase.java index 7e5e7bce1..932eda14e 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitBranchPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitBranchPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -31,13 +30,10 @@ * @author Brett Porter */ @Singleton -@Named( "scm-commit-branch" ) -public class ScmCommitBranchPhase - extends AbstractScmCommitPreparationPhase -{ +@Named("scm-commit-branch") +public class ScmCommitBranchPhase extends AbstractScmCommitPreparationPhase { @Inject - public ScmCommitBranchPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator, "getScmBranchCommitComment" ); + public ScmCommitBranchPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super(scmRepositoryConfigurator, "getScmBranchCommitComment"); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhase.java index 76643331c..c5ccb4989 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -31,14 +30,13 @@ * @author Brett Porter */ @Singleton -@Named( "scm-commit-development" ) -public class ScmCommitDevelopmentPhase - extends AbstractScmCommitDevelopmentPhase -{ +@Named("scm-commit-development") +public class ScmCommitDevelopmentPhase extends AbstractScmCommitDevelopmentPhase { @Inject - public ScmCommitDevelopmentPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator, "getScmDevelopmentCommitComment", - "rollback changes from release preparation of {0}" ); + public ScmCommitDevelopmentPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super( + scmRepositoryConfigurator, + "getScmDevelopmentCommitComment", + "rollback changes from release preparation of {0}"); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitReleasePhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitReleasePhase.java index bb27a8422..5aff6ee4a 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitReleasePhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitReleasePhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -31,13 +30,10 @@ * @author Brett Porter */ @Singleton -@Named( "scm-commit-release" ) -public class ScmCommitReleasePhase - extends AbstractScmCommitPreparationPhase -{ +@Named("scm-commit-release") +public class ScmCommitReleasePhase extends AbstractScmCommitPreparationPhase { @Inject - public ScmCommitReleasePhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator, "getScmReleaseCommitComment" ); + public ScmCommitReleasePhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super(scmRepositoryConfigurator, "getScmReleaseCommitComment"); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitRollbackPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitRollbackPhase.java index 1acf1ab52..a342c6718 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitRollbackPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCommitRollbackPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -31,13 +30,10 @@ * @author Brett Porter */ @Singleton -@Named( "scm-commit-rollback" ) -public class ScmCommitRollbackPhase - extends AbstractScmCommitPreparationPhase -{ +@Named("scm-commit-rollback") +public class ScmCommitRollbackPhase extends AbstractScmCommitPreparationPhase { @Inject - public ScmCommitRollbackPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { - super( scmRepositoryConfigurator, "getScmRollbackCommitComment" ); + public ScmCommitRollbackPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { + super(scmRepositoryConfigurator, "getScmRollbackCommitComment"); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmTagPhase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmTagPhase.java index 362f6145a..9ec739f97 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmTagPhase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmTagPhase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Inject; import javax.inject.Named; @@ -51,152 +50,129 @@ * @author Brett Porter */ @Singleton -@Named( "scm-tag" ) -public class ScmTagPhase - extends AbstractReleasePhase -{ +@Named("scm-tag") +public class ScmTagPhase extends AbstractReleasePhase { /** * Tool that gets a configured SCM repository from release configuration. */ private final ScmRepositoryConfigurator scmRepositoryConfigurator; @Inject - public ScmTagPhase( ScmRepositoryConfigurator scmRepositoryConfigurator ) - { + public ScmTagPhase(ScmRepositoryConfigurator scmRepositoryConfigurator) { this.scmRepositoryConfigurator = scmRepositoryConfigurator; } @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult relResult = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); - if ( releaseDescriptor.getWaitBeforeTagging() > 0 ) - { - logInfo( relResult, "Waiting for " + releaseDescriptor.getWaitBeforeTagging() - + " seconds before tagging the release." ); - try - { - Thread.sleep( 1000L * releaseDescriptor.getWaitBeforeTagging() ); - } - catch ( InterruptedException e ) - { + if (releaseDescriptor.getWaitBeforeTagging() > 0) { + logInfo( + relResult, + "Waiting for " + releaseDescriptor.getWaitBeforeTagging() + " seconds before tagging the release."); + try { + Thread.sleep(1000L * releaseDescriptor.getWaitBeforeTagging()); + } catch (InterruptedException e) { // Ignore } } - logInfo( relResult, "Tagging release with the label " + releaseDescriptor.getScmReleaseLabel() + "..." ); + logInfo(relResult, "Tagging release with the label " + releaseDescriptor.getScmReleaseLabel() + "..."); ReleaseDescriptor basedirAlignedReleaseDescriptor = - ReleaseUtil.createBasedirAlignedReleaseDescriptor( releaseDescriptor, reactorProjects ); + ReleaseUtil.createBasedirAlignedReleaseDescriptor(releaseDescriptor, reactorProjects); ScmRepository repository; ScmProvider provider; - try - { - repository = - scmRepositoryConfigurator.getConfiguredRepository( basedirAlignedReleaseDescriptor.getScmSourceUrl(), - releaseDescriptor, - releaseEnvironment.getSettings() ); + try { + repository = scmRepositoryConfigurator.getConfiguredRepository( + basedirAlignedReleaseDescriptor.getScmSourceUrl(), + releaseDescriptor, + releaseEnvironment.getSettings()); - repository.getProviderRepository().setPushChanges( releaseDescriptor.isPushChanges() ); + repository.getProviderRepository().setPushChanges(releaseDescriptor.isPushChanges()); - repository.getProviderRepository().setWorkItem( releaseDescriptor.getWorkItem() ); + repository.getProviderRepository().setWorkItem(releaseDescriptor.getWorkItem()); - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); - } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); - } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + provider = scmRepositoryConfigurator.getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e.getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException("Unable to configure SCM repository: " + e.getMessage(), e); } TagScmResult result; - try - { + try { // TODO: want includes/excludes? - ScmFileSet fileSet = new ScmFileSet( new File( basedirAlignedReleaseDescriptor.getWorkingDirectory() ) ); + ScmFileSet fileSet = new ScmFileSet(new File(basedirAlignedReleaseDescriptor.getWorkingDirectory())); String tagName = releaseDescriptor.getScmReleaseLabel(); ScmTagParameters scmTagParameters = - new ScmTagParameters( releaseDescriptor.getScmCommentPrefix() + "copy for tag " + tagName ); - scmTagParameters.setRemoteTagging( releaseDescriptor.isRemoteTagging() ); - scmTagParameters.setSign( releaseDescriptor.isScmSignTags() ); - scmTagParameters.setScmRevision( releaseDescriptor.getScmReleasedPomRevision() ); - scmTagParameters.setPinExternals( releaseDescriptor.isPinExternals() ); - if ( getLogger().isDebugEnabled() ) - { - getLogger().debug( - "ScmTagPhase :: scmTagParameters remotingTag " + releaseDescriptor.isRemoteTagging() ); - getLogger().debug( - "ScmTagPhase :: scmTagParameters scmRevision " + releaseDescriptor.getScmReleasedPomRevision() ); - getLogger().debug( - "ScmTagPhase :: scmTagParameters pinExternals " + releaseDescriptor.isPinExternals() ); - getLogger().debug( "ScmTagPhase :: fileSet " + fileSet ); + new ScmTagParameters(releaseDescriptor.getScmCommentPrefix() + "copy for tag " + tagName); + scmTagParameters.setRemoteTagging(releaseDescriptor.isRemoteTagging()); + scmTagParameters.setSign(releaseDescriptor.isScmSignTags()); + scmTagParameters.setScmRevision(releaseDescriptor.getScmReleasedPomRevision()); + scmTagParameters.setPinExternals(releaseDescriptor.isPinExternals()); + if (getLogger().isDebugEnabled()) { + getLogger().debug("ScmTagPhase :: scmTagParameters remotingTag " + releaseDescriptor.isRemoteTagging()); + getLogger() + .debug("ScmTagPhase :: scmTagParameters scmRevision " + + releaseDescriptor.getScmReleasedPomRevision()); + getLogger().debug("ScmTagPhase :: scmTagParameters pinExternals " + releaseDescriptor.isPinExternals()); + getLogger().debug("ScmTagPhase :: fileSet " + fileSet); } - result = provider.tag( repository, fileSet, tagName, scmTagParameters ); - } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error is occurred in the tag process: " + e.getMessage(), e ); + result = provider.tag(repository, fileSet, tagName, scmTagParameters); + } catch (ScmException e) { + throw new ReleaseExecutionException("An error is occurred in the tag process: " + e.getMessage(), e); } - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to tag SCM", result ); + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to tag SCM", result); } - relResult.setResultCode( ReleaseResult.SUCCESS ); + relResult.setResultCode(ReleaseResult.SUCCESS); return relResult; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, - List reactorProjects ) - throws ReleaseExecutionException, ReleaseFailureException - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) + throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult result = new ReleaseResult(); - validateConfiguration( releaseDescriptor ); + validateConfiguration(releaseDescriptor); ReleaseDescriptor basedirAlignedReleaseDescriptor = - ReleaseUtil.createBasedirAlignedReleaseDescriptor( releaseDescriptor, reactorProjects ); - - if ( releaseDescriptor.isRemoteTagging() ) - { - logInfo( result, - "Full run would tag working copy '" - + basedirAlignedReleaseDescriptor.getWorkingDirectory() + "'" ); - } - else - { - logInfo( result, "Full run would tag remotely '" - + basedirAlignedReleaseDescriptor.getScmSourceUrl() + "'" ); + ReleaseUtil.createBasedirAlignedReleaseDescriptor(releaseDescriptor, reactorProjects); + + if (releaseDescriptor.isRemoteTagging()) { + logInfo( + result, + "Full run would tag working copy '" + basedirAlignedReleaseDescriptor.getWorkingDirectory() + "'"); + } else { + logInfo(result, "Full run would tag remotely '" + basedirAlignedReleaseDescriptor.getScmSourceUrl() + "'"); } - logInfo( result, " with label '" + releaseDescriptor.getScmReleaseLabel() + "'" ); - if ( releaseDescriptor.isPinExternals() ) - { - logInfo( result, " and pinned externals" ); + logInfo(result, " with label '" + releaseDescriptor.getScmReleaseLabel() + "'"); + if (releaseDescriptor.isPinExternals()) { + logInfo(result, " and pinned externals"); } - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - private static void validateConfiguration( ReleaseDescriptor releaseDescriptor ) - throws ReleaseFailureException - { - if ( releaseDescriptor.getScmReleaseLabel() == null ) - { - throw new ReleaseFailureException( "A release label is required for committing" ); + private static void validateConfiguration(ReleaseDescriptor releaseDescriptor) throws ReleaseFailureException { + if (releaseDescriptor.getScmReleaseLabel() == null) { + throw new ReleaseFailureException("A release label is required for committing"); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java index c76fc6bc6..1f6208b9d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policies; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policies; import javax.inject.Named; import javax.inject.Singleton; @@ -35,12 +34,9 @@ */ @Singleton @Named -public class DefaultNamingPolicy implements NamingPolicy -{ +public class DefaultNamingPolicy implements NamingPolicy { @Override - public NamingPolicyResult getName( NamingPolicyRequest request ) - throws PolicyException - { - return new NamingPolicyResult().setName( request.getArtifactId() + "-" + request.getVersion() ); + public NamingPolicyResult getName(NamingPolicyRequest request) throws PolicyException { + return new NamingPolicyResult().setName(request.getArtifactId() + "-" + request.getVersion()); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultVersionPolicy.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultVersionPolicy.java index a3df92a0b..8e019e0d7 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultVersionPolicy.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultVersionPolicy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policies; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policies; import javax.inject.Named; import javax.inject.Singleton; @@ -36,24 +35,17 @@ */ @Singleton @Named -public class DefaultVersionPolicy - implements VersionPolicy -{ +public class DefaultVersionPolicy implements VersionPolicy { @Override - public VersionPolicyResult getReleaseVersion( VersionPolicyRequest request ) - throws VersionParseException - { - String releaseVersion = new DefaultVersionInfo( request.getVersion() ).getReleaseVersionString(); - return new VersionPolicyResult().setVersion( releaseVersion ); + public VersionPolicyResult getReleaseVersion(VersionPolicyRequest request) throws VersionParseException { + String releaseVersion = new DefaultVersionInfo(request.getVersion()).getReleaseVersionString(); + return new VersionPolicyResult().setVersion(releaseVersion); } @Override - public VersionPolicyResult getDevelopmentVersion( VersionPolicyRequest request ) - throws VersionParseException - { + public VersionPolicyResult getDevelopmentVersion(VersionPolicyRequest request) throws VersionParseException { String developmentVersion = - new DefaultVersionInfo( request.getVersion() ).getNextVersion().getSnapshotVersionString(); - return new VersionPolicyResult().setVersion( developmentVersion ); + new DefaultVersionInfo(request.getVersion()).getNextVersion().getSnapshotVersionString(); + return new VersionPolicyResult().setVersion(developmentVersion); } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslator.java index 642c5c7b5..a6f716f5e 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Named; import javax.inject.Singleton; @@ -28,38 +27,29 @@ * @author Arne Degenring */ @Singleton -@Named( "clearcase" ) -public class ClearCaseScmTranslator - implements ScmTranslator -{ +@Named("clearcase") +public class ClearCaseScmTranslator implements ScmTranslator { @Override - public String translateBranchUrl( String url, String branchName, String branchBase ) - { + public String translateBranchUrl(String url, String branchName, String branchBase) { return url; } @Override - public String translateTagUrl( String url, String tag, String tagBase ) - { + public String translateTagUrl(String url, String tag, String tagBase) { return url; } @Override - public String resolveTag( String tag ) - { - if ( !"HEAD".equals( tag ) ) - { + public String resolveTag(String tag) { + if (!"HEAD".equals(tag)) { return tag; - } - else - { + } else { return null; } } @Override - public String toRelativePath( String path ) - { + public String toRelativePath(String path) { return path; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/CvsScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/CvsScmTranslator.java index e6c1aa07e..5968682ed 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/CvsScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/CvsScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Named; import javax.inject.Singleton; @@ -28,38 +27,29 @@ * @author Brett Porter */ @Singleton -@Named( "cvs" ) -public class CvsScmTranslator - implements ScmTranslator -{ +@Named("cvs") +public class CvsScmTranslator implements ScmTranslator { @Override - public String translateBranchUrl( String url, String branchName, String branchBase ) - { + public String translateBranchUrl(String url, String branchName, String branchBase) { return url; } @Override - public String translateTagUrl( String url, String tag, String tagBase ) - { + public String translateTagUrl(String url, String tag, String tagBase) { return url; } @Override - public String resolveTag( String tag ) - { - if ( !"HEAD".equals( tag ) ) - { + public String resolveTag(String tag) { + if (!"HEAD".equals(tag)) { return tag; - } - else - { + } else { return null; } } @Override - public String toRelativePath( String path ) - { + public String toRelativePath(String path) { return path; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfigurator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfigurator.java index e6be92496..f2adb28e1 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfigurator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfigurator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Inject; import javax.inject.Named; @@ -51,174 +50,142 @@ */ @Singleton @Named -public class DefaultScmRepositoryConfigurator - implements ScmRepositoryConfigurator -{ - private final Logger logger = LoggerFactory.getLogger( getClass() ); +public class DefaultScmRepositoryConfigurator implements ScmRepositoryConfigurator { + private final Logger logger = LoggerFactory.getLogger(getClass()); private final AtomicReference scmManager; private final MavenCrypto mavenCrypto; @Inject - public DefaultScmRepositoryConfigurator( ScmManager scmManager, MavenCrypto mavenCrypto ) - { - this.scmManager = new AtomicReference<>( requireNonNull( scmManager ) ); - this.mavenCrypto = requireNonNull( mavenCrypto ); + public DefaultScmRepositoryConfigurator(ScmManager scmManager, MavenCrypto mavenCrypto) { + this.scmManager = new AtomicReference<>(requireNonNull(scmManager)); + this.mavenCrypto = requireNonNull(mavenCrypto); } /** * For testing purposes only! */ - public void setScmManager( ScmManager scmManager ) - { - this.scmManager.set( scmManager ); + public void setScmManager(ScmManager scmManager) { + this.scmManager.set(scmManager); } @Override - public ScmRepository getConfiguredRepository( ReleaseDescriptor releaseDescriptor, Settings settings ) - throws ScmRepositoryException, NoSuchScmProviderException - { + public ScmRepository getConfiguredRepository(ReleaseDescriptor releaseDescriptor, Settings settings) + throws ScmRepositoryException, NoSuchScmProviderException { String url = releaseDescriptor.getScmSourceUrl(); - return getConfiguredRepository( url, releaseDescriptor, settings ); + return getConfiguredRepository(url, releaseDescriptor, settings); } @Override - public ScmRepository getConfiguredRepository( String url, ReleaseDescriptor releaseDescriptor, Settings settings ) - throws ScmRepositoryException, NoSuchScmProviderException - { + public ScmRepository getConfiguredRepository(String url, ReleaseDescriptor releaseDescriptor, Settings settings) + throws ScmRepositoryException, NoSuchScmProviderException { String username = releaseDescriptor.getScmUsername(); String password = releaseDescriptor.getScmPassword(); String privateKey = releaseDescriptor.getScmPrivateKey(); String passphrase = releaseDescriptor.getScmPrivateKeyPassPhrase(); - ScmRepository repository = scmManager.get().makeScmRepository( url ); + ScmRepository repository = scmManager.get().makeScmRepository(url); ScmProviderRepository scmRepo = repository.getProviderRepository(); - //MRELEASE-76 - scmRepo.setPersistCheckout( false ); + // MRELEASE-76 + scmRepo.setPersistCheckout(false); - if ( settings != null ) - { + if (settings != null) { Server server = null; - if ( releaseDescriptor.getScmId() != null ) - { - server = settings.getServer( releaseDescriptor.getScmId() ); + if (releaseDescriptor.getScmId() != null) { + server = settings.getServer(releaseDescriptor.getScmId()); } - if ( server == null && repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost ) - { + if (server == null && repository.getProviderRepository() instanceof ScmProviderRepositoryWithHost) { ScmProviderRepositoryWithHost repositoryWithHost = - (ScmProviderRepositoryWithHost) repository.getProviderRepository(); + (ScmProviderRepositoryWithHost) repository.getProviderRepository(); String host = repositoryWithHost.getHost(); int port = repositoryWithHost.getPort(); - if ( port > 0 ) - { + if (port > 0) { host += ":" + port; } - // TODO: this is a bit dodgy - id is not host, but since we don't have a field we make an assumption - server = settings.getServer( host ); + // TODO: this is a bit dodgy - id is not host, but since we don't have a field we make an + // assumption + server = settings.getServer(host); } - if ( server != null ) - { - if ( username == null ) - { + if (server != null) { + if (username == null) { username = server.getUsername(); } - if ( password == null ) - { - password = decrypt( server.getPassword(), server.getId() ); + if (password == null) { + password = decrypt(server.getPassword(), server.getId()); } - if ( privateKey == null ) - { + if (privateKey == null) { privateKey = server.getPrivateKey(); } - if ( passphrase == null ) - { - passphrase = decrypt( server.getPassphrase(), server.getId() ); + if (passphrase == null) { + passphrase = decrypt(server.getPassphrase(), server.getId()); } } } - if ( !StringUtils.isEmpty( username ) ) - { - scmRepo.setUser( username ); + if (!StringUtils.isEmpty(username)) { + scmRepo.setUser(username); } - if ( !StringUtils.isEmpty( password ) ) - { - scmRepo.setPassword( password ); + if (!StringUtils.isEmpty(password)) { + scmRepo.setPassword(password); } - if ( scmRepo instanceof ScmProviderRepositoryWithHost ) - { + if (scmRepo instanceof ScmProviderRepositoryWithHost) { ScmProviderRepositoryWithHost repositoryWithHost = (ScmProviderRepositoryWithHost) scmRepo; - if ( !StringUtils.isEmpty( privateKey ) ) - { - repositoryWithHost.setPrivateKey( privateKey ); + if (!StringUtils.isEmpty(privateKey)) { + repositoryWithHost.setPrivateKey(privateKey); } - if ( !StringUtils.isEmpty( passphrase ) ) - { - repositoryWithHost.setPassphrase( passphrase ); + if (!StringUtils.isEmpty(passphrase)) { + repositoryWithHost.setPassphrase(passphrase); } } - if ( "svn".equals( repository.getProvider() ) ) - { + if ("svn".equals(repository.getProvider())) { SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) repository.getProviderRepository(); String tagBase = releaseDescriptor.getScmTagBase(); - if ( !StringUtils.isEmpty( tagBase ) ) - { - svnRepo.setTagBase( tagBase ); + if (!StringUtils.isEmpty(tagBase)) { + svnRepo.setTagBase(tagBase); } String branchBase = releaseDescriptor.getScmBranchBase(); - if ( !StringUtils.isEmpty( branchBase ) ) - { - svnRepo.setBranchBase( branchBase ); + if (!StringUtils.isEmpty(branchBase)) { + svnRepo.setBranchBase(branchBase); } } return repository; } - private String decrypt( String str, String server ) - { - try - { - return mavenCrypto.decrypt( str ); - } - catch ( MavenCryptoException e ) - { - String msg = - "Failed to decrypt password/passphrase for server " + server + ", using auth token as is: " + private String decrypt(String str, String server) { + try { + return mavenCrypto.decrypt(str); + } catch (MavenCryptoException e) { + String msg = "Failed to decrypt password/passphrase for server " + server + ", using auth token as is: " + e.getMessage(); - if ( logger.isDebugEnabled() ) - { - logger.warn( msg, e ); - } - else - { - logger.warn( msg ); + if (logger.isDebugEnabled()) { + logger.warn(msg, e); + } else { + logger.warn(msg); } return str; } } @Override - public ScmProvider getRepositoryProvider( ScmRepository repository ) - throws NoSuchScmProviderException - { - return scmManager.get().getProviderByRepository( repository ); + public ScmProvider getRepositoryProvider(ScmRepository repository) throws NoSuchScmProviderException { + return scmManager.get().getProviderByRepository(repository); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/GitScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/GitScmTranslator.java index 4399479f1..5ad884386 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/GitScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/GitScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Named; import javax.inject.Singleton; @@ -26,32 +25,26 @@ *

GitScmTranslator class.

*/ @Singleton -@Named( "git" ) -public class GitScmTranslator - implements ScmTranslator -{ +@Named("git") +public class GitScmTranslator implements ScmTranslator { @Override - public String translateBranchUrl( String url, String branchName, String branchBase ) - { + public String translateBranchUrl(String url, String branchName, String branchBase) { return url; } @Override - public String translateTagUrl( String url, String tag, String tagBase ) - { + public String translateTagUrl(String url, String tag, String tagBase) { return url; } @Override - public String resolveTag( String tag ) - { + public String resolveTag(String tag) { return tag; } @Override - public String toRelativePath( String path ) - { + public String toRelativePath(String path) { return path; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/HgScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/HgScmTranslator.java index 73a038ac0..dac80125c 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/HgScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/HgScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Named; import javax.inject.Singleton; @@ -26,32 +25,26 @@ *

HgScmTranslator class.

*/ @Singleton -@Named( "hg" ) -public class HgScmTranslator - implements ScmTranslator -{ +@Named("hg") +public class HgScmTranslator implements ScmTranslator { @Override - public String translateBranchUrl( String url, String branchName, String branchBase ) - { + public String translateBranchUrl(String url, String branchName, String branchBase) { return url; } @Override - public String translateTagUrl( String url, String tag, String tagBase ) - { + public String translateTagUrl(String url, String tag, String tagBase) { return url; } @Override - public String resolveTag( String tag ) - { + public String resolveTag(String tag) { return tag; } @Override - public String toRelativePath( String path ) - { + public String toRelativePath(String path) { return path; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/IdentifiedScm.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/IdentifiedScm.java index 0a963fb89..1cf9ce792 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/IdentifiedScm.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/IdentifiedScm.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.apache.maven.model.Scm; @@ -28,9 +27,7 @@ * @author Robert Scholte * @since 2.3 */ -public class IdentifiedScm - extends Scm -{ +public class IdentifiedScm extends Scm { private String id; @@ -39,8 +36,7 @@ public class IdentifiedScm * * @return the id */ - public String getId() - { + public String getId() { return id; } @@ -49,8 +45,7 @@ public String getId() * * @param id the id to set */ - public void setId( String id ) - { + public void setId(String id) { this.id = id; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/JazzScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/JazzScmTranslator.java index 8da9b534e..9bb5cafdd 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/JazzScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/JazzScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Named; import javax.inject.Singleton; @@ -30,65 +29,54 @@ * @author Chris Graham */ @Singleton -@Named( "jazz" ) -public class JazzScmTranslator - implements ScmTranslator -{ +@Named("jazz") +public class JazzScmTranslator implements ScmTranslator { @Override - public String translateBranchUrl( String url, String branchName, String branchBase ) - { + public String translateBranchUrl(String url, String branchName, String branchBase) { // Jazz URL's (currently) take the form: // "scm:jazz:[username[;password]@]http[s]://server_name[:port]/jazzPath:repositoryWorkspace" // Eg: // scm:jazz:Deb;Deb@https://rtc:9444/jazz:BogusRepositoryWorkspace - int i = url.lastIndexOf( ':' ); - url = url.substring( 0, i + 1 ); - if ( branchName != null && branchName.endsWith( "/" ) ) - { + int i = url.lastIndexOf(':'); + url = url.substring(0, i + 1); + if (branchName != null && branchName.endsWith("/")) { // Remove the trailing "/", if present. - branchName = branchName.substring( 0, branchName.length() - 1 ); + branchName = branchName.substring(0, branchName.length() - 1); } url = url + branchName; return url; } @Override - public String translateTagUrl( String url, String tag, String tagBase ) - { + public String translateTagUrl(String url, String tag, String tagBase) { // Jazz URL's (currently) take the form: // "scm:jazz:[username[;password]@]http[s]://server_name[:port]/jazzPath:repositoryWorkspace" // Eg: // scm:jazz:Deb;Deb@https://rtc:9444/jazz:BogusRepositoryWorkspace - int i = url.lastIndexOf( ':' ); - url = url.substring( 0, i + 1 ); - if ( tag != null && tag.endsWith( "/" ) ) - { + int i = url.lastIndexOf(':'); + url = url.substring(0, i + 1); + if (tag != null && tag.endsWith("/")) { // Remove the trailing "/", if present. - tag = tag.substring( 0, tag.length() - 1 ); + tag = tag.substring(0, tag.length() - 1); } url = url + tag; return url; } @Override - public String resolveTag( String tag ) - { + public String resolveTag(String tag) { // project.scm.tag is not required, so return null. return null; } @Override - public String toRelativePath( String path ) - { + public String toRelativePath(String path) { String relativePath; - if ( path.startsWith( "\\" ) || path.startsWith( "/" ) ) - { - relativePath = path.substring( 1 ); - } - else - { + if (path.startsWith("\\") || path.startsWith("/")) { + relativePath = path.substring(1); + } else { relativePath = path; } - return relativePath.replace( "\\", File.separator ).replace( "/", File.separator ); + return relativePath.replace("\\", File.separator).replace("/", File.separator); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmCommandException.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmCommandException.java index a372a2b3a..779678a7a 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmCommandException.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmCommandException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.apache.maven.scm.ScmResult; import org.apache.maven.shared.release.ReleaseFailureException; @@ -27,18 +26,15 @@ * * @author Brett Porter */ -public class ReleaseScmCommandException - extends ReleaseFailureException -{ +public class ReleaseScmCommandException extends ReleaseFailureException { /** *

Constructor for ReleaseScmCommandException.

* * @param message a {@link java.lang.String} object * @param result a {@link org.apache.maven.scm.ScmResult} object */ - public ReleaseScmCommandException( String message, ScmResult result ) - { - super( message + "\nProvider message:\n" + result.getProviderMessage() + "\nCommand output:\n" - + result.getCommandOutput() ); + public ReleaseScmCommandException(String message, ScmResult result) { + super(message + "\nProvider message:\n" + result.getProviderMessage() + "\nCommand output:\n" + + result.getCommandOutput()); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmRepositoryException.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmRepositoryException.java index f644b3b7e..d3f062207 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmRepositoryException.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ReleaseScmRepositoryException.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,40 +16,35 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.shared.release.ReleaseFailureException; +package org.apache.maven.shared.release.scm; import java.util.List; +import org.apache.maven.shared.release.ReleaseFailureException; + /** * Exception occurring during an SCM repository operation. * * @author Brett Porter */ -public class ReleaseScmRepositoryException - extends ReleaseFailureException -{ +public class ReleaseScmRepositoryException extends ReleaseFailureException { /** *

Constructor for ReleaseScmRepositoryException.

* * @param message a {@link java.lang.String} object * @param validationMessages a {@link java.util.List} object */ - public ReleaseScmRepositoryException( String message, List validationMessages ) - { - super( message + listValidationMessages( validationMessages ) ); + public ReleaseScmRepositoryException(String message, List validationMessages) { + super(message + listValidationMessages(validationMessages)); } - private static String listValidationMessages( List messages ) - { + private static String listValidationMessages(List messages) { StringBuilder buffer = new StringBuilder(); - if ( messages != null ) - { - for ( String message : messages ) - { - buffer.append( "\n - " ); - buffer.append( message ); + if (messages != null) { + for (String message : messages) { + buffer.append("\n - "); + buffer.append(message); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmRepositoryConfigurator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmRepositoryConfigurator.java index b4c759aed..a406de832 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmRepositoryConfigurator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmRepositoryConfigurator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.apache.maven.scm.manager.NoSuchScmProviderException; import org.apache.maven.scm.provider.ScmProvider; @@ -31,8 +30,7 @@ * * @author Brett Porter */ -public interface ScmRepositoryConfigurator -{ +public interface ScmRepositoryConfigurator { /** * Construct a configured SCM repository from a release configuration. * @@ -43,8 +41,8 @@ public interface ScmRepositoryConfigurator * SCM repository * @throws org.apache.maven.scm.manager.NoSuchScmProviderException if the requested SCM provider is not available */ - ScmRepository getConfiguredRepository( ReleaseDescriptor releaseDescriptor, Settings settings ) - throws ScmRepositoryException, NoSuchScmProviderException; + ScmRepository getConfiguredRepository(ReleaseDescriptor releaseDescriptor, Settings settings) + throws ScmRepositoryException, NoSuchScmProviderException; /** * Get the SCM provider used for the given SCM repository. @@ -53,8 +51,7 @@ ScmRepository getConfiguredRepository( ReleaseDescriptor releaseDescriptor, Sett * @return the SCM provider * @throws org.apache.maven.scm.manager.NoSuchScmProviderException if the requested SCM provider is not available */ - ScmProvider getRepositoryProvider( ScmRepository repository ) - throws NoSuchScmProviderException; + ScmProvider getRepositoryProvider(ScmRepository repository) throws NoSuchScmProviderException; /** * Construct a configured SCM repository from a release configuration with an overridden base SCM URL. @@ -67,6 +64,6 @@ ScmProvider getRepositoryProvider( ScmRepository repository ) * SCM repository * @throws org.apache.maven.scm.manager.NoSuchScmProviderException if the requested SCM provider is not available */ - ScmRepository getConfiguredRepository( String url, ReleaseDescriptor releaseDescriptor, Settings settings ) - throws ScmRepositoryException, NoSuchScmProviderException; + ScmRepository getConfiguredRepository(String url, ReleaseDescriptor releaseDescriptor, Settings settings) + throws ScmRepositoryException, NoSuchScmProviderException; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmTranslator.java index 693f6469a..ac22d4562 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/ScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; /** * Translate the SCM information after tagging/reverting to trunk. @@ -25,8 +24,7 @@ * @author Brett Porter */ // TODO move this API into SCM? -public interface ScmTranslator -{ +public interface ScmTranslator { /** * Take an URL and find the correct replacement URL for a given branch. * @@ -35,7 +33,7 @@ public interface ScmTranslator * @param branchBase the branch base for providers that support it * @return the replacement URL */ - String translateBranchUrl( String url, String branchName, String branchBase ); + String translateBranchUrl(String url, String branchName, String branchBase); /** * Take an URL and find the correct replacement URL for a given tag. @@ -45,7 +43,7 @@ public interface ScmTranslator * @param tagBase the tag base for providers that support it * @return the replacement URL */ - String translateTagUrl( String url, String tag, String tagBase ); + String translateTagUrl(String url, String tag, String tagBase); /** * Determine what tag should be added to the POM given the original tag and the new one. @@ -53,7 +51,7 @@ public interface ScmTranslator * @param tag the new tag * @return the tag to use, or null if the provider does not use tags */ - String resolveTag( String tag ); + String resolveTag(String tag); /** * Translates an ScmFile path to a path relative to the working directory. @@ -62,5 +60,5 @@ public interface ScmTranslator * @return the relative path with OS specific File separator * @since 2.3.1 */ - String toRelativePath( String path ); + String toRelativePath(String path); } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/SubversionScmTranslator.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/SubversionScmTranslator.java index 0f8db4b78..a3427f964 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/SubversionScmTranslator.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/scm/SubversionScmTranslator.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import javax.inject.Named; import javax.inject.Singleton; @@ -32,32 +31,25 @@ * @author Brett Porter */ @Singleton -@Named( "svn" ) -public class SubversionScmTranslator - implements ScmTranslator -{ +@Named("svn") +public class SubversionScmTranslator implements ScmTranslator { @Override - public String translateBranchUrl( String url, String branchName, String branchBase ) - { - return SvnTagBranchUtils.resolveUrl( url, branchBase, SvnTagBranchUtils.SVN_BRANCHES, - new ScmBranch( branchName ) ); + public String translateBranchUrl(String url, String branchName, String branchBase) { + return SvnTagBranchUtils.resolveUrl(url, branchBase, SvnTagBranchUtils.SVN_BRANCHES, new ScmBranch(branchName)); } @Override - public String translateTagUrl( String url, String tag, String tagBase ) - { - return SvnTagBranchUtils.resolveUrl( url, tagBase, SvnTagBranchUtils.SVN_TAGS, new ScmTag( tag ) ); + public String translateTagUrl(String url, String tag, String tagBase) { + return SvnTagBranchUtils.resolveUrl(url, tagBase, SvnTagBranchUtils.SVN_TAGS, new ScmTag(tag)); } @Override - public String resolveTag( String tag ) - { + public String resolveTag(String tag) { return null; } @Override - public String toRelativePath( String path ) - { + public String toRelativePath(String path) { return path; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/strategies/DefaultStrategy.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/strategies/DefaultStrategy.java index 60b51485a..fdbe761e6 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/strategies/DefaultStrategy.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/strategies/DefaultStrategy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.strategies; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.strategies; import javax.inject.Named; import javax.inject.Singleton; @@ -36,8 +35,7 @@ */ @Singleton @Named -public class DefaultStrategy implements Strategy -{ +public class DefaultStrategy implements Strategy { /** * The phases of release to run to prepare. */ @@ -63,10 +61,9 @@ public class DefaultStrategy implements Strategy */ private final List updateVersionsPhases; - public DefaultStrategy() - { - this.preparePhases = Collections.unmodifiableList( Arrays.asList( - //START SNIPPET: prepare + public DefaultStrategy() { + this.preparePhases = Collections.unmodifiableList(Arrays.asList( + // START SNIPPET: prepare "check-poms", "scm-check-modifications", "check-dependency-snapshots", @@ -84,24 +81,20 @@ public DefaultStrategy() "run-completion-goals", "scm-commit-development", "end-release" - //END SNIPPET: prepare - ) ); - this.performPhases = Collections.unmodifiableList( Arrays.asList( - //START SNIPPET: perform - "verify-completed-prepare-phases", - "checkout-project-from-scm", - "run-perform-goals" - //END SNIPPET: perform - ) ); - this.rollbackPhases = Collections.unmodifiableList( Arrays.asList( - //START SNIPPET: rollback - "restore-backup-poms", - "scm-commit-rollback", - "remove-scm-tag" - //END SNIPPET: rollback - ) ); - this.branchPhases = Collections.unmodifiableList( Arrays.asList( - //START SNIPPET: branch + // END SNIPPET: prepare + )); + this.performPhases = Collections.unmodifiableList(Arrays.asList( + // START SNIPPET: perform + "verify-completed-prepare-phases", "checkout-project-from-scm", "run-perform-goals" + // END SNIPPET: perform + )); + this.rollbackPhases = Collections.unmodifiableList(Arrays.asList( + // START SNIPPET: rollback + "restore-backup-poms", "scm-commit-rollback", "remove-scm-tag" + // END SNIPPET: rollback + )); + this.branchPhases = Collections.unmodifiableList(Arrays.asList( + // START SNIPPET: branch "check-poms", "scm-check-modifications", "create-backup-poms", @@ -114,45 +107,37 @@ public DefaultStrategy() "rewrite-poms-for-development", "scm-commit-development", "end-release" - //END SNIPPET: branch - ) ); - this.updateVersionsPhases = Collections.unmodifiableList( Arrays.asList( - //START SNIPPET: update-versions - "check-poms-updateversions", - "create-backup-poms", - "map-development-versions", - "rewrite-pom-versions" - //END SNIPPET: update-versions - ) ); + // END SNIPPET: branch + )); + this.updateVersionsPhases = Collections.unmodifiableList(Arrays.asList( + // START SNIPPET: update-versions + "check-poms-updateversions", "create-backup-poms", "map-development-versions", "rewrite-pom-versions" + // END SNIPPET: update-versions + )); } @Override - public final List getPreparePhases() - { + public final List getPreparePhases() { return preparePhases; } @Override - public List getPerformPhases() - { + public List getPerformPhases() { return performPhases; } @Override - public List getRollbackPhases() - { + public List getRollbackPhases() { return rollbackPhases; } @Override - public List getBranchPhases() - { + public List getBranchPhases() { return branchPhases; } @Override - public List getUpdateVersionsPhases() - { + public List getUpdateVersionsPhases() { return updateVersionsPhases; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/MavenCoordinate.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/MavenCoordinate.java index 422b66c3d..b07eb940e 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/MavenCoordinate.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/MavenCoordinate.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform; /** *

MavenCoordinate interface.

@@ -25,8 +24,7 @@ * @author Robert Scholte * @since 3.0 */ -public interface MavenCoordinate -{ +public interface MavenCoordinate { /** *

getGroupId.

* @@ -53,7 +51,7 @@ public interface MavenCoordinate * * @param version a {@link java.lang.String} object */ - void setVersion( String version ); + void setVersion(String version); // @todo helper method during refactoring, will be removed /** diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETL.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETL.java index 4ebd36578..fc4fe1812 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETL.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETL.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform; import java.io.File; @@ -30,15 +29,14 @@ * @author Robert Scholte * @since 3.0 */ -public interface ModelETL -{ +public interface ModelETL { /** *

extract.

* * @param pomFile a {@link java.io.File} object * @throws org.apache.maven.shared.release.ReleaseExecutionException if any. */ - void extract( File pomFile ) throws ReleaseExecutionException; + void extract(File pomFile) throws ReleaseExecutionException; /** *

transform.

@@ -51,7 +49,7 @@ public interface ModelETL * @param pomFile a {@link java.io.File} object * @throws org.apache.maven.shared.release.ReleaseExecutionException if any. */ - void load( File pomFile ) throws ReleaseExecutionException; + void load(File pomFile) throws ReleaseExecutionException; // will be removed once transform() is implemented /** diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLFactory.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLFactory.java index 618d93ead..195ba5b36 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLFactory.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLFactory.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform; /** *

ModelETLFactory interface.

@@ -25,13 +24,12 @@ * @author Robert Scholte * @since 3.0 */ -public interface ModelETLFactory -{ +public interface ModelETLFactory { /** *

newInstance.

* * @param request a {@link org.apache.maven.shared.release.transform.ModelETLRequest} object * @return a {@link org.apache.maven.shared.release.transform.ModelETL} object */ - ModelETL newInstance( ModelETLRequest request ); + ModelETL newInstance(ModelETLRequest request); } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLRequest.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLRequest.java index 85083f049..9684a1513 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLRequest.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/ModelETLRequest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.release.config.ReleaseDescriptor; @@ -28,8 +27,7 @@ * @author Robert Scholte * @since 3.0 */ -public class ModelETLRequest -{ +public class ModelETLRequest { private MavenProject project; @@ -40,8 +38,7 @@ public class ModelETLRequest * * @return a {@link java.lang.String} object */ - public String getLineSeparator() - { + public String getLineSeparator() { return releaseDescriptor.getLineSeparator(); } @@ -50,8 +47,7 @@ public String getLineSeparator() * * @return a {@link org.apache.maven.project.MavenProject} object */ - public MavenProject getProject() - { + public MavenProject getProject() { return project; } @@ -60,8 +56,7 @@ public MavenProject getProject() * * @param project a {@link org.apache.maven.project.MavenProject} object */ - public void setProject( MavenProject project ) - { + public void setProject(MavenProject project) { this.project = project; } @@ -70,8 +65,7 @@ public void setProject( MavenProject project ) * * @return a {@link org.apache.maven.shared.release.config.ReleaseDescriptor} object */ - public ReleaseDescriptor getReleaseDescriptor() - { + public ReleaseDescriptor getReleaseDescriptor() { return releaseDescriptor; } @@ -80,8 +74,7 @@ public ReleaseDescriptor getReleaseDescriptor() * * @param releaseDescriptor a {@link org.apache.maven.shared.release.config.ReleaseDescriptor} object */ - public void setReleaseDescriptor( ReleaseDescriptor releaseDescriptor ) - { + public void setReleaseDescriptor(ReleaseDescriptor releaseDescriptor) { this.releaseDescriptor = releaseDescriptor; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomBuild.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomBuild.java index 53fb678f5..fc0f81bc3 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomBuild.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomBuild.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -30,15 +29,14 @@ import org.apache.maven.model.PluginManagement; import org.apache.maven.model.Resource; import org.jdom2.Element; + /** * JDOM2 implementation of poms BUILD element * * @author Robert Scholte * @since 3.0 */ -public class JDomBuild - extends Build -{ +public class JDomBuild extends Build { private final Element build; /** @@ -46,262 +44,213 @@ public class JDomBuild * * @param build a {@link org.jdom2.Element} object */ - public JDomBuild( Element build ) - { + public JDomBuild(Element build) { this.build = build; } @Override - public void addExtension( Extension extension ) - { + public void addExtension(Extension extension) { throw new UnsupportedOperationException(); } @Override - public List getExtensions() - { - Element extensionsElm = build.getChild( "extensions", build.getNamespace() ); - if ( extensionsElm == null ) - { + public List getExtensions() { + Element extensionsElm = build.getChild("extensions", build.getNamespace()); + if (extensionsElm == null) { return Collections.emptyList(); - } - else - { - List extensionElms = extensionsElm.getChildren( "extension", build.getNamespace() ); - - List extensions = new ArrayList<>( extensionElms.size() ); - for ( Element extensionElm : extensionElms ) - { - extensions.add( new JDomExtension( extensionElm ) ); + } else { + List extensionElms = extensionsElm.getChildren("extension", build.getNamespace()); + + List extensions = new ArrayList<>(extensionElms.size()); + for (Element extensionElm : extensionElms) { + extensions.add(new JDomExtension(extensionElm)); } return extensions; } } @Override - public String getOutputDirectory() - { + public String getOutputDirectory() { throw new UnsupportedOperationException(); } @Override - public String getScriptSourceDirectory() - { + public String getScriptSourceDirectory() { throw new UnsupportedOperationException(); } @Override - public String getSourceDirectory() - { + public String getSourceDirectory() { throw new UnsupportedOperationException(); } @Override - public String getTestOutputDirectory() - { + public String getTestOutputDirectory() { throw new UnsupportedOperationException(); } @Override - public String getTestSourceDirectory() - { + public String getTestSourceDirectory() { throw new UnsupportedOperationException(); } @Override - public void removeExtension( Extension extension ) - { + public void removeExtension(Extension extension) { throw new UnsupportedOperationException(); } @Override - public void setExtensions( List extensions ) - { + public void setExtensions(List extensions) { throw new UnsupportedOperationException(); } @Override - public void setOutputDirectory( String outputDirectory ) - { + public void setOutputDirectory(String outputDirectory) { throw new UnsupportedOperationException(); } @Override - public void setScriptSourceDirectory( String scriptSourceDirectory ) - { + public void setScriptSourceDirectory(String scriptSourceDirectory) { throw new UnsupportedOperationException(); } @Override - public void setSourceDirectory( String sourceDirectory ) - { + public void setSourceDirectory(String sourceDirectory) { throw new UnsupportedOperationException(); } @Override - public void setTestOutputDirectory( String testOutputDirectory ) - { + public void setTestOutputDirectory(String testOutputDirectory) { throw new UnsupportedOperationException(); } @Override - public void setTestSourceDirectory( String testSourceDirectory ) - { + public void setTestSourceDirectory(String testSourceDirectory) { throw new UnsupportedOperationException(); } @Override - public void addFilter( String string ) - { + public void addFilter(String string) { throw new UnsupportedOperationException(); } @Override - public void addResource( Resource resource ) - { + public void addResource(Resource resource) { throw new UnsupportedOperationException(); } @Override - public void addTestResource( Resource resource ) - { + public void addTestResource(Resource resource) { throw new UnsupportedOperationException(); } @Override - public String getDefaultGoal() - { + public String getDefaultGoal() { throw new UnsupportedOperationException(); } @Override - public String getDirectory() - { + public String getDirectory() { throw new UnsupportedOperationException(); } @Override - public List getFilters() - { + public List getFilters() { throw new UnsupportedOperationException(); } @Override - public String getFinalName() - { + public String getFinalName() { throw new UnsupportedOperationException(); } @Override - public List getResources() - { + public List getResources() { throw new UnsupportedOperationException(); } @Override - public List getTestResources() - { + public List getTestResources() { throw new UnsupportedOperationException(); } @Override - public void removeFilter( String string ) - { + public void removeFilter(String string) { throw new UnsupportedOperationException(); } @Override - public void removeResource( Resource resource ) - { + public void removeResource(Resource resource) { throw new UnsupportedOperationException(); } @Override - public void removeTestResource( Resource resource ) - { + public void removeTestResource(Resource resource) { throw new UnsupportedOperationException(); } @Override - public void setDefaultGoal( String defaultGoal ) - { + public void setDefaultGoal(String defaultGoal) { throw new UnsupportedOperationException(); } @Override - public void setDirectory( String directory ) - { + public void setDirectory(String directory) { throw new UnsupportedOperationException(); } @Override - public void setFilters( List filters ) - { + public void setFilters(List filters) { throw new UnsupportedOperationException(); } @Override - public void setFinalName( String finalName ) - { + public void setFinalName(String finalName) { throw new UnsupportedOperationException(); } @Override - public void setResources( List resources ) - { + public void setResources(List resources) { throw new UnsupportedOperationException(); } @Override - public void setTestResources( List testResources ) - { + public void setTestResources(List testResources) { throw new UnsupportedOperationException(); } @Override - public PluginManagement getPluginManagement() - { - Element pluginManagementElm = build.getChild( "pluginManagement", build.getNamespace() ); - if ( pluginManagementElm == null ) - { + public PluginManagement getPluginManagement() { + Element pluginManagementElm = build.getChild("pluginManagement", build.getNamespace()); + if (pluginManagementElm == null) { return null; - } - else - { - return new JDomPluginManagement( pluginManagementElm ); + } else { + return new JDomPluginManagement(pluginManagementElm); } } @Override - public void setPluginManagement( PluginManagement pluginManagement ) - { + public void setPluginManagement(PluginManagement pluginManagement) { throw new UnsupportedOperationException(); } @Override - public void addPlugin( Plugin plugin ) - { + public void addPlugin(Plugin plugin) { throw new UnsupportedOperationException(); } @Override - public List getPlugins() - { - Element pluginsElm = build.getChild( "plugins", build.getNamespace() ); - if ( pluginsElm == null ) - { + public List getPlugins() { + Element pluginsElm = build.getChild("plugins", build.getNamespace()); + if (pluginsElm == null) { return Collections.emptyList(); - } - else - { - List pluginElms = - pluginsElm.getChildren( "plugin", build.getNamespace() ); + } else { + List pluginElms = pluginsElm.getChildren("plugin", build.getNamespace()); - List plugins = new ArrayList<>( pluginElms.size() ); + List plugins = new ArrayList<>(pluginElms.size()); - for ( Element pluginElm : pluginElms ) - { - plugins.add( new JDomPlugin( pluginElm ) ); + for (Element pluginElm : pluginElms) { + plugins.add(new JDomPlugin(pluginElm)); } return plugins; @@ -309,26 +258,22 @@ public List getPlugins() } @Override - public void removePlugin( Plugin plugin ) - { + public void removePlugin(Plugin plugin) { throw new UnsupportedOperationException(); } @Override - public void setPlugins( List plugins ) - { + public void setPlugins(List plugins) { throw new UnsupportedOperationException(); } @Override - public void flushPluginMap() - { + public void flushPluginMap() { throw new UnsupportedOperationException(); } @Override - public Map getPluginsAsMap() - { + public Map getPluginsAsMap() { throw new UnsupportedOperationException(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependency.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependency.java index 3d94cc730..08218eece 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependency.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependency.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.List; @@ -32,8 +31,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomDependency extends Dependency implements MavenCoordinate -{ +public class JDomDependency extends Dependency implements MavenCoordinate { private final MavenCoordinate coordinate; /** @@ -41,134 +39,112 @@ public class JDomDependency extends Dependency implements MavenCoordinate * * @param dependency a {@link org.jdom2.Element} object */ - public JDomDependency( Element dependency ) - { - this.coordinate = new JDomMavenCoordinate( dependency ); + public JDomDependency(Element dependency) { + this.coordinate = new JDomMavenCoordinate(dependency); } @Override - public void addExclusion( Exclusion exclusion ) - { + public void addExclusion(Exclusion exclusion) { throw new UnsupportedOperationException(); } @Override - public String getArtifactId() - { + public String getArtifactId() { return coordinate.getArtifactId(); } @Override - public String getClassifier() - { + public String getClassifier() { throw new UnsupportedOperationException(); } @Override - public List getExclusions() - { + public List getExclusions() { throw new UnsupportedOperationException(); } @Override - public String getGroupId() - { + public String getGroupId() { return coordinate.getGroupId(); } @Override - public String getScope() - { + public String getScope() { throw new UnsupportedOperationException(); } @Override - public String getSystemPath() - { + public String getSystemPath() { throw new UnsupportedOperationException(); } @Override - public String getType() - { + public String getType() { throw new UnsupportedOperationException(); } @Override - public String getVersion() - { + public String getVersion() { return coordinate.getVersion(); } @Override - public boolean isOptional() - { + public boolean isOptional() { throw new UnsupportedOperationException(); } @Override - public void removeExclusion( Exclusion exclusion ) - { + public void removeExclusion(Exclusion exclusion) { throw new UnsupportedOperationException(); } @Override - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { throw new UnsupportedOperationException(); } @Override - public void setClassifier( String classifier ) - { + public void setClassifier(String classifier) { throw new UnsupportedOperationException(); } @Override - public void setExclusions( List exclusions ) - { + public void setExclusions(List exclusions) { throw new UnsupportedOperationException(); } @Override - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { throw new UnsupportedOperationException(); } @Override - public void setOptional( boolean optional ) - { + public void setOptional(boolean optional) { throw new UnsupportedOperationException(); } @Override - public void setScope( String scope ) - { + public void setScope(String scope) { throw new UnsupportedOperationException(); } @Override - public void setSystemPath( String systemPath ) - { + public void setSystemPath(String systemPath) { throw new UnsupportedOperationException(); } @Override - public void setType( String type ) - { + public void setType(String type) { throw new UnsupportedOperationException(); } @Override - public void setVersion( String version ) - { - coordinate.setVersion( version ); + public void setVersion(String version) { + coordinate.setVersion(version); } @Override - public String getName() - { + public String getName() { return "dependency"; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagement.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagement.java index 5fcf48865..5db9b2d1c 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagement.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagement.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -33,8 +32,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomDependencyManagement extends DependencyManagement -{ +public class JDomDependencyManagement extends DependencyManagement { private final Element dependencyManagement; /** @@ -42,35 +40,28 @@ public class JDomDependencyManagement extends DependencyManagement * * @param dependencyManagement a {@link org.jdom2.Element} object */ - public JDomDependencyManagement( Element dependencyManagement ) - { + public JDomDependencyManagement(Element dependencyManagement) { this.dependencyManagement = dependencyManagement; } @Override - public void addDependency( Dependency dependency ) - { + public void addDependency(Dependency dependency) { throw new UnsupportedOperationException(); } @Override - public List getDependencies() - { - Element dependenciesElm = dependencyManagement.getChild( "dependencies", dependencyManagement.getNamespace() ); - if ( dependenciesElm == null ) - { + public List getDependencies() { + Element dependenciesElm = dependencyManagement.getChild("dependencies", dependencyManagement.getNamespace()); + if (dependenciesElm == null) { return Collections.emptyList(); - } - else - { + } else { List dependencyElms = - dependenciesElm.getChildren( "dependency", dependencyManagement.getNamespace() ); + dependenciesElm.getChildren("dependency", dependencyManagement.getNamespace()); - List dependencies = new ArrayList<>( dependencyElms.size() ); + List dependencies = new ArrayList<>(dependencyElms.size()); - for ( Element dependencyElm : dependencyElms ) - { - dependencies.add( new JDomDependency( dependencyElm ) ); + for (Element dependencyElm : dependencyElms) { + dependencies.add(new JDomDependency(dependencyElm)); } return dependencies; @@ -78,15 +69,12 @@ public List getDependencies() } @Override - public void removeDependency( Dependency dependency ) - { + public void removeDependency(Dependency dependency) { throw new UnsupportedOperationException(); } @Override - public void setDependencies( List dependencies ) - { + public void setDependencies(List dependencies) { throw new UnsupportedOperationException(); } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomExtension.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomExtension.java index 947364012..cf7c52367 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomExtension.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomExtension.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import org.apache.maven.model.Extension; import org.apache.maven.shared.release.transform.MavenCoordinate; @@ -29,8 +28,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomExtension extends Extension implements MavenCoordinate -{ +public class JDomExtension extends Extension implements MavenCoordinate { private final MavenCoordinate coordinate; /** @@ -38,50 +36,42 @@ public class JDomExtension extends Extension implements MavenCoordinate * * @param extension a {@link org.jdom2.Element} object */ - public JDomExtension( Element extension ) - { - this.coordinate = new JDomMavenCoordinate( extension ); + public JDomExtension(Element extension) { + this.coordinate = new JDomMavenCoordinate(extension); } @Override - public String getArtifactId() - { + public String getArtifactId() { return coordinate.getArtifactId(); } @Override - public String getGroupId() - { + public String getGroupId() { return coordinate.getGroupId(); } @Override - public String getVersion() - { + public String getVersion() { return coordinate.getVersion(); } @Override - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { throw new UnsupportedOperationException(); } @Override - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { throw new UnsupportedOperationException(); } @Override - public void setVersion( String version ) - { - coordinate.setVersion( version ); + public void setVersion(String version) { + coordinate.setVersion(version); } @Override - public String getName() - { + public String getName() { return "extension"; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomMavenCoordinate.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomMavenCoordinate.java index c2e10aa49..7f431d816 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomMavenCoordinate.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomMavenCoordinate.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import org.apache.maven.shared.release.transform.MavenCoordinate; import org.jdom2.Element; @@ -28,8 +27,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomMavenCoordinate implements MavenCoordinate -{ +public class JDomMavenCoordinate implements MavenCoordinate { private final Element element; /** @@ -37,52 +35,41 @@ public class JDomMavenCoordinate implements MavenCoordinate * * @param elm a {@link org.jdom2.Element} object */ - public JDomMavenCoordinate( Element elm ) - { + public JDomMavenCoordinate(Element elm) { this.element = elm; } @Override - public String getGroupId() - { - return element.getChildTextTrim( "groupId", element.getNamespace() ); + public String getGroupId() { + return element.getChildTextTrim("groupId", element.getNamespace()); } @Override - public String getArtifactId() - { - return element.getChildTextTrim( "artifactId", element.getNamespace() ); + public String getArtifactId() { + return element.getChildTextTrim("artifactId", element.getNamespace()); } @Override - public String getVersion() - { + public String getVersion() { Element version = getVersionElement(); - if ( version == null ) - { + if (version == null) { return null; - } - else - { + } else { return version.getTextTrim(); } - } - private Element getVersionElement() - { - return element.getChild( "version", element.getNamespace() ); + private Element getVersionElement() { + return element.getChild("version", element.getNamespace()); } @Override - public void setVersion( String version ) - { - JDomUtils.rewriteValue( getVersionElement(), version ); + public void setVersion(String version) { + JDomUtils.rewriteValue(getVersionElement(), version); } @Override - public String getName() - { + public String getName() { return element.getName(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java index 5567e6886..d219b6cdd 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModel.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -42,8 +41,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomModel extends Model -{ +public class JDomModel extends Model { private final Element project; private final JDomModelBase modelBase; @@ -53,9 +51,8 @@ public class JDomModel extends Model * * @param document a {@link org.jdom2.Document} object */ - public JDomModel( Document document ) - { - this( document.getRootElement() ); + public JDomModel(Document document) { + this(document.getRootElement()); } /** @@ -63,175 +60,136 @@ public JDomModel( Document document ) * * @param project a {@link org.jdom2.Element} object */ - public JDomModel( Element project ) - { + public JDomModel(Element project) { this.project = project; - this.modelBase = new JDomModelBase( project ); + this.modelBase = new JDomModelBase(project); } @Override - public Build getBuild() - { + public Build getBuild() { return modelBase.getBuild(); } @Override - public List getDependencies() - { + public List getDependencies() { return modelBase.getDependencies(); } @Override - public DependencyManagement getDependencyManagement() - { + public DependencyManagement getDependencyManagement() { return modelBase.getDependencyManagement(); } @Override - public Parent getParent() - { + public Parent getParent() { Element elm = getParentElement(); - if ( elm == null ) - { + if (elm == null) { return null; - } - else - { + } else { // this way scm setters change DOM tree immediately - return new JDomParent( elm ); + return new JDomParent(elm); } } - private Element getParentElement() - { - return project.getChild( "parent", project.getNamespace() ); + private Element getParentElement() { + return project.getChild("parent", project.getNamespace()); } @Override - public List getProfiles() - { - Element profilesElm = project.getChild( "profiles", project.getNamespace() ); - if ( profilesElm == null ) - { + public List getProfiles() { + Element profilesElm = project.getChild("profiles", project.getNamespace()); + if (profilesElm == null) { return Collections.emptyList(); - } - else - { - List profileElms = profilesElm.getChildren( "profile", project.getNamespace() ); + } else { + List profileElms = profilesElm.getChildren("profile", project.getNamespace()); - List profiles = new ArrayList<>( profileElms.size() ); + List profiles = new ArrayList<>(profileElms.size()); - for ( Element profileElm : profileElms ) - { - profiles.add( new JDomProfile( profileElm ) ); + for (Element profileElm : profileElms) { + profiles.add(new JDomProfile(profileElm)); } return profiles; } } - @Override - public Properties getProperties() - { - Element properties = project.getChild( "properties", project.getNamespace() ); + public Properties getProperties() { + Element properties = project.getChild("properties", project.getNamespace()); - if ( properties == null ) - { + if (properties == null) { return null; - } - else - { - return new JDomProperties( properties ); + } else { + return new JDomProperties(properties); } } @Override - public Reporting getReporting() - { - Element reporting = project.getChild( "reporting", project.getNamespace() ); + public Reporting getReporting() { + Element reporting = project.getChild("reporting", project.getNamespace()); - if ( reporting == null ) - { + if (reporting == null) { return null; - } - else - { - return new JDomReporting( reporting ); + } else { + return new JDomReporting(reporting); } } @Override - public void setScm( Scm scm ) - { - if ( scm == null ) - { - JDomUtils.rewriteElement( "scm", null, project, project.getNamespace() ); - } - else - { - Element scmRoot = new Element( "scm" ); - scmRoot.addContent( "\n " ); + public void setScm(Scm scm) { + if (scm == null) { + JDomUtils.rewriteElement("scm", null, project, project.getNamespace()); + } else { + Element scmRoot = new Element("scm"); + scmRoot.addContent("\n "); // Write current values to JDOM2 tree - Scm jdomScm = new JDomScm( scmRoot ); - jdomScm.setConnection( scm.getConnection() ); - jdomScm.setDeveloperConnection( scm.getDeveloperConnection() ); - jdomScm.setTag( scm.getTag() ); - jdomScm.setUrl( scm.getUrl() ); + Scm jdomScm = new JDomScm(scmRoot); + jdomScm.setConnection(scm.getConnection()); + jdomScm.setDeveloperConnection(scm.getDeveloperConnection()); + jdomScm.setTag(scm.getTag()); + jdomScm.setUrl(scm.getUrl()); - project.addContent( "\n " ).addContent( scmRoot ).addContent( "\n" ); + project.addContent("\n ").addContent(scmRoot).addContent("\n"); } } @Override - public Scm getScm() - { - Element elm = project.getChild( "scm", project.getNamespace() ); - if ( elm == null ) - { + public Scm getScm() { + Element elm = project.getChild("scm", project.getNamespace()); + if (elm == null) { return null; - } - else - { + } else { // this way scm setters change DOM tree immediately - return new JDomScm( elm ); + return new JDomScm(elm); } } @Override - public void setVersion( String version ) - { - Element versionElement = project.getChild( "version", project.getNamespace() ); + public void setVersion(String version) { + Element versionElement = project.getChild("version", project.getNamespace()); String parentVersion; Element parent = getParentElement(); - if ( parent != null ) - { - parentVersion = parent.getChildTextTrim( "version", project.getNamespace() ); - } - else - { + if (parent != null) { + parentVersion = parent.getChildTextTrim("version", project.getNamespace()); + } else { parentVersion = null; } - if ( versionElement == null ) - { - if ( !version.equals( parentVersion ) ) - { + if (versionElement == null) { + if (!version.equals(parentVersion)) { // we will add this after artifactId, since it was missing but different from the inherited version - Element artifactIdElement = project.getChild( "artifactId", project.getNamespace() ); - int index = project.indexOf( artifactIdElement ); + Element artifactIdElement = project.getChild("artifactId", project.getNamespace()); + int index = project.indexOf(artifactIdElement); - versionElement = new Element( "version", project.getNamespace() ); - versionElement.setText( version ); - project.addContent( index + 1, new Text( "\n " ) ); - project.addContent( index + 2, versionElement ); + versionElement = new Element("version", project.getNamespace()); + versionElement.setText(version); + project.addContent(index + 1, new Text("\n ")); + project.addContent(index + 2, versionElement); } - } - else - { - JDomUtils.rewriteValue( versionElement, version ); + } else { + JDomUtils.rewriteValue(versionElement, version); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelBase.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelBase.java index c97d59985..209af354c 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelBase.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelBase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -34,8 +33,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomModelBase -{ +public class JDomModelBase { private final Element modelBase; /** @@ -43,8 +41,7 @@ public class JDomModelBase * * @param modelBase a {@link org.jdom2.Element} object */ - public JDomModelBase( Element modelBase ) - { + public JDomModelBase(Element modelBase) { this.modelBase = modelBase; } @@ -53,17 +50,13 @@ public JDomModelBase( Element modelBase ) * * @return a {@link org.apache.maven.model.Build} object */ - public Build getBuild() - { - Element elm = modelBase.getChild( "build", modelBase.getNamespace() ); - if ( elm == null ) - { + public Build getBuild() { + Element elm = modelBase.getChild("build", modelBase.getNamespace()); + if (elm == null) { return null; - } - else - { + } else { // this way build setters change DOM tree immediately - return new JDomBuild( elm ); + return new JDomBuild(elm); } } @@ -72,22 +65,17 @@ public Build getBuild() * * @return a {@link java.util.List} object */ - public List getDependencies() - { - Element dependenciesElm = modelBase.getChild( "dependencies", modelBase.getNamespace() ); - if ( dependenciesElm == null ) - { + public List getDependencies() { + Element dependenciesElm = modelBase.getChild("dependencies", modelBase.getNamespace()); + if (dependenciesElm == null) { return Collections.emptyList(); - } - else - { - List dependencyElms = dependenciesElm.getChildren( "dependency", modelBase.getNamespace() ); + } else { + List dependencyElms = dependenciesElm.getChildren("dependency", modelBase.getNamespace()); - List dependencies = new ArrayList<>( dependencyElms.size() ); + List dependencies = new ArrayList<>(dependencyElms.size()); - for ( Element dependencyElm : dependencyElms ) - { - dependencies.add( new JDomDependency( dependencyElm ) ); + for (Element dependencyElm : dependencyElms) { + dependencies.add(new JDomDependency(dependencyElm)); } return dependencies; @@ -99,17 +87,13 @@ public List getDependencies() * * @return a {@link org.apache.maven.model.DependencyManagement} object */ - public DependencyManagement getDependencyManagement() - { - Element elm = modelBase.getChild( "dependencyManagement", modelBase.getNamespace() ); - if ( elm == null ) - { + public DependencyManagement getDependencyManagement() { + Element elm = modelBase.getChild("dependencyManagement", modelBase.getNamespace()); + if (elm == null) { return null; - } - else - { + } else { // this way build setters change DOM tree immediately - return new JDomDependencyManagement( elm ); + return new JDomDependencyManagement(elm); } } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java index e0cb7c5d1..86bf8e272 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETL.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.io.File; import java.io.IOException; @@ -53,8 +52,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomModelETL implements ModelETL -{ +public class JDomModelETL implements ModelETL { private ReleaseDescriptor releaseDescriptor; private MavenProject project; @@ -71,8 +69,7 @@ public class JDomModelETL implements ModelETL * * @param ls a {@link java.lang.String} object */ - public void setLs( String ls ) - { + public void setLs(String ls) { this.ls = ls; } @@ -81,8 +78,7 @@ public void setLs( String ls ) * * @param releaseDescriptor a {@link org.apache.maven.shared.release.config.ReleaseDescriptor} object */ - public void setReleaseDescriptor( ReleaseDescriptor releaseDescriptor ) - { + public void setReleaseDescriptor(ReleaseDescriptor releaseDescriptor) { this.releaseDescriptor = releaseDescriptor; } @@ -91,43 +87,37 @@ public void setReleaseDescriptor( ReleaseDescriptor releaseDescriptor ) * * @param project a {@link org.apache.maven.project.MavenProject} object */ - public void setProject( MavenProject project ) - { + public void setProject(MavenProject project) { this.project = project; } @Override - public void extract( File pomFile ) throws ReleaseExecutionException - { - try - { - String content = ReleaseUtil.readXmlFile( pomFile, ls ); + public void extract(File pomFile) throws ReleaseExecutionException { + try { + String content = ReleaseUtil.readXmlFile(pomFile, ls); // we need to eliminate any extra whitespace inside elements, as JDOM2 will nuke it - content = content.replaceAll( "<([^!][^>]*?)\\s{2,}([^>]*?)>", "<$1 $2>" ); - content = content.replaceAll( "(\\s{2,})/>", "$1 />" ); + content = content.replaceAll("<([^!][^>]*?)\\s{2,}([^>]*?)>", "<$1 $2>"); + content = content.replaceAll("(\\s{2,})/>", "$1 />"); SAXBuilder builder = new SAXBuilder(); - document = builder.build( new StringReader( content ) ); + document = builder.build(new StringReader(content)); // Normalize line endings to platform's style (XML processors like JDOM2 normalize line endings to "\n" as // per section 2.11 of the XML spec) - normaliseLineEndings( document ); + normaliseLineEndings(document); // rewrite DOM as a string to find differences, since text outside the root element is not tracked StringWriter w = new StringWriter(); Format format = Format.getRawFormat(); - format.setLineSeparator( ls ); - XMLOutputter out = new XMLOutputter( format ); - out.output( document.getRootElement(), w ); - - int index = content.indexOf( w.toString() ); - if ( index >= 0 ) - { - intro = content.substring( 0, index ); - outtro = content.substring( index + w.toString().length() ); - } - else - { + format.setLineSeparator(ls); + XMLOutputter out = new XMLOutputter(format); + out.output(document.getRootElement(), w); + + int index = content.indexOf(w.toString()); + if (index >= 0) { + intro = content.substring(0, index); + outtro = content.substring(index + w.toString().length()); + } else { /* * NOTE: Due to whitespace, attribute reordering or entity expansion the above indexOf test can easily * fail. So let's try harder. Maybe some day, when JDOM2 offers a StaxBuilder and this builder employes @@ -138,112 +128,98 @@ public void extract( File pomFile ) throws ReleaseExecutionException final String XML = "<\\?(?:(?:[^\"'>]++)|(?:\"[^\"]*+\")|(?:'[^\']*+'))*+>"; final String INTSUB = "\\[(?:(?:[^\"'\\]]++)|(?:\"[^\"]*+\")|(?:'[^\']*+'))*+\\]"; final String DOCTYPE = - "]++)|(?:\"[^\"]*+\")|(?:'[^\']*+')|(?:" + INTSUB + "))*+>"; + "]++)|(?:\"[^\"]*+\")|(?:'[^\']*+')|(?:" + INTSUB + "))*+>"; final String PI = XML; final String COMMENT = ""; final String INTRO = - "(?:(?:" + SPACE + ")|(?:" + XML + ")|(?:" + DOCTYPE + ")|(?:" + COMMENT + ")|(?:" + PI + "))*"; + "(?:(?:" + SPACE + ")|(?:" + XML + ")|(?:" + DOCTYPE + ")|(?:" + COMMENT + ")|(?:" + PI + "))*"; final String OUTRO = "(?:(?:" + SPACE + ")|(?:" + COMMENT + ")|(?:" + PI + "))*"; final String POM = "(?s)(" + INTRO + ")(.*?)(" + OUTRO + ")"; // CHECKSTYLE_ON: LocalFinalVariableName - Matcher matcher = Pattern.compile( POM ).matcher( content ); - if ( matcher.matches() ) - { - intro = matcher.group( 1 ); - outtro = matcher.group( matcher.groupCount() ); + Matcher matcher = Pattern.compile(POM).matcher(content); + if (matcher.matches()) { + intro = matcher.group(1); + outtro = matcher.group(matcher.groupCount()); } } - } - catch ( JDOMException | IOException e ) - { - throw new ReleaseExecutionException( "Error reading POM: " + e.getMessage(), e ); + } catch (JDOMException | IOException e) { + throw new ReleaseExecutionException("Error reading POM: " + e.getMessage(), e); } } @Override - public void transform() - { - - } + public void transform() {} @Override - public void load( File targetFile ) throws ReleaseExecutionException - { - writePom( targetFile, document, releaseDescriptor, project.getModelVersion(), intro, outtro ); + public void load(File targetFile) throws ReleaseExecutionException { + writePom(targetFile, document, releaseDescriptor, project.getModelVersion(), intro, outtro); } @Override - public Model getModel() - { - return new JDomModel( document ); + public Model getModel() { + return new JDomModel(document); } - private void normaliseLineEndings( Document document ) - { - for ( Iterator i = document.getDescendants( new ContentFilter( ContentFilter.COMMENT ) ); i.hasNext(); ) - { + private void normaliseLineEndings(Document document) { + for (Iterator i = document.getDescendants(new ContentFilter(ContentFilter.COMMENT)); i.hasNext(); ) { Comment c = (Comment) i.next(); - c.setText( ReleaseUtil.normalizeLineEndings( c.getText(), ls ) ); + c.setText(ReleaseUtil.normalizeLineEndings(c.getText(), ls)); } - for ( Iterator i = document.getDescendants( new ContentFilter( ContentFilter.CDATA ) ); i.hasNext(); ) - { + for (Iterator i = document.getDescendants(new ContentFilter(ContentFilter.CDATA)); i.hasNext(); ) { CDATA c = (CDATA) i.next(); - c.setText( ReleaseUtil.normalizeLineEndings( c.getText(), ls ) ); + c.setText(ReleaseUtil.normalizeLineEndings(c.getText(), ls)); } } - private void writePom( File pomFile, Document document, ReleaseDescriptor releaseDescriptor, String modelVersion, - String intro, String outtro ) - throws ReleaseExecutionException - { + private void writePom( + File pomFile, + Document document, + ReleaseDescriptor releaseDescriptor, + String modelVersion, + String intro, + String outtro) + throws ReleaseExecutionException { Element rootElement = document.getRootElement(); - if ( releaseDescriptor.isAddSchema() ) - { - Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion ); - rootElement.setNamespace( pomNamespace ); - Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" ); - rootElement.addNamespaceDeclaration( xsiNamespace ); - - if ( rootElement.getAttribute( "schemaLocation", xsiNamespace ) == null ) - { - rootElement.setAttribute( "schemaLocation", "http://maven.apache.org/POM/" + modelVersion - + " https://maven.apache.org/xsd/maven-" + modelVersion + ".xsd", xsiNamespace ); + if (releaseDescriptor.isAddSchema()) { + Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/" + modelVersion); + rootElement.setNamespace(pomNamespace); + Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + rootElement.addNamespaceDeclaration(xsiNamespace); + + if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) { + rootElement.setAttribute( + "schemaLocation", + "http://maven.apache.org/POM/" + modelVersion + " https://maven.apache.org/xsd/maven-" + + modelVersion + ".xsd", + xsiNamespace); } // the empty namespace is considered equal to the POM namespace, so match them up to avoid extra xmlns="" - ElementFilter elementFilter = new ElementFilter( Namespace.getNamespace( "" ) ); - for ( Iterator i = rootElement.getDescendants( elementFilter ); i.hasNext(); ) - { + ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace("")); + for (Iterator i = rootElement.getDescendants(elementFilter); i.hasNext(); ) { Element e = (Element) i.next(); - e.setNamespace( pomNamespace ); + e.setNamespace(pomNamespace); } } - - try ( Writer writer = WriterFactory.newXmlWriter( pomFile ) ) - { - if ( intro != null ) - { - writer.write( intro ); + try (Writer writer = WriterFactory.newXmlWriter(pomFile)) { + if (intro != null) { + writer.write(intro); } Format format = Format.getRawFormat(); - format.setLineSeparator( ls ); - XMLOutputter out = new XMLOutputter( format ); - out.output( document.getRootElement(), writer ); + format.setLineSeparator(ls); + XMLOutputter out = new XMLOutputter(format); + out.output(document.getRootElement(), writer); - if ( outtro != null ) - { - writer.write( outtro ); + if (outtro != null) { + writer.write(outtro); } - } - catch ( IOException e ) - { - throw new ReleaseExecutionException( "Error writing POM: " + e.getMessage(), e ); + } catch (IOException e) { + throw new ReleaseExecutionException("Error writing POM: " + e.getMessage(), e); } } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETLFactory.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETLFactory.java index 4d4414d73..cb9045551 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETLFactory.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomModelETLFactory.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,12 +16,13 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import javax.inject.Named; import javax.inject.Singleton; -import org.apache.maven.shared.release.transform.ModelETLRequest; import org.apache.maven.shared.release.transform.ModelETLFactory; +import org.apache.maven.shared.release.transform.ModelETLRequest; /** *

JDomModelETLFactory class.

@@ -32,19 +31,17 @@ * @since 3.0 */ @Singleton -@Named( JDomModelETLFactory.NAME ) -public class JDomModelETLFactory implements ModelETLFactory -{ +@Named(JDomModelETLFactory.NAME) +public class JDomModelETLFactory implements ModelETLFactory { public static final String NAME = "jdom2-sax"; @Override - public JDomModelETL newInstance( ModelETLRequest request ) - { + public JDomModelETL newInstance(ModelETLRequest request) { JDomModelETL result = new JDomModelETL(); - result.setLs( request.getLineSeparator() ); - result.setProject( request.getProject() ); - result.setReleaseDescriptor( request.getReleaseDescriptor() ); + result.setLs(request.getLineSeparator()); + result.setProject(request.getProject()); + result.setReleaseDescriptor(request.getReleaseDescriptor()); return result; } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomParent.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomParent.java index 9d179c834..bbfc1ab78 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomParent.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomParent.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import org.apache.maven.model.Parent; import org.jdom2.Element; @@ -28,8 +27,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomParent extends Parent -{ +public class JDomParent extends Parent { private Element parent; /** @@ -37,62 +35,52 @@ public class JDomParent extends Parent * * @param parent a {@link org.jdom2.Element} object */ - public JDomParent( Element parent ) - { + public JDomParent(Element parent) { this.parent = parent; } @Override - public String getVersion() - { + public String getVersion() { throw new UnsupportedOperationException(); } @Override - public void setVersion( String version ) - { - JDomUtils.rewriteElement( "version", version, parent, parent.getNamespace() ); + public void setVersion(String version) { + JDomUtils.rewriteElement("version", version, parent, parent.getNamespace()); } @Override - public String getArtifactId() - { + public String getArtifactId() { throw new UnsupportedOperationException(); } @Override - public String getGroupId() - { + public String getGroupId() { throw new UnsupportedOperationException(); } @Override - public String getRelativePath() - { + public String getRelativePath() { throw new UnsupportedOperationException(); } @Override - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { throw new UnsupportedOperationException(); } @Override - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { throw new UnsupportedOperationException(); } @Override - public void setRelativePath( String relativePath ) - { + public void setRelativePath(String relativePath) { throw new UnsupportedOperationException(); } @Override - public String getId() - { + public String getId() { throw new UnsupportedOperationException(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPlugin.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPlugin.java index 128405acd..60cc9bc55 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPlugin.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPlugin.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -36,8 +35,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomPlugin extends Plugin implements MavenCoordinate -{ +public class JDomPlugin extends Plugin implements MavenCoordinate { private Element plugin; private final MavenCoordinate coordinate; @@ -46,48 +44,38 @@ public class JDomPlugin extends Plugin implements MavenCoordinate * * @param plugin a {@link org.jdom2.Element} object */ - public JDomPlugin( Element plugin ) - { + public JDomPlugin(Element plugin) { this.plugin = plugin; - this.coordinate = new JDomMavenCoordinate( plugin ); + this.coordinate = new JDomMavenCoordinate(plugin); } @Override - public void addDependency( Dependency dependency ) - { + public void addDependency(Dependency dependency) { throw new UnsupportedOperationException(); } @Override - public void addExecution( PluginExecution pluginExecution ) - { + public void addExecution(PluginExecution pluginExecution) { throw new UnsupportedOperationException(); } @Override - public String getArtifactId() - { + public String getArtifactId() { return coordinate.getArtifactId(); } @Override - public List getDependencies() - { - Element dependenciesElm = plugin.getChild( "dependencies", plugin.getNamespace() ); - if ( dependenciesElm == null ) - { + public List getDependencies() { + Element dependenciesElm = plugin.getChild("dependencies", plugin.getNamespace()); + if (dependenciesElm == null) { return Collections.emptyList(); - } - else - { - List dependencyElms = - dependenciesElm.getChildren( "dependency", plugin.getNamespace() ); + } else { + List dependencyElms = dependenciesElm.getChildren("dependency", plugin.getNamespace()); - List dependencies = new ArrayList<>( dependencyElms.size() ); + List dependencies = new ArrayList<>(dependencyElms.size()); - for ( Element dependencyElm : dependencyElms ) - { - dependencies.add( new JDomDependency( dependencyElm ) ); + for (Element dependencyElm : dependencyElms) { + dependencies.add(new JDomDependency(dependencyElm)); } return dependencies; @@ -95,104 +83,87 @@ public List getDependencies() } @Override - public List getExecutions() - { + public List getExecutions() { throw new UnsupportedOperationException(); } @Override - public Object getGoals() - { + public Object getGoals() { throw new UnsupportedOperationException(); } @Override - public String getGroupId() - { + public String getGroupId() { return coordinate.getGroupId(); } @Override - public String getVersion() - { + public String getVersion() { return coordinate.getVersion(); } @Override - public boolean isExtensions() - { + public boolean isExtensions() { throw new UnsupportedOperationException(); } @Override - public void removeDependency( Dependency dependency ) - { + public void removeDependency(Dependency dependency) { throw new UnsupportedOperationException(); } @Override - public void removeExecution( PluginExecution pluginExecution ) - { + public void removeExecution(PluginExecution pluginExecution) { throw new UnsupportedOperationException(); } @Override - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { throw new UnsupportedOperationException(); } @Override - public void setDependencies( List dependencies ) - { + public void setDependencies(List dependencies) { throw new UnsupportedOperationException(); } @Override - public void setExecutions( List executions ) - { + public void setExecutions(List executions) { throw new UnsupportedOperationException(); } @Override - public void setExtensions( boolean extensions ) - { + public void setExtensions(boolean extensions) { throw new UnsupportedOperationException(); } @Override - public void setGoals( Object goals ) - { + public void setGoals(Object goals) { throw new UnsupportedOperationException(); } @Override - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { throw new UnsupportedOperationException(); } @Override - public void setVersion( String version ) - { - coordinate.setVersion( version ); + public void setVersion(String version) { + coordinate.setVersion(version); } @Override - public void flushExecutionMap() - { + public void flushExecutionMap() { throw new UnsupportedOperationException(); } @Override - public Map getExecutionsAsMap() - { + public Map getExecutionsAsMap() { throw new UnsupportedOperationException(); } @Override - public String getName() - { + public String getName() { return "plugin"; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPluginManagement.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPluginManagement.java index 39bd06140..57044c7f4 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPluginManagement.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomPluginManagement.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -34,8 +33,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomPluginManagement extends PluginManagement -{ +public class JDomPluginManagement extends PluginManagement { private final Element pluginManagement; /** @@ -43,34 +41,27 @@ public class JDomPluginManagement extends PluginManagement * * @param pluginManagement a {@link org.jdom2.Element} object */ - public JDomPluginManagement( Element pluginManagement ) - { + public JDomPluginManagement(Element pluginManagement) { this.pluginManagement = pluginManagement; } @Override - public void addPlugin( Plugin plugin ) - { + public void addPlugin(Plugin plugin) { throw new UnsupportedOperationException(); } @Override - public List getPlugins() - { - Element pluginsElm = pluginManagement.getChild( "plugins", pluginManagement.getNamespace() ); - if ( pluginsElm == null ) - { + public List getPlugins() { + Element pluginsElm = pluginManagement.getChild("plugins", pluginManagement.getNamespace()); + if (pluginsElm == null) { return Collections.emptyList(); - } - else - { - List pluginElms = pluginsElm.getChildren( "plugin", pluginManagement.getNamespace() ); + } else { + List pluginElms = pluginsElm.getChildren("plugin", pluginManagement.getNamespace()); - List plugins = new ArrayList<>( pluginElms.size() ); + List plugins = new ArrayList<>(pluginElms.size()); - for ( Element pluginElm : pluginElms ) - { - plugins.add( new JDomPlugin( pluginElm ) ); + for (Element pluginElm : pluginElms) { + plugins.add(new JDomPlugin(pluginElm)); } return plugins; @@ -78,26 +69,22 @@ public List getPlugins() } @Override - public void removePlugin( Plugin plugin ) - { + public void removePlugin(Plugin plugin) { throw new UnsupportedOperationException(); } @Override - public void setPlugins( List plugins ) - { + public void setPlugins(List plugins) { throw new UnsupportedOperationException(); } @Override - public void flushPluginMap() - { + public void flushPluginMap() { throw new UnsupportedOperationException(); } @Override - public Map getPluginsAsMap() - { + public Map getPluginsAsMap() { throw new UnsupportedOperationException(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProfile.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProfile.java index 0a95f9d1c..a8863386d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProfile.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProfile.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.List; @@ -33,9 +32,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomProfile - extends Profile -{ +public class JDomProfile extends Profile { private final JDomModelBase modelBase; /** @@ -43,26 +40,22 @@ public class JDomProfile * * @param profile a {@link org.jdom2.Element} object */ - public JDomProfile( Element profile ) - { - this.modelBase = new JDomModelBase( profile ) ; + public JDomProfile(Element profile) { + this.modelBase = new JDomModelBase(profile); } @Override - public BuildBase getBuild() - { + public BuildBase getBuild() { return modelBase.getBuild(); } @Override - public List getDependencies() - { + public List getDependencies() { return modelBase.getDependencies(); } @Override - public DependencyManagement getDependencyManagement() - { + public DependencyManagement getDependencyManagement() { return modelBase.getDependencyManagement(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java index ea7eb75a1..b2c314f34 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomProperties.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.io.IOException; import java.io.InputStream; @@ -39,8 +38,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomProperties extends Properties -{ +public class JDomProperties extends Properties { private final Element properties; /** @@ -48,120 +46,94 @@ public class JDomProperties extends Properties * * @param properties a {@link org.jdom2.Element} object */ - public JDomProperties( Element properties ) - { + public JDomProperties(Element properties) { this.properties = properties; } @Override - public synchronized Object setProperty( String key, String value ) - { - Element property = properties.getChild( key, properties.getNamespace() ); + public synchronized Object setProperty(String key, String value) { + Element property = properties.getChild(key, properties.getNamespace()); - JDomUtils.rewriteValue( property, value ); + JDomUtils.rewriteValue(property, value); // todo follow specs of Hashtable.put return null; } @Override - public synchronized void load( Reader reader ) - throws IOException - { + public synchronized void load(Reader reader) throws IOException { throw new UnsupportedOperationException(); } @Override - public synchronized void load( InputStream inStream ) - throws IOException - { + public synchronized void load(InputStream inStream) throws IOException { throw new UnsupportedOperationException(); } - @SuppressWarnings( "deprecation" ) + @SuppressWarnings("deprecation") @Override - public void save( OutputStream out, String comments ) - { + public void save(OutputStream out, String comments) { throw new UnsupportedOperationException(); } @Override - public void store( Writer writer, String comments ) - throws IOException - { + public void store(Writer writer, String comments) throws IOException { throw new UnsupportedOperationException(); } @Override - public void store( OutputStream out, String comments ) - throws IOException - { + public void store(OutputStream out, String comments) throws IOException { throw new UnsupportedOperationException(); } @Override - public synchronized void loadFromXML( InputStream in ) - throws IOException, InvalidPropertiesFormatException - { + public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException { throw new UnsupportedOperationException(); } @Override - public void storeToXML( OutputStream os, String comment ) - throws IOException - { + public void storeToXML(OutputStream os, String comment) throws IOException { throw new UnsupportedOperationException(); } @Override - public void storeToXML( OutputStream os, String comment, String encoding ) - throws IOException - { + public void storeToXML(OutputStream os, String comment, String encoding) throws IOException { throw new UnsupportedOperationException(); } @Override - public String getProperty( String key ) - { - Element property = properties.getChild( key, properties.getNamespace() ); + public String getProperty(String key) { + Element property = properties.getChild(key, properties.getNamespace()); - if ( property == null ) - { + if (property == null) { return null; - } - else - { + } else { return property.getTextTrim(); } } @Override - public String getProperty( String key, String defaultValue ) - { + public String getProperty(String key, String defaultValue) { throw new UnsupportedOperationException(); } @Override - public Enumeration propertyNames() - { + public Enumeration propertyNames() { throw new UnsupportedOperationException(); } @Override - public Set stringPropertyNames() - { + public Set stringPropertyNames() { throw new UnsupportedOperationException(); } @Override - public void list( PrintStream out ) - { + public void list(PrintStream out) { throw new UnsupportedOperationException(); } @Override - public void list( PrintWriter out ) - { + public void list(PrintWriter out) { throw new UnsupportedOperationException(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReportPlugin.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReportPlugin.java index 12dcc9fd1..792b77f7d 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReportPlugin.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReportPlugin.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.List; import java.util.Map; @@ -33,9 +32,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomReportPlugin - extends ReportPlugin implements MavenCoordinate -{ +public class JDomReportPlugin extends ReportPlugin implements MavenCoordinate { private final MavenCoordinate coordinate; /** @@ -43,128 +40,107 @@ public class JDomReportPlugin * * @param reportPlugin a {@link org.jdom2.Element} object */ - public JDomReportPlugin( Element reportPlugin ) - { - this.coordinate = new JDomMavenCoordinate( reportPlugin ); + public JDomReportPlugin(Element reportPlugin) { + this.coordinate = new JDomMavenCoordinate(reportPlugin); } @Override - public void addReportSet( ReportSet reportSet ) - { + public void addReportSet(ReportSet reportSet) { throw new UnsupportedOperationException(); } @Override - public String getArtifactId() - { + public String getArtifactId() { return coordinate.getArtifactId(); } @Override - public Object getConfiguration() - { + public Object getConfiguration() { throw new UnsupportedOperationException(); } @Override - public String getGroupId() - { + public String getGroupId() { return coordinate.getGroupId(); } @Override - public String getInherited() - { + public String getInherited() { throw new UnsupportedOperationException(); } @Override - public List getReportSets() - { + public List getReportSets() { throw new UnsupportedOperationException(); } @Override - public String getVersion() - { + public String getVersion() { return coordinate.getVersion(); } @Override - public void removeReportSet( ReportSet reportSet ) - { + public void removeReportSet(ReportSet reportSet) { throw new UnsupportedOperationException(); } @Override - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { throw new UnsupportedOperationException(); } @Override - public void setConfiguration( Object configuration ) - { + public void setConfiguration(Object configuration) { throw new UnsupportedOperationException(); } @Override - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { throw new UnsupportedOperationException(); } @Override - public void setInherited( String inherited ) - { + public void setInherited(String inherited) { throw new UnsupportedOperationException(); } @Override - public void setReportSets( List reportSets ) - { + public void setReportSets(List reportSets) { throw new UnsupportedOperationException(); } @Override - public void setVersion( String version ) - { - coordinate.setVersion( version ); + public void setVersion(String version) { + coordinate.setVersion(version); } @Override - public void flushReportSetMap() - { + public void flushReportSetMap() { throw new UnsupportedOperationException(); } @Override - public Map getReportSetsAsMap() - { + public Map getReportSetsAsMap() { throw new UnsupportedOperationException(); } @Override - public String getKey() - { + public String getKey() { throw new UnsupportedOperationException(); } @Override - public void unsetInheritanceApplied() - { + public void unsetInheritanceApplied() { throw new UnsupportedOperationException(); } @Override - public boolean isInheritanceApplied() - { + public boolean isInheritanceApplied() { throw new UnsupportedOperationException(); } @Override - public String getName() - { + public String getName() { return "plugin"; } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReporting.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReporting.java index 1f50fec93..505f0a384 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReporting.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomReporting.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.ArrayList; import java.util.Collections; @@ -34,8 +33,7 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomReporting extends Reporting -{ +public class JDomReporting extends Reporting { private final Element reporting; @@ -44,40 +42,32 @@ public class JDomReporting extends Reporting * * @param reporting a {@link org.jdom2.Element} object */ - public JDomReporting( Element reporting ) - { + public JDomReporting(Element reporting) { this.reporting = reporting; } @Override - public void addPlugin( ReportPlugin reportPlugin ) - { + public void addPlugin(ReportPlugin reportPlugin) { throw new UnsupportedOperationException(); } @Override - public String getOutputDirectory() - { + public String getOutputDirectory() { throw new UnsupportedOperationException(); } @Override - public List getPlugins() - { - Element pluginsElm = reporting.getChild( "plugins", reporting.getNamespace() ); - if ( pluginsElm == null ) - { + public List getPlugins() { + Element pluginsElm = reporting.getChild("plugins", reporting.getNamespace()); + if (pluginsElm == null) { return Collections.emptyList(); - } - else - { - List pluginElms = pluginsElm.getChildren( "plugin", reporting.getNamespace() ); + } else { + List pluginElms = pluginsElm.getChildren("plugin", reporting.getNamespace()); - List plugins = new ArrayList<>( pluginElms.size() ); + List plugins = new ArrayList<>(pluginElms.size()); - for ( Element pluginElm : pluginElms ) - { - plugins.add( new JDomReportPlugin( pluginElm ) ); + for (Element pluginElm : pluginElms) { + plugins.add(new JDomReportPlugin(pluginElm)); } return plugins; @@ -85,44 +75,37 @@ public List getPlugins() } @Override - public void removePlugin( ReportPlugin reportPlugin ) - { + public void removePlugin(ReportPlugin reportPlugin) { throw new UnsupportedOperationException(); } @Override - public void setOutputDirectory( String outputDirectory ) - { + public void setOutputDirectory(String outputDirectory) { throw new UnsupportedOperationException(); } @Override - public void setPlugins( List plugins ) - { + public void setPlugins(List plugins) { throw new UnsupportedOperationException(); } @Override - public void flushReportPluginMap() - { + public void flushReportPluginMap() { throw new UnsupportedOperationException(); } @Override - public Map getReportPluginsAsMap() - { + public Map getReportPluginsAsMap() { throw new UnsupportedOperationException(); } @Override - public boolean isExcludeDefaults() - { + public boolean isExcludeDefaults() { throw new UnsupportedOperationException(); } @Override - public void setExcludeDefaults( boolean excludeDefaults ) - { + public void setExcludeDefaults(boolean excludeDefaults) { throw new UnsupportedOperationException(); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomScm.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomScm.java index 3592cda9f..7ff2a48eb 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomScm.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomScm.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import org.apache.maven.model.Scm; import org.jdom2.Element; @@ -28,60 +27,50 @@ * @author Robert Scholte * @since 3.0 */ -public class JDomScm extends Scm -{ +public class JDomScm extends Scm { private Element scm; - JDomScm( Element scm ) - { + JDomScm(Element scm) { this.scm = scm; } @Override - public String getConnection() - { + public String getConnection() { throw new UnsupportedOperationException(); } @Override - public void setConnection( String connection ) - { - JDomUtils.rewriteElement( "connection", connection, scm, scm.getNamespace() ); + public void setConnection(String connection) { + JDomUtils.rewriteElement("connection", connection, scm, scm.getNamespace()); } @Override - public String getDeveloperConnection() - { + public String getDeveloperConnection() { throw new UnsupportedOperationException(); } @Override - public void setDeveloperConnection( String developerConnection ) - { - JDomUtils.rewriteElement( "developerConnection", developerConnection, scm, scm.getNamespace() ); + public void setDeveloperConnection(String developerConnection) { + JDomUtils.rewriteElement("developerConnection", developerConnection, scm, scm.getNamespace()); } @Override - public String getTag() - { + public String getTag() { throw new UnsupportedOperationException(); } @Override - public void setTag( String tag ) - { - JDomUtils.rewriteElement( "tag", tag, scm, scm.getNamespace() ); + public void setTag(String tag) { + JDomUtils.rewriteElement("tag", tag, scm, scm.getNamespace()); } @Override - public String getUrl() - { + public String getUrl() { throw new UnsupportedOperationException(); } @Override - public void setUrl( String url ) - { - JDomUtils.rewriteElement( "url", url, scm, scm.getNamespace() ); + public void setUrl(String url) { + JDomUtils.rewriteElement("url", url, scm, scm.getNamespace()); } } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomUtils.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomUtils.java index d40b652c9..4783b2e40 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomUtils.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/transform/jdom2/JDomUtils.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.transform.jdom2; import java.util.Iterator; @@ -31,11 +30,9 @@ * @author Robert Scholte * @since 3.0 */ -public final class JDomUtils -{ +public final class JDomUtils { - private JDomUtils() - { + private JDomUtils() { // noop } @@ -46,27 +43,19 @@ private JDomUtils() * @param element The element to update, must not be null. * @param value The text string to set, must not be null. */ - public static void rewriteValue( Element element, String value ) - { + public static void rewriteValue(Element element, String value) { Text text = null; - if ( element.getContent() != null ) - { - for ( Iterator it = element.getContent().iterator(); it.hasNext(); ) - { + if (element.getContent() != null) { + for (Iterator it = element.getContent().iterator(); it.hasNext(); ) { Object content = it.next(); - if ( ( content instanceof Text ) && ( (Text) content ).getTextTrim().length() > 0 ) - { + if ((content instanceof Text) && ((Text) content).getTextTrim().length() > 0) { text = (Text) content; - while ( it.hasNext() ) - { + while (it.hasNext()) { content = it.next(); - if ( content instanceof Text ) - { - text.append( (Text) content ); + if (content instanceof Text) { + text.append((Text) content); it.remove(); - } - else - { + } else { break; } } @@ -74,18 +63,15 @@ public static void rewriteValue( Element element, String value ) } } } - if ( text == null ) - { - element.addContent( value ); - } - else - { + if (text == null) { + element.addContent(value); + } else { String chars = text.getText(); String trimmed = text.getTextTrim(); - int idx = chars.indexOf( trimmed ); - String leadingWhitespace = chars.substring( 0, idx ); - String trailingWhitespace = chars.substring( idx + trimmed.length() ); - text.setText( leadingWhitespace + value + trailingWhitespace ); + int idx = chars.indexOf(trimmed); + String leadingWhitespace = chars.substring(0, idx); + String trailingWhitespace = chars.substring(idx + trimmed.length()); + text.setText(leadingWhitespace + value + trailingWhitespace); } } @@ -98,44 +84,30 @@ public static void rewriteValue( Element element, String value ) * @param namespace a {@link org.jdom2.Namespace} object * @return a {@link org.jdom2.Element} object */ - public static Element rewriteElement( String name, String value, Element root, Namespace namespace ) - { - Element tagElement = root.getChild( name, namespace ); - if ( tagElement != null ) - { - if ( value != null ) - { - rewriteValue( tagElement, value ); - } - else - { - int index = root.indexOf( tagElement ); - root.removeContent( index ); - for ( int i = index - 1; i >= 0; i-- ) - { - if ( root.getContent( i ) instanceof Text ) - { - root.removeContent( i ); - } - else - { + public static Element rewriteElement(String name, String value, Element root, Namespace namespace) { + Element tagElement = root.getChild(name, namespace); + if (tagElement != null) { + if (value != null) { + rewriteValue(tagElement, value); + } else { + int index = root.indexOf(tagElement); + root.removeContent(index); + for (int i = index - 1; i >= 0; i--) { + if (root.getContent(i) instanceof Text) { + root.removeContent(i); + } else { break; } } } - } - else - { - if ( value != null ) - { - Element element = new Element( name, namespace ); - element.setText( value ); - root.addContent( " " ).addContent( element ).addContent( "\n " ); + } else { + if (value != null) { + Element element = new Element(name, namespace); + element.setText(value); + root.addContent(" ").addContent(element).addContent("\n "); tagElement = element; } } return tagElement; } - - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenCrypto.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenCrypto.java index 3d82414b6..cc9bb11bf 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenCrypto.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/MavenCrypto.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.util; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.util; import javax.inject.Inject; import javax.inject.Named; @@ -33,7 +32,6 @@ import org.sonatype.plexus.components.sec.dispatcher.SecUtil; import org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity; - /** * A shared utility to access {@link DefaultSecDispatcher} service. * @@ -41,23 +39,19 @@ */ @Singleton @Named -public class MavenCrypto -{ +public class MavenCrypto { /** * Exception thrown when "something" of crypto operation did not succeed. All the code all over the place * was catching sec dispatcher and plexus cipher exceptions just to neglect it (maybe log in DEBUG), so * this is one single exception here. */ - public static class MavenCryptoException extends Exception - { - private MavenCryptoException( String message ) - { - super( message ); + public static class MavenCryptoException extends Exception { + private MavenCryptoException(String message) { + super(message); } - private MavenCryptoException( String message, Throwable cause ) - { - super( message, cause ); + private MavenCryptoException(String message, Throwable cause) { + super(message, cause); } } @@ -66,104 +60,80 @@ private MavenCryptoException( String message, Throwable cause ) private final PlexusCipher plexusCipher; @Inject - public MavenCrypto( DefaultSecDispatcher secDispatcher, PlexusCipher plexusCipher ) - { + public MavenCrypto(DefaultSecDispatcher secDispatcher, PlexusCipher plexusCipher) { this.secDispatcher = secDispatcher; this.plexusCipher = plexusCipher; } - public String decrypt( String value ) throws MavenCryptoException - { - try - { - return secDispatcher.decrypt( value ); - } - catch ( SecDispatcherException e ) - { - throw new MavenCryptoException( "decrypt failed", e ); + public String decrypt(String value) throws MavenCryptoException { + try { + return secDispatcher.decrypt(value); + } catch (SecDispatcherException e) { + throw new MavenCryptoException("decrypt failed", e); } } - public void decryptProperties( Properties properties ) throws MavenCryptoException - { + public void decryptProperties(Properties properties) throws MavenCryptoException { String[] keys = new String[] {"scm.password", "scm.passphrase"}; - for ( String key : keys ) - { - String value = properties.getProperty( key ); - if ( value != null ) - { - properties.put( key, decryptDecorated( value ) ); + for (String key : keys) { + String value = properties.getProperty(key); + if (value != null) { + properties.put(key, decryptDecorated(value)); } } } - public String encryptAndDecorate( String passwd ) throws MavenCryptoException - { - try - { + public String encryptAndDecorate(String passwd) throws MavenCryptoException { + try { final String master = getMaster(); DefaultPlexusCipher cipher = new DefaultPlexusCipher(); - String masterPasswd = cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ); - return cipher.encryptAndDecorate( passwd, masterPasswd ); - } - catch ( PlexusCipherException e ) - { - throw new MavenCryptoException( "encrypt failed", e ); + String masterPasswd = cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION); + return cipher.encryptAndDecorate(passwd, masterPasswd); + } catch (PlexusCipherException e) { + throw new MavenCryptoException("encrypt failed", e); } } - public boolean isEncryptedString( String str ) - { - return plexusCipher.isEncryptedString( str ); + public boolean isEncryptedString(String str) { + return plexusCipher.isEncryptedString(str); } - private String decryptDecorated( String value ) throws MavenCryptoException - { - try - { + private String decryptDecorated(String value) throws MavenCryptoException { + try { final String master = getMaster(); DefaultPlexusCipher cipher = new DefaultPlexusCipher(); - String masterPasswd = cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ); - return cipher.decryptDecorated( value, masterPasswd ); - } - catch ( PlexusCipherException e ) - { - throw new MavenCryptoException( "decrypt failed", e ); + String masterPasswd = cipher.decryptDecorated(master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION); + return cipher.decryptDecorated(value, masterPasswd); + } catch (PlexusCipherException e) { + throw new MavenCryptoException("decrypt failed", e); } } - private String getMaster() throws MavenCryptoException - { + private String getMaster() throws MavenCryptoException { String configurationFile = secDispatcher.getConfigurationFile(); - if ( configurationFile.startsWith( "~" ) ) - { - configurationFile = System.getProperty( "user.home" ) + configurationFile.substring( 1 ); + if (configurationFile.startsWith("~")) { + configurationFile = System.getProperty("user.home") + configurationFile.substring(1); } - String file = System.getProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile ); + String file = System.getProperty(DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile); String master = null; - try - { - SettingsSecurity sec = SecUtil.read( file, true ); - if ( sec != null ) - { + try { + SettingsSecurity sec = SecUtil.read(file, true); + if (sec != null) { master = sec.getMaster(); } - } - catch ( SecDispatcherException e ) - { - throw new MavenCryptoException( "config file read failed", e ); + } catch (SecDispatcherException e) { + throw new MavenCryptoException("config file read failed", e); } - if ( master == null ) - { - throw new MavenCryptoException( "Master password is not set in the setting security file: " + file ); + if (master == null) { + throw new MavenCryptoException("Master password is not set in the setting security file: " + file); } return master; diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java index 28586aea0..858da49f5 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/util/PomFinder.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.util; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.util; import java.io.File; import java.io.IOException; @@ -61,15 +60,13 @@ * * @author Mark Struberg */ -public class PomFinder -{ +public class PomFinder { private final Logger log; private PomInfo foundPomInfo; - public PomFinder( Logger log ) - { - this.log = requireNonNull( log ); + public PomFinder(Logger log) { + this.log = requireNonNull(log); } /** @@ -77,20 +74,15 @@ public PomFinder( Logger log ) * @param originPom the pom File which should be used as blueprint for the search * @return true if a pom got parsed successfully, false otherwise */ - public boolean parsePom( File originPom ) - { - if ( !originPom.exists() ) - { + public boolean parsePom(File originPom) { + if (!originPom.exists()) { return false; } - try - { - foundPomInfo = readPomInfo( originPom ); - } - catch ( Exception e ) - { - log.warn( "Error while parsing pom file", e ); + try { + foundPomInfo = readPomInfo(originPom); + } catch (Exception e) { + log.warn("Error while parsing pom file", e); return false; } @@ -104,67 +96,51 @@ public boolean parsePom( File originPom ) * @return the pom file which matches the previously parsed pom or null * if no matching pom file could have been found. */ - public File findMatchingPom( File startDirectory ) - { - if ( !startDirectory.exists() ) - { + public File findMatchingPom(File startDirectory) { + if (!startDirectory.exists()) { return null; } - if ( !startDirectory.isDirectory() ) - { - log.error( "PomFinder must be started with a directory! Got " + startDirectory.getAbsolutePath() ); + if (!startDirectory.isDirectory()) { + log.error("PomFinder must be started with a directory! Got " + startDirectory.getAbsolutePath()); return null; } - if ( foundPomInfo == null ) - { - log.error( "Please run parsePom first!" ); + if (foundPomInfo == null) { + log.error("Please run parsePom first!"); return null; } // look for the file in the current directory - File matchingPom = new File( startDirectory, foundPomInfo.getFileName() ); - if ( matchingPom.exists() ) - { + File matchingPom = new File(startDirectory, foundPomInfo.getFileName()); + if (matchingPom.exists()) { PomInfo pi = null; - try - { - pi = readPomInfo( matchingPom ); - } - catch ( Exception e ) - { - log.warn( "Error while parsing pom file", e ); + try { + pi = readPomInfo(matchingPom); + } catch (Exception e) { + log.warn("Error while parsing pom file", e); // do nothing, just continue with the search // this might happen if a build contains unfinished pom.xml // files in integration tests, etc } - if ( pi == null || !pi.equals( foundPomInfo ) ) - { + if (pi == null || !pi.equals(foundPomInfo)) { matchingPom = null; } - } - else - { + } else { matchingPom = null; } - if ( matchingPom == null ) - { + if (matchingPom == null) { String[] childFiles = startDirectory.list(); - if ( childFiles != null ) - { - for ( String childFile : childFiles ) - { - File subDir = new File( startDirectory, childFile ); - if ( subDir.isDirectory() && !subDir.isHidden() ) - { - matchingPom = findMatchingPom( subDir ); + if (childFiles != null) { + for (String childFile : childFiles) { + File subDir = new File(startDirectory, childFile); + if (subDir.isDirectory() && !subDir.isHidden()) { + matchingPom = findMatchingPom(subDir); } - if ( matchingPom != null ) - { + if (matchingPom != null) { break; } } @@ -174,44 +150,37 @@ public File findMatchingPom( File startDirectory ) return matchingPom; } - /** * Read the {@link PomInfo} from the given pom file * @param pomFile pom.xml file * @return the PomInfo or nullEmmanuel Venisse */ -public class ReleaseUtil -{ - @SuppressWarnings( "checkstyle:constantname" ) +public class ReleaseUtil { + @SuppressWarnings("checkstyle:constantname") public static final String RELEASE_POMv4 = "release-pom.xml"; - @SuppressWarnings( "checkstyle:constantname" ) + @SuppressWarnings("checkstyle:constantname") public static final String POMv4 = "pom.xml"; /** * The line separator to use. */ - public static final String LS = System.getProperty( "line.separator" ); + public static final String LS = System.getProperty("line.separator"); - private ReleaseUtil() - { + private ReleaseUtil() { // noop } - public static MavenProject getRootProject( List reactorProjects ) - { - MavenProject project = reactorProjects.get( 0 ); - for ( MavenProject currentProject : reactorProjects ) - { - if ( currentProject.isExecutionRoot() ) - { + public static MavenProject getRootProject(List reactorProjects) { + MavenProject project = reactorProjects.get(0); + for (MavenProject currentProject : reactorProjects) { + if (currentProject.isExecutionRoot()) { project = currentProject; break; } @@ -79,44 +73,37 @@ public static MavenProject getRootProject( List reactorProjects ) return project; } - public static File getStandardPom( MavenProject project ) - { - if ( project == null ) - { + public static File getStandardPom(MavenProject project) { + if (project == null) { return null; } File pom = project.getFile(); - if ( pom == null ) - { + if (pom == null) { return null; } - File releasePom = getReleasePom( project ); - if ( pom.equals( releasePom ) ) - { - pom = new File( pom.getParent(), POMv4 ); + File releasePom = getReleasePom(project); + if (pom.equals(releasePom)) { + pom = new File(pom.getParent(), POMv4); } return pom; } - public static File getReleasePom( MavenProject project ) - { - if ( project == null ) - { + public static File getReleasePom(MavenProject project) { + if (project == null) { return null; } File pom = project.getFile(); - if ( pom == null ) - { + if (pom == null) { return null; } - return new File( pom.getParent(), RELEASE_POMv4 ); + return new File(pom.getParent(), RELEASE_POMv4); } /** @@ -128,18 +115,13 @@ public static File getReleasePom( MavenProject project ) * @return The string contents of the XML file. * @throws IOException If the file could not be opened/read. */ - public static String readXmlFile( File file ) - throws IOException - { - return readXmlFile( file, LS ); + public static String readXmlFile(File file) throws IOException { + return readXmlFile(file, LS); } - public static String readXmlFile( File file, String ls ) - throws IOException - { - try ( Reader reader = ReaderFactory.newXmlReader( file ) ) - { - return normalizeLineEndings( IOUtil.toString( reader ), ls ); + public static String readXmlFile(File file, String ls) throws IOException { + try (Reader reader = ReaderFactory.newXmlReader(file)) { + return normalizeLineEndings(IOUtil.toString(reader), ls); } } @@ -152,86 +134,73 @@ public static String readXmlFile( File file, String ls ) * @return The input string with normalized line separators or null if the string was null * . */ - public static String normalizeLineEndings( String text, String separator ) - { + public static String normalizeLineEndings(String text, String separator) { String norm = text; - if ( text != null ) - { - norm = text.replaceAll( "(\r\n)|(\n)|(\r)", separator ); + if (text != null) { + norm = text.replaceAll("(\r\n)|(\n)|(\r)", separator); } return norm; } - public static ReleaseDescriptor createBasedirAlignedReleaseDescriptor( ReleaseDescriptor releaseDescriptor, - List reactorProjects ) - throws ReleaseExecutionException - { - int parentLevels = Paths.get( releaseDescriptor.getPomFileName() ).getNameCount() - 1; + public static ReleaseDescriptor createBasedirAlignedReleaseDescriptor( + ReleaseDescriptor releaseDescriptor, List reactorProjects) throws ReleaseExecutionException { + int parentLevels = Paths.get(releaseDescriptor.getPomFileName()).getNameCount() - 1; String url = releaseDescriptor.getScmSourceUrl(); - url = realignScmUrl( parentLevels, url ); + url = realignScmUrl(parentLevels, url); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setWorkingDirectory( releaseDescriptor.getWorkingDirectory() ); - builder.setScmSourceUrl( url ); + builder.setWorkingDirectory(releaseDescriptor.getWorkingDirectory()); + builder.setScmSourceUrl(url); - return ReleaseUtils.buildReleaseDescriptor( builder ); + return ReleaseUtils.buildReleaseDescriptor(builder); } - public static int getBaseWorkingDirectoryParentCount( final Path baseDirectory, final Path workingDirectory ) - { - return Math.max( 0, workingDirectory.normalize().getNameCount() - baseDirectory.normalize().getNameCount() ); + public static int getBaseWorkingDirectoryParentCount(final Path baseDirectory, final Path workingDirectory) { + return Math.max( + 0, + workingDirectory.normalize().getNameCount() + - baseDirectory.normalize().getNameCount()); } - public static String realignScmUrl( int parentLevels, String url ) - { - if ( !StringUtils.isEmpty( url ) ) - { + public static String realignScmUrl(int parentLevels, String url) { + if (!StringUtils.isEmpty(url)) { // normalize - url = url.replaceAll( "/\\./", "/" ).replaceAll( "/\\.$", "" ). - replaceAll( "/[^/]+/\\.\\./", "/" ).replaceAll( "/[^/]+/\\.\\.$", "" ); + url = url.replaceAll("/\\./", "/") + .replaceAll("/\\.$", "") + .replaceAll("/[^/]+/\\.\\./", "/") + .replaceAll("/[^/]+/\\.\\.$", ""); int index = url.length(); String suffix = ""; - if ( url.endsWith( "/" ) ) - { + if (url.endsWith("/")) { index--; suffix = "/"; } - for ( int i = 0; i < parentLevels && index > 0; i++ ) - { - index = url.lastIndexOf( '/', index - 1 ); + for (int i = 0; i < parentLevels && index > 0; i++) { + index = url.lastIndexOf('/', index - 1); } - if ( index > 0 ) - { - url = url.substring( 0, index ) + suffix; + if (index > 0) { + url = url.substring(0, index) + suffix; } - } return url; } - public static String interpolate( String value, Model model ) - throws ReleaseExecutionException - { - if ( value != null && value.contains( "${" ) ) - { + public static String interpolate(String value, Model model) throws ReleaseExecutionException { + if (value != null && value.contains("${")) { StringSearchInterpolator interpolator = new StringSearchInterpolator(); - List pomPrefixes = Arrays.asList( "pom.", "project." ); - interpolator.addValueSource( new PrefixedObjectValueSource( pomPrefixes, model, false ) ); - interpolator.addValueSource( new MapBasedValueSource( model.getProperties() ) ); - interpolator.addValueSource( new ObjectBasedValueSource( model ) ); - try - { - value = interpolator.interpolate( value, new PrefixAwareRecursionInterceptor( pomPrefixes ) ); - } - catch ( InterpolationException e ) - { + List pomPrefixes = Arrays.asList("pom.", "project."); + interpolator.addValueSource(new PrefixedObjectValueSource(pomPrefixes, model, false)); + interpolator.addValueSource(new MapBasedValueSource(model.getProperties())); + interpolator.addValueSource(new ObjectBasedValueSource(model)); + try { + value = interpolator.interpolate(value, new PrefixAwareRecursionInterceptor(pomPrefixes)); + } catch (InterpolationException e) { throw new ReleaseExecutionException( - "Failed to interpolate " + value + " for project " + model.getId(), - e ); + "Failed to interpolate " + value + " for project " + model.getId(), e); } } return value; diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/DefaultVersionInfo.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/DefaultVersionInfo.java index d879cdaaf..85dc12145 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/DefaultVersionInfo.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/DefaultVersionInfo.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,11 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.codehaus.plexus.util.StringUtils; +package org.apache.maven.shared.release.versions; import java.util.ArrayList; import java.util.Arrays; @@ -31,6 +25,11 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.codehaus.plexus.util.StringUtils; + /** * This compares and increments versions for a common java versioning scheme. *

@@ -54,9 +53,7 @@ * TODO: this parser is better than DefaultArtifactVersion - replace it with this (but align naming) and then remove * this from here. */ -public class DefaultVersionInfo - implements VersionInfo -{ +public class DefaultVersionInfo implements VersionInfo { private final String strVersion; private final List digits; @@ -93,12 +90,12 @@ public class DefaultVersionInfo /** Constant STANDARD_PATTERN */ public static final Pattern STANDARD_PATTERN = Pattern.compile( - "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated - followed by digit (version digits 1.22.0, etc) - + "([-_])?" // optional - or _ (annotation separator) - + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.) - + "([-_])?" // optional - or _ (annotation revision separator) - + "(\\d*)" // digits (any digits after rc or beta is an annotation revision) - + "(?:([-_])?(.*?))?$" ); // - or _ followed everything else (build specifier) + "^((?:\\d+\\.)*\\d+)" // digit(s) and '.' repeated - followed by digit (version digits 1.22.0, etc) + + "([-_])?" // optional - or _ (annotation separator) + + "([a-zA-Z]*)" // alpha characters (looking for annotation - alpha, beta, RC, etc.) + + "([-_])?" // optional - or _ (annotation revision separator) + + "(\\d*)" // digits (any digits after rc or beta is an annotation revision) + + "(?:([-_])?(.*?))?$"); // - or _ followed everything else (build specifier) /* * * cmaki 02242009 @@ -110,7 +107,7 @@ public class DefaultVersionInfo */ // for SNAPSHOT releases only (possible versions include: trunk-SNAPSHOT or SNAPSHOT) /** Constant ALTERNATE_PATTERN */ - public static final Pattern ALTERNATE_PATTERN = Pattern.compile( "^(SNAPSHOT|[a-zA-Z]+[_-]SNAPSHOT)" ); + public static final Pattern ALTERNATE_PATTERN = Pattern.compile("^(SNAPSHOT|[a-zA-Z]+[_-]SNAPSHOT)"); /** * Constructs this object and parses the supplied version string. @@ -118,16 +115,13 @@ public class DefaultVersionInfo * @param version the version string * @throws org.apache.maven.shared.release.versions.VersionParseException if an exception during parsing the input */ - public DefaultVersionInfo( String version ) - throws VersionParseException - { + public DefaultVersionInfo(String version) throws VersionParseException { strVersion = version; // FIX for non-digit release numbers, e.g. trunk-SNAPSHOT or just SNAPSHOT - Matcher matcher = ALTERNATE_PATTERN.matcher( strVersion ); + Matcher matcher = ALTERNATE_PATTERN.matcher(strVersion); // TODO: hack because it didn't support "SNAPSHOT" - if ( matcher.matches() ) - { + if (matcher.matches()) { annotation = null; digits = null; buildSpecifier = version; @@ -135,41 +129,32 @@ public DefaultVersionInfo( String version ) return; } - Matcher m = STANDARD_PATTERN.matcher( strVersion ); - if ( m.matches() ) - { - digits = parseDigits( m.group( DIGITS_INDEX ) ); - if ( !SNAPSHOT_IDENTIFIER.equals( m.group( ANNOTATION_INDEX ) ) ) - { - annotationSeparator = m.group( ANNOTATION_SEPARATOR_INDEX ); - annotation = nullIfEmpty( m.group( ANNOTATION_INDEX ) ); - - if ( StringUtils.isNotEmpty( m.group( ANNOTATION_REV_SEPARATOR_INDEX ) ) - && StringUtils.isEmpty( m.group( ANNOTATION_REVISION_INDEX ) ) ) - { - // The build separator was picked up as the annotation revision separator - buildSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX ); - buildSpecifier = nullIfEmpty( m.group( BUILD_SPECIFIER_INDEX ) ); - } - else - { - annotationRevSeparator = m.group( ANNOTATION_REV_SEPARATOR_INDEX ); - annotationRevision = nullIfEmpty( m.group( ANNOTATION_REVISION_INDEX ) ); + Matcher m = STANDARD_PATTERN.matcher(strVersion); + if (m.matches()) { + digits = parseDigits(m.group(DIGITS_INDEX)); + if (!SNAPSHOT_IDENTIFIER.equals(m.group(ANNOTATION_INDEX))) { + annotationSeparator = m.group(ANNOTATION_SEPARATOR_INDEX); + annotation = nullIfEmpty(m.group(ANNOTATION_INDEX)); - buildSeparator = m.group( BUILD_SEPARATOR_INDEX ); - buildSpecifier = nullIfEmpty( m.group( BUILD_SPECIFIER_INDEX ) ); + if (StringUtils.isNotEmpty(m.group(ANNOTATION_REV_SEPARATOR_INDEX)) + && StringUtils.isEmpty(m.group(ANNOTATION_REVISION_INDEX))) { + // The build separator was picked up as the annotation revision separator + buildSeparator = m.group(ANNOTATION_REV_SEPARATOR_INDEX); + buildSpecifier = nullIfEmpty(m.group(BUILD_SPECIFIER_INDEX)); + } else { + annotationRevSeparator = m.group(ANNOTATION_REV_SEPARATOR_INDEX); + annotationRevision = nullIfEmpty(m.group(ANNOTATION_REVISION_INDEX)); + + buildSeparator = m.group(BUILD_SEPARATOR_INDEX); + buildSpecifier = nullIfEmpty(m.group(BUILD_SPECIFIER_INDEX)); } - } - else - { + } else { // Annotation was "SNAPSHOT" so populate the build specifier with that data - buildSeparator = m.group( ANNOTATION_SEPARATOR_INDEX ); - buildSpecifier = nullIfEmpty( m.group( ANNOTATION_INDEX ) ); + buildSeparator = m.group(ANNOTATION_SEPARATOR_INDEX); + buildSpecifier = nullIfEmpty(m.group(ANNOTATION_INDEX)); } - } - else - { - throw new VersionParseException( "Unable to parse the version string: \"" + version + "\"" ); + } else { + throw new VersionParseException("Unable to parse the version string: \"" + version + "\""); } } @@ -184,9 +169,14 @@ public DefaultVersionInfo( String version ) * @param annotationRevSeparator a {@link java.lang.String} object * @param buildSeparator a {@link java.lang.String} object */ - public DefaultVersionInfo( List digits, String annotation, String annotationRevision, String buildSpecifier, - String annotationSeparator, String annotationRevSeparator, String buildSeparator ) - { + public DefaultVersionInfo( + List digits, + String annotation, + String annotationRevision, + String buildSpecifier, + String annotationSeparator, + String annotationRevSeparator, + String buildSeparator) { this.digits = digits; this.annotation = annotation; this.annotationRevision = annotationRevision; @@ -194,34 +184,34 @@ public DefaultVersionInfo( List digits, String annotation, String annota this.annotationSeparator = annotationSeparator; this.annotationRevSeparator = annotationRevSeparator; this.buildSeparator = buildSeparator; - this.strVersion = getVersionString( this, buildSpecifier, buildSeparator ); + this.strVersion = getVersionString(this, buildSpecifier, buildSeparator); } @Override - public boolean isSnapshot() - { - return ArtifactUtils.isSnapshot( strVersion ); + public boolean isSnapshot() { + return ArtifactUtils.isSnapshot(strVersion); } @Override - public VersionInfo getNextVersion() - { + public VersionInfo getNextVersion() { DefaultVersionInfo version = null; - if ( digits != null ) - { - List digits = new ArrayList<>( this.digits ); + if (digits != null) { + List digits = new ArrayList<>(this.digits); String annotationRevision = this.annotationRevision; - if ( StringUtils.isNumeric( annotationRevision ) ) - { - annotationRevision = incrementVersionString( annotationRevision ); - } - else - { - digits.set( digits.size() - 1, incrementVersionString( digits.get( digits.size() - 1 ) ) ); + if (StringUtils.isNumeric(annotationRevision)) { + annotationRevision = incrementVersionString(annotationRevision); + } else { + digits.set(digits.size() - 1, incrementVersionString(digits.get(digits.size() - 1))); } - version = new DefaultVersionInfo( digits, annotation, annotationRevision, buildSpecifier, - annotationSeparator, annotationRevSeparator, buildSeparator ); + version = new DefaultVersionInfo( + digits, + annotation, + annotationRevision, + buildSpecifier, + annotationSeparator, + annotationRevSeparator, + buildSeparator); } return version; } @@ -233,49 +223,43 @@ public VersionInfo getNextVersion() * greater. */ @Override - public int compareTo( VersionInfo obj ) - { + public int compareTo(VersionInfo obj) { DefaultVersionInfo that = (DefaultVersionInfo) obj; int result; // TODO: this is a workaround for a bug in DefaultArtifactVersion - fix there - 1.01 < 1.01.01 - if ( strVersion.startsWith( that.strVersion ) && !strVersion.equals( that.strVersion ) - && strVersion.charAt( that.strVersion.length() ) != '-' ) - { + if (strVersion.startsWith(that.strVersion) + && !strVersion.equals(that.strVersion) + && strVersion.charAt(that.strVersion.length()) != '-') { result = 1; - } - else if ( that.strVersion.startsWith( strVersion ) && !strVersion.equals( that.strVersion ) - && that.strVersion.charAt( strVersion.length() ) != '-' ) - { + } else if (that.strVersion.startsWith(strVersion) + && !strVersion.equals(that.strVersion) + && that.strVersion.charAt(strVersion.length()) != '-') { result = -1; - } - else - { - // TODO: this is a workaround for a bug in DefaultArtifactVersion - fix there - it should not consider case in comparing the qualifier + } else { + // TODO: this is a workaround for a bug in DefaultArtifactVersion - fix there - it should not consider case + // in comparing the qualifier // NOTE: The combination of upper-casing and lower-casing is an approximation of String.equalsIgnoreCase() - String thisVersion = strVersion.toUpperCase( Locale.ENGLISH ).toLowerCase( Locale.ENGLISH ); - String thatVersion = that.strVersion.toUpperCase( Locale.ENGLISH ).toLowerCase( Locale.ENGLISH ); + String thisVersion = strVersion.toUpperCase(Locale.ENGLISH).toLowerCase(Locale.ENGLISH); + String thatVersion = that.strVersion.toUpperCase(Locale.ENGLISH).toLowerCase(Locale.ENGLISH); - result = new DefaultArtifactVersion( thisVersion ).compareTo( new DefaultArtifactVersion( thatVersion ) ); + result = new DefaultArtifactVersion(thisVersion).compareTo(new DefaultArtifactVersion(thatVersion)); } return result; } @Override - public boolean equals( Object obj ) - { - if ( !( obj instanceof DefaultVersionInfo ) ) - { + public boolean equals(Object obj) { + if (!(obj instanceof DefaultVersionInfo)) { return false; } - return compareTo( (VersionInfo) obj ) == 0; + return compareTo((VersionInfo) obj) == 0; } @Override - public int hashCode() - { - return strVersion.toLowerCase( Locale.ENGLISH ).hashCode(); + public int hashCode() { + return strVersion.toLowerCase(Locale.ENGLISH).hashCode(); } /** @@ -286,30 +270,25 @@ public int hashCode() * @return {@code String} increments the input {@code String} as an integer * and Preserves any lpad of "0" zeros. */ - protected String incrementVersionString( String s ) - { - int n = Integer.valueOf( s ).intValue() + 1; - String value = String.valueOf( n ); - if ( value.length() < s.length() ) - { + protected String incrementVersionString(String s) { + int n = Integer.valueOf(s).intValue() + 1; + String value = String.valueOf(n); + if (value.length() < s.length()) { // String was left-padded with zeros - value = StringUtils.leftPad( value, s.length(), "0" ); + value = StringUtils.leftPad(value, s.length(), "0"); } return value; } @Override - public String getSnapshotVersionString() - { - if ( strVersion.equals( Artifact.SNAPSHOT_VERSION ) ) - { + public String getSnapshotVersionString() { + if (strVersion.equals(Artifact.SNAPSHOT_VERSION)) { return strVersion; } String baseVersion = getReleaseVersionString(); - if ( baseVersion.length() > 0 ) - { + if (baseVersion.length() > 0) { baseVersion += "-"; } @@ -317,30 +296,24 @@ public String getSnapshotVersionString() } @Override - public String getReleaseVersionString() - { + public String getReleaseVersionString() { String baseVersion = strVersion; - Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( baseVersion ); - if ( m.matches() ) - { - baseVersion = m.group( 1 ); + Matcher m = Artifact.VERSION_FILE_PATTERN.matcher(baseVersion); + if (m.matches()) { + baseVersion = m.group(1); } // MRELEASE-623 SNAPSHOT is case-insensitive - else if ( StringUtils.right( baseVersion, 9 ).equalsIgnoreCase( "-" + Artifact.SNAPSHOT_VERSION ) ) - { - baseVersion = baseVersion.substring( 0, baseVersion.length() - Artifact.SNAPSHOT_VERSION.length() - 1 ); - } - else if ( baseVersion.equals( Artifact.SNAPSHOT_VERSION ) ) - { + else if (StringUtils.right(baseVersion, 9).equalsIgnoreCase("-" + Artifact.SNAPSHOT_VERSION)) { + baseVersion = baseVersion.substring(0, baseVersion.length() - Artifact.SNAPSHOT_VERSION.length() - 1); + } else if (baseVersion.equals(Artifact.SNAPSHOT_VERSION)) { baseVersion = "1.0"; } return baseVersion; } @Override - public String toString() - { + public String toString() { return strVersion; } @@ -352,38 +325,30 @@ public String toString() * @param buildSeparator a {@link java.lang.String} object * @return a {@link java.lang.String} object */ - protected static String getVersionString( DefaultVersionInfo info, String buildSpecifier, String buildSeparator ) - { + protected static String getVersionString(DefaultVersionInfo info, String buildSpecifier, String buildSeparator) { StringBuilder sb = new StringBuilder(); - if ( info.digits != null ) - { - sb.append( joinDigitString( info.digits ) ); + if (info.digits != null) { + sb.append(joinDigitString(info.digits)); } - if ( StringUtils.isNotEmpty( info.annotation ) ) - { - sb.append( StringUtils.defaultString( info.annotationSeparator ) ); - sb.append( info.annotation ); + if (StringUtils.isNotEmpty(info.annotation)) { + sb.append(StringUtils.defaultString(info.annotationSeparator)); + sb.append(info.annotation); } - if ( StringUtils.isNotEmpty( info.annotationRevision ) ) - { - if ( StringUtils.isEmpty( info.annotation ) ) - { - sb.append( StringUtils.defaultString( info.annotationSeparator ) ); - } - else - { - sb.append( StringUtils.defaultString( info.annotationRevSeparator ) ); + if (StringUtils.isNotEmpty(info.annotationRevision)) { + if (StringUtils.isEmpty(info.annotation)) { + sb.append(StringUtils.defaultString(info.annotationSeparator)); + } else { + sb.append(StringUtils.defaultString(info.annotationRevSeparator)); } - sb.append( info.annotationRevision ); + sb.append(info.annotationRevision); } - if ( StringUtils.isNotEmpty( buildSpecifier ) ) - { - sb.append( StringUtils.defaultString( buildSeparator ) ); - sb.append( buildSpecifier ); + if (StringUtils.isNotEmpty(buildSpecifier)) { + sb.append(StringUtils.defaultString(buildSeparator)); + sb.append(buildSpecifier); } return sb.toString(); @@ -395,9 +360,8 @@ protected static String getVersionString( DefaultVersionInfo info, String buildS * @return a single {@code String} of the items in the passed list, joined with a "." * @param digits {@code List} of digits */ - protected static String joinDigitString( List digits ) - { - return digits != null ? StringUtils.join( digits.iterator(), DIGIT_SEPARATOR_STRING ) : null; + protected static String joinDigitString(List digits) { + return digits != null ? StringUtils.join(digits.iterator(), DIGIT_SEPARATOR_STRING) : null; } /** @@ -406,18 +370,16 @@ protected static String joinDigitString( List digits ) * * @param strDigits */ - private List parseDigits( String strDigits ) - { - return Arrays.asList( StringUtils.split( strDigits, DIGIT_SEPARATOR_STRING ) ); + private List parseDigits(String strDigits) { + return Arrays.asList(StringUtils.split(strDigits, DIGIT_SEPARATOR_STRING)); } - //-------------------------------------------------- + // -------------------------------------------------- // Getters & Setters - //-------------------------------------------------- + // -------------------------------------------------- - private static String nullIfEmpty( String s ) - { - return StringUtils.isEmpty( s ) ? null : s; + private static String nullIfEmpty(String s) { + return StringUtils.isEmpty(s) ? null : s; } /** @@ -425,8 +387,7 @@ private static String nullIfEmpty( String s ) * * @return a {@link java.util.List} object */ - public List getDigits() - { + public List getDigits() { return digits; } @@ -435,8 +396,7 @@ public List getDigits() * * @return a {@link java.lang.String} object */ - public String getAnnotation() - { + public String getAnnotation() { return annotation; } @@ -445,8 +405,7 @@ public String getAnnotation() * * @return a {@link java.lang.String} object */ - public String getAnnotationRevision() - { + public String getAnnotationRevision() { return annotationRevision; } @@ -455,9 +414,7 @@ public String getAnnotationRevision() * * @return a {@link java.lang.String} object */ - public String getBuildSpecifier() - { + public String getBuildSpecifier() { return buildSpecifier; } - } diff --git a/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/VersionInfo.java b/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/VersionInfo.java index f1cd57880..000520ec1 100644 --- a/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/VersionInfo.java +++ b/maven-release-manager/src/main/java/org/apache/maven/shared/release/versions/VersionInfo.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.versions; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,13 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; /** * Represent the different version representations during the release-prepare phase * */ -public interface VersionInfo - extends Comparable -{ +public interface VersionInfo extends Comparable { /** * Returns a string representing the version with a snapshot specification diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/DefaultReleaseManagerTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/DefaultReleaseManagerTest.java index a7fcf7028..e434a696c 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/DefaultReleaseManagerTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/DefaultReleaseManagerTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,20 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release; import java.io.File; import java.io.IOException; @@ -66,784 +51,727 @@ import org.junit.Ignore; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the default release manager. * * @author Brett Porter */ -public class DefaultReleaseManagerTest - extends PlexusJUnit4TestCase -{ +public class DefaultReleaseManagerTest extends PlexusJUnit4TestCase { private ReleaseDescriptorStoreStub configStore; - @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - configStore = (ReleaseDescriptorStoreStub) lookup( ReleaseDescriptorStore.class, "stub" ); + configStore = (ReleaseDescriptorStoreStub) lookup(ReleaseDescriptorStore.class, "stub"); } @Override - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[] { - new AbstractModule() - { - @Override - protected void configure() - { - bind( ScmManager.class ).toInstance( new ScmManagerStub() ); - bind( ReleaseDescriptorStore.class ).toInstance( new ReleaseDescriptorStoreStub() ); - } + new AbstractModule() { + @Override + protected void configure() { + bind(ScmManager.class).toInstance(new ScmManagerStub()); + bind(ReleaseDescriptorStore.class).toInstance(new ReleaseDescriptorStoreStub()); } + } }; } @Test - public void testPrepareNoCompletedPhase() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareNoCompletedPhase() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( null ); + builder.setCompletedPhase(null); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertTrue( "step1 executed", phase.isExecuted() ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 executed", phase.isExecuted() ); - assertFalse( "step2 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 executed", phase.isExecuted() ); - assertFalse( "step3 not simulated", phase.isSimulated() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertTrue("step1 executed", phase.isExecuted()); + assertFalse("step1 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 executed", phase.isExecuted()); + assertFalse("step2 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 executed", phase.isExecuted()); + assertFalse("step3 not simulated", phase.isSimulated()); } @Test - public void testPrepareCompletedPhase() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareCompletedPhase() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "step1" ); + builder.setCompletedPhase("step1"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertFalse( "step1 not executed", phase.isExecuted() ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 executed", phase.isExecuted() ); - assertFalse( "step2 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 executed", phase.isExecuted() ); - assertFalse( "step3 not simulated", phase.isSimulated() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertFalse("step1 not executed", phase.isExecuted()); + assertFalse("step1 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 executed", phase.isExecuted()); + assertFalse("step2 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 executed", phase.isExecuted()); + assertFalse("step3 not simulated", phase.isSimulated()); } @Test - public void testPrepareCompletedPhaseNoResume() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareCompletedPhaseNoResume() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "step1" ); + builder.setCompletedPhase("step1"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setDryRun( false ); - prepareRequest.setResume( false ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertFalse( "step1 executed", phase.isExecuted() ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 executed", phase.isExecuted() ); - assertFalse( "step2 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 executed", phase.isExecuted() ); - assertFalse( "step3 not simulated", phase.isSimulated() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setDryRun(false); + prepareRequest.setResume(false); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertFalse("step1 executed", phase.isExecuted()); + assertFalse("step1 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 executed", phase.isExecuted()); + assertFalse("step2 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 executed", phase.isExecuted()); + assertFalse("step3 not simulated", phase.isSimulated()); } @Test - public void testPrepareCompletedAllPhases() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareCompletedAllPhases() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "step3" ); - + builder.setCompletedPhase("step3"); + ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertFalse( "step1 not executed", phase.isExecuted() ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertFalse( "step2 not executed", phase.isExecuted() ); - assertFalse( "step2 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertFalse( "step3 not executed", phase.isExecuted() ); - assertFalse( "step3 not simulated", phase.isSimulated() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertFalse("step1 not executed", phase.isExecuted()); + assertFalse("step1 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertFalse("step2 not executed", phase.isExecuted()); + assertFalse("step2 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertFalse("step3 not executed", phase.isExecuted()); + assertFalse("step3 not simulated", phase.isSimulated()); } @Test - public void testPrepareInvalidCompletedPhase() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareInvalidCompletedPhase() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "foo" ); + builder.setCompletedPhase("foo"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertTrue( "step1 executed", phase.isExecuted() ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 executed", phase.isExecuted() ); - assertFalse( "step2 not simulated", phase.isSimulated() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 executed", phase.isExecuted() ); - assertFalse( "step3 not simulated", phase.isSimulated() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertTrue("step1 executed", phase.isExecuted()); + assertFalse("step1 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 executed", phase.isExecuted()); + assertFalse("step2 not simulated", phase.isSimulated()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 executed", phase.isExecuted()); + assertFalse("step3 not simulated", phase.isSimulated()); } @Test - public void testPrepareSimulateNoCompletedPhase() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareSimulateNoCompletedPhase() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( null ); + builder.setCompletedPhase(null); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setDryRun( true ); - prepareRequest.setResume( true ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertTrue( "step1 simulated", phase.isSimulated() ); - assertFalse( "step1 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 simulated", phase.isSimulated() ); - assertFalse( "step2 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 simulated", phase.isSimulated() ); - assertFalse( "step3 not executed", phase.isExecuted() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setDryRun(true); + prepareRequest.setResume(true); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertTrue("step1 simulated", phase.isSimulated()); + assertFalse("step1 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 simulated", phase.isSimulated()); + assertFalse("step2 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 simulated", phase.isSimulated()); + assertFalse("step3 not executed", phase.isExecuted()); } @Test - public void testPrepareSimulateCompletedPhase() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareSimulateCompletedPhase() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "step1" ); + builder.setCompletedPhase("step1"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setDryRun( true ); - prepareRequest.setResume( true ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - assertFalse( "step1 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 simulated", phase.isSimulated() ); - assertFalse( "step2 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 simulated", phase.isSimulated() ); - assertFalse( "step3 not executed", phase.isExecuted() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setDryRun(true); + prepareRequest.setResume(true); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertFalse("step1 not simulated", phase.isSimulated()); + assertFalse("step1 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 simulated", phase.isSimulated()); + assertFalse("step2 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 simulated", phase.isSimulated()); + assertFalse("step3 not executed", phase.isExecuted()); } @Test - public void testPrepareSimulateCompletedAllPhases() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareSimulateCompletedAllPhases() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "step3" ); + builder.setCompletedPhase("step3"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setDryRun( true ); - prepareRequest.setResume( true ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertFalse( "step1 not simulated", phase.isSimulated() ); - assertFalse( "step1 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertFalse( "step2 not simulated", phase.isSimulated() ); - assertFalse( "step2 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertFalse( "step3 not simulated", phase.isSimulated() ); - assertFalse( "step3 not executed", phase.isExecuted() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setDryRun(true); + prepareRequest.setResume(true); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertFalse("step1 not simulated", phase.isSimulated()); + assertFalse("step1 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertFalse("step2 not simulated", phase.isSimulated()); + assertFalse("step2 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertFalse("step3 not simulated", phase.isSimulated()); + assertFalse("step3 not executed", phase.isExecuted()); } @Test - public void testPrepareSimulateInvalidCompletedPhase() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testPrepareSimulateInvalidCompletedPhase() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = configStore.getReleaseConfiguration(); - builder.setCompletedPhase( "foo" ); + builder.setCompletedPhase("foo"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setDryRun( true ); - prepareRequest.setResume( true ); - prepareRequest.setUserProperties( new Properties() ); - - releaseManager.prepare( prepareRequest ); - - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertTrue( "step1 simulated", phase.isSimulated() ); - assertFalse( "step1 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 simulated", phase.isSimulated() ); - assertFalse( "step2 not executed", phase.isExecuted() ); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 simulated", phase.isSimulated() ); - assertFalse( "step3 not executed", phase.isExecuted() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setDryRun(true); + prepareRequest.setResume(true); + prepareRequest.setUserProperties(new Properties()); + + releaseManager.prepare(prepareRequest); + + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertTrue("step1 simulated", phase.isSimulated()); + assertFalse("step1 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 simulated", phase.isSimulated()); + assertFalse("step2 not executed", phase.isExecuted()); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 simulated", phase.isSimulated()); + assertFalse("step3 not executed", phase.isExecuted()); } - @Ignore( "This is testing messed up XML?" ) + @Ignore("This is testing messed up XML?") @Test - public void testPrepareUnknownPhaseConfigured() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "bad-phase-configured" ); + public void testPrepareUnknownPhaseConfigured() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "bad-phase-configured"); ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setReleaseStrategyId( "foo" ); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setUserProperties( new Properties() ); - - try - { - releaseManager.prepare( prepareRequest ); - fail( "Should have failed to find a phase" ); - } - catch ( ReleaseExecutionException e ) - { + builder.setReleaseStrategyId("foo"); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setUserProperties(new Properties()); + + try { + releaseManager.prepare(prepareRequest); + fail("Should have failed to find a phase"); + } catch (ReleaseExecutionException e) { // good } } @Test - public void testReleaseConfigurationStoreReadFailure() - throws Exception - { + public void testReleaseConfigurationStoreReadFailure() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); - DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup( ReleaseManager.class, "test" ); + DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup(ReleaseManager.class, "test"); - ReleaseDescriptorStore configStoreMock = mock( ReleaseDescriptorStore.class ); - when( configStoreMock.read( builder ) ).thenThrow( new ReleaseDescriptorStoreException( "message", new IOException( "ioExceptionMsg" ) ) ); + ReleaseDescriptorStore configStoreMock = mock(ReleaseDescriptorStore.class); + when(configStoreMock.read(builder)) + .thenThrow(new ReleaseDescriptorStoreException("message", new IOException("ioExceptionMsg"))); + + releaseManager.setConfigStore(configStoreMock); - releaseManager.setConfigStore( configStoreMock ); - ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setUserProperties( new Properties() ); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setUserProperties(new Properties()); // execute - try - { - releaseManager.prepare( prepareRequest ); - fail( "Should have failed to read configuration" ); - } - catch ( ReleaseExecutionException e ) - { + try { + releaseManager.prepare(prepareRequest); + fail("Should have failed to read configuration"); + } catch (ReleaseExecutionException e) { // good - assertEquals( "check cause", ReleaseDescriptorStoreException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + ReleaseDescriptorStoreException.class, + e.getCause().getClass()); } // verify - verify( configStoreMock ).read( builder ); - verifyNoMoreInteractions( configStoreMock ); + verify(configStoreMock).read(builder); + verifyNoMoreInteractions(configStoreMock); } @Test - public void testReleaseConfigurationStoreWriteFailure() - throws Exception - { + public void testReleaseConfigurationStoreWriteFailure() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); - DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup( ReleaseManager.class, "test" ); + DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup(ReleaseManager.class, "test"); - ReleaseDescriptorStore configStoreMock = mock( ReleaseDescriptorStore.class ); - doThrow( new ReleaseDescriptorStoreException( "message", new IOException( "ioExceptionMsg" ) ) ).when( configStoreMock ).write( any( ReleaseDescriptor.class) ); + ReleaseDescriptorStore configStoreMock = mock(ReleaseDescriptorStore.class); + doThrow(new ReleaseDescriptorStoreException("message", new IOException("ioExceptionMsg"))) + .when(configStoreMock) + .write(any(ReleaseDescriptor.class)); - releaseManager.setConfigStore( configStoreMock ); - - ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( builder ); - prepareRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - prepareRequest.setDryRun( false ); - prepareRequest.setResume( false ); - prepareRequest.setUserProperties( new Properties() ); + releaseManager.setConfigStore(configStoreMock); + ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); + prepareRequest.setReleaseDescriptorBuilder(builder); + prepareRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + prepareRequest.setDryRun(false); + prepareRequest.setResume(false); + prepareRequest.setUserProperties(new Properties()); // execute - try - { - releaseManager.prepare( prepareRequest ); - fail( "Should have failed to read configuration" ); - } - catch ( ReleaseExecutionException e ) - { + try { + releaseManager.prepare(prepareRequest); + fail("Should have failed to read configuration"); + } catch (ReleaseExecutionException e) { // good - assertEquals( "check cause", ReleaseDescriptorStoreException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + ReleaseDescriptorStoreException.class, + e.getCause().getClass()); } // verify - verify( configStoreMock ).write( any( ReleaseDescriptor.class ) ) ; - verifyNoMoreInteractions( configStoreMock ); + verify(configStoreMock).write(any(ReleaseDescriptor.class)); + verifyNoMoreInteractions(configStoreMock); } @Test - public void testReleaseConfigurationStoreClean() - throws Exception - { + public void testReleaseConfigurationStoreClean() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); - DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup( ReleaseManager.class, "test" ); + DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup(ReleaseManager.class, "test"); - ReleaseDescriptorStore configStoreMock = mock( ReleaseDescriptorStore.class ); + ReleaseDescriptorStore configStoreMock = mock(ReleaseDescriptorStore.class); - releaseManager.setConfigStore( configStoreMock ); + releaseManager.setConfigStore(configStoreMock); ReleaseCleanRequest cleanRequest = new ReleaseCleanRequest(); - cleanRequest.setReleaseDescriptorBuilder( builder ); - + cleanRequest.setReleaseDescriptorBuilder(builder); + // execute - releaseManager.clean( cleanRequest ); + releaseManager.clean(cleanRequest); // verify - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step1" ); - assertTrue( "step1 not cleaned", phase.isCleaned() ); + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step1"); + assertTrue("step1 not cleaned", phase.isCleaned()); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step2" ); - assertTrue( "step2 not cleaned", phase.isCleaned() ); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step2"); + assertTrue("step2 not cleaned", phase.isCleaned()); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "step3" ); - assertTrue( "step3 not cleaned", phase.isCleaned() ); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "step3"); + assertTrue("step3 not cleaned", phase.isCleaned()); - phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "branch1" ); - assertTrue( "branch1 not cleaned", phase.isCleaned() ); + phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "branch1"); + assertTrue("branch1 not cleaned", phase.isCleaned()); - verify( configStoreMock ).delete( any( ReleaseDescriptor.class ) ); - verifyNoMoreInteractions( configStoreMock ); + verify(configStoreMock).delete(any(ReleaseDescriptor.class)); + verifyNoMoreInteractions(configStoreMock); } - private static List createReactorProjects() throws IOException - { + private static List createReactorProjects() throws IOException { MavenProject project = new MavenProject(); - - File projectFile = getTestFile( "target/dummy-project/pom.xml" ); - if ( !projectFile.exists() ) - { + + File projectFile = getTestFile("target/dummy-project/pom.xml"); + if (!projectFile.exists()) { projectFile.getParentFile().mkdirs(); projectFile.createNewFile(); } - project.setFile( projectFile ); - return Collections.singletonList( project ); + project.setFile(projectFile); + return Collections.singletonList(project); } @Test - public void testReleasePerformWithResult() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testReleasePerformWithResult() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setWorkingDirectory( getTestPath( "target/dummy-project" ) ); - + builder.setScmSourceUrl("scm-url"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setWorkingDirectory(getTestPath("target/dummy-project")); + ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - performRequest.setReactorProjects( createReactorProjects() ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + performRequest.setReactorProjects(createReactorProjects()); - ReleaseResult result = releaseManager.performWithResult( performRequest ); + ReleaseResult result = releaseManager.performWithResult(performRequest); - assertTrue( result.getOutput().length() > 0 ); + assertTrue(result.getOutput().length() > 0); } @Test - public void testReleaseConfigurationStoreReadFailureOnPerform() - throws Exception - { + public void testReleaseConfigurationStoreReadFailureOnPerform() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); - DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup( ReleaseManager.class, "test" ); + DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup(ReleaseManager.class, "test"); - ReleaseDescriptorStore configStoreMock = mock( ReleaseDescriptorStore.class ); - when( configStoreMock.read( builder ) ).thenThrow( new ReleaseDescriptorStoreException( "message", new IOException( "ioExceptionMsg" ) ) ); + ReleaseDescriptorStore configStoreMock = mock(ReleaseDescriptorStore.class); + when(configStoreMock.read(builder)) + .thenThrow(new ReleaseDescriptorStoreException("message", new IOException("ioExceptionMsg"))); + + releaseManager.setConfigStore(configStoreMock); - releaseManager.setConfigStore( configStoreMock ); - ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); // execute - try - { - builder.setUseReleaseProfile( false ); + try { + builder.setUseReleaseProfile(false); - releaseManager.perform( performRequest ); - fail( "Should have failed to read configuration" ); - } - catch ( ReleaseExecutionException e ) - { + releaseManager.perform(performRequest); + fail("Should have failed to read configuration"); + } catch (ReleaseExecutionException e) { // good - assertEquals( "check cause", ReleaseDescriptorStoreException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + ReleaseDescriptorStoreException.class, + e.getCause().getClass()); } // verify - verify( configStoreMock ).read( builder ); - verifyNoMoreInteractions( configStoreMock ); + verify(configStoreMock).read(builder); + verifyNoMoreInteractions(configStoreMock); } @Test - public void testReleasePerformWithIncompletePrepare() - throws Exception - { + public void testReleasePerformWithIncompletePrepare() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); - DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup( ReleaseManager.class, "test" ); + DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup(ReleaseManager.class, "test"); ReleaseDescriptorStoreStub configStore = new ReleaseDescriptorStoreStub(); - builder.setCompletedPhase( "scm-tag" ); - releaseManager.setConfigStore( configStore ); + builder.setCompletedPhase("scm-tag"); + releaseManager.setConfigStore(configStore); ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); - try - { - builder.setUseReleaseProfile( false ); + try { + builder.setUseReleaseProfile(false); - releaseManager.perform( performRequest ); - fail( "Should have failed to perform" ); - } - catch ( ReleaseFailureException e ) - { + releaseManager.perform(performRequest); + fail("Should have failed to perform"); + } catch (ReleaseFailureException e) { // good - assertTrue( true ); + assertTrue(true); } } // MRELEASE-758: release:perform no longer removes release.properties @Test - public void testPerformWithDefaultClean() - throws Exception - { + public void testPerformWithDefaultClean() throws Exception { // prepare ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setDryRun( true ); - performRequest.setReactorProjects( createReactorProjects() ); + performRequest.setDryRun(true); + performRequest.setReactorProjects(createReactorProjects()); - ReleaseManagerListener managerListener = mock( ReleaseManagerListener.class ); - performRequest.setReleaseManagerListener( managerListener ); + ReleaseManagerListener managerListener = mock(ReleaseManagerListener.class); + performRequest.setReleaseManagerListener(managerListener); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); - performRequest.setReleaseDescriptorBuilder( builder ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); + performRequest.setReleaseDescriptorBuilder(builder); - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); // test - releaseManager.perform( performRequest ); + releaseManager.perform(performRequest); // verify - verify( managerListener ).phaseStart( "verify-completed-prepare-phases" ); - verify( managerListener ).phaseStart( "checkout-project-from-scm" ); - verify( managerListener ).phaseStart( "run-perform-goals" ); - verify( managerListener, times( 3 ) ).phaseEnd(); + verify(managerListener).phaseStart("verify-completed-prepare-phases"); + verify(managerListener).phaseStart("checkout-project-from-scm"); + verify(managerListener).phaseStart("run-perform-goals"); + verify(managerListener, times(3)).phaseEnd(); // not part of actual test, but required to confirm 'no more interactions' - verify( managerListener ).goalStart( anyString(), any() ); - verify( managerListener ).goalEnd(); + verify(managerListener).goalStart(anyString(), any()); + verify(managerListener).goalEnd(); - verifyNoMoreInteractions( managerListener ); + verifyNoMoreInteractions(managerListener); } @Test - public void testNoScmUrlPerform() - throws Exception - { + public void testNoScmUrlPerform() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - - try - { - builder.setUseReleaseProfile( false ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); - releaseManager.perform( performRequest ); + try { + builder.setUseReleaseProfile(false); - fail( "perform should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertNull( "check no cause", e.getCause() ); + releaseManager.perform(performRequest); + + fail("perform should have failed"); + } catch (ReleaseFailureException e) { + assertNull("check no cause", e.getCause()); } } @Test - public void testScmExceptionThrown() - throws Exception - { + public void testScmExceptionThrown() throws Exception { // prepare - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkOut( any( ScmRepository.class ), - any( ScmFileSet.class ), - any( ScmTag.class ), - any(CommandParameters.class)) ) - .thenThrow( new ScmException( "..." ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkOut( + any(ScmRepository.class), + any(ScmFileSet.class), + any(ScmTag.class), + any(CommandParameters.class))) + .thenThrow(new ScmException("...")); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - performRequest.setReactorProjects( createReactorProjects() ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + performRequest.setReactorProjects(createReactorProjects()); // execute - try - { - releaseManager.perform( performRequest ); + try { + releaseManager.perform(performRequest); - fail( "commit should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); + fail("commit should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause().getClass()); } // verify - verify( scmProviderMock ).checkOut( any( ScmRepository.class ), any( ScmFileSet.class ), - any( ScmTag.class ), any( CommandParameters.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkOut( + any(ScmRepository.class), any(ScmFileSet.class), + any(ScmTag.class), any(CommandParameters.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testScmResultFailure() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); + public void testScmResultFailure() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setWorkingDirectory( getTestPath( "target/dummy-project" ) ); + builder.setScmSourceUrl("scm-url"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setWorkingDirectory(getTestPath("target/dummy-project")); + + ScmManager scmManager = (ScmManager) lookup(ScmManager.class); + ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl("scm-url"); - ScmManager scmManager = (ScmManager) lookup( ScmManager.class ); - ScmProviderStub providerStub = - (ScmProviderStub) scmManager.getProviderByUrl( "scm-url" ); + providerStub.setCheckOutScmResult(new CheckOutScmResult("", "", "", false)); - providerStub.setCheckOutScmResult( new CheckOutScmResult( "", "", "", false ) ); - ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( new DefaultReleaseEnvironment() ); - performRequest.setReactorProjects( createReactorProjects() ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(new DefaultReleaseEnvironment()); + performRequest.setReactorProjects(createReactorProjects()); - try - { - releaseManager.perform( performRequest ); + try { + releaseManager.perform(performRequest); - fail( "commit should have failed" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("commit should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } } // MRELEASE-1042 @Test - public void testKeepProfilesOnPerform() - throws Exception - { + public void testKeepProfilesOnPerform() throws Exception { // prepare ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setDryRun( true ); - performRequest.setReactorProjects( createReactorProjects() ); + performRequest.setDryRun(true); + performRequest.setReactorProjects(createReactorProjects()); - ReleaseManagerListener managerListener = mock( ReleaseManagerListener.class ); - performRequest.setReleaseManagerListener( managerListener ); + ReleaseManagerListener managerListener = mock(ReleaseManagerListener.class); + performRequest.setReleaseManagerListener(managerListener); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setActivateProfiles( Arrays.asList("aProfile", "anotherOne") ); - builder.setWorkingDirectory( getTestFile( "target/working-directory" ).getAbsolutePath() ); - performRequest.setReleaseDescriptorBuilder( builder ); + builder.setActivateProfiles(Arrays.asList("aProfile", "anotherOne")); + builder.setWorkingDirectory(getTestFile("target/working-directory").getAbsolutePath()); + performRequest.setReleaseDescriptorBuilder(builder); - DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup( ReleaseManager.class, "test" ); + DefaultReleaseManager releaseManager = (DefaultReleaseManager) lookup(ReleaseManager.class, "test"); ReleaseDescriptorBuilder secondBuilder = new ReleaseDescriptorBuilder(); - secondBuilder.setActivateProfiles( Arrays.asList("aProfile", "bProfile") ); - secondBuilder.setScmSourceUrl( "scm-url" ); - ReleaseDescriptorStore configStoreMock = mock( ReleaseDescriptorStore.class ); - when( configStoreMock.read( any( ReleaseDescriptorBuilder.class ) ) ).thenReturn( secondBuilder ); - releaseManager.setConfigStore( configStoreMock ); + secondBuilder.setActivateProfiles(Arrays.asList("aProfile", "bProfile")); + secondBuilder.setScmSourceUrl("scm-url"); + ReleaseDescriptorStore configStoreMock = mock(ReleaseDescriptorStore.class); + when(configStoreMock.read(any(ReleaseDescriptorBuilder.class))).thenReturn(secondBuilder); + releaseManager.setConfigStore(configStoreMock); // test - ReleaseResult result = releaseManager.performWithResult( performRequest ); + ReleaseResult result = releaseManager.performWithResult(performRequest); // verify - assertTrue( result.getOutput().contains( "-P aProfile,bProfile,anotherOne" ) ); + assertTrue(result.getOutput().contains("-P aProfile,bProfile,anotherOne")); } @Test - public void testDetermineWorkingDirectory() - throws Exception - { + public void testDetermineWorkingDirectory() throws Exception { DefaultReleaseManager defaultReleaseManager = new DefaultReleaseManager( - Collections.emptyMap(), - Collections.emptyMap(), - mock( ReleaseDescriptorStore.class ) - ); + Collections.emptyMap(), Collections.emptyMap(), mock(ReleaseDescriptorStore.class)); - File checkoutDir = getTestFile( "target/checkout" ); - FileUtils.forceDelete( checkoutDir ); + File checkoutDir = getTestFile("target/checkout"); + FileUtils.forceDelete(checkoutDir); checkoutDir.mkdirs(); - File projectDir = getTestFile( "target/checkout/my/project" ); + File projectDir = getTestFile("target/checkout/my/project"); projectDir.mkdirs(); // only checkout dir - assertEquals( checkoutDir, defaultReleaseManager.determineWorkingDirectory( checkoutDir, "" ) ); - assertEquals( checkoutDir, defaultReleaseManager.determineWorkingDirectory( checkoutDir, null ) ); + assertEquals(checkoutDir, defaultReleaseManager.determineWorkingDirectory(checkoutDir, "")); + assertEquals(checkoutDir, defaultReleaseManager.determineWorkingDirectory(checkoutDir, null)); // checkout dir and relative path project dir - assertEquals( projectDir, defaultReleaseManager.determineWorkingDirectory( checkoutDir, "my/project" ) ); - assertEquals( projectDir, defaultReleaseManager.determineWorkingDirectory( checkoutDir, "my/project/" ) ); - assertEquals( projectDir, defaultReleaseManager.determineWorkingDirectory( checkoutDir, "my" + File.separator + - "project" ) ); + assertEquals(projectDir, defaultReleaseManager.determineWorkingDirectory(checkoutDir, "my/project")); + assertEquals(projectDir, defaultReleaseManager.determineWorkingDirectory(checkoutDir, "my/project/")); + assertEquals( + projectDir, + defaultReleaseManager.determineWorkingDirectory(checkoutDir, "my" + File.separator + "project")); - FileUtils.forceDelete( checkoutDir ); + FileUtils.forceDelete(checkoutDir); } // MRELEASE-761 @Test - public void testRollbackCall() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); - + public void testRollbackCall() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); + ReleaseRollbackRequest rollbackRequest = new ReleaseRollbackRequest(); - rollbackRequest.setReleaseDescriptorBuilder( configStore.getReleaseConfiguration() ); + rollbackRequest.setReleaseDescriptorBuilder(configStore.getReleaseConfiguration()); - releaseManager.rollback( rollbackRequest ); + releaseManager.rollback(rollbackRequest); - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "rollbackPhase1" ); + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "rollbackPhase1"); - assertTrue( "rollbackPhase1 executed", phase.isExecuted() ); + assertTrue("rollbackPhase1 executed", phase.isExecuted()); } - // MRELEASE-765 @Test - public void testUpdateVersionsCall() - throws Exception - { - ReleaseManager releaseManager = lookup( ReleaseManager.class, "test" ); - + public void testUpdateVersionsCall() throws Exception { + ReleaseManager releaseManager = lookup(ReleaseManager.class, "test"); + ReleaseUpdateVersionsRequest updateVersionsRequest = new ReleaseUpdateVersionsRequest(); - updateVersionsRequest.setReleaseDescriptorBuilder( configStore.getReleaseConfiguration() ); - updateVersionsRequest.setUserProperties( new Properties() ); + updateVersionsRequest.setReleaseDescriptorBuilder(configStore.getReleaseConfiguration()); + updateVersionsRequest.setUserProperties(new Properties()); - releaseManager.updateVersions( updateVersionsRequest ); + releaseManager.updateVersions(updateVersionsRequest); - ReleasePhaseStub phase = (ReleasePhaseStub) lookup( ReleasePhase.class, "updateVersionsPhase1" ); + ReleasePhaseStub phase = (ReleasePhaseStub) lookup(ReleasePhase.class, "updateVersionsPhase1"); - assertTrue( "updateVersionsPhase1 executed", phase.isExecuted() ); + assertTrue("updateVersionsPhase1 executed", phase.isExecuted()); } -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/PlexusJUnit4TestCase.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/PlexusJUnit4TestCase.java index 59b0ab696..9b471fa60 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/PlexusJUnit4TestCase.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/PlexusJUnit4TestCase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,11 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release; import javax.inject.Singleton; -import static org.junit.Assert.fail; - import java.io.File; import java.io.InputStream; import java.util.Map; @@ -30,8 +27,6 @@ import com.google.inject.AbstractModule; import com.google.inject.Module; import org.apache.maven.scm.manager.ScmManager; -import org.apache.maven.shared.release.config.ReleaseDescriptorStore; -import org.apache.maven.shared.release.config.ReleaseDescriptorStoreStub; import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.DefaultContainerConfiguration; @@ -45,48 +40,44 @@ import org.junit.After; import org.junit.Before; +import static org.junit.Assert.fail; + /** * Based on PlexusTestCase from org.sonatype.sisu:sisu-inject-plexus * * @author Robert Scholte */ -public abstract class PlexusJUnit4TestCase -{ +public abstract class PlexusJUnit4TestCase { private PlexusContainer container; private static String basedir; @Before - public void setUp() - throws Exception - { + public void setUp() throws Exception { basedir = getBasedir(); } - protected void setupContainer() - { + protected void setupContainer() { // ---------------------------------------------------------------------------- // Context Setup // ---------------------------------------------------------------------------- final DefaultContext context = new DefaultContext(); - context.put( "basedir", getBasedir() ); + context.put("basedir", getBasedir()); - customizeContext( context ); + customizeContext(context); - final boolean hasPlexusHome = context.contains( "plexus.home" ); + final boolean hasPlexusHome = context.contains("plexus.home"); - if ( !hasPlexusHome ) - { - final File f = getTestFile( "target/plexus-home" ); + if (!hasPlexusHome) { + final File f = getTestFile("target/plexus-home"); - if ( !f.isDirectory() ) - { + if (!f.isDirectory()) { f.mkdir(); } - context.put( "plexus.home", f.getAbsolutePath() ); + context.put("plexus.home", f.getAbsolutePath()); } // ---------------------------------------------------------------------------- @@ -95,51 +86,41 @@ protected void setupContainer() final String config = getCustomConfigurationName(); - final ContainerConfiguration containerConfiguration = - new DefaultContainerConfiguration() - .setName( "test" ) - .setContext( context.getContextData() ) - .setAutoWiring( true ) - .setClassPathScanning( PlexusConstants.SCANNING_CACHE ); + final ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration() + .setName("test") + .setContext(context.getContextData()) + .setAutoWiring(true) + .setClassPathScanning(PlexusConstants.SCANNING_CACHE); - if ( config != null ) - { - containerConfiguration.setContainerConfiguration( config ); - } - else - { - final String resource = getConfigurationName( null ); + if (config != null) { + containerConfiguration.setContainerConfiguration(config); + } else { + final String resource = getConfigurationName(null); - containerConfiguration.setContainerConfiguration( resource ); + containerConfiguration.setContainerConfiguration(resource); } - customizeContainerConfiguration( containerConfiguration ); + customizeContainerConfiguration(containerConfiguration); - try - { - container = new DefaultPlexusContainer( containerConfiguration, getCustomModules() ); - } - catch ( final PlexusContainerException e ) - { + try { + container = new DefaultPlexusContainer(containerConfiguration, getCustomModules()); + } catch (final PlexusContainerException e) { e.printStackTrace(); - fail( "Failed to create plexus container." ); + fail("Failed to create plexus container."); } } /** * Allows test to define custom modules. */ - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[] { - new AbstractModule() - { - @Override - protected void configure() - { - bind( ScmManager.class ).to( ScmManagerStub.class ).in( Singleton.class ); - } + new AbstractModule() { + @Override + protected void configure() { + bind(ScmManager.class).to(ScmManagerStub.class).in(Singleton.class); } + } }; } @@ -148,56 +129,41 @@ protected void configure() * * @param containerConfiguration */ - protected void customizeContainerConfiguration( final ContainerConfiguration containerConfiguration ) - { - } + protected void customizeContainerConfiguration(final ContainerConfiguration containerConfiguration) {} - protected void customizeContext( final Context context ) - { - } + protected void customizeContext(final Context context) {} - protected PlexusConfiguration customizeComponentConfiguration() - { + protected PlexusConfiguration customizeComponentConfiguration() { return null; } @After - public void tearDown() - throws Exception - { - if ( container != null ) - { + public void tearDown() throws Exception { + if (container != null) { container.dispose(); container = null; } } - protected PlexusContainer getContainer() - { - if ( container == null ) - { + protected PlexusContainer getContainer() { + if (container == null) { setupContainer(); } return container; } - protected InputStream getConfiguration() - throws Exception - { - return getConfiguration( null ); + protected InputStream getConfiguration() throws Exception { + return getConfiguration(null); } - @SuppressWarnings( "unused" ) - protected InputStream getConfiguration( final String subname ) - throws Exception - { - return getResourceAsStream( getConfigurationName( subname ) ); + @SuppressWarnings("unused") + protected InputStream getConfiguration(final String subname) throws Exception { + return getResourceAsStream(getConfigurationName(subname)); } - protected String getCustomConfigurationName() - { + protected String getCustomConfigurationName() { return null; } @@ -209,18 +175,15 @@ protected String getCustomConfigurationName() * @param subname * @return */ - protected String getConfigurationName( final String subname ) - { - return getClass().getName().replace( '.', '/' ) + ".xml"; + protected String getConfigurationName(final String subname) { + return getClass().getName().replace('.', '/') + ".xml"; } - protected InputStream getResourceAsStream( final String resource ) - { - return getClass().getResourceAsStream( resource ); + protected InputStream getResourceAsStream(final String resource) { + return getClass().getResourceAsStream(resource); } - protected ClassLoader getClassLoader() - { + protected ClassLoader getClassLoader() { return getClass().getClassLoader(); } @@ -228,101 +191,79 @@ protected ClassLoader getClassLoader() // Container access // ---------------------------------------------------------------------- - protected Object lookup( final String componentKey ) - throws Exception - { - return getContainer().lookup( componentKey ); + protected Object lookup(final String componentKey) throws Exception { + return getContainer().lookup(componentKey); } - protected Object lookup( final String role, final String roleHint ) - throws Exception - { - return getContainer().lookup( role, roleHint ); + protected Object lookup(final String role, final String roleHint) throws Exception { + return getContainer().lookup(role, roleHint); } - protected T lookup( final Class componentClass ) - throws Exception - { - return getContainer().lookup( componentClass ); + protected T lookup(final Class componentClass) throws Exception { + return getContainer().lookup(componentClass); } - protected T lookup( final Class componentClass, final String roleHint ) - throws Exception - { - return getContainer().lookup( componentClass, roleHint ); + protected T lookup(final Class componentClass, final String roleHint) throws Exception { + return getContainer().lookup(componentClass, roleHint); } - protected Map lookupMap( final Class componentClass ) - throws Exception - { - return getContainer().lookupMap( componentClass ); + protected Map lookupMap(final Class componentClass) throws Exception { + return getContainer().lookupMap(componentClass); } - protected void release( final Object component ) - throws Exception - { - getContainer().release( component ); + protected void release(final Object component) throws Exception { + getContainer().release(component); } // ---------------------------------------------------------------------- // Helper methods for sub classes // ---------------------------------------------------------------------- - public static File getTestFile( final String path ) - { - return new File( getBasedir(), path ); + public static File getTestFile(final String path) { + return new File(getBasedir(), path); } - @SuppressWarnings( "hiding" ) - public static File getTestFile( final String basedir, final String path ) - { - File basedirFile = new File( basedir ); + @SuppressWarnings("hiding") + public static File getTestFile(final String basedir, final String path) { + File basedirFile = new File(basedir); - if ( !basedirFile.isAbsolute() ) - { - basedirFile = getTestFile( basedir ); + if (!basedirFile.isAbsolute()) { + basedirFile = getTestFile(basedir); } - return new File( basedirFile, path ); + return new File(basedirFile, path); } - public static String getTestPath( final String path ) - { - return getTestFile( path ).getAbsolutePath(); + public static String getTestPath(final String path) { + return getTestFile(path).getAbsolutePath(); } - @SuppressWarnings( "hiding" ) - public static String getTestPath( final String basedir, final String path ) - { - return getTestFile( basedir, path ).getAbsolutePath(); + @SuppressWarnings("hiding") + public static String getTestPath(final String basedir, final String path) { + return getTestFile(basedir, path).getAbsolutePath(); } - public static String getBasedir() - { - if ( basedir != null ) - { + public static String getBasedir() { + if (basedir != null) { return basedir; } - basedir = System.getProperty( "basedir" ); + basedir = System.getProperty("basedir"); - if ( basedir == null ) - { - basedir = new File( "" ).getAbsolutePath(); + if (basedir == null) { + basedir = new File("").getAbsolutePath(); } return basedir; } - public String getTestConfiguration() - { - return getTestConfiguration( getClass() ); + public String getTestConfiguration() { + return getTestConfiguration(getClass()); } - public static String getTestConfiguration( final Class clazz ) - { - final String s = clazz.getName().replace( '.', '/' ); + public static String getTestConfiguration(final Class clazz) { + final String s = clazz.getName().replace('.', '/'); - return s.substring( 0, s.indexOf( "$" ) ) + ".xml"; + return s.substring(0, s.indexOf("$")) + ".xml"; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStoreTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStoreTest.java index a45861c72..8692b9601 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStoreTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/PropertiesReleaseDescriptorStoreTest.java @@ -1,21 +1,3 @@ -package org.apache.maven.shared.release.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import org.apache.maven.shared.release.PlexusJUnit4TestCase; -import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder.BuilderReleaseDescriptor; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -34,490 +16,459 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.maven.shared.release.PlexusJUnit4TestCase; +import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder.BuilderReleaseDescriptor; import org.apache.maven.shared.release.phase.AbstractReleaseTestCase; import org.apache.maven.shared.release.scm.IdentifiedScm; import org.junit.Test; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * Test the properties store. * * @author Brett Porter */ -public class PropertiesReleaseDescriptorStoreTest - extends PlexusJUnit4TestCase -{ +public class PropertiesReleaseDescriptorStoreTest extends PlexusJUnit4TestCase { private PropertiesReleaseDescriptorStore store; private SecDispatcher secDispatcher; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - store = (PropertiesReleaseDescriptorStore) lookup( ReleaseDescriptorStore.class, "properties" ); - secDispatcher = lookup( SecDispatcher.class ); + store = (PropertiesReleaseDescriptorStore) lookup(ReleaseDescriptorStore.class, "properties"); + secDispatcher = lookup(SecDispatcher.class); } @Test - public void testReadFromFile() - throws ReleaseDescriptorStoreException - { - File file = getTestFile( "target/test-classes/release.properties" ); + public void testReadFromFile() throws ReleaseDescriptorStoreException { + File file = getTestFile("target/test-classes/release.properties"); - ReleaseDescriptor config = store.read( file ).build(); + ReleaseDescriptor config = store.read(file).build(); ReleaseDescriptor expected = createExpectedReleaseConfiguration().build(); - assertEquals( "check matches", expected, config ); + assertEquals("check matches", expected, config); } @Test - public void testReadFromFileUsingWorkingDirectory() - throws Exception - { + public void testReadFromFileUsingWorkingDirectory() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setWorkingDirectory( AbstractReleaseTestCase.getPath( getTestFile( "target/test-classes" ) ) ); - ReleaseDescriptor config = store.read( builder ).build(); + builder.setWorkingDirectory(AbstractReleaseTestCase.getPath(getTestFile("target/test-classes"))); + ReleaseDescriptor config = store.read(builder).build(); ReleaseDescriptorBuilder expected = createExpectedReleaseConfiguration(); - expected.setWorkingDirectory( builder.build().getWorkingDirectory() ); + expected.setWorkingDirectory(builder.build().getWorkingDirectory()); - assertEquals( "check matches", expected.build(), config ); + assertEquals("check matches", expected.build(), config); } @Test - public void testReadFromEmptyFile() - throws ReleaseDescriptorStoreException - { - File file = getTestFile( "target/test-classes/empty-release.properties" ); + public void testReadFromEmptyFile() throws ReleaseDescriptorStoreException { + File file = getTestFile("target/test-classes/empty-release.properties"); - BuilderReleaseDescriptor config = store.read( file ).build(); + BuilderReleaseDescriptor config = store.read(file).build(); - assertDefaultReleaseConfiguration( config ); + assertDefaultReleaseConfiguration(config); } @Test - public void testReadMissingFile() - throws ReleaseDescriptorStoreException - { - File file = getTestFile( "target/test-classes/no-release.properties" ); + public void testReadMissingFile() throws ReleaseDescriptorStoreException { + File file = getTestFile("target/test-classes/no-release.properties"); - BuilderReleaseDescriptor config = store.read( file ).build(); + BuilderReleaseDescriptor config = store.read(file).build(); - assertDefaultReleaseConfiguration( config ); + assertDefaultReleaseConfiguration(config); } @Test - public void testMergeFromEmptyFile() - throws ReleaseDescriptorStoreException, IOException - { - File file = getTestFile( "target/test-classes/empty-release.properties" ); + public void testMergeFromEmptyFile() throws ReleaseDescriptorStoreException, IOException { + File file = getTestFile("target/test-classes/empty-release.properties"); ReleaseDescriptorBuilder mergeDescriptor = createMergeConfiguration(); - ReleaseDescriptor config = store.read( mergeDescriptor, file ).build(); + ReleaseDescriptor config = store.read(mergeDescriptor, file).build(); - assertEquals( "Check configurations merged", mergeDescriptor.build(), config ); + assertEquals("Check configurations merged", mergeDescriptor.build(), config); } @Test - public void testMergeFromMissingFile() - throws ReleaseDescriptorStoreException, IOException - { - File file = getTestFile( "target/test-classes/no-release.properties" ); + public void testMergeFromMissingFile() throws ReleaseDescriptorStoreException, IOException { + File file = getTestFile("target/test-classes/no-release.properties"); ReleaseDescriptorBuilder mergeDescriptor = createMergeConfiguration(); - ReleaseDescriptor config = store.read( mergeDescriptor, file ).build(); + ReleaseDescriptor config = store.read(mergeDescriptor, file).build(); - assertEquals( "Check configurations merged", mergeDescriptor.build(), config ); + assertEquals("Check configurations merged", mergeDescriptor.build(), config); } @Test - public void testWriteToNewFile() - throws Exception - { - File file = getTestFile( "target/test-classes/new-release.properties" ); + public void testWriteToNewFile() throws Exception { + File file = getTestFile("target/test-classes/new-release.properties"); file.delete(); - assertFalse( "Check file doesn't exist", file.exists() ); + assertFalse("Check file doesn't exist", file.exists()); ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting(); - store.write( config.build(), file ); + store.write(config.build(), file); - ReleaseDescriptor rereadDescriptor = store.read( file ).build(); + ReleaseDescriptor rereadDescriptor = store.read(file).build(); - assertAndAdjustScmPassword( config, rereadDescriptor ); - assertAndAdjustScmPrivateKeyPassPhrase( config, rereadDescriptor ); + assertAndAdjustScmPassword(config, rereadDescriptor); + assertAndAdjustScmPrivateKeyPassPhrase(config, rereadDescriptor); - assertEquals( "compare configuration", config.build(), rereadDescriptor ); + assertEquals("compare configuration", config.build(), rereadDescriptor); } @Test - public void testWriteToWorkingDirectory() - throws Exception - { - File file = getTestFile( "target/test-classes/new/release.properties" ); + public void testWriteToWorkingDirectory() throws Exception { + File file = getTestFile("target/test-classes/new/release.properties"); file.delete(); - assertFalse( "Check file doesn't exist", file.exists() ); + assertFalse("Check file doesn't exist", file.exists()); file.getParentFile().mkdirs(); ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting(); - config.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) ); + config.setWorkingDirectory(AbstractReleaseTestCase.getPath(file.getParentFile())); - store.write( config.build() ); + store.write(config.build()); - ReleaseDescriptorBuilder rereadDescriptorBuilder = store.read( file ); - rereadDescriptorBuilder.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) ); + ReleaseDescriptorBuilder rereadDescriptorBuilder = store.read(file); + rereadDescriptorBuilder.setWorkingDirectory(AbstractReleaseTestCase.getPath(file.getParentFile())); - assertAndAdjustScmPassword( config, rereadDescriptorBuilder.build() ); - assertAndAdjustScmPrivateKeyPassPhrase( config, rereadDescriptorBuilder.build() ); + assertAndAdjustScmPassword(config, rereadDescriptorBuilder.build()); + assertAndAdjustScmPrivateKeyPassPhrase(config, rereadDescriptorBuilder.build()); - assertEquals( "compare configuration", config.build(), rereadDescriptorBuilder.build() ); + assertEquals("compare configuration", config.build(), rereadDescriptorBuilder.build()); } @Test - public void testWriteToNewFileRequiredOnly() - throws ReleaseDescriptorStoreException - { - File file = getTestFile( "target/test-classes/new-release.properties" ); + public void testWriteToNewFileRequiredOnly() throws ReleaseDescriptorStoreException { + File file = getTestFile("target/test-classes/new-release.properties"); file.delete(); - assertFalse( "Check file doesn't exist", file.exists() ); + assertFalse("Check file doesn't exist", file.exists()); ReleaseDescriptorBuilder config = new ReleaseDescriptorBuilder(); - config.setCompletedPhase( "completed-phase-write" ); - config.setScmSourceUrl( "url-write" ); + config.setCompletedPhase("completed-phase-write"); + config.setScmSourceUrl("url-write"); - store.write( config.build(), file ); + store.write(config.build(), file); - ReleaseDescriptor rereadDescriptor = store.read( file ).build(); + ReleaseDescriptor rereadDescriptor = store.read(file).build(); - assertEquals( "compare configuration", config.build(), rereadDescriptor ); + assertEquals("compare configuration", config.build(), rereadDescriptor); } @Test - public void testWriteToNewFileDottedIds() - throws ReleaseDescriptorStoreException - { - File file = getTestFile( "target/test-classes/new-release.properties" ); + public void testWriteToNewFileDottedIds() throws ReleaseDescriptorStoreException { + File file = getTestFile("target/test-classes/new-release.properties"); file.delete(); - assertFalse( "Check file doesn't exist", file.exists() ); + assertFalse("Check file doesn't exist", file.exists()); ReleaseDescriptorBuilder config = new ReleaseDescriptorBuilder(); - config.setCompletedPhase( "completed-phase-write" ); - config.setScmSourceUrl( "url-write" ); + config.setCompletedPhase("completed-phase-write"); + config.setScmSourceUrl("url-write"); - config.addReleaseVersion( "group.id:artifact.id", "1.1" ); - config.addDevelopmentVersion( "group.id:artifact.id", "1.2-SNAPSHOT" ); + config.addReleaseVersion("group.id:artifact.id", "1.1"); + config.addDevelopmentVersion("group.id:artifact.id", "1.2-SNAPSHOT"); IdentifiedScm scm = new IdentifiedScm(); - scm.setId( "id" ); - scm.setConnection( "connection" ); - scm.setDeveloperConnection( "devConnection" ); - scm.setTag( "tag" ); - scm.setUrl( "url" ); - config.addOriginalScmInfo( "group.id:artifact.id", scm ); + scm.setId("id"); + scm.setConnection("connection"); + scm.setDeveloperConnection("devConnection"); + scm.setTag("tag"); + scm.setUrl("url"); + config.addOriginalScmInfo("group.id:artifact.id", scm); - store.write( config.build(), file ); + store.write(config.build(), file); - ReleaseDescriptor rereadDescriptor = store.read( file ).build(); + ReleaseDescriptor rereadDescriptor = store.read(file).build(); - assertEquals( "compare configuration", config.build(), rereadDescriptor ); + assertEquals("compare configuration", config.build(), rereadDescriptor); } @Test - public void testWriteToNewFileNullMappedScm() - throws ReleaseDescriptorStoreException - { - File file = getTestFile( "target/test-classes/new-release.properties" ); + public void testWriteToNewFileNullMappedScm() throws ReleaseDescriptorStoreException { + File file = getTestFile("target/test-classes/new-release.properties"); file.delete(); - assertFalse( "Check file doesn't exist", file.exists() ); + assertFalse("Check file doesn't exist", file.exists()); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletedPhase( "completed-phase-write" ); - builder.setScmSourceUrl( "url-write" ); + builder.setCompletedPhase("completed-phase-write"); + builder.setScmSourceUrl("url-write"); - builder.addReleaseVersion( "group.id:artifact.id", "1.1" ); - builder.addDevelopmentVersion( "group.id:artifact.id", "1.2-SNAPSHOT" ); + builder.addReleaseVersion("group.id:artifact.id", "1.1"); + builder.addDevelopmentVersion("group.id:artifact.id", "1.2-SNAPSHOT"); - builder.addOriginalScmInfo( "group.id:artifact.id", null ); + builder.addOriginalScmInfo("group.id:artifact.id", null); - store.write( builder.build(), file ); + store.write(builder.build(), file); - ReleaseDescriptor rereadDescriptor = store.read( file ).build(); + ReleaseDescriptor rereadDescriptor = store.read(file).build(); - assertNull( "check null scm is mapped correctly", - rereadDescriptor.getOriginalScmInfo( "group.id:artifact.id" ) ); + assertNull("check null scm is mapped correctly", rereadDescriptor.getOriginalScmInfo("group.id:artifact.id")); - assertEquals( "compare configuration", builder.build(), rereadDescriptor ); + assertEquals("compare configuration", builder.build(), rereadDescriptor); } @Test - public void testOverwriteFile() - throws Exception - { - File file = getTestFile( "target/test-classes/rewrite-release.properties" ); - assertTrue( "Check file already exists", file.exists() ); + public void testOverwriteFile() throws Exception { + File file = getTestFile("target/test-classes/rewrite-release.properties"); + assertTrue("Check file already exists", file.exists()); ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting(); - store.write( config.build(), file ); + store.write(config.build(), file); - ReleaseDescriptor rereadDescriptor = store.read( file ).build(); + ReleaseDescriptor rereadDescriptor = store.read(file).build(); - assertAndAdjustScmPassword( config, rereadDescriptor ); - assertAndAdjustScmPrivateKeyPassPhrase( config, rereadDescriptor ); + assertAndAdjustScmPassword(config, rereadDescriptor); + assertAndAdjustScmPrivateKeyPassPhrase(config, rereadDescriptor); - assertEquals( "compare configuration", config.build(), rereadDescriptor ); + assertEquals("compare configuration", config.build(), rereadDescriptor); } @Test - public void testDeleteFile() - throws ReleaseDescriptorStoreException, IOException - { - File file = getTestFile( "target/test-classes/delete/release.properties" ); + public void testDeleteFile() throws ReleaseDescriptorStoreException, IOException { + File file = getTestFile("target/test-classes/delete/release.properties"); file.getParentFile().mkdirs(); file.createNewFile(); - assertTrue( "Check file already exists", file.exists() ); + assertTrue("Check file already exists", file.exists()); ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting(); - config.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) ); + config.setWorkingDirectory(AbstractReleaseTestCase.getPath(file.getParentFile())); - store.delete( config.build() ); + store.delete(config.build()); - assertFalse( "Check file already exists", file.exists() ); + assertFalse("Check file already exists", file.exists()); } @Test - public void testMissingDeleteFile() - throws ReleaseDescriptorStoreException, IOException - { - File file = getTestFile( "target/test-classes/delete/release.properties" ); + public void testMissingDeleteFile() throws ReleaseDescriptorStoreException, IOException { + File file = getTestFile("target/test-classes/delete/release.properties"); file.getParentFile().mkdirs(); file.delete(); - assertFalse( "Check file already exists", file.exists() ); + assertFalse("Check file already exists", file.exists()); ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting(); - config.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) ); + config.setWorkingDirectory(AbstractReleaseTestCase.getPath(file.getParentFile())); - store.delete( config.build() ); + store.delete(config.build()); - assertFalse( "Check file already exists", file.exists() ); + assertFalse("Check file already exists", file.exists()); } @Test - public void testWriteEncryptedProperties() - throws Exception - { + public void testWriteEncryptedProperties() throws Exception { final String scmPassword = "s3cr3t_SCMPASSWORD"; final String scmPassPhrase = "s3cr3t_SCMPASSPHRASE"; ReleaseDescriptorBuilder config = new ReleaseDescriptorBuilder(); - config.setCompletedPhase( "completed-phase-write" ); - config.setScmSourceUrl( "url-write" ); - - config.setScmPassword( scmPassword ); - config.setScmPrivateKeyPassPhrase( scmPassPhrase ); + config.setCompletedPhase("completed-phase-write"); + config.setScmSourceUrl("url-write"); - File file = getTestFile( "target/test-classes/encrypt/release.properties" ); + config.setScmPassword(scmPassword); + config.setScmPrivateKeyPassPhrase(scmPassPhrase); + + File file = getTestFile("target/test-classes/encrypt/release.properties"); file.getParentFile().mkdirs(); - - store.write( config.build(), file ); - + + store.write(config.build(), file); + Properties persistedProperties = new Properties(); - try ( InputStream is = new FileInputStream( file ) ) - { - persistedProperties.load( is ); + try (InputStream is = new FileInputStream(file)) { + persistedProperties.load(is); } - String persistedPassword = persistedProperties.getProperty( "scm.password" ); - assertNotNull( persistedPassword ); - assertNotEquals( scmPassword, persistedPassword ); + String persistedPassword = persistedProperties.getProperty("scm.password"); + assertNotNull(persistedPassword); + assertNotEquals(scmPassword, persistedPassword); + + String persistedPassPhrase = persistedProperties.getProperty("scm.passphrase"); + assertNotNull(persistedPassPhrase); + assertNotEquals(scmPassPhrase, persistedPassPhrase); - String persistedPassPhrase = persistedProperties.getProperty( "scm.passphrase" ); - assertNotNull( persistedPassPhrase ); - assertNotEquals( scmPassPhrase, persistedPassPhrase ); - - ReleaseDescriptorBuilder builder = store.read( file ); + ReleaseDescriptorBuilder builder = store.read(file); BuilderReleaseDescriptor descriptor = builder.build(); - assertEquals( scmPassword, descriptor.getScmPassword() ); - assertEquals( scmPassPhrase, descriptor.getScmPrivateKeyPassPhrase() ); + assertEquals(scmPassword, descriptor.getScmPassword()); + assertEquals(scmPassPhrase, descriptor.getScmPrivateKeyPassPhrase()); } - private ReleaseDescriptorBuilder createReleaseConfigurationForWriting() - { + private ReleaseDescriptorBuilder createReleaseConfigurationForWriting() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletedPhase( "completed-phase-write" ); - builder.setCommitByProject( true ); - builder.setScmSourceUrl( "url-write" ); - builder.setScmId( "id-write" ); - builder.setScmUsername( "username-write" ); - builder.setScmPassword( "password-write" ); - builder.setScmPrivateKey( "private-key-write" ); - builder.setScmPrivateKeyPassPhrase( "passphrase-write" ); - builder.setScmTagBase( "tag-base-write" ); - builder.setScmBranchBase( "branch-base-write" ); - builder.setScmReleaseLabel( "tag-write" ); - builder.setAdditionalArguments( "additional-args-write" ); - builder.setPreparationGoals( "preparation-goals-write" ); - builder.setCompletionGoals( "completion-goals-write" ); - builder.setPomFileName( "pom-file-name-write" ); - - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.addDevelopmentVersion( "groupId:artifactId", "1.1-SNAPSHOT" ); + builder.setCompletedPhase("completed-phase-write"); + builder.setCommitByProject(true); + builder.setScmSourceUrl("url-write"); + builder.setScmId("id-write"); + builder.setScmUsername("username-write"); + builder.setScmPassword("password-write"); + builder.setScmPrivateKey("private-key-write"); + builder.setScmPrivateKeyPassPhrase("passphrase-write"); + builder.setScmTagBase("tag-base-write"); + builder.setScmBranchBase("branch-base-write"); + builder.setScmReleaseLabel("tag-write"); + builder.setAdditionalArguments("additional-args-write"); + builder.setPreparationGoals("preparation-goals-write"); + builder.setCompletionGoals("completion-goals-write"); + builder.setPomFileName("pom-file-name-write"); + + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.addDevelopmentVersion("groupId:artifactId", "1.1-SNAPSHOT"); // The actual kind of string you will get when setting the projectVersionPolicyConfig - builder.setProjectVersionPolicyConfig("bar"); + builder.setProjectVersionPolicyConfig( + "bar"); IdentifiedScm scm = new IdentifiedScm(); - scm.setId( "id-write" ); - scm.setConnection( "connection-write" ); - scm.setDeveloperConnection( "developerConnection-write" ); - scm.setUrl( "url-write" ); - scm.setTag( "tag-write" ); - builder.addOriginalScmInfo( "groupId:artifactId", scm ); + scm.setId("id-write"); + scm.setConnection("connection-write"); + scm.setDeveloperConnection("developerConnection-write"); + scm.setUrl("url-write"); + scm.setTag("tag-write"); + builder.addOriginalScmInfo("groupId:artifactId", scm); scm = new IdentifiedScm(); - scm.setConnection( "connection-write" ); + scm.setConnection("connection-write"); // omit optional elements - builder.addOriginalScmInfo( "groupId:subproject1", scm ); + builder.addOriginalScmInfo("groupId:subproject1", scm); return builder; } - private static void assertDefaultReleaseConfiguration( BuilderReleaseDescriptor config ) - { - assertNull( "Expected no completedPhase", config.getCompletedPhase() ); - assertFalse( "Expected no commitPerProject", config.isCommitByProject() ); - assertNull( "Expected no id", config.getScmId() ); - assertNull( "Expected no url", config.getScmSourceUrl() ); - assertNull( "Expected no username", config.getScmUsername() ); - assertNull( "Expected no password", config.getScmPassword() ); - assertNull( "Expected no privateKey", config.getScmPrivateKey() ); - assertNull( "Expected no passphrase", config.getScmPrivateKeyPassPhrase() ); - assertNull( "Expected no tagBase", config.getScmTagBase() ); - assertNull( "Expected no tag", config.getScmReleaseLabel() ); - assertNull( "Expected no additional arguments", config.getAdditionalArguments() ); - assertNull( "Expected no preparation goals", config.getPreparationGoals() ); - assertNull( "Expected no completion goals", config.getCompletionGoals() ); - assertNull( "Expected no pom file name", config.getPomFileName() ); - - assertNull( "Expected no workingDirectory", config.getWorkingDirectory() ); - assertFalse( "Expected no generateReleasePoms", config.isGenerateReleasePoms() ); - assertFalse( "Expected no useEditMode", config.isScmUseEditMode() ); - assertTrue( "Expected default interactive", config.isInteractive() ); - assertFalse( "Expected no addScema", config.isAddSchema() ); - - for ( ReleaseStageVersions versions : config.getProjectVersions().values() ) - { - assertNull( "Expected no release version mappings", versions.getRelease() ); - assertNull( "Expected no dev version mappings", versions.getDevelopment() ); + private static void assertDefaultReleaseConfiguration(BuilderReleaseDescriptor config) { + assertNull("Expected no completedPhase", config.getCompletedPhase()); + assertFalse("Expected no commitPerProject", config.isCommitByProject()); + assertNull("Expected no id", config.getScmId()); + assertNull("Expected no url", config.getScmSourceUrl()); + assertNull("Expected no username", config.getScmUsername()); + assertNull("Expected no password", config.getScmPassword()); + assertNull("Expected no privateKey", config.getScmPrivateKey()); + assertNull("Expected no passphrase", config.getScmPrivateKeyPassPhrase()); + assertNull("Expected no tagBase", config.getScmTagBase()); + assertNull("Expected no tag", config.getScmReleaseLabel()); + assertNull("Expected no additional arguments", config.getAdditionalArguments()); + assertNull("Expected no preparation goals", config.getPreparationGoals()); + assertNull("Expected no completion goals", config.getCompletionGoals()); + assertNull("Expected no pom file name", config.getPomFileName()); + + assertNull("Expected no workingDirectory", config.getWorkingDirectory()); + assertFalse("Expected no generateReleasePoms", config.isGenerateReleasePoms()); + assertFalse("Expected no useEditMode", config.isScmUseEditMode()); + assertTrue("Expected default interactive", config.isInteractive()); + assertFalse("Expected no addScema", config.isAddSchema()); + + for (ReleaseStageVersions versions : config.getProjectVersions().values()) { + assertNull("Expected no release version mappings", versions.getRelease()); + assertNull("Expected no dev version mappings", versions.getDevelopment()); } - assertTrue( "Expected no scm mappings", config.getOriginalScmInfo().isEmpty() ); - assertNotNull( "Expected resolved snapshot dependencies map", config.getResolvedSnapshotDependencies() ); + assertTrue("Expected no scm mappings", config.getOriginalScmInfo().isEmpty()); + assertNotNull("Expected resolved snapshot dependencies map", config.getResolvedSnapshotDependencies()); } - public ReleaseDescriptorBuilder createMergeConfiguration() - throws IOException - { + public ReleaseDescriptorBuilder createMergeConfiguration() throws IOException { ReleaseDescriptorBuilder releaseDescriptor = new ReleaseDescriptorBuilder(); - releaseDescriptor.setScmSourceUrl( "scm-url" ); - releaseDescriptor.setScmUsername( "username" ); + releaseDescriptor.setScmSourceUrl("scm-url"); + releaseDescriptor.setScmUsername("username"); // Not setting other optional SCM settings for brevity - - File workingDir = getTestFile( "target/test-working-directory" ); - if ( !workingDir.exists() ) - { - assertTrue( "Failed to create the directory, along with all necessary parent directories", - workingDir.mkdirs() ); + + File workingDir = getTestFile("target/test-working-directory"); + if (!workingDir.exists()) { + assertTrue( + "Failed to create the directory, along with all necessary parent directories", workingDir.mkdirs()); } - - releaseDescriptor.setWorkingDirectory( AbstractReleaseTestCase.getPath( workingDir ) ); + + releaseDescriptor.setWorkingDirectory(AbstractReleaseTestCase.getPath(workingDir)); // Not setting non-override setting completedPhase return releaseDescriptor; } - private void assertAndAdjustScmPassword( ReleaseDescriptorBuilder expected, ReleaseDescriptor original ) - throws Exception - { + private void assertAndAdjustScmPassword(ReleaseDescriptorBuilder expected, ReleaseDescriptor original) + throws Exception { String expectedPassword = expected.build().getScmPassword(); String originalPassword = original.getScmPassword(); // encrypting the same password twice doesn't have to be the same result - if ( expectedPassword != null ? !expectedPassword.equals( originalPassword ) : originalPassword != null ) - { - assertEquals( secDispatcher.decrypt( expectedPassword ), secDispatcher.decrypt( originalPassword ) ); + if (expectedPassword != null ? !expectedPassword.equals(originalPassword) : originalPassword != null) { + assertEquals(secDispatcher.decrypt(expectedPassword), secDispatcher.decrypt(originalPassword)); - expected.setScmPassword( originalPassword ); + expected.setScmPassword(originalPassword); } - assertEquals( expected.build().getScmPassword(), original.getScmPassword() ); + assertEquals(expected.build().getScmPassword(), original.getScmPassword()); } - private void assertAndAdjustScmPrivateKeyPassPhrase( ReleaseDescriptorBuilder expected, ReleaseDescriptor original ) - throws Exception - { + private void assertAndAdjustScmPrivateKeyPassPhrase(ReleaseDescriptorBuilder expected, ReleaseDescriptor original) + throws Exception { String expectedPassPhrase = expected.build().getScmPrivateKeyPassPhrase(); String originalPassPhrase = original.getScmPrivateKeyPassPhrase(); // encrypting the same passphrase twice doesn't have to be the same result - if ( expectedPassPhrase != null ? !expectedPassPhrase.equals( originalPassPhrase ) : originalPassPhrase != null ) - { - assertEquals( secDispatcher.decrypt( expectedPassPhrase ), secDispatcher.decrypt( originalPassPhrase ) ); + if (expectedPassPhrase != null ? !expectedPassPhrase.equals(originalPassPhrase) : originalPassPhrase != null) { + assertEquals(secDispatcher.decrypt(expectedPassPhrase), secDispatcher.decrypt(originalPassPhrase)); - expected.setScmPrivateKeyPassPhrase( originalPassPhrase ); + expected.setScmPrivateKeyPassPhrase(originalPassPhrase); } - assertEquals( expected.build().getScmPrivateKeyPassPhrase(), original.getScmPrivateKeyPassPhrase() ); + assertEquals(expected.build().getScmPrivateKeyPassPhrase(), original.getScmPrivateKeyPassPhrase()); } - private ReleaseDescriptorBuilder createExpectedReleaseConfiguration() - { + private ReleaseDescriptorBuilder createExpectedReleaseConfiguration() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletedPhase( "step1" ); - builder.setCommitByProject( true ); - builder.setScmId( "scm-id" ); - builder.setScmSourceUrl( "scm-url" ); - builder.setScmUsername( "username" ); - builder.setScmPassword( "password" ); - builder.setScmPrivateKey( "private-key" ); - builder.setScmPrivateKeyPassPhrase( "passphrase" ); - builder.setScmTagBase( "tagBase" ); - builder.setScmTagNameFormat( "expectedTagNameFormat" ); - builder.setScmBranchBase( "branchBase" ); - builder.setScmReleaseLabel( "tag" ); - builder.setAdditionalArguments( "additional-arguments" ); - builder.setPreparationGoals( "preparation-goals" ); - builder.setCompletionGoals( "completion-goals" ); - builder.setPomFileName( "pom-file-name" ); - builder.setWorkingDirectory( null ); - builder.setGenerateReleasePoms( false ); - builder.setScmUseEditMode( false ); - builder.setInteractive( true ); - builder.setAddSchema( false ); - builder.addReleaseVersion( "groupId:artifactId1", "2.0" ); - builder.addReleaseVersion( "groupId:artifactId2", "3.0" ); - builder.addDevelopmentVersion( "groupId:artifactId1", "2.1-SNAPSHOT" ); - builder.addDevelopmentVersion( "groupId:artifactId2", "3.0.1-SNAPSHOT" ); + builder.setCompletedPhase("step1"); + builder.setCommitByProject(true); + builder.setScmId("scm-id"); + builder.setScmSourceUrl("scm-url"); + builder.setScmUsername("username"); + builder.setScmPassword("password"); + builder.setScmPrivateKey("private-key"); + builder.setScmPrivateKeyPassPhrase("passphrase"); + builder.setScmTagBase("tagBase"); + builder.setScmTagNameFormat("expectedTagNameFormat"); + builder.setScmBranchBase("branchBase"); + builder.setScmReleaseLabel("tag"); + builder.setAdditionalArguments("additional-arguments"); + builder.setPreparationGoals("preparation-goals"); + builder.setCompletionGoals("completion-goals"); + builder.setPomFileName("pom-file-name"); + builder.setWorkingDirectory(null); + builder.setGenerateReleasePoms(false); + builder.setScmUseEditMode(false); + builder.setInteractive(true); + builder.setAddSchema(false); + builder.addReleaseVersion("groupId:artifactId1", "2.0"); + builder.addReleaseVersion("groupId:artifactId2", "3.0"); + builder.addDevelopmentVersion("groupId:artifactId1", "2.1-SNAPSHOT"); + builder.addDevelopmentVersion("groupId:artifactId2", "3.0.1-SNAPSHOT"); IdentifiedScm scm = new IdentifiedScm(); - scm.setId( "id" ); - scm.setConnection( "connection" ); - scm.setDeveloperConnection( "developerConnection" ); - scm.setUrl( "url" ); - scm.setTag( "tag" ); - builder.addOriginalScmInfo( "groupId:artifactId1", scm ); + scm.setId("id"); + scm.setConnection("connection"); + scm.setDeveloperConnection("developerConnection"); + scm.setUrl("url"); + scm.setTag("tag"); + builder.addOriginalScmInfo("groupId:artifactId1", scm); scm = new IdentifiedScm(); - scm.setId( null ); - scm.setConnection( "connection2" ); - scm.setUrl( "url2" ); - scm.setTag( null ); - scm.setDeveloperConnection( null ); - builder.addOriginalScmInfo( "groupId:artifactId2", scm ); - builder.addDependencyReleaseVersion( "external:artifactId", "1.0" ); - builder.addDependencyDevelopmentVersion( "external:artifactId", "1.1-SNAPSHOT" ); + scm.setId(null); + scm.setConnection("connection2"); + scm.setUrl("url2"); + scm.setTag(null); + scm.setDeveloperConnection(null); + builder.addOriginalScmInfo("groupId:artifactId2", scm); + builder.addDependencyReleaseVersion("external:artifactId", "1.0"); + builder.addDependencyDevelopmentVersion("external:artifactId", "1.1-SNAPSHOT"); return builder; } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilderTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilderTest.java index 907033c8e..0e46fe225 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilderTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorBuilderTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; import org.junit.Test; import org.mockito.Mockito; @@ -31,32 +30,29 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; -public class ReleaseDescriptorBuilderTest -{ - private final Logger logger = Mockito.mock( Logger.class ); +public class ReleaseDescriptorBuilderTest { + private final Logger logger = Mockito.mock(Logger.class); @Test - public void testCleanupArguments() - { - setAdditionalArguments( "abc abc -Dxxx", "abc abc -Dxxx"); - verifyZeroInteractions( logger ); - reset( logger ); - - setAdditionalArguments( "abc abc ${arguments}", "abc abc " ); - verify( logger ).warn( anyString(), eq( "${arguments}" ) ); - verifyNoMoreInteractions( logger ); - reset( logger ); - - setAdditionalArguments( "abc ${first} abc ${arguments}", "abc abc " ); - verify( logger ).warn( anyString(), eq( "${first}" ) ); - verify( logger ).warn( anyString(), eq( "${arguments}" ) ); - verifyNoMoreInteractions( logger ); + public void testCleanupArguments() { + setAdditionalArguments("abc abc -Dxxx", "abc abc -Dxxx"); + verifyZeroInteractions(logger); + reset(logger); + + setAdditionalArguments("abc abc ${arguments}", "abc abc "); + verify(logger).warn(anyString(), eq("${arguments}")); + verifyNoMoreInteractions(logger); + reset(logger); + + setAdditionalArguments("abc ${first} abc ${arguments}", "abc abc "); + verify(logger).warn(anyString(), eq("${first}")); + verify(logger).warn(anyString(), eq("${arguments}")); + verifyNoMoreInteractions(logger); } - private void setAdditionalArguments(String input, String expected) - { - ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder( logger ); - builder.setAdditionalArguments( input ); - assertEquals( expected, builder.build().getAdditionalArguments() ); + private void setAdditionalArguments(String input, String expected) { + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(logger); + builder.setAdditionalArguments(input); + assertEquals(expected, builder.build().getAdditionalArguments()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreStub.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreStub.java index 1352d288a..d730f42f6 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreStub.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseDescriptorStoreStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,38 +16,31 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; /** * Test stub for the release configuration store that holds a single configuration in memory. * * @author Brett Porter */ -public class ReleaseDescriptorStoreStub - implements ReleaseDescriptorStore -{ +public class ReleaseDescriptorStoreStub implements ReleaseDescriptorStore { /** * The release configuration to use. */ private ReleaseDescriptorBuilder releaseDescriptor = new ReleaseDescriptorBuilder(); @Override - public ReleaseDescriptorBuilder read( ReleaseDescriptorBuilder mergeDescriptor ) - { + public ReleaseDescriptorBuilder read(ReleaseDescriptorBuilder mergeDescriptor) { return mergeDescriptor; } @Override - public void write( ReleaseDescriptor config ) - { - } + public void write(ReleaseDescriptor config) {} @Override - public void delete( ReleaseDescriptor config ) - { - } + public void delete(ReleaseDescriptor config) {} - public ReleaseDescriptorBuilder getReleaseConfiguration() - { + public ReleaseDescriptorBuilder getReleaseConfiguration() { return releaseDescriptor; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseUtilsTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseUtilsTest.java index 841210036..b7da13491 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseUtilsTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/config/ReleaseUtilsTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.config; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.config; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Properties; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.model.Scm; @@ -25,11 +29,6 @@ import org.apache.maven.shared.release.phase.AbstractReleaseTestCase; import org.junit.Test; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Properties; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -39,275 +38,266 @@ * * @author Brett Porter */ -public class ReleaseUtilsTest -{ +public class ReleaseUtilsTest { @Test - public void testEquals() - throws IOException - { + public void testEquals() throws IOException { ReleaseDescriptorBuilder originalReleaseDescriptor = createReleaseDescriptor(); - ReleaseDescriptorBuilder builder = copyReleaseDescriptor( originalReleaseDescriptor.build() ); - doEqualsAssertions( builder, originalReleaseDescriptor, "other", new File( "target/test-working-directory" ) ); + ReleaseDescriptorBuilder builder = copyReleaseDescriptor(originalReleaseDescriptor.build()); + doEqualsAssertions(builder, originalReleaseDescriptor, "other", new File("target/test-working-directory")); originalReleaseDescriptor = createReleaseDescriptor(); - builder = copyReleaseDescriptor( originalReleaseDescriptor.build() ); - doEqualsAssertions( originalReleaseDescriptor, builder, "other", new File( "target/test-working-directory" ) ); + builder = copyReleaseDescriptor(originalReleaseDescriptor.build()); + doEqualsAssertions(originalReleaseDescriptor, builder, "other", new File("target/test-working-directory")); originalReleaseDescriptor = createReleaseDescriptor(); - builder = copyReleaseDescriptor( originalReleaseDescriptor.build() ); - doEqualsAssertions( builder, originalReleaseDescriptor, null, null ); + builder = copyReleaseDescriptor(originalReleaseDescriptor.build()); + doEqualsAssertions(builder, originalReleaseDescriptor, null, null); originalReleaseDescriptor = createReleaseDescriptor(); - builder = copyReleaseDescriptor( originalReleaseDescriptor.build() ); - doEqualsAssertions( originalReleaseDescriptor, builder, null, null ); + builder = copyReleaseDescriptor(originalReleaseDescriptor.build()); + doEqualsAssertions(originalReleaseDescriptor, builder, null, null); - assertEquals( "test ==", builder, builder ); + assertEquals("test ==", builder, builder); Object obj = this; - assertFalse( "test class instance", builder.equals( obj ) ); + assertFalse("test class instance", builder.equals(obj)); } - private static void doEqualsAssertions( ReleaseDescriptorBuilder releaseDescriptor, - ReleaseDescriptorBuilder originalReleaseDescriptor, String other, File otherFile ) - throws IOException - { + private static void doEqualsAssertions( + ReleaseDescriptorBuilder releaseDescriptor, + ReleaseDescriptorBuilder originalReleaseDescriptor, + String other, + File otherFile) + throws IOException { BuilderReleaseDescriptor origConfig = originalReleaseDescriptor.build(); ReleaseDescriptorBuilder configBuilder = releaseDescriptor; - assertEquals( "Check original comparison", configBuilder.build(), origConfig ); - - configBuilder.setScmSourceUrl( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmSourceUrl( origConfig.getScmSourceUrl() ); - - configBuilder.setAdditionalArguments( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setAdditionalArguments( origConfig.getAdditionalArguments() ); - - configBuilder.setAddSchema( !origConfig.isAddSchema() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setAddSchema( origConfig.isAddSchema() ); - - configBuilder.setGenerateReleasePoms( !origConfig.isAddSchema() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setGenerateReleasePoms( origConfig.isGenerateReleasePoms() ); - - configBuilder.setScmUseEditMode( !origConfig.isScmUseEditMode() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmUseEditMode( origConfig.isScmUseEditMode() ); - - configBuilder.setInteractive( !origConfig.isInteractive() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setInteractive( origConfig.isInteractive() ); - - configBuilder.setCommitByProject( !origConfig.isCommitByProject() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setCommitByProject( origConfig.isCommitByProject() ); - - configBuilder.setCompletedPhase( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setCompletedPhase( origConfig.getCompletedPhase() ); - - configBuilder.setScmPrivateKeyPassPhrase( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmPrivateKeyPassPhrase( origConfig.getScmPrivateKeyPassPhrase() ); - - configBuilder.setScmPassword( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmPassword( origConfig.getScmPassword() ); - - configBuilder.setScmUsername( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmUsername( origConfig.getScmUsername() ); - - configBuilder.setScmPrivateKey( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmPrivateKey( origConfig.getScmPrivateKey() ); - - configBuilder.setPomFileName( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setPomFileName( origConfig.getPomFileName() ); - - configBuilder.setPreparationGoals( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setPreparationGoals( origConfig.getPreparationGoals() ); - - configBuilder.setScmReleaseLabel( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmReleaseLabel( origConfig.getScmReleaseLabel() ); - - configBuilder.setScmTagBase( other ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder.setScmTagBase( origConfig.getScmTagBase() ); - - if ( otherFile != null ) - { - if ( !otherFile.exists() ) - { - assertTrue( "Failed to create the directory, along with all necessary parent directories", - otherFile.mkdirs() ); + assertEquals("Check original comparison", configBuilder.build(), origConfig); + + configBuilder.setScmSourceUrl(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmSourceUrl(origConfig.getScmSourceUrl()); + + configBuilder.setAdditionalArguments(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setAdditionalArguments(origConfig.getAdditionalArguments()); + + configBuilder.setAddSchema(!origConfig.isAddSchema()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setAddSchema(origConfig.isAddSchema()); + + configBuilder.setGenerateReleasePoms(!origConfig.isAddSchema()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setGenerateReleasePoms(origConfig.isGenerateReleasePoms()); + + configBuilder.setScmUseEditMode(!origConfig.isScmUseEditMode()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmUseEditMode(origConfig.isScmUseEditMode()); + + configBuilder.setInteractive(!origConfig.isInteractive()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setInteractive(origConfig.isInteractive()); + + configBuilder.setCommitByProject(!origConfig.isCommitByProject()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setCommitByProject(origConfig.isCommitByProject()); + + configBuilder.setCompletedPhase(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setCompletedPhase(origConfig.getCompletedPhase()); + + configBuilder.setScmPrivateKeyPassPhrase(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmPrivateKeyPassPhrase(origConfig.getScmPrivateKeyPassPhrase()); + + configBuilder.setScmPassword(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmPassword(origConfig.getScmPassword()); + + configBuilder.setScmUsername(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmUsername(origConfig.getScmUsername()); + + configBuilder.setScmPrivateKey(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmPrivateKey(origConfig.getScmPrivateKey()); + + configBuilder.setPomFileName(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setPomFileName(origConfig.getPomFileName()); + + configBuilder.setPreparationGoals(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setPreparationGoals(origConfig.getPreparationGoals()); + + configBuilder.setScmReleaseLabel(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmReleaseLabel(origConfig.getScmReleaseLabel()); + + configBuilder.setScmTagBase(other); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder.setScmTagBase(origConfig.getScmTagBase()); + + if (otherFile != null) { + if (!otherFile.exists()) { + assertTrue( + "Failed to create the directory, along with all necessary parent directories", + otherFile.mkdirs()); } - configBuilder.setWorkingDirectory( AbstractReleaseTestCase.getPath( otherFile ) ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); + configBuilder.setWorkingDirectory(AbstractReleaseTestCase.getPath(otherFile)); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); } - configBuilder.setWorkingDirectory( origConfig.getWorkingDirectory() ); + configBuilder.setWorkingDirectory(origConfig.getWorkingDirectory()); // sanity check the test was resetting correctly - assertEquals( "Check original comparison", configBuilder.build(), origConfig ); + assertEquals("Check original comparison", configBuilder.build(), origConfig); - configBuilder.addDevelopmentVersion( "groupId:artifactId", "1.0-SNAPSHOT" ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder.addDevelopmentVersion("groupId:artifactId", "1.0-SNAPSHOT"); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addReleaseVersion( "groupId:artifactId", "1.0" ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder.addReleaseVersion("groupId:artifactId", "1.0"); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", new Scm() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder.addOriginalScmInfo("groupId:artifactId", new Scm()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", new Scm() ); - origConfig.addOriginalScmInfo( "foo", new Scm() ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); + configBuilder.addOriginalScmInfo("groupId:artifactId", new Scm()); + origConfig.addOriginalScmInfo("foo", new Scm()); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); origConfig = createReleaseDescriptor().build(); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", new Scm() ); - origConfig.addOriginalScmInfo( "groupId:artifactId", new Scm() ); - assertEquals( "Check original comparison", configBuilder.build(), origConfig ); + configBuilder.addOriginalScmInfo("groupId:artifactId", new Scm()); + origConfig.addOriginalScmInfo("groupId:artifactId", new Scm()); + assertEquals("Check original comparison", configBuilder.build(), origConfig); origConfig = createReleaseDescriptor().build(); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "tag" ) ); - origConfig.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "tag" ) ); - assertEquals( "Check original comparison", configBuilder.build(), origConfig ); + configBuilder.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "tag")); + origConfig.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "tag")); + assertEquals("Check original comparison", configBuilder.build(), origConfig); origConfig = createReleaseDescriptor().build(); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", getScm( "-", "dev", "url", "tag" ) ); - origConfig.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "tag" ) ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); + configBuilder.addOriginalScmInfo("groupId:artifactId", getScm("-", "dev", "url", "tag")); + origConfig.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "tag")); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); origConfig = createReleaseDescriptor().build(); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "-", "url", "tag" ) ); - origConfig.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "tag" ) ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); + configBuilder.addOriginalScmInfo("groupId:artifactId", getScm("conn", "-", "url", "tag")); + origConfig.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "tag")); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); origConfig = createReleaseDescriptor().build(); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "-", "tag" ) ); - origConfig.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "tag" ) ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); + configBuilder.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "-", "tag")); + origConfig.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "tag")); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); origConfig = createReleaseDescriptor().build(); - configBuilder = copyReleaseDescriptor( origConfig ); + configBuilder = copyReleaseDescriptor(origConfig); - configBuilder.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "-" ) ); - origConfig.addOriginalScmInfo( "groupId:artifactId", getScm( "conn", "dev", "url", "tag" ) ); - assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) ); + configBuilder.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "-")); + origConfig.addOriginalScmInfo("groupId:artifactId", getScm("conn", "dev", "url", "tag")); + assertFalse("Check original comparison", configBuilder.build().equals(origConfig)); } @Test - public void testHashCode() - throws IOException - { + public void testHashCode() throws IOException { ReleaseDescriptor releaseDescriptor = createReleaseDescriptor().build(); - assertEquals( "Check hash code", releaseDescriptor.hashCode(), - createReleaseDescriptor( releaseDescriptor.getWorkingDirectory() ).build().hashCode() ); + assertEquals( + "Check hash code", + releaseDescriptor.hashCode(), + createReleaseDescriptor(releaseDescriptor.getWorkingDirectory()) + .build() + .hashCode()); } @Test - public void testLoadResolvedDependencies() - { + public void testLoadResolvedDependencies() { Properties properties = new Properties(); - String dependencyKey = ArtifactUtils.versionlessKey( "com.groupId", "artifactId" ); - properties.put( "dependency." + dependencyKey + ".release", "1.3" ); - properties.put( "dependency." + dependencyKey + ".development", "1.3-SNAPSHOT" ); - + String dependencyKey = ArtifactUtils.versionlessKey("com.groupId", "artifactId"); + properties.put("dependency." + dependencyKey + ".release", "1.3"); + properties.put("dependency." + dependencyKey + ".development", "1.3-SNAPSHOT"); + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - ReleaseUtils.copyPropertiesToReleaseDescriptor( properties, builder ); + ReleaseUtils.copyPropertiesToReleaseDescriptor(properties, builder); ReleaseDescriptor descriptor = builder.build(); - assertEquals( "1.3", descriptor.getDependencyReleaseVersion( dependencyKey ) ); - assertEquals( "1.3-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( dependencyKey ) ); + assertEquals("1.3", descriptor.getDependencyReleaseVersion(dependencyKey)); + assertEquals("1.3-SNAPSHOT", descriptor.getDependencyDevelopmentVersion(dependencyKey)); } // MRELEASE-750 @Test - public void testArtifactIdEndswithDependency() - { + public void testArtifactIdEndswithDependency() { Properties properties = new Properties(); - String relDependencyKey = ArtifactUtils.versionlessKey( "com.release.magic", "dependency" ); - properties.put( "dependency." + relDependencyKey + ".release", "1.3" ); - String devDependencyKey = ArtifactUtils.versionlessKey( "com.development.magic", "dependency" ); - properties.put( "dependency." + devDependencyKey + ".development", "1.3-SNAPSHOT" ); - + String relDependencyKey = ArtifactUtils.versionlessKey("com.release.magic", "dependency"); + properties.put("dependency." + relDependencyKey + ".release", "1.3"); + String devDependencyKey = ArtifactUtils.versionlessKey("com.development.magic", "dependency"); + properties.put("dependency." + devDependencyKey + ".development", "1.3-SNAPSHOT"); + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - ReleaseUtils.copyPropertiesToReleaseDescriptor( properties, builder ); + ReleaseUtils.copyPropertiesToReleaseDescriptor(properties, builder); ReleaseDescriptor descriptor = builder.build(); - assertEquals( "1.3", descriptor.getDependencyReleaseVersion( relDependencyKey ) ); - assertEquals( "1.3-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( devDependencyKey ) ); + assertEquals("1.3", descriptor.getDependencyReleaseVersion(relDependencyKey)); + assertEquals("1.3-SNAPSHOT", descriptor.getDependencyDevelopmentVersion(devDependencyKey)); } // MRELEASE-834 @Test - public void testSystemPropertyStartingWithDependency() - { + public void testSystemPropertyStartingWithDependency() { Properties properties = new Properties(); - properties.setProperty( "dependency.locations.enabled", "false" ); - ReleaseUtils.copyPropertiesToReleaseDescriptor( properties, new ReleaseDescriptorBuilder() ); + properties.setProperty("dependency.locations.enabled", "false"); + ReleaseUtils.copyPropertiesToReleaseDescriptor(properties, new ReleaseDescriptorBuilder()); } - + // MRELEASE-1038 @Test - public void testActiveProfilesProperty() - { + public void testActiveProfilesProperty() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); Properties properties = new Properties(); - properties.setProperty( "exec.activateProfiles", "aProfile,anotherOne" ); - ReleaseUtils.copyPropertiesToReleaseDescriptor( properties, builder ); + properties.setProperty("exec.activateProfiles", "aProfile,anotherOne"); + ReleaseUtils.copyPropertiesToReleaseDescriptor(properties, builder); - assertEquals( Arrays.asList("aProfile", "anotherOne"), builder.build().getActivateProfiles() ); + assertEquals(Arrays.asList("aProfile", "anotherOne"), builder.build().getActivateProfiles()); } - private static ReleaseDescriptorBuilder copyReleaseDescriptor( ReleaseDescriptor originalReleaseDescriptor ) - { - return createReleaseDescriptor( originalReleaseDescriptor.getWorkingDirectory() ); + private static ReleaseDescriptorBuilder copyReleaseDescriptor(ReleaseDescriptor originalReleaseDescriptor) { + return createReleaseDescriptor(originalReleaseDescriptor.getWorkingDirectory()); } - private static Scm getScm( String connection, String developerConnection, String url, String tag ) - { + private static Scm getScm(String connection, String developerConnection, String url, String tag) { Scm scm = new Scm(); - scm.setConnection( connection ); - scm.setDeveloperConnection( developerConnection ); - scm.setTag( tag ); - scm.setUrl( url ); + scm.setConnection(connection); + scm.setDeveloperConnection(developerConnection); + scm.setTag(tag); + scm.setUrl(url); return scm; } - private static ReleaseDescriptorBuilder createReleaseDescriptor() - throws IOException - { - File workingDirectory = new File( "." ); + private static ReleaseDescriptorBuilder createReleaseDescriptor() throws IOException { + File workingDirectory = new File("."); - return createReleaseDescriptor(AbstractReleaseTestCase.getPath( workingDirectory ) ); + return createReleaseDescriptor(AbstractReleaseTestCase.getPath(workingDirectory)); } - private static ReleaseDescriptorBuilder createReleaseDescriptor( String workingDirectory ) - { + private static ReleaseDescriptorBuilder createReleaseDescriptor(String workingDirectory) { ReleaseDescriptorBuilder releaseDescriptor = new ReleaseDescriptorBuilder(); - releaseDescriptor.setScmSourceUrl( "scm-url" ); - releaseDescriptor.setCompletedPhase( "completed-phase" ); - releaseDescriptor.setScmPrivateKeyPassPhrase( "passphrase" ); - releaseDescriptor.setScmPassword( "password" ); - releaseDescriptor.setScmPrivateKey( "private-key" ); - releaseDescriptor.setScmTagBase( "tag-base" ); - releaseDescriptor.setScmReleaseLabel( "tag" ); - releaseDescriptor.setScmUsername( "username" ); - releaseDescriptor.setWorkingDirectory( workingDirectory ); - releaseDescriptor.setAdditionalArguments( "additional-arguments" ); - releaseDescriptor.setPomFileName( "pom-file-name" ); - releaseDescriptor.setPreparationGoals( "preparation-goals" ); + releaseDescriptor.setScmSourceUrl("scm-url"); + releaseDescriptor.setCompletedPhase("completed-phase"); + releaseDescriptor.setScmPrivateKeyPassPhrase("passphrase"); + releaseDescriptor.setScmPassword("password"); + releaseDescriptor.setScmPrivateKey("private-key"); + releaseDescriptor.setScmTagBase("tag-base"); + releaseDescriptor.setScmReleaseLabel("tag"); + releaseDescriptor.setScmUsername("username"); + releaseDescriptor.setWorkingDirectory(workingDirectory); + releaseDescriptor.setAdditionalArguments("additional-arguments"); + releaseDescriptor.setPomFileName("pom-file-name"); + releaseDescriptor.setPreparationGoals("preparation-goals"); return releaseDescriptor; } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/AbstractMavenExecutorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/AbstractMavenExecutorTest.java index 385a232a5..60d9e5f6a 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/AbstractMavenExecutorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/AbstractMavenExecutorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; +package org.apache.maven.shared.release.exec; import java.io.File; import java.util.ArrayList; @@ -35,83 +26,122 @@ import org.apache.maven.shared.release.ReleaseResult; import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; import org.apache.maven.shared.release.env.ReleaseEnvironment; - -import junit.framework.TestCase; import org.apache.maven.shared.release.util.MavenCrypto; import org.junit.Test; -public class AbstractMavenExecutorTest -{ - - @Test - public void testGoalSeparation() - throws MavenExecutorException - { - AbstractMavenExecutor executor = spy( new AbstractMavenExecutorSpy( mock( MavenCrypto.class ) ) ); - - executor.executeGoals( null, (String) null, new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), eq( new ArrayList() ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); - - executor.executeGoals( null, " clean verify ", new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), - eq( Arrays.asList( "clean", "verify" ) ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); - - executor.executeGoals( null, ",clean,verify,", new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), - eq( Arrays.asList( "clean", "verify" ) ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); - - executor.executeGoals( null, "\nclean\nverify\n", new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), - eq( Arrays.asList( "clean", "verify" ) ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); - - executor.executeGoals( null, "\rclean\rverify\r", new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), - eq( Arrays.asList( "clean", "verify" ) ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; - executor.executeGoals( null, "\r\nclean\r\nverify\r\n", new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), - eq( Arrays.asList( "clean", "verify" ) ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); +public class AbstractMavenExecutorTest { - executor.executeGoals( null, "\tclean\tverify\t", new DefaultReleaseEnvironment(), true, null, null, null ); - verify( executor ).executeGoals( isNull(), - eq( Arrays.asList( "clean", "verify" ) ), - isA( ReleaseEnvironment.class ), eq( true ), isNull(), - isNull(), isNull() ); - reset( executor ); + @Test + public void testGoalSeparation() throws MavenExecutorException { + AbstractMavenExecutor executor = spy(new AbstractMavenExecutorSpy(mock(MavenCrypto.class))); + + executor.executeGoals(null, (String) null, new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(new ArrayList()), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); + + executor.executeGoals(null, " clean verify ", new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(Arrays.asList("clean", "verify")), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); + + executor.executeGoals(null, ",clean,verify,", new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(Arrays.asList("clean", "verify")), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); + + executor.executeGoals(null, "\nclean\nverify\n", new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(Arrays.asList("clean", "verify")), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); + + executor.executeGoals(null, "\rclean\rverify\r", new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(Arrays.asList("clean", "verify")), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); + + executor.executeGoals(null, "\r\nclean\r\nverify\r\n", new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(Arrays.asList("clean", "verify")), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); + + executor.executeGoals(null, "\tclean\tverify\t", new DefaultReleaseEnvironment(), true, null, null, null); + verify(executor) + .executeGoals( + isNull(), + eq(Arrays.asList("clean", "verify")), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isNull()); + reset(executor); } - protected class AbstractMavenExecutorSpy - extends AbstractMavenExecutor - { - public AbstractMavenExecutorSpy( MavenCrypto mavenCrypto ) - { - super( mavenCrypto ); + protected class AbstractMavenExecutorSpy extends AbstractMavenExecutor { + public AbstractMavenExecutorSpy(MavenCrypto mavenCrypto) { + super(mavenCrypto); } @Override - protected void executeGoals( File workingDirectory, List goals, ReleaseEnvironment releaseEnvironment, - boolean interactive, String additionalArguments, String pomFileName, - ReleaseResult result ) - throws MavenExecutorException - { - } + protected void executeGoals( + File workingDirectory, + List goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult result) + throws MavenExecutorException {} } -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/CommandLineFactoryTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/CommandLineFactoryTest.java index 813b38443..28340e965 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/CommandLineFactoryTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/CommandLineFactoryTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import org.apache.maven.shared.release.PlexusJUnit4TestCase; import org.codehaus.plexus.util.cli.Commandline; @@ -32,29 +31,23 @@ * * @author Brett Porter */ -public class CommandLineFactoryTest - extends PlexusJUnit4TestCase -{ +public class CommandLineFactoryTest extends PlexusJUnit4TestCase { private CommandLineFactory factory; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - factory = lookup( CommandLineFactory.class ); + factory = lookup(CommandLineFactory.class); } @Test - public void testCreation() - throws Exception - { - Commandline cl = factory.createCommandLine( "exec" ); + public void testCreation() throws Exception { + Commandline cl = factory.createCommandLine("exec"); String executable = cl.getExecutable(); - assertTrue( "Check executable " + executable, executable.contains("exec") ); - assertNotNull( "Check environment", cl.getEnvironmentVariables() ); - assertFalse( "Check environment", cl.getEnvironmentVariables().length == 0 ); + assertTrue("Check executable " + executable, executable.contains("exec")); + assertNotNull("Check environment", cl.getEnvironmentVariables()); + assertFalse("Check environment", cl.getEnvironmentVariables().length == 0); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/ForkedMavenExecutorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/ForkedMavenExecutorTest.java index 1420030e2..6bc048264 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/ForkedMavenExecutorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/ForkedMavenExecutorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,21 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.endsWith; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.exec; import java.io.File; import java.io.InputStream; @@ -54,317 +38,344 @@ import org.mockito.ArgumentCaptor; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.endsWith; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the forked Maven executor. * * @author Brett Porter */ -public class ForkedMavenExecutorTest - extends PlexusJUnit4TestCase -{ +public class ForkedMavenExecutorTest extends PlexusJUnit4TestCase { private MavenCrypto mavenCrypto; private SecDispatcher secDispatcher; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - mavenCrypto = lookup( MavenCrypto.class ); - secDispatcher = lookup( SecDispatcher.class ); + mavenCrypto = lookup(MavenCrypto.class); + secDispatcher = lookup(SecDispatcher.class); } @Test - public void testExecution() - throws Exception - { + public void testExecution() throws Exception { // prepare - File workingDirectory = getTestFile( "target/working-directory" ); - Process mockProcess = mock( Process.class ); - when( mockProcess.getInputStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getErrorStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getOutputStream() ).thenReturn( mock( OutputStream.class ) ); - when( mockProcess.waitFor() ).thenReturn( 0 ); + File workingDirectory = getTestFile("target/working-directory"); + Process mockProcess = mock(Process.class); + when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class)); + when(mockProcess.waitFor()).thenReturn(0); - Commandline commandLineMock = mock( Commandline.class ); - when( commandLineMock.execute() ).thenReturn( mockProcess ); + Commandline commandLineMock = mock(Commandline.class); + when(commandLineMock.execute()).thenReturn(mockProcess); - Arg valueArgument = mock( Arg.class ); - when( commandLineMock.createArg() ).thenReturn( valueArgument ); + Arg valueArgument = mock(Arg.class); + when(commandLineMock.createArg()).thenReturn(valueArgument); - CommandLineFactory commandLineFactoryMock = mock( CommandLineFactory.class ); - when( commandLineFactoryMock.createCommandLine( isA( String.class ) /*"mvn"*/ ) ).thenReturn( commandLineMock ); + CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class); + when(commandLineFactoryMock.createCommandLine(isA(String.class) /*"mvn"*/)) + .thenReturn(commandLineMock); - ForkedMavenExecutor executor = new ForkedMavenExecutor( mavenCrypto, commandLineFactoryMock ); + ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock); // execute - executor.executeGoals( workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, null, - null, new ReleaseResult() ); + executor.executeGoals( + workingDirectory, + "clean integration-test", + new DefaultReleaseEnvironment(), + false, + null, + null, + new ReleaseResult()); // verify - verify( mockProcess ).getInputStream(); - verify( mockProcess ).getErrorStream(); - verify( mockProcess ).getOutputStream(); - verify( mockProcess ).waitFor(); - verify( commandLineMock ).setWorkingDirectory( workingDirectory.getAbsolutePath() ); - verify( commandLineMock ).addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); - verify( commandLineMock ).execute(); - verify( commandLineMock, times( 3 ) ).createArg(); - verify( valueArgument ).setValue( "clean" ); - verify( valueArgument ).setValue( "integration-test" ); - verify( valueArgument ).setValue( "--batch-mode" ); - verify( commandLineFactoryMock ).createCommandLine( endsWith( "mvn" ) ); - - verifyNoMoreInteractions( mockProcess, commandLineFactoryMock, commandLineMock, valueArgument ); + verify(mockProcess).getInputStream(); + verify(mockProcess).getErrorStream(); + verify(mockProcess).getOutputStream(); + verify(mockProcess).waitFor(); + verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath()); + verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on"); + verify(commandLineMock).execute(); + verify(commandLineMock, times(3)).createArg(); + verify(valueArgument).setValue("clean"); + verify(valueArgument).setValue("integration-test"); + verify(valueArgument).setValue("--batch-mode"); + verify(commandLineFactoryMock).createCommandLine(endsWith("mvn")); + + verifyNoMoreInteractions(mockProcess, commandLineFactoryMock, commandLineMock, valueArgument); } @Test - public void testExecutionWithCustomPomFile() - throws Exception - { - File workingDirectory = getTestFile( "target/working-directory" ); - Process mockProcess = mock( Process.class ); - when( mockProcess.getInputStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getErrorStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getOutputStream() ).thenReturn( mock( OutputStream.class ) ); - when( mockProcess.waitFor() ).thenReturn( 0 ); + public void testExecutionWithCustomPomFile() throws Exception { + File workingDirectory = getTestFile("target/working-directory"); + Process mockProcess = mock(Process.class); + when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class)); + when(mockProcess.waitFor()).thenReturn(0); - Commandline commandLineMock = mock( Commandline.class ); - when( commandLineMock.execute() ).thenReturn( mockProcess ); + Commandline commandLineMock = mock(Commandline.class); + when(commandLineMock.execute()).thenReturn(mockProcess); - Arg argMock = mock( Arg.class ); - when( commandLineMock.createArg() ).thenReturn( argMock ); + Arg argMock = mock(Arg.class); + when(commandLineMock.createArg()).thenReturn(argMock); - CommandLineFactory commandLineFactoryMock = mock( CommandLineFactory.class ); - when( commandLineFactoryMock.createCommandLine( isA( String.class ) /* "mvn" */ ) ).thenReturn( commandLineMock ); + CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class); + when(commandLineFactoryMock.createCommandLine(isA(String.class) /* "mvn" */)) + .thenReturn(commandLineMock); - ForkedMavenExecutor executor = new ForkedMavenExecutor( mavenCrypto, commandLineFactoryMock ); + ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock); // execute - executor.executeGoals( workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, null, "my-pom.xml", - new ReleaseResult() ); + executor.executeGoals( + workingDirectory, + "clean integration-test", + new DefaultReleaseEnvironment(), + false, + null, + "my-pom.xml", + new ReleaseResult()); // verify - verify( mockProcess ).getInputStream(); - verify( mockProcess ).getErrorStream(); - verify( mockProcess ).getOutputStream(); - verify( mockProcess ).waitFor(); - verify( commandLineMock ).setWorkingDirectory( workingDirectory.getAbsolutePath() ); - verify( commandLineMock ).addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); - verify( commandLineMock ).execute(); - verify( commandLineMock, times( 5 ) ).createArg(); - verify( argMock ).setValue( "clean" ); - verify( argMock ).setValue( "integration-test" ); - verify( argMock ).setValue( "-f" ); - verify( argMock ).setValue( "my-pom.xml" ); - verify( argMock ).setValue( "--batch-mode" ); - verify( commandLineFactoryMock ).createCommandLine( endsWith( "mvn" ) ); - - verifyNoMoreInteractions( mockProcess, commandLineMock, argMock, commandLineFactoryMock ); + verify(mockProcess).getInputStream(); + verify(mockProcess).getErrorStream(); + verify(mockProcess).getOutputStream(); + verify(mockProcess).waitFor(); + verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath()); + verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on"); + verify(commandLineMock).execute(); + verify(commandLineMock, times(5)).createArg(); + verify(argMock).setValue("clean"); + verify(argMock).setValue("integration-test"); + verify(argMock).setValue("-f"); + verify(argMock).setValue("my-pom.xml"); + verify(argMock).setValue("--batch-mode"); + verify(commandLineFactoryMock).createCommandLine(endsWith("mvn")); + + verifyNoMoreInteractions(mockProcess, commandLineMock, argMock, commandLineFactoryMock); } @Test - public void testExecutionWithArguments() - throws Exception - { - File workingDirectory = getTestFile( "target/working-directory" ); - Process mockProcess = mock( Process.class ); - when( mockProcess.getInputStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getErrorStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getOutputStream() ).thenReturn( mock( OutputStream.class ) ); - when( mockProcess.waitFor() ).thenReturn( 0 ); + public void testExecutionWithArguments() throws Exception { + File workingDirectory = getTestFile("target/working-directory"); + Process mockProcess = mock(Process.class); + when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class)); + when(mockProcess.waitFor()).thenReturn(0); - Commandline commandLineMock = mock( Commandline.class ); - when( commandLineMock.execute() ).thenReturn( mockProcess ); + Commandline commandLineMock = mock(Commandline.class); + when(commandLineMock.execute()).thenReturn(mockProcess); - Arg argMock = mock( Arg.class ); - when( commandLineMock.createArg() ).thenReturn( argMock ); + Arg argMock = mock(Arg.class); + when(commandLineMock.createArg()).thenReturn(argMock); - CommandLineFactory commandLineFactoryMock = mock( CommandLineFactory.class ); - when( commandLineFactoryMock.createCommandLine( endsWith( "mvn" ) ) ).thenReturn( commandLineMock ); + CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class); + when(commandLineFactoryMock.createCommandLine(endsWith("mvn"))).thenReturn(commandLineMock); - ForkedMavenExecutor executor = new ForkedMavenExecutor( mavenCrypto, commandLineFactoryMock ); + ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock); // execute String arguments = "-DperformRelease=true -Dmaven.test.skip=true"; - executor.executeGoals( workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, arguments, null, new ReleaseResult() ); + executor.executeGoals( + workingDirectory, + "clean integration-test", + new DefaultReleaseEnvironment(), + false, + arguments, + null, + new ReleaseResult()); // verify - verify( mockProcess ).getInputStream(); - verify( mockProcess ).getErrorStream(); - verify( mockProcess ).getOutputStream(); - verify( mockProcess ).waitFor(); - verify( commandLineMock ).setWorkingDirectory( workingDirectory.getAbsolutePath() ); - verify( commandLineMock ).addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); - verify( commandLineMock ).execute(); - verify( commandLineMock, times( 4 ) ).createArg(); - verify( argMock ).setValue( "clean" ); - verify( argMock ).setValue( "integration-test" ); - verify( argMock ).setValue( "--batch-mode" ); - verify( argMock ).setLine( "-DperformRelease=true -Dmaven.test.skip=true" ); - verify( commandLineFactoryMock ).createCommandLine( endsWith( "mvn" ) ); - - verifyNoMoreInteractions( mockProcess, commandLineMock, argMock, commandLineFactoryMock ); + verify(mockProcess).getInputStream(); + verify(mockProcess).getErrorStream(); + verify(mockProcess).getOutputStream(); + verify(mockProcess).waitFor(); + verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath()); + verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on"); + verify(commandLineMock).execute(); + verify(commandLineMock, times(4)).createArg(); + verify(argMock).setValue("clean"); + verify(argMock).setValue("integration-test"); + verify(argMock).setValue("--batch-mode"); + verify(argMock).setLine("-DperformRelease=true -Dmaven.test.skip=true"); + verify(commandLineFactoryMock).createCommandLine(endsWith("mvn")); + + verifyNoMoreInteractions(mockProcess, commandLineMock, argMock, commandLineFactoryMock); } @Test - public void testExecutionWithNonZeroExitCode() - throws Exception - { + public void testExecutionWithNonZeroExitCode() throws Exception { // prepare - File workingDirectory = getTestFile( "target/working-directory" ); - Process mockProcess = mock( Process.class ); - when( mockProcess.getInputStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getErrorStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getOutputStream() ).thenReturn( mock( OutputStream.class ) ); - when( mockProcess.waitFor() ).thenReturn( 1 ); - when( mockProcess.exitValue() ).thenReturn( 1 ); // why was this here in the original test? + File workingDirectory = getTestFile("target/working-directory"); + Process mockProcess = mock(Process.class); + when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class)); + when(mockProcess.waitFor()).thenReturn(1); + when(mockProcess.exitValue()).thenReturn(1); // why was this here in the original test? - Commandline commandLineMock = mock( Commandline.class ); - when( commandLineMock.execute() ).thenReturn( mockProcess ); + Commandline commandLineMock = mock(Commandline.class); + when(commandLineMock.execute()).thenReturn(mockProcess); - Arg argMock = mock( Arg.class ); - when( commandLineMock.createArg() ).thenReturn( argMock ); + Arg argMock = mock(Arg.class); + when(commandLineMock.createArg()).thenReturn(argMock); - CommandLineFactory commandLineFactoryMock = mock( CommandLineFactory.class ); - when( commandLineFactoryMock.createCommandLine( endsWith( "mvn" ) ) ).thenReturn( commandLineMock ); + CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class); + when(commandLineFactoryMock.createCommandLine(endsWith("mvn"))).thenReturn(commandLineMock); - ForkedMavenExecutor executor = new ForkedMavenExecutor( mavenCrypto, commandLineFactoryMock ); + ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock); // execute - try - { - executor.executeGoals( workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, null, null, new ReleaseResult() ); - - fail( "Should have thrown an exception" ); - } - catch ( MavenExecutorException e ) - { - assertEquals( "Check exit code", 1, e.getExitCode() ); + try { + executor.executeGoals( + workingDirectory, + "clean integration-test", + new DefaultReleaseEnvironment(), + false, + null, + null, + new ReleaseResult()); + + fail("Should have thrown an exception"); + } catch (MavenExecutorException e) { + assertEquals("Check exit code", 1, e.getExitCode()); } // verify - verify( mockProcess ).getInputStream(); - verify( mockProcess ).getErrorStream(); - verify( mockProcess ).getOutputStream(); - verify( mockProcess ).waitFor(); -// verify( mockProcess ).exitValue(); - verify( commandLineMock ).setWorkingDirectory( workingDirectory.getAbsolutePath() ); - verify( commandLineMock ).addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); - verify( commandLineMock ).execute(); - verify( commandLineMock, times( 3 ) ).createArg(); - verify( argMock ).setValue( "clean" ); - verify( argMock ).setValue( "integration-test" ); - verify( argMock ).setValue( "--batch-mode" ); - verify( commandLineFactoryMock ).createCommandLine( endsWith( "mvn" ) ); - - verifyNoMoreInteractions( mockProcess, commandLineMock, argMock, commandLineFactoryMock ); + verify(mockProcess).getInputStream(); + verify(mockProcess).getErrorStream(); + verify(mockProcess).getOutputStream(); + verify(mockProcess).waitFor(); + // verify( mockProcess ).exitValue(); + verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath()); + verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on"); + verify(commandLineMock).execute(); + verify(commandLineMock, times(3)).createArg(); + verify(argMock).setValue("clean"); + verify(argMock).setValue("integration-test"); + verify(argMock).setValue("--batch-mode"); + verify(commandLineFactoryMock).createCommandLine(endsWith("mvn")); + + verifyNoMoreInteractions(mockProcess, commandLineMock, argMock, commandLineFactoryMock); } @Test - public void testExecutionWithCommandLineException() - throws Exception - { + public void testExecutionWithCommandLineException() throws Exception { // prepare - File workingDirectory = getTestFile( "target/working-directory" ); + File workingDirectory = getTestFile("target/working-directory"); - Commandline commandLineMock = mock( Commandline.class ); - when( commandLineMock.execute() ).thenThrow( new CommandLineException( "..." ) ); + Commandline commandLineMock = mock(Commandline.class); + when(commandLineMock.execute()).thenThrow(new CommandLineException("...")); - Arg argMock = mock( Arg.class ); - when ( commandLineMock.createArg() ).thenReturn( argMock ); + Arg argMock = mock(Arg.class); + when(commandLineMock.createArg()).thenReturn(argMock); - CommandLineFactory commandLineFactoryMock = mock( CommandLineFactory.class ); - when( commandLineFactoryMock.createCommandLine( endsWith( "mvn" ) ) ).thenReturn( commandLineMock ); + CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class); + when(commandLineFactoryMock.createCommandLine(endsWith("mvn"))).thenReturn(commandLineMock); - ForkedMavenExecutor executor = new ForkedMavenExecutor( mavenCrypto, commandLineFactoryMock ); + ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock); // execute - try - { - executor.executeGoals( workingDirectory, "clean integration-test", new DefaultReleaseEnvironment(), false, null, null, new ReleaseResult() ); - - fail( "Should have thrown an exception" ); - } - catch ( MavenExecutorException e ) - { - assertEquals( "Check cause", CommandLineException.class, e.getCause().getClass() ); + try { + executor.executeGoals( + workingDirectory, + "clean integration-test", + new DefaultReleaseEnvironment(), + false, + null, + null, + new ReleaseResult()); + + fail("Should have thrown an exception"); + } catch (MavenExecutorException e) { + assertEquals("Check cause", CommandLineException.class, e.getCause().getClass()); } // verify - verify( commandLineMock ).setWorkingDirectory( workingDirectory.getAbsolutePath() ); - verify( commandLineMock ).addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); - verify( commandLineMock ).execute(); - verify( commandLineMock, times( 3 ) ).createArg(); - verify( argMock ).setValue( "clean" ); - verify( argMock ).setValue( "integration-test" ); - verify( argMock ).setValue( "--batch-mode" ); - verify( commandLineFactoryMock ).createCommandLine( endsWith( "mvn" ) ); - - verifyNoMoreInteractions( commandLineMock, argMock, commandLineFactoryMock ); + verify(commandLineMock).setWorkingDirectory(workingDirectory.getAbsolutePath()); + verify(commandLineMock).addEnvironment("MAVEN_TERMINATE_CMD", "on"); + verify(commandLineMock).execute(); + verify(commandLineMock, times(3)).createArg(); + verify(argMock).setValue("clean"); + verify(argMock).setValue("integration-test"); + verify(argMock).setValue("--batch-mode"); + verify(commandLineFactoryMock).createCommandLine(endsWith("mvn")); + + verifyNoMoreInteractions(commandLineMock, argMock, commandLineFactoryMock); } @Test - public void testEncryptSettings() - throws Exception - { + public void testEncryptSettings() throws Exception { // prepare - File workingDirectory = getTestFile( "target/working-directory" ); - Process mockProcess = mock( Process.class ); - when( mockProcess.getInputStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getErrorStream() ).thenReturn( mock( InputStream.class ) ); - when( mockProcess.getOutputStream() ).thenReturn( mock( OutputStream.class ) ); - when( mockProcess.waitFor() ).thenReturn( 0 ); + File workingDirectory = getTestFile("target/working-directory"); + Process mockProcess = mock(Process.class); + when(mockProcess.getInputStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getErrorStream()).thenReturn(mock(InputStream.class)); + when(mockProcess.getOutputStream()).thenReturn(mock(OutputStream.class)); + when(mockProcess.waitFor()).thenReturn(0); - Commandline commandLineMock = mock( Commandline.class ); - when( commandLineMock.execute() ).thenReturn( mockProcess ); + Commandline commandLineMock = mock(Commandline.class); + when(commandLineMock.execute()).thenReturn(mockProcess); - Arg valueArgument = mock( Arg.class ); - when( commandLineMock.createArg() ).thenReturn( valueArgument ); + Arg valueArgument = mock(Arg.class); + when(commandLineMock.createArg()).thenReturn(valueArgument); - CommandLineFactory commandLineFactoryMock = mock( CommandLineFactory.class ); - when( commandLineFactoryMock.createCommandLine( isA( String.class ) /* "mvn" */) ).thenReturn( commandLineMock ); + CommandLineFactory commandLineFactoryMock = mock(CommandLineFactory.class); + when(commandLineFactoryMock.createCommandLine(isA(String.class) /* "mvn" */)) + .thenReturn(commandLineMock); - ForkedMavenExecutor executor = new ForkedMavenExecutor( mavenCrypto, commandLineFactoryMock ); + ForkedMavenExecutor executor = new ForkedMavenExecutor(mavenCrypto, commandLineFactoryMock); Settings settings = new Settings(); Server server = new Server(); - server.setPassphrase( "server_passphrase" ); - server.setPassword( "server_password" ); - settings.addServer( server ); + server.setPassphrase("server_passphrase"); + server.setPassword("server_password"); + settings.addServer(server); Proxy proxy = new Proxy(); - proxy.setPassword( "proxy_password" ); - settings.addProxy( proxy ); + proxy.setPassword("proxy_password"); + settings.addProxy(proxy); DefaultReleaseEnvironment releaseEnvironment = new DefaultReleaseEnvironment(); - releaseEnvironment.setSettings( settings ); + releaseEnvironment.setSettings(settings); - AbstractMavenExecutor executorSpy = spy( executor ); - SettingsXpp3Writer settingsWriter = mock( SettingsXpp3Writer.class ); + AbstractMavenExecutor executorSpy = spy(executor); + SettingsXpp3Writer settingsWriter = mock(SettingsXpp3Writer.class); - ArgumentCaptor encryptedSettings = ArgumentCaptor.forClass( Settings.class ); + ArgumentCaptor encryptedSettings = ArgumentCaptor.forClass(Settings.class); - when( executorSpy.getSettingsWriter() ).thenReturn( settingsWriter ); + when(executorSpy.getSettingsWriter()).thenReturn(settingsWriter); - executorSpy.executeGoals( workingDirectory, "validate", releaseEnvironment, false, null, null, new ReleaseResult() ); + executorSpy.executeGoals( + workingDirectory, "validate", releaseEnvironment, false, null, null, new ReleaseResult()); - verify( settingsWriter ).write( isA( Writer.class ), encryptedSettings.capture() ); + verify(settingsWriter).write(isA(Writer.class), encryptedSettings.capture()); - assertNotSame( settings, encryptedSettings.getValue() ); + assertNotSame(settings, encryptedSettings.getValue()); - Server encryptedServer = encryptedSettings.getValue().getServers().get( 0 ); - assertEquals( "server_passphrase", secDispatcher.decrypt( encryptedServer.getPassphrase() ) ); - assertEquals( "server_password", secDispatcher.decrypt( encryptedServer.getPassword() ) ); + Server encryptedServer = encryptedSettings.getValue().getServers().get(0); + assertEquals("server_passphrase", secDispatcher.decrypt(encryptedServer.getPassphrase())); + assertEquals("server_password", secDispatcher.decrypt(encryptedServer.getPassword())); - Proxy encryptedProxy = encryptedSettings.getValue().getProxies().get( 0 ); - assertEquals( "proxy_password", secDispatcher.decrypt( encryptedProxy.getPassword() ) ); + Proxy encryptedProxy = encryptedSettings.getValue().getProxies().get(0); + assertEquals("proxy_password", secDispatcher.decrypt(encryptedProxy.getPassword())); - File settingsSecurity = new File( System.getProperty( "user.home" ), ".m2/settings-security.xml" ); - if ( settingsSecurity.exists() ) - { - assertNotEquals( "server_passphrase", encryptedServer.getPassphrase() ); - assertNotEquals( "server_password", encryptedServer.getPassword() ); - assertNotEquals( "proxy_password", encryptedProxy.getPassword() ); + File settingsSecurity = new File(System.getProperty("user.home"), ".m2/settings-security.xml"); + if (settingsSecurity.exists()) { + assertNotEquals("server_passphrase", encryptedServer.getPassphrase()); + assertNotEquals("server_password", encryptedServer.getPassword()); + assertNotEquals("proxy_password", encryptedProxy.getPassword()); } } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/InvokerMavenExecutorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/InvokerMavenExecutorTest.java index 73da65af8..761878599 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/InvokerMavenExecutorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/InvokerMavenExecutorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.File; import java.io.Writer; @@ -30,7 +29,6 @@ import org.apache.maven.shared.release.ReleaseResult; import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; import org.apache.maven.shared.release.util.MavenCrypto; -import org.junit.Test; import org.mockito.ArgumentCaptor; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; @@ -43,79 +41,69 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class InvokerMavenExecutorTest - extends PlexusJUnit4TestCase -{ +public class InvokerMavenExecutorTest extends PlexusJUnit4TestCase { private MavenCrypto mavenCrypto; private SecDispatcher secDispatcher; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - mavenCrypto = lookup( MavenCrypto.class ); - secDispatcher = lookup( SecDispatcher.class ); + mavenCrypto = lookup(MavenCrypto.class); + secDispatcher = lookup(SecDispatcher.class); } - public void testEncryptSettings() - throws Exception - { - InvokerMavenExecutor executor = new InvokerMavenExecutor( mavenCrypto ); + public void testEncryptSettings() throws Exception { + InvokerMavenExecutor executor = new InvokerMavenExecutor(mavenCrypto); // prepare - File workingDirectory = getTestFile( "target/working-directory" ); + File workingDirectory = getTestFile("target/working-directory"); workingDirectory.mkdirs(); - Settings settings = new Settings(); Server server = new Server(); - server.setPassphrase( "server_passphrase" ); - server.setPassword( "server_password" ); - settings.addServer( server ); + server.setPassphrase("server_passphrase"); + server.setPassword("server_password"); + settings.addServer(server); Proxy proxy = new Proxy(); - proxy.setPassword( "proxy_password" ); - settings.addProxy( proxy ); + proxy.setPassword("proxy_password"); + settings.addProxy(proxy); DefaultReleaseEnvironment releaseEnvironment = new DefaultReleaseEnvironment(); - releaseEnvironment.setSettings( settings ); - releaseEnvironment.setMavenHome( new File( System.getProperty( "injectedMavenHome" ) ) ); + releaseEnvironment.setSettings(settings); + releaseEnvironment.setMavenHome(new File(System.getProperty("injectedMavenHome"))); - InvokerMavenExecutor executorSpy = spy( executor ); - SettingsXpp3Writer settingsWriter = mock( SettingsXpp3Writer.class ); + InvokerMavenExecutor executorSpy = spy(executor); + SettingsXpp3Writer settingsWriter = mock(SettingsXpp3Writer.class); - ArgumentCaptor encryptedSettings = ArgumentCaptor.forClass( Settings.class ); + ArgumentCaptor encryptedSettings = ArgumentCaptor.forClass(Settings.class); - when( executorSpy.getSettingsWriter() ).thenReturn( settingsWriter ); + when(executorSpy.getSettingsWriter()).thenReturn(settingsWriter); - try - { - executorSpy.executeGoals( workingDirectory, "validate", releaseEnvironment, false, null, null, new ReleaseResult() ); - } - catch ( MavenExecutorException e ) - { + try { + executorSpy.executeGoals( + workingDirectory, "validate", releaseEnvironment, false, null, null, new ReleaseResult()); + } catch (MavenExecutorException e) { } - verify( settingsWriter ).write( isA( Writer.class ), encryptedSettings.capture() ); + verify(settingsWriter).write(isA(Writer.class), encryptedSettings.capture()); - assertNotSame( settings, encryptedSettings.getValue() ); + assertNotSame(settings, encryptedSettings.getValue()); - Server encryptedServer = encryptedSettings.getValue().getServers().get( 0 ); - assertEquals( "server_passphrase", secDispatcher.decrypt( encryptedServer.getPassphrase() ) ); - assertEquals( "server_password", secDispatcher.decrypt( encryptedServer.getPassword() ) ); + Server encryptedServer = encryptedSettings.getValue().getServers().get(0); + assertEquals("server_passphrase", secDispatcher.decrypt(encryptedServer.getPassphrase())); + assertEquals("server_password", secDispatcher.decrypt(encryptedServer.getPassword())); - Proxy encryptedProxy = encryptedSettings.getValue().getProxies().get( 0 ); - assertEquals( "proxy_password", secDispatcher.decrypt( encryptedProxy.getPassword() ) ); + Proxy encryptedProxy = encryptedSettings.getValue().getProxies().get(0); + assertEquals("proxy_password", secDispatcher.decrypt(encryptedProxy.getPassword())); - File settingsSecurity = new File( System.getProperty( "user.home" ), ".m2/settings-security.xml" ); - if ( settingsSecurity.exists() ) - { - assertNotEquals( "server_passphrase", encryptedServer.getPassphrase() ); - assertNotEquals( "server_password", encryptedServer.getPassword() ); - assertNotEquals( "proxy_password", encryptedProxy.getPassword() ); + File settingsSecurity = new File(System.getProperty("user.home"), ".m2/settings-security.xml"); + if (settingsSecurity.exists()) { + assertNotEquals("server_passphrase", encryptedServer.getPassphrase()); + assertNotEquals("server_password", encryptedServer.getPassword()); + assertNotEquals("proxy_password", encryptedProxy.getPassword()); } } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeConsumerTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeConsumerTest.java index f7af78bfa..c8368f4e5 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeConsumerTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeConsumerTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,13 +16,13 @@ * specific language governing permissions and limitations * under the License. */ - -import junit.framework.TestCase; -import org.junit.Test; +package org.apache.maven.shared.release.exec; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** @@ -32,23 +30,21 @@ * * @author Brett Porter */ -public class TeeConsumerTest -{ +public class TeeConsumerTest { private final ByteArrayOutputStream out = new ByteArrayOutputStream(); - private final TeeConsumer consumer = new TeeConsumer( new PrintStream( out ), "xxx " ); + private final TeeConsumer consumer = new TeeConsumer(new PrintStream(out), "xxx "); - private static final String LS = System.getProperty( "line.separator" ); + private static final String LS = System.getProperty("line.separator"); @Test - public void testConsumeLine() - { - consumer.consumeLine( "line" ); + public void testConsumeLine() { + consumer.consumeLine("line"); - assertEquals( "Check output", "xxx line" + LS, out.toString() ); + assertEquals("Check output", "xxx line" + LS, out.toString()); - assertEquals( "Check content", "line" + LS, consumer.getContent() ); + assertEquals("Check content", "line" + LS, consumer.getContent()); - assertEquals( "Check toString", "line" + LS, consumer.toString() ); + assertEquals("Check toString", "line" + LS, consumer.toString()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java index 50cd6c7f1..c0d1dc604 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/exec/TeeOutputStreamTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.exec; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.exec; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -31,24 +30,21 @@ * * @author Benjamin Bentmann */ -public class TeeOutputStreamTest -{ +public class TeeOutputStreamTest { private final ByteArrayOutputStream out = new ByteArrayOutputStream(); - private final TeeOutputStream stream = new TeeOutputStream( new PrintStream( out ), "xxx " ); + private final TeeOutputStream stream = new TeeOutputStream(new PrintStream(out), "xxx "); - private static final String LS = System.getProperty( "line.separator" ); + private static final String LS = System.getProperty("line.separator"); @Test - public void testConsumeLine() - throws Exception - { - stream.write( ( "the first line" + LS + "line2" + LS + "3" + LS ).getBytes() ); + public void testConsumeLine() throws Exception { + stream.write(("the first line" + LS + "line2" + LS + "3" + LS).getBytes()); - assertEquals( "Check output", "xxx the first line" + LS + "xxx line2" + LS + "xxx 3" + LS, out.toString() ); + assertEquals("Check output", "xxx the first line" + LS + "xxx line2" + LS + "xxx 3" + LS, out.toString()); - assertEquals( "Check content", "the first line" + LS + "line2" + LS + "3" + LS, stream.getContent() ); + assertEquals("Check content", "the first line" + LS + "line2" + LS + "3" + LS, stream.getContent()); - assertEquals( "Check toString", "the first line" + LS + "line2" + LS + "3" + LS, stream.toString() ); + assertEquals("Check toString", "the first line" + LS + "line2" + LS + "3" + LS, stream.toString()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhaseTest.java index 22c1a010f..ad0e863db 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractBackupPomsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; @@ -27,17 +31,10 @@ import org.codehaus.plexus.util.xml.XmlStreamReader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - /** * @author Edwin Punzalan */ -public abstract class AbstractBackupPomsPhaseTest - extends PlexusJUnit4TestCase -{ +public abstract class AbstractBackupPomsPhaseTest extends PlexusJUnit4TestCase { private final String pomFilename = "pom.xml"; protected final String releaseBackupSuffix = ".releaseBackup"; @@ -45,51 +42,42 @@ public abstract class AbstractBackupPomsPhaseTest protected ReleasePhase phase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); phase = getReleasePhase(); } - abstract ReleasePhase getReleasePhase() - throws Exception; + abstract ReleasePhase getReleasePhase() throws Exception; - protected List getReactorProjects( String projectPath ) - throws Exception - { + protected List getReactorProjects(String projectPath) throws Exception { List reactorProjects = new ArrayList<>(); - File pomFile = new File( projectPath, pomFilename ); + File pomFile = new File(projectPath, pomFilename); - MavenProject mainProject = createMavenProject( pomFile ); + MavenProject mainProject = createMavenProject(pomFile); - reactorProjects.add( mainProject ); + reactorProjects.add(mainProject); - for ( String module : mainProject.getModel().getModules() ) - { - File modulePom = new File( projectPath + "/" + module, pomFilename ); + for (String module : mainProject.getModel().getModules()) { + File modulePom = new File(projectPath + "/" + module, pomFilename); - MavenProject subproject = createMavenProject( modulePom ); + MavenProject subproject = createMavenProject(modulePom); - reactorProjects.add( subproject ); + reactorProjects.add(subproject); } return reactorProjects; } - private MavenProject createMavenProject( File pomFile ) throws IOException, XmlPullParserException - { + private MavenProject createMavenProject(File pomFile) throws IOException, XmlPullParserException { MavenXpp3Reader reader = new MavenXpp3Reader(); Model model; - try ( XmlStreamReader xmlStreamReader = ReaderFactory.newXmlReader( pomFile )) - { - model = reader.read( xmlStreamReader ); + try (XmlStreamReader xmlStreamReader = ReaderFactory.newXmlReader(pomFile)) { + model = reader.read(xmlStreamReader); } - MavenProject project = new MavenProject( model ); - project.setFile( pomFile ); + MavenProject project = new MavenProject(model); + project.setFile(pomFile); return project; } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractEditModeRewritingReleasePhaseTestCase.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractEditModeRewritingReleasePhaseTestCase.java index 5541e6f03..46e89bf61 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractEditModeRewritingReleasePhaseTestCase.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractEditModeRewritingReleasePhaseTestCase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,16 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.List; @@ -50,164 +39,149 @@ import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Base class with tests for rewriting POMs with edit mode. * * @author Brett Porter */ -public abstract class AbstractEditModeRewritingReleasePhaseTestCase - extends AbstractRewritingReleasePhaseTestCase -{ - public AbstractEditModeRewritingReleasePhaseTestCase( String modelETL ) - { - super( modelETL ); +public abstract class AbstractEditModeRewritingReleasePhaseTestCase extends AbstractRewritingReleasePhaseTestCase { + public AbstractEditModeRewritingReleasePhaseTestCase(String modelETL) { + super(modelETL); } @Override - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[0]; // real SCM needed } @Test - public void testRewriteBasicPomWithEditMode() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.setScmUseEditMode( true ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithEditMode() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.setScmUseEditMode(true); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithEditModeFailure() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom" ); - builder.setScmUseEditMode( true ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithEditModeFailure() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom"); + builder.setScmUseEditMode(true); + mapNextVersion(builder, "groupId:artifactId"); ScmManagerStub scmManager = new ScmManagerStub(); DefaultScmRepositoryConfigurator configurator = - (DefaultScmRepositoryConfigurator) lookup( ScmRepositoryConfigurator.class, "default" ); - configurator.setScmManager( scmManager ); + (DefaultScmRepositoryConfigurator) lookup(ScmRepositoryConfigurator.class, "default"); + configurator.setScmManager(scmManager); - ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl( ReleaseUtils.buildReleaseDescriptor( builder ).getScmSourceUrl() ); - providerStub.setEditScmResult( new EditScmResult( "", "", "", false ) ); + ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl( + ReleaseUtils.buildReleaseDescriptor(builder).getScmSourceUrl()); + providerStub.setEditScmResult(new EditScmResult("", "", "", false)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "Check no other cause", e.getCause() ); + fail("Should have thrown an exception"); + } catch (ReleaseScmCommandException e) { + assertNull("Check no other cause", e.getCause()); } } @Test - public void testRewriteBasicPomWithEditModeException() - throws Exception - { + public void testRewriteBasicPomWithEditModeException() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom" ); - builder.setScmUseEditMode( true ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom"); + builder.setScmUseEditMode(true); + mapNextVersion(builder, "groupId:artifactId"); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.edit( isA( ScmRepository.class ), - isA( ScmFileSet.class ) ) ).thenThrow( new ScmException( "..." ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.edit(isA(ScmRepository.class), isA(ScmFileSet.class))) + .thenThrow(new ScmException("...")); ScmManagerStub scmManager = new ScmManagerStub(); DefaultScmRepositoryConfigurator configurator = - (DefaultScmRepositoryConfigurator) lookup( ScmRepositoryConfigurator.class, "default" ); - configurator.setScmManager( scmManager ); - scmManager.setScmProvider( scmProviderMock ); + (DefaultScmRepositoryConfigurator) lookup(ScmRepositoryConfigurator.class, "default"); + configurator.setScmManager(scmManager); + scmManager.setScmProvider(scmProviderMock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", ScmException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("Check cause", ScmException.class, e.getCause().getClass()); } // verify - verify( scmProviderMock ).edit( isA( ScmRepository.class ), isA( ScmFileSet.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock).edit(isA(ScmRepository.class), isA(ScmFileSet.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testRewritePomPluginDependencies() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-plugin-deps" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-plugin-deps" ); + public void testRewritePomPluginDependencies() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-plugin-deps"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "internal-snapshot-plugin-deps"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomUnmappedPluginDependencies() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-plugin-deps" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-snapshot-plugin-deps" ); - - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + public void testRewritePomUnmappedPluginDependencies() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-plugin-deps"); + ReleaseDescriptorBuilder builder = + createUnmappedConfiguration(reactorProjects, "internal-snapshot-plugin-deps"); + + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomProfile() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-profile" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-profile" ); + public void testRewritePomProfile() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-profile"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "internal-snapshot-profile"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomUnmappedProfile() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-profile" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-snapshot-profile" ); + public void testRewritePomUnmappedProfile() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-profile"); + ReleaseDescriptorBuilder builder = createUnmappedConfiguration(reactorProjects, "internal-snapshot-profile"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java index a4cca42e8..c84e91c70 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractReleaseTestCase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertFalse; +package org.apache.maven.shared.release.phase; import java.io.File; import java.io.IOException; @@ -53,9 +50,9 @@ import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest.RepositoryMerging; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.ProjectBuildingResult; import org.apache.maven.project.ProjectSorter; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.shared.release.PlexusJUnit4TestCase; import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; import org.eclipse.aether.DefaultRepositorySystemSession; @@ -72,14 +69,14 @@ import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.ElementSelectors; +import static org.junit.Assert.assertFalse; + /** * Base class for some release tests. * * @author Brett Porter */ -public abstract class AbstractReleaseTestCase - extends PlexusJUnit4TestCase -{ +public abstract class AbstractReleaseTestCase extends PlexusJUnit4TestCase { protected ProjectBuilder projectBuilder; protected ArtifactRepository localRepository; @@ -89,36 +86,30 @@ public abstract class AbstractReleaseTestCase protected ReleasePhase phase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - projectBuilder = lookup( ProjectBuilder.class ); - artifactFactory = lookup( ArtifactFactory.class ); + projectBuilder = lookup(ProjectBuilder.class); + artifactFactory = lookup(ArtifactFactory.class); - ArtifactRepositoryLayout layout = lookup( ArtifactRepositoryLayout.class, "default" ); - String localRepoPath = getTestFile( "target/local-repository" ).getAbsolutePath().replace( '\\', '/' ); - localRepository = new MavenArtifactRepository( "local", "file://" + localRepoPath, layout, null, null ); + ArtifactRepositoryLayout layout = lookup(ArtifactRepositoryLayout.class, "default"); + String localRepoPath = + getTestFile("target/local-repository").getAbsolutePath().replace('\\', '/'); + localRepository = new MavenArtifactRepository("local", "file://" + localRepoPath, layout, null, null); } - protected Path getWorkingDirectory( String workingDir ) - { - return Paths.get( getBasedir(), "target/test-classes" ).resolve( Paths.get( "projects", workingDir ) ) ; + protected Path getWorkingDirectory(String workingDir) { + return Paths.get(getBasedir(), "target/test-classes").resolve(Paths.get("projects", workingDir)); } - protected List createReactorProjects( String path, String subpath ) - throws Exception - { - return createReactorProjects( path, path, subpath ); + protected List createReactorProjects(String path, String subpath) throws Exception { + return createReactorProjects(path, path, subpath); } - protected ReleaseDescriptorBuilder createReleaseDescriptorBuilder( List reactorProjects ) - { + protected ReleaseDescriptorBuilder createReleaseDescriptorBuilder(List reactorProjects) { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - for ( MavenProject project : reactorProjects ) - { - builder.putOriginalVersion( project.getGroupId() + ':' + project.getArtifactId(), project.getVersion() ); + for (MavenProject project : reactorProjects) { + builder.putOriginalVersion(project.getGroupId() + ':' + project.getArtifactId(), project.getVersion()); } return builder; } @@ -131,27 +122,24 @@ protected ReleaseDescriptorBuilder createReleaseDescriptorBuilder( List createReactorProjects( String sourcePath, String targetPath, String executionRoot ) - throws Exception - { - final Path testCaseRootFrom = Paths.get( getBasedir(), "src/test/resources" ).resolve( Paths.get( "projects", sourcePath ) ) ; + protected List createReactorProjects(String sourcePath, String targetPath, String executionRoot) + throws Exception { + final Path testCaseRootFrom = + Paths.get(getBasedir(), "src/test/resources").resolve(Paths.get("projects", sourcePath)); - final Path testCaseRootTo = getWorkingDirectory( targetPath ); + final Path testCaseRootTo = getWorkingDirectory(targetPath); // Recopy the test resources since they are modified in some tests - Files.walkFileTree( testCaseRootFrom, new SimpleFileVisitor() { + Files.walkFileTree(testCaseRootFrom, new SimpleFileVisitor() { @Override - public FileVisitResult visitFile( Path file, BasicFileAttributes attrs ) - throws IOException - { - Path relPath = testCaseRootFrom.relativize( file ); + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Path relPath = testCaseRootFrom.relativize(file); - if ( !relPath.toFile().getName().startsWith( "expected-" ) ) - { - Files.createDirectories( testCaseRootTo.resolve( relPath ).getParent() ); + if (!relPath.toFile().getName().startsWith("expected-")) { + Files.createDirectories(testCaseRootTo.resolve(relPath).getParent()); - Files.copy( file, testCaseRootTo.resolve( relPath ), StandardCopyOption.REPLACE_EXISTING ); + Files.copy(file, testCaseRootTo.resolve(relPath), StandardCopyOption.REPLACE_EXISTING); } return FileVisitResult.CONTINUE; @@ -159,266 +147,227 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs ) }); Path projectFile; - if ( executionRoot == null ) - { - projectFile = testCaseRootTo.resolve( "pom.xml" ); - } - else - { - projectFile = testCaseRootTo.resolve( Paths.get( executionRoot, "pom.xml" ) ); + if (executionRoot == null) { + projectFile = testCaseRootTo.resolve("pom.xml"); + } else { + projectFile = testCaseRootTo.resolve(Paths.get(executionRoot, "pom.xml")); } - List repos = - Collections.singletonList( new DefaultArtifactRepository( "central", - getRemoteRepositoryURL(), - new DefaultRepositoryLayout() ) ); + List repos = Collections.singletonList( + new DefaultArtifactRepository("central", getRemoteRepositoryURL(), new DefaultRepositoryLayout())); Repository repository = new Repository(); - repository.setId( "central" ); - repository.setUrl( getRemoteRepositoryURL() ); + repository.setId("central"); + repository.setUrl(getRemoteRepositoryURL()); Profile profile = new Profile(); - profile.setId( "profile" ); - profile.addRepository( repository ); + profile.setId("profile"); + profile.addRepository(repository); ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); - buildingRequest.setLocalRepository( localRepository ); - buildingRequest.setRemoteRepositories( repos ); - buildingRequest.setPluginArtifactRepositories( repos ); - buildingRequest.setRepositoryMerging( RepositoryMerging.REQUEST_DOMINANT ); + buildingRequest.setLocalRepository(localRepository); + buildingRequest.setRemoteRepositories(repos); + buildingRequest.setPluginArtifactRepositories(repos); + buildingRequest.setRepositoryMerging(RepositoryMerging.REQUEST_DOMINANT); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); - repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repositorySession, new LocalRepository( localRepository.getBasedir() ) ) ); - buildingRequest.setRepositorySession( repositorySession ); - buildingRequest.addProfile( profile ); - buildingRequest.setActiveProfileIds( Collections.singletonList( profile.getId() ) ); - buildingRequest.setResolveDependencies( true ); + repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() + .newInstance(repositorySession, new LocalRepository(localRepository.getBasedir()))); + buildingRequest.setRepositorySession(repositorySession); + buildingRequest.addProfile(profile); + buildingRequest.setActiveProfileIds(Collections.singletonList(profile.getId())); + buildingRequest.setResolveDependencies(true); List buildingResults = - projectBuilder.build( Collections.singletonList( projectFile.toFile() ), true, buildingRequest ); + projectBuilder.build(Collections.singletonList(projectFile.toFile()), true, buildingRequest); List reactorProjects = new ArrayList<>(); - for ( ProjectBuildingResult buildingResult : buildingResults ) - { - reactorProjects.add( buildingResult.getProject() ) ; + for (ProjectBuildingResult buildingResult : buildingResults) { + reactorProjects.add(buildingResult.getProject()); } - WorkspaceReader simpleReactorReader = new SimpleReactorWorkspaceReader( reactorProjects ); - repositorySession.setWorkspaceReader( simpleReactorReader ); + WorkspaceReader simpleReactorReader = new SimpleReactorWorkspaceReader(reactorProjects); + repositorySession.setWorkspaceReader(simpleReactorReader); - ProjectSorter sorter = new ProjectSorter( reactorProjects ); + ProjectSorter sorter = new ProjectSorter(reactorProjects); reactorProjects = sorter.getSortedProjects(); - List resolvedProjects = new ArrayList<>( reactorProjects.size() ); - for ( MavenProject project : reactorProjects ) - { - MavenProject resolvedProject = projectBuilder.build( project.getFile(), buildingRequest ).getProject(); + List resolvedProjects = new ArrayList<>(reactorProjects.size()); + for (MavenProject project : reactorProjects) { + MavenProject resolvedProject = + projectBuilder.build(project.getFile(), buildingRequest).getProject(); // from LifecycleDependencyResolver - if ( resolvedProject.getDependencyArtifacts() == null ) - { - try - { - resolvedProject.setDependencyArtifacts( resolvedProject.createArtifacts( artifactFactory, null, null ) ); - } - catch ( InvalidDependencyVersionException e ) - { - throw new LifecycleExecutionException( e ); + if (resolvedProject.getDependencyArtifacts() == null) { + try { + resolvedProject.setDependencyArtifacts( + resolvedProject.createArtifacts(artifactFactory, null, null)); + } catch (InvalidDependencyVersionException e) { + throw new LifecycleExecutionException(e); } } // TODO .... understand why this is working ... :-) // why projectBuilder doesn't resolve and set in proper way DependencyArtifacts and Artifacts - if ( resolvedProject.getDependencyArtifacts().size() >= resolvedProject.getArtifacts().size() - && resolvedProject.getDependencyArtifacts().stream().noneMatch( a -> a.getVersion() == null ) ) - { - resolvedProject.setArtifacts( resolvedProject.getDependencyArtifacts() ); + if (resolvedProject.getDependencyArtifacts().size() + >= resolvedProject.getArtifacts().size() + && resolvedProject.getDependencyArtifacts().stream().noneMatch(a -> a.getVersion() == null)) { + resolvedProject.setArtifacts(resolvedProject.getDependencyArtifacts()); } - resolvedProjects.add( resolvedProject ); + resolvedProjects.add(resolvedProject); } return resolvedProjects; } - protected static Map getProjectsAsMap( List reactorProjects ) - { - Map map = new HashMap<>(); - for ( MavenProject project : reactorProjects ) - { - map.put( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ), project ); + protected static Map getProjectsAsMap(List reactorProjects) { + Map map = new HashMap<>(); + for (MavenProject project : reactorProjects) { + map.put(ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()), project); } return map; } - protected boolean comparePomFiles( List reactorProjects ) - throws IOException - { - return comparePomFiles( reactorProjects, true ); + protected boolean comparePomFiles(List reactorProjects) throws IOException { + return comparePomFiles(reactorProjects, true); } - protected boolean comparePomFiles( List reactorProjects, boolean normalizeLineEndings ) - throws IOException - { - comparePomFiles( reactorProjects, "", normalizeLineEndings ); + protected boolean comparePomFiles(List reactorProjects, boolean normalizeLineEndings) + throws IOException { + comparePomFiles(reactorProjects, "", normalizeLineEndings); // TODO: return void since this is redundant return true; } - protected void comparePomFiles( List reactorProjects, String expectedFileSuffix ) - throws IOException - { - comparePomFiles( reactorProjects, expectedFileSuffix, true ); + protected void comparePomFiles(List reactorProjects, String expectedFileSuffix) throws IOException { + comparePomFiles(reactorProjects, expectedFileSuffix, true); } - protected void comparePomFiles( List reactorProjects, String expectedFileSuffix, boolean normalizeLineEndings ) - throws IOException - { - for ( MavenProject project : reactorProjects ) - { - comparePomFiles( project, expectedFileSuffix, normalizeLineEndings ); + protected void comparePomFiles( + List reactorProjects, String expectedFileSuffix, boolean normalizeLineEndings) + throws IOException { + for (MavenProject project : reactorProjects) { + comparePomFiles(project, expectedFileSuffix, normalizeLineEndings); } } - protected void comparePomFiles( MavenProject project, String expectedFileSuffix ) - throws IOException - { - comparePomFiles( project, expectedFileSuffix, true ); + protected void comparePomFiles(MavenProject project, String expectedFileSuffix) throws IOException { + comparePomFiles(project, expectedFileSuffix, true); } - protected void comparePomFiles( MavenProject project, String expectedFileSuffix, boolean normalizeLineEndings ) - throws IOException - { + protected void comparePomFiles(MavenProject project, String expectedFileSuffix, boolean normalizeLineEndings) + throws IOException { File actualFile = project.getFile(); - File expectedFile = new File( actualFile.getParentFile(), "expected-pom" + expectedFileSuffix + ".xml" ); + File expectedFile = new File(actualFile.getParentFile(), "expected-pom" + expectedFileSuffix + ".xml"); - comparePomFiles( expectedFile, actualFile, normalizeLineEndings, false ); + comparePomFiles(expectedFile, actualFile, normalizeLineEndings, false); } - protected void comparePomFiles( File expectedFile, File actualFile ) - throws IOException - { - comparePomFiles( expectedFile, actualFile, true, false ); + protected void comparePomFiles(File expectedFile, File actualFile) throws IOException { + comparePomFiles(expectedFile, actualFile, true, false); } - protected void comparePomFiles( File expectedFile, File actualFile, boolean normalizeLineEndings, boolean ignoreComments ) - throws IOException - { - StringBuffer sb = new StringBuffer( "Check the transformed POM " + actualFile ); - sb.append( System.lineSeparator() ); + protected void comparePomFiles( + File expectedFile, File actualFile, boolean normalizeLineEndings, boolean ignoreComments) + throws IOException { + StringBuffer sb = new StringBuffer("Check the transformed POM " + actualFile); + sb.append(System.lineSeparator()); final String remoteRepositoryURL = getRemoteRepositoryURL(); - DiffBuilder diffBuilder = DiffBuilder.compare( expectedFile ).withTest( actualFile ); - if ( normalizeLineEndings ) - { + DiffBuilder diffBuilder = DiffBuilder.compare(expectedFile).withTest(actualFile); + if (normalizeLineEndings) { diffBuilder = diffBuilder.normalizeWhitespace(); } - if ( ignoreComments ) - { + if (ignoreComments) { diffBuilder.ignoreComments(); } // Order of elements has changed between M2 and M3, so match by name - diffBuilder.withNodeMatcher( new DefaultNodeMatcher( ElementSelectors.byName ) ).checkForSimilar(); + diffBuilder + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)) + .checkForSimilar(); - diffBuilder.withDifferenceEvaluator( new DifferenceEvaluator() - { + diffBuilder.withDifferenceEvaluator(new DifferenceEvaluator() { @Override - public ComparisonResult evaluate( Comparison comparison, ComparisonResult outcome ) - { - if ( "${remoterepo}".equals( comparison.getControlDetails().getValue() ) && - remoteRepositoryURL.equals( comparison.getTestDetails().getValue() ) ) - { + public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { + if ("${remoterepo}".equals(comparison.getControlDetails().getValue()) + && remoteRepositoryURL.equals( + comparison.getTestDetails().getValue())) { return ComparisonResult.EQUAL; - } - else if ( outcome == ComparisonResult.DIFFERENT - && comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE ) - { + } else if (outcome == ComparisonResult.DIFFERENT + && comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE) { // Order of elements has changed between M2 and M3 return ComparisonResult.EQUAL; - } - else if ( outcome == ComparisonResult.DIFFERENT - && comparison.getType() == ComparisonType.TEXT_VALUE - && "${project.build.directory}/site".equals( comparison.getTestDetails().getValue() ) ) - { + } else if (outcome == ComparisonResult.DIFFERENT + && comparison.getType() == ComparisonType.TEXT_VALUE + && "${project.build.directory}/site" + .equals(comparison.getTestDetails().getValue())) { // M2 was target/site, M3 is ${project.build.directory}/site return ComparisonResult.EQUAL; - } - else - { + } else { return outcome; } } - } ); + }); Diff diff = diffBuilder.build(); - sb.append( diff.toString() ); + sb.append(diff.toString()); - assertFalse( sb.toString(), diff.hasDifferences() ); + assertFalse(sb.toString(), diff.hasDifferences()); } - private String getRemoteRepositoryURL() - throws IOException - { - File testFile = getTestFile( "src/test/remote-repository" ); - if (testFile.getAbsolutePath().equals( testFile.getCanonicalPath() ) ) - { - return "file://" + getTestFile( "src/test/remote-repository" ).getAbsolutePath().replace( '\\', '/' ); + private String getRemoteRepositoryURL() throws IOException { + File testFile = getTestFile("src/test/remote-repository"); + if (testFile.getAbsolutePath().equals(testFile.getCanonicalPath())) { + return "file://" + + getTestFile("src/test/remote-repository") + .getAbsolutePath() + .replace('\\', '/'); } - return "file://" + getTestFile( "src/test/remote-repository" ).getCanonicalPath().replace( '\\', '/' ); + return "file://" + + getTestFile("src/test/remote-repository").getCanonicalPath().replace('\\', '/'); } - public static String getPath( File file ) - throws IOException - { - return file.toPath().toRealPath( LinkOption.NOFOLLOW_LINKS ).toString(); + public static String getPath(File file) throws IOException { + return file.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); } /** * WorkspaceReader to find versions and artifacts from reactor */ - private static final class SimpleReactorWorkspaceReader - implements WorkspaceReader - { + private static final class SimpleReactorWorkspaceReader implements WorkspaceReader { private final List reactorProjects; - private SimpleReactorWorkspaceReader( List reactorProjects ) - { + private SimpleReactorWorkspaceReader(List reactorProjects) { this.reactorProjects = reactorProjects; } @Override - public WorkspaceRepository getRepository() - { + public WorkspaceRepository getRepository() { return null; } @Override - public List findVersions( org.eclipse.aether.artifact.Artifact artifact ) - { - for ( MavenProject mavenProject : reactorProjects ) - { - if ( Objects.equals( artifact.toString(), mavenProject.getArtifact().toString() ) ) - { - return Collections.singletonList( mavenProject.getArtifact().getVersion() ); + public List findVersions(org.eclipse.aether.artifact.Artifact artifact) { + for (MavenProject mavenProject : reactorProjects) { + if (Objects.equals( + artifact.toString(), mavenProject.getArtifact().toString())) { + return Collections.singletonList(mavenProject.getArtifact().getVersion()); } } return Collections.emptyList(); } @Override - public File findArtifact( org.eclipse.aether.artifact.Artifact artifact ) - { - for ( MavenProject mavenProject : reactorProjects ) - { + public File findArtifact(org.eclipse.aether.artifact.Artifact artifact) { + for (MavenProject mavenProject : reactorProjects) { String pom = mavenProject.getGroupId() + ':' + mavenProject.getArtifactId() + ":pom:" - + mavenProject.getVersion(); - if ( Objects.equals( artifact.toString(), pom ) ) - { + + mavenProject.getVersion(); + if (Objects.equals(artifact.toString(), pom)) { return mavenProject.getFile(); - } - else if ( Objects.equals( artifact.toString(), mavenProject.getArtifact().toString() ) ) - { + } else if (Objects.equals( + artifact.toString(), mavenProject.getArtifact().toString())) { // just an existing, content doesn't matter return mavenProject.getFile(); } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractRewritingReleasePhaseTestCase.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractRewritingReleasePhaseTestCase.java index 40e4eb7c1..3dea7ba11 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractRewritingReleasePhaseTestCase.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractRewritingReleasePhaseTestCase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,13 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoMoreInteractions; +package org.apache.maven.shared.release.phase; import java.io.IOException; import java.util.ArrayList; @@ -55,714 +47,628 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verifyNoMoreInteractions; + /** * Base class with tests for rewriting POMs. * * @author Brett Porter */ @RunWith(Parameterized.class) -public abstract class AbstractRewritingReleasePhaseTestCase - extends AbstractReleaseTestCase -{ +public abstract class AbstractRewritingReleasePhaseTestCase extends AbstractReleaseTestCase { private final String modelETL; @Parameters - public static Collection data() - { - return Arrays.asList( new Object[][] { { JDomModelETLFactory.NAME } } ); + public static Collection data() { + return Arrays.asList(new Object[][] {{JDomModelETLFactory.NAME}}); } - public AbstractRewritingReleasePhaseTestCase( String modelETL ) - { + public AbstractRewritingReleasePhaseTestCase(String modelETL) { this.modelETL = modelETL; } @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, getRoleHint() ); + phase = lookup(ReleasePhase.class, getRoleHint()); - if( phase instanceof AbstractRewritePomsPhase) - { - ((AbstractRewritePomsPhase) phase).setModelETL( modelETL ); - ((AbstractRewritePomsPhase) phase).setStartTime( 0 ); + if (phase instanceof AbstractRewritePomsPhase) { + ((AbstractRewritePomsPhase) phase).setModelETL(modelETL); + ((AbstractRewritePomsPhase) phase).setStartTime(0); } } protected abstract String getRoleHint(); @Test - public void testRewriteBasicPom() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPom() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomEntities() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-entities" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom-entities" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomEntities() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-entities"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-entities"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomNamespace() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-namespace" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom-namespace" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomNamespace() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-namespace"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-namespace"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithEncoding() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-encoding" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom-with-encoding" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithEncoding() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-encoding"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-with-encoding"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithParent() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-parent" ); - ReleaseDescriptorBuilder builder = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "pom-with-parent" ); + public void testRewritePomWithParent() throws Exception { + List reactorProjects = createReactorProjects("pom-with-parent"); + ReleaseDescriptorBuilder builder = + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "pom-with-parent"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithUnmappedParent() - throws Exception - { + public void testRewritePomWithUnmappedParent() throws Exception { - List reactorProjects = createReactorProjects( "pom-with-parent" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-parent" ); + List reactorProjects = createReactorProjects("pom-with-parent"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "pom-with-parent"); // Process the child first - reactorProjects = new ArrayList<>( reactorProjects ); - Collections.reverse( reactorProjects ); + reactorProjects = new ArrayList<>(reactorProjects); + Collections.reverse(reactorProjects); - mapAlternateNextVersion( builder, "groupId:subproject1" ); + mapAlternateNextVersion(builder, "groupId:subproject1"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomWithReleasedParent() - throws Exception - { + public void testRewritePomWithReleasedParent() throws Exception { - List reactorProjects = createReactorProjects( "pom-with-released-parent" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-released-parent" ); + List reactorProjects = createReactorProjects("pom-with-released-parent"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "pom-with-released-parent"); - mapAlternateNextVersion( builder, "groupId:subproject1" ); - builder.addReleaseVersion( "groupId:artifactId", "1" ); - builder.addDevelopmentVersion( "groupId:artifactId", "1" ); + mapAlternateNextVersion(builder, "groupId:subproject1"); + builder.addReleaseVersion("groupId:artifactId", "1"); + builder.addDevelopmentVersion("groupId:artifactId", "1"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } - protected abstract void mapAlternateNextVersion( ReleaseDescriptorBuilder config, String projectId ); + protected abstract void mapAlternateNextVersion(ReleaseDescriptorBuilder config, String projectId); @Test - public void testRewritePomWithInheritedVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-inherited-version" ); - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, "pom-with-inherited-version" ); + public void testRewritePomWithInheritedVersion() throws Exception { + List reactorProjects = createReactorProjects("pom-with-inherited-version"); + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, "pom-with-inherited-version"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithChangedInheritedVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-inherited-version" ); - ReleaseDescriptorBuilder builder = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "pom-with-inherited-version" ); + public void testRewritePomWithChangedInheritedVersion() throws Exception { + List reactorProjects = createReactorProjects("pom-with-inherited-version"); + ReleaseDescriptorBuilder builder = + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "pom-with-inherited-version"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - MavenProject project = getProjectsAsMap( reactorProjects ).get( "groupId:subproject1" ); - comparePomFiles( project, "-version-changed" ); + MavenProject project = getProjectsAsMap(reactorProjects).get("groupId:subproject1"); + comparePomFiles(project, "-version-changed"); } - protected abstract ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( List reactorProjects, String workingDirectory ) - throws Exception; + protected abstract ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( + List reactorProjects, String workingDirectory) throws Exception; @Test - public void testRewritePomDependencies() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-dependencies" ); - mapNextVersion( builder, "groupId:subsubproject" ); + public void testRewritePomDependencies() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = + createDefaultConfiguration(reactorProjects, "internal-snapshot-dependencies"); + mapNextVersion(builder, "groupId:subsubproject"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomUnmappedDependencies() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-snapshot-dependencies" ); + public void testRewritePomUnmappedDependencies() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = + createUnmappedConfiguration(reactorProjects, "internal-snapshot-dependencies"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomDependenciesDifferentVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-differing-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration( reactorProjects, "internal-differing-snapshot-dependencies" ); + public void testRewritePomDependenciesDifferentVersion() throws Exception { + List reactorProjects = createReactorProjects("internal-differing-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = + createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-dependencies"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteManagedPomDependencies() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-managed-snapshot-dependency" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "internal-managed-snapshot-dependency" ); + public void testRewriteManagedPomDependencies() throws Exception { + List reactorProjects = createReactorProjects("internal-managed-snapshot-dependency"); + ReleaseDescriptorBuilder builder = + createMappedConfiguration(reactorProjects, "internal-managed-snapshot-dependency"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteManagedPomUnmappedDependencies() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-managed-snapshot-dependency" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-managed-snapshot-dependency" ); + public void testRewriteManagedPomUnmappedDependencies() throws Exception { + List reactorProjects = createReactorProjects("internal-managed-snapshot-dependency"); + ReleaseDescriptorBuilder builder = + createUnmappedConfiguration(reactorProjects, "internal-managed-snapshot-dependency"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomPlugins() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-plugins" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-plugins" ); + public void testRewritePomPlugins() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-plugins"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "internal-snapshot-plugins"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomUnmappedPlugins() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-plugins" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-snapshot-plugins" ); + public void testRewritePomUnmappedPlugins() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-plugins"); + ReleaseDescriptorBuilder builder = createUnmappedConfiguration(reactorProjects, "internal-snapshot-plugins"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomPluginsDifferentVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-differing-snapshot-plugins" ); - ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration( reactorProjects, "internal-differing-snapshot-plugins" ); + public void testRewritePomPluginsDifferentVersion() throws Exception { + List reactorProjects = createReactorProjects("internal-differing-snapshot-plugins"); + ReleaseDescriptorBuilder builder = + createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-plugins"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteManagedPomPlugins() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-managed-snapshot-plugin" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "internal-managed-snapshot-plugin" ); + public void testRewriteManagedPomPlugins() throws Exception { + List reactorProjects = createReactorProjects("internal-managed-snapshot-plugin"); + ReleaseDescriptorBuilder builder = + createMappedConfiguration(reactorProjects, "internal-managed-snapshot-plugin"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteManagedPomUnmappedPlugins() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-managed-snapshot-plugin" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-managed-snapshot-plugin" ); + public void testRewriteManagedPomUnmappedPlugins() throws Exception { + List reactorProjects = createReactorProjects("internal-managed-snapshot-plugin"); + ReleaseDescriptorBuilder builder = + createUnmappedConfiguration(reactorProjects, "internal-managed-snapshot-plugin"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomReportPlugins() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-report-plugins" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-report-plugins" ); + public void testRewritePomReportPlugins() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-report-plugins"); + ReleaseDescriptorBuilder builder = + createDefaultConfiguration(reactorProjects, "internal-snapshot-report-plugins"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomUnmappedReportPlugins() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-report-plugins" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-snapshot-report-plugins" ); + public void testRewritePomUnmappedReportPlugins() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-report-plugins"); + ReleaseDescriptorBuilder builder = + createUnmappedConfiguration(reactorProjects, "internal-snapshot-report-plugins"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewritePomReportPluginsDifferentVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-differing-snapshot-report-plugins" ); - ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration( reactorProjects, "internal-differing-snapshot-report-plugins" ); + public void testRewritePomReportPluginsDifferentVersion() throws Exception { + List reactorProjects = createReactorProjects("internal-differing-snapshot-report-plugins"); + ReleaseDescriptorBuilder builder = + createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-report-plugins"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - @Ignore( "Extensions being part of reactor is not supported anymore" ) - public void testRewritePomExtension() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-extension" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-extension" ); + @Ignore("Extensions being part of reactor is not supported anymore") + public void testRewritePomExtension() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-extension"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "internal-snapshot-extension"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - @Ignore( "Extensions being part of reactor is not supported anymore" ) - public void testRewritePomUnmappedExtension() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-snapshot-extension" ); - ReleaseDescriptorBuilder builder = createUnmappedConfiguration( reactorProjects, "internal-snapshot-extension" ); + @Ignore("Extensions being part of reactor is not supported anymore") + public void testRewritePomUnmappedExtension() throws Exception { + List reactorProjects = createReactorProjects("internal-snapshot-extension"); + ReleaseDescriptorBuilder builder = createUnmappedConfiguration(reactorProjects, "internal-snapshot-extension"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - @Ignore( "Extensions being part of reactor is not supported anymore" ) - public void testRewritePomExtensionDifferentVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "internal-differing-snapshot-extension" ); - ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration( reactorProjects, "internal-differing-snapshot-extension" ); + @Ignore("Extensions being part of reactor is not supported anymore") + public void testRewritePomExtensionDifferentVersion() throws Exception { + List reactorProjects = createReactorProjects("internal-differing-snapshot-extension"); + ReleaseDescriptorBuilder builder = + createDifferingVersionConfiguration(reactorProjects, "internal-differing-snapshot-extension"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - @Ignore( "Extensions being part of reactor is not supported anymore" ) - public void testRewritePomExtensionUndefinedVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-without-extension-version" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "pom-without-extension-version" ); + @Ignore("Extensions being part of reactor is not supported anymore") + public void testRewritePomExtensionUndefinedVersion() throws Exception { + List reactorProjects = createReactorProjects("pom-without-extension-version"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "pom-without-extension-version"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteAddSchema() - throws Exception - { + public void testRewriteAddSchema() throws Exception { boolean copyFiles = true; // Run a second time to check they are not duplicated - for ( int i = 0; i < 2; i++ ) - { + for (int i = 0; i < 2; i++) { String path = "basic-pom"; - List reactorProjects = prepareReactorProjects( path ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - mapNextVersion( builder, "groupId:artifactId" ); - builder.setAddSchema( true ); + List reactorProjects = prepareReactorProjects(path); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + mapNextVersion(builder, "groupId:artifactId"); + builder.setAddSchema(true); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - comparePomFiles( reactorProjects, "-with-schema" ); + comparePomFiles(reactorProjects, "-with-schema"); copyFiles = false; - verifyReactorProjects( path, copyFiles ); + verifyReactorProjects(path, copyFiles); } } @Test - public void testSimulateRewriteEditModeSkipped() - throws Exception - { + public void testSimulateRewriteEditModeSkipped() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.setScmUseEditMode( true ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.setScmUseEditMode(true); + mapNextVersion(builder, "groupId:artifactId"); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); ScmManagerStub scmManager = new ScmManagerStub(); DefaultScmRepositoryConfigurator configurator = - (DefaultScmRepositoryConfigurator) lookup( ScmRepositoryConfigurator.class ); - configurator.setScmManager( scmManager ); - scmManager.setScmProvider( scmProviderMock ); + (DefaultScmRepositoryConfigurator) lookup(ScmRepositoryConfigurator.class); + configurator.setScmManager(scmManager); + scmManager.setScmProvider(scmProviderMock); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testRewriteUnmappedPom() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); + public void testRewriteUnmappedPom() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRewriteBasicPomWithScmRepoException() - throws Exception - { + public void testRewriteBasicPomWithScmRepoException() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.setScmUseEditMode( true ); - builder.setScmSourceUrl( "scm:svn:fail" ); - mapNextVersion( builder, "groupId:artifactId" ); - - ScmManager scmManager = lookup( ScmManager.class ); - if ( scmManager instanceof ScmManagerStub ) - { - ((ScmManagerStub) scmManager ).setException( new ScmRepositoryException( "..." ) ); + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.setScmUseEditMode(true); + builder.setScmSourceUrl("scm:svn:fail"); + mapNextVersion(builder, "groupId:artifactId"); + + ScmManager scmManager = lookup(ScmManager.class); + if (scmManager instanceof ScmManagerStub) { + ((ScmManagerStub) scmManager).setException(new ScmRepositoryException("...")); } - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseScmRepositoryException e ) - { - assertNull( "Check no additional cause", e.getCause() ); + fail("Should have thrown an exception"); + } catch (ReleaseScmRepositoryException e) { + assertNull("Check no additional cause", e.getCause()); } } @Test - public void testRewriteBasicPomWithNoSuchProviderException() - throws Exception - { + public void testRewriteBasicPomWithNoSuchProviderException() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.setScmUseEditMode( true ); - builder.setScmSourceUrl( "scm:fail:path" ); - mapNextVersion( builder, "groupId:artifactId" ); - - ScmManager scmManager = (ScmManager) lookup( ScmManager.class ); - if ( scmManager instanceof ScmManagerStub ) - { - ((ScmManagerStub) scmManager ).setException( new NoSuchScmProviderException( "..." ) );; + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.setScmUseEditMode(true); + builder.setScmSourceUrl("scm:fail:path"); + mapNextVersion(builder, "groupId:artifactId"); + + ScmManager scmManager = (ScmManager) lookup(ScmManager.class); + if (scmManager instanceof ScmManagerStub) { + ((ScmManagerStub) scmManager).setException(new NoSuchScmProviderException("...")); + ; } // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { // verify - assertEquals( "Check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + assertEquals( + "Check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } } @Test - public void testRewriteWhitespaceAroundValues() - throws Exception - { - List reactorProjects = createReactorProjects( "whitespace-around-values" ); - ReleaseDescriptorBuilder builder = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "whitespace-around-values" ); - mapNextVersion( builder, "groupId:subproject2" ); + public void testRewriteWhitespaceAroundValues() throws Exception { + List reactorProjects = createReactorProjects("whitespace-around-values"); + ReleaseDescriptorBuilder builder = + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "whitespace-around-values"); + mapNextVersion(builder, "groupId:subproject2"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteCommentsAroundValues() - throws Exception - { - List reactorProjects = createReactorProjects( "comments-around-values" ); - ReleaseDescriptorBuilder builder = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "comments-around-values" ); - mapNextVersion( builder, "groupId:subproject2" ); + public void testRewriteCommentsAroundValues() throws Exception { + List reactorProjects = createReactorProjects("comments-around-values"); + ReleaseDescriptorBuilder builder = + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "comments-around-values"); + mapNextVersion(builder, "groupId:subproject2"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteCDataAroundValues() - throws Exception - { - List reactorProjects = createReactorProjects( "cdata-around-values" ); - ReleaseDescriptorBuilder builder = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "cdata-around-values" ); - mapNextVersion( builder, "groupId:subproject2" ); + public void testRewriteCDataAroundValues() throws Exception { + List reactorProjects = createReactorProjects("cdata-around-values"); + ReleaseDescriptorBuilder builder = + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "cdata-around-values"); + mapNextVersion(builder, "groupId:subproject2"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testCleanNoProjects() - throws Exception - { + public void testCleanNoProjects() throws Exception { // This occurs when it is release:perform run standalone. Just check there are no errors. - ( (ResourceGenerator) phase ).clean( Collections.emptyList() ); + ((ResourceGenerator) phase).clean(Collections.emptyList()); } - protected ReleaseDescriptorBuilder createUnmappedConfiguration( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createUnmappedConfiguration( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - unmapNextVersion( builder, "groupId:subproject1" ); - mapNextVersion( builder, "groupId:subproject2" ); - mapNextVersion( builder, "groupId:subproject3" ); - mapNextVersion( builder, "groupId:artifactId" ); + unmapNextVersion(builder, "groupId:subproject1"); + mapNextVersion(builder, "groupId:subproject2"); + mapNextVersion(builder, "groupId:subproject3"); + mapNextVersion(builder, "groupId:artifactId"); return builder; } - protected List createReactorProjects( String path ) - throws Exception - { - return prepareReactorProjects( path ); + protected List createReactorProjects(String path) throws Exception { + return prepareReactorProjects(path); } - protected ReleaseDescriptorBuilder createDefaultConfiguration( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createDefaultConfiguration( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createMappedConfiguration(reactorProjects, workingDirectory); - mapNextVersion( builder, "groupId:subproject4" ); + mapNextVersion(builder, "groupId:subproject4"); return builder; } - protected ReleaseDescriptorBuilder createMappedConfiguration( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createMappedConfiguration( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDifferingVersionConfiguration(reactorProjects, workingDirectory); - mapNextVersion( builder, "groupId:subproject3" ); + mapNextVersion(builder, "groupId:subproject3"); return builder; } - private ReleaseDescriptorBuilder createDifferingVersionConfiguration( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, workingDirectory ); + private ReleaseDescriptorBuilder createDifferingVersionConfiguration( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, workingDirectory); - mapNextVersion( builder, "groupId:subproject2" ); + mapNextVersion(builder, "groupId:subproject2"); return builder; } - protected abstract ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( List reactorProjects, String workingDirectory ) - throws Exception; + protected abstract ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( + List reactorProjects, String workingDirectory) throws Exception; - protected abstract void unmapNextVersion( ReleaseDescriptorBuilder config, String projectId ); + protected abstract void unmapNextVersion(ReleaseDescriptorBuilder config, String projectId); - protected abstract void mapNextVersion( ReleaseDescriptorBuilder config, String projectId ); + protected abstract void mapNextVersion(ReleaseDescriptorBuilder config, String projectId); - protected ReleaseDescriptorBuilder createDescriptorFromBasicPom( List reactorProjects, String workingDirectory ) - throws Exception - { - return createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createDescriptorFromBasicPom( + List reactorProjects, String workingDirectory) throws Exception { + return createDescriptorFromProjects(reactorProjects, workingDirectory); } - protected abstract String readTestProjectFile( String fileName ) - throws IOException; + protected abstract String readTestProjectFile(String fileName) throws IOException; @Test - public void testRewritePomDependenciesWithNamespace() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-namespace" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "pom-with-namespace" ); + public void testRewritePomDependenciesWithNamespace() throws Exception { + List reactorProjects = createReactorProjects("pom-with-namespace"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration(reactorProjects, "pom-with-namespace"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } - protected abstract List prepareReactorProjects( String path ) - throws Exception; + protected abstract List prepareReactorProjects(String path) throws Exception; - protected void verifyReactorProjects( String path, boolean copyFiles ) - throws Exception - { - } + protected void verifyReactorProjects(String path, boolean copyFiles) throws Exception {} - protected ReleaseDescriptorBuilder createDescriptorFromProjects( List reactorProjects, String workingDirectory ) - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( new ReleaseDescriptorBuilder(), reactorProjects ); - builder.setWorkingDirectory( getWorkingDirectory( workingDirectory ).toString() ); + protected ReleaseDescriptorBuilder createDescriptorFromProjects( + List reactorProjects, String workingDirectory) { + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(new ReleaseDescriptorBuilder(), reactorProjects); + builder.setWorkingDirectory(getWorkingDirectory(workingDirectory).toString()); return builder; } - - private ReleaseDescriptorBuilder createDescriptorFromProjects( ReleaseDescriptorBuilder builder, List reactorProjects ) - { - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - - for ( MavenProject project : reactorProjects ) - { + + private ReleaseDescriptorBuilder createDescriptorFromProjects( + ReleaseDescriptorBuilder builder, List reactorProjects) { + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + + for (MavenProject project : reactorProjects) { String key = project.getGroupId() + ':' + project.getArtifactId(); - builder.putOriginalVersion( key, project.getVersion() ); - builder.addOriginalScmInfo( key, project.getScm() ); + builder.putOriginalVersion(key, project.getVersion()); + builder.addOriginalScmInfo(key, project.getScm()); } - - if ( rootProject.getScm() == null ) - { - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo/trunk" ); - } - else - { - builder.setScmSourceUrl( rootProject.getScm().getConnection() ); + + if (rootProject.getScm() == null) { + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo/trunk"); + } else { + builder.setScmSourceUrl(rootProject.getScm().getConnection()); } return builder; diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhaseTest.java index 594a446e3..e4a4962d9 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/AbstractScmCommitPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.List; @@ -31,66 +27,61 @@ import org.apache.maven.shared.release.config.ReleaseUtils; import org.junit.Test; -public class AbstractScmCommitPhaseTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class AbstractScmCommitPhaseTest { @Test - public void testDefaultCreatePomFiles() - { - List files = - AbstractScmCommitPhase.createPomFiles( ReleaseUtils.buildReleaseDescriptor( new ReleaseDescriptorBuilder() ), - createProject( "artifactId", "1.0-SNAPSHOT", - new File( "pom.xml" ) ) ); - assertEquals( "Number of created files", files.size(), 1 ); - assertTrue( files.contains( new File( "pom.xml" ) ) ); + public void testDefaultCreatePomFiles() { + List files = AbstractScmCommitPhase.createPomFiles( + ReleaseUtils.buildReleaseDescriptor(new ReleaseDescriptorBuilder()), + createProject("artifactId", "1.0-SNAPSHOT", new File("pom.xml"))); + assertEquals("Number of created files", files.size(), 1); + assertTrue(files.contains(new File("pom.xml"))); } - @Test - public void testCreatePomFilesSuppressCommitBeforeTag() - { + public void testCreatePomFilesSuppressCommitBeforeTag() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setSuppressCommitBeforeTagOrBranch( true ); - List files = - AbstractScmCommitPhase.createPomFiles( ReleaseUtils.buildReleaseDescriptor( builder ), - createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) ); - assertEquals( "Number of created files", files.size(), 1 ); - assertTrue( files.contains( new File( "pom.xml" ) ) ); + builder.setSuppressCommitBeforeTagOrBranch(true); + List files = AbstractScmCommitPhase.createPomFiles( + ReleaseUtils.buildReleaseDescriptor(builder), + createProject("artifactId", "1.0-SNAPSHOT", new File("pom.xml"))); + assertEquals("Number of created files", files.size(), 1); + assertTrue(files.contains(new File("pom.xml"))); } @Test - public void testCreatePomFilesWithReleasePom() - { + public void testCreatePomFilesWithReleasePom() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setGenerateReleasePoms( true ); - List files = - AbstractScmCommitPhase.createPomFiles( ReleaseUtils.buildReleaseDescriptor( builder ), - createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) ); - assertEquals( "Number of created files", files.size(), 2 ); - assertTrue( files.contains( new File( "pom.xml" ) ) ); - assertTrue( files.contains( new File( "release-pom.xml" ) ) ); + builder.setGenerateReleasePoms(true); + List files = AbstractScmCommitPhase.createPomFiles( + ReleaseUtils.buildReleaseDescriptor(builder), + createProject("artifactId", "1.0-SNAPSHOT", new File("pom.xml"))); + assertEquals("Number of created files", files.size(), 2); + assertTrue(files.contains(new File("pom.xml"))); + assertTrue(files.contains(new File("release-pom.xml"))); } @Test - public void testCreatePomFilesWithReleasePomAndSuppressCommitBeforeTag() - { + public void testCreatePomFilesWithReleasePomAndSuppressCommitBeforeTag() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setGenerateReleasePoms( true ); - builder.setSuppressCommitBeforeTagOrBranch( true ); - List files = - AbstractScmCommitPhase.createPomFiles( ReleaseUtils.buildReleaseDescriptor( builder ), - createProject( "artifactId", "1.0-SNAPSHOT", new File( "pom.xml" ) ) ); - assertEquals( "Number of created files", files.size(), 1 ); - assertTrue( files.contains( new File( "pom.xml" ) ) ); + builder.setGenerateReleasePoms(true); + builder.setSuppressCommitBeforeTagOrBranch(true); + List files = AbstractScmCommitPhase.createPomFiles( + ReleaseUtils.buildReleaseDescriptor(builder), + createProject("artifactId", "1.0-SNAPSHOT", new File("pom.xml"))); + assertEquals("Number of created files", files.size(), 1); + assertTrue(files.contains(new File("pom.xml"))); } - private static MavenProject createProject( String artifactId, String version, File file ) - { + private static MavenProject createProject(String artifactId, String version, File file) { Model model = new Model(); - model.setGroupId( "groupId" ); - model.setArtifactId( artifactId ); - model.setVersion( version ); - MavenProject project = new MavenProject( model ); - project.setFile( file ); + model.setGroupId("groupId"); + model.setArtifactId(artifactId); + model.setVersion(version); + MavenProject project = new MavenProject(model); + project.setFile(file); return project; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhaseTest.java index 67e51b736..ca39e1a1d 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/BranchInputVariablesPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,319 +16,304 @@ * specific language governing permissions and limitations * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.Collections; import java.util.List; -import com.google.inject.AbstractModule; -import com.google.inject.Module; import org.apache.maven.model.Model; import org.apache.maven.project.MavenProject; -import org.apache.maven.scm.manager.ScmManager; import org.apache.maven.shared.release.PlexusJUnit4TestCase; import org.apache.maven.shared.release.ReleaseExecutionException; import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; import org.apache.maven.shared.release.config.ReleaseUtils; import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; -import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.codehaus.plexus.components.interactivity.Prompter; import org.codehaus.plexus.components.interactivity.PrompterException; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the variable input phase. * * @author Brett Porter */ -public class BranchInputVariablesPhaseTest - extends PlexusJUnit4TestCase -{ +public class BranchInputVariablesPhaseTest extends PlexusJUnit4TestCase { private BranchInputVariablesPhase phase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (BranchInputVariablesPhase) lookup( ReleasePhase.class, "branch-input-variables" ); + phase = (BranchInputVariablesPhase) lookup(ReleasePhase.class, "branch-input-variables"); } @Test - public void testInputVariablesInteractive() - throws Exception - { + public void testInputVariablesInteractive() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - when( mockPrompter.prompt( isA( String.class ) ) ).thenReturn( "tag-value", "simulated-tag-value" ); + Prompter mockPrompter = mock(Prompter.class); + when(mockPrompter.prompt(isA(String.class))).thenReturn("tag-value", "simulated-tag-value"); + phase.setPrompter(mockPrompter); - phase.setPrompter( mockPrompter ); - - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); - verify( mockPrompter, times( 2 ) ).prompt( isA( String.class ) ); - verifyNoMoreInteractions( mockPrompter ); + verify(mockPrompter, times(2)).prompt(isA(String.class)); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testUnmappedVersion() - { - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + public void testUnmappedVersion() { + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertNull( "check no cause", e.getCause() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertNull("check no cause", e.getCause()); } builder = new ReleaseDescriptorBuilder(); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertNull( "check no cause", e.getCause() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertNull("check no cause", e.getCause()); } } @Test - public void testInputVariablesNonInteractiveConfigured() - throws Exception - { + public void testInputVariablesNonInteractiveConfigured() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = mock(Prompter.class); + phase.setPrompter(mockPrompter); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setScmReleaseLabel( "tag-value" ); + builder.setInteractive(false); + builder.setScmReleaseLabel("tag-value"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setScmReleaseLabel( "simulated-tag-value" ); + builder.setInteractive(false); + builder.setScmReleaseLabel("simulated-tag-value"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testInputVariablesInteractiveConfigured() - throws Exception - { + public void testInputVariablesInteractiveConfigured() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = mock(Prompter.class); + phase.setPrompter(mockPrompter); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "tag-value" ); + builder.setScmReleaseLabel("tag-value"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "simulated-tag-value" ); + builder.setScmReleaseLabel("simulated-tag-value"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testPrompterException() - throws Exception - { + public void testPrompterException() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - when( mockPrompter.prompt( isA( String.class ), - isA( String.class ) ) ).thenThrow( new PrompterException( "..." ) ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = mock(Prompter.class); + when(mockPrompter.prompt(isA(String.class), isA(String.class))).thenThrow(new PrompterException("...")); + phase.setPrompter(mockPrompter); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "No branch name was given.", e.getMessage() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("No branch name was given.", e.getMessage()); } // prepare builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "No branch name was given.", e.getMessage() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("No branch name was given.", e.getMessage()); } // verify - verify( mockPrompter, times( 2 ) ).prompt( isA( String.class ) ); - verifyNoMoreInteractions( mockPrompter ); + verify(mockPrompter, times(2)).prompt(isA(String.class)); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testBranchOperation() - { - assertTrue( phase.isBranchOperation() ); + public void testBranchOperation() { + assertTrue(phase.isBranchOperation()); } @Test - public void testEmptyBranchName() - { + public void testEmptyBranchName() { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = mock(Prompter.class); + phase.setPrompter(mockPrompter); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setScmReleaseLabel( null ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.setInteractive(false); + builder.setScmReleaseLabel(null); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "No branch name was given.", e.getMessage() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("No branch name was given.", e.getMessage()); } // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setScmReleaseLabel( null ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.setInteractive(false); + builder.setScmReleaseLabel(null); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "No branch name was given.", e.getMessage() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("No branch name was given.", e.getMessage()); } // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testNamingPolicy() throws Exception - { + public void testNamingPolicy() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setInteractive( false ); - builder.setProjectNamingPolicyId( "stub" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setInteractive(false); + builder.setProjectNamingPolicyId("stub"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertEquals( "STUB", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals("STUB", ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); } - private static MavenProject createProject( String artifactId, String version ) - { + private static MavenProject createProject(String artifactId, String version) { Model model = new Model(); - model.setGroupId( "groupId" ); - model.setArtifactId( artifactId ); - model.setVersion( version ); - return new MavenProject( model ); + model.setGroupId("groupId"); + model.setArtifactId(artifactId); + model.setVersion(version); + return new MavenProject(model); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java index 7d53434d5..325ea4b34 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.Arrays; import java.util.Collections; @@ -43,1215 +34,1061 @@ import org.codehaus.plexus.components.interactivity.PrompterException; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * Test the dependency snapshot check phase. * * @author Brett Porter */ -public class CheckDependencySnapshotsPhaseTest - extends AbstractReleaseTestCase -{ +public class CheckDependencySnapshotsPhaseTest extends AbstractReleaseTestCase { private static final String NO = "no"; private static final String YES = "yes"; - private static final List YES_NO_ARRAY = Arrays.asList( YES, NO ); + private static final List YES_NO_ARRAY = Arrays.asList(YES, NO); private static final String DEFAULT_CHOICE = "1"; - private static final List CHOICE_ARRAY = Arrays.asList( "0", DEFAULT_CHOICE, "2", "3" ); + private static final List CHOICE_ARRAY = Arrays.asList("0", DEFAULT_CHOICE, "2", "3"); @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "check-dependency-snapshots" ); + phase = lookup(ReleasePhase.class, "check-dependency-snapshots"); } @Test - public void testNoSnapshotDependencies() - throws Exception - { - ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();; - List reactorProjects = createDescriptorFromProjects( "no-snapshot-dependencies" ); + public void testNoSnapshotDependencies() throws Exception { + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); + ; + List reactorProjects = createDescriptorFromProjects("no-snapshot-dependencies"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testNoSnapshotRangeDependencies() - throws Exception - { + public void testNoSnapshotRangeDependencies() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "no-snapshot-range-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("no-snapshot-range-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.1", "1.2-SNAPSHOT" ) ) ); + phase.setPrompter(createMockPrompter(YES, DEFAULT_CHOICE, new VersionPair("1.1", "1.2-SNAPSHOT"))); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.1", "1.2-SNAPSHOT" ) ) ); + phase.setPrompter(createMockPrompter(YES, DEFAULT_CHOICE, new VersionPair("1.1", "1.2-SNAPSHOT"))); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } // MRELEASE-985 @Test public void testSnapshotDependenciesInProjectAndResolveFromCommandLine() throws Exception { - List reactorProjects = createDescriptorFromProjects( "internal-snapshot-dependencies-no-reactor" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("internal-snapshot-dependencies-no-reactor"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); builder.addDependencyReleaseVersion("groupId:test", "1.0"); builder.addDependencyDevelopmentVersion("groupId:test", "1.1"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - assertTrue( true ); - } - catch ( ReleaseFailureException e ) - { - fail( "There should be no failed execution" ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + assertTrue(true); + } catch (ReleaseFailureException e) { + fail("There should be no failed execution"); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - assertTrue( true ); - } - catch ( ReleaseFailureException e ) - { - fail( "There should be no failed execution" ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + assertTrue(true); + } catch (ReleaseFailureException e) { + fail("There should be no failed execution"); } } @Test - public void testSnapshotDependenciesInProjectOnly() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "internal-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotDependenciesInProjectOnly() throws Exception { + List reactorProjects = createDescriptorFromProjects("internal-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotReleasePluginNonInteractive() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "snapshot-release-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); - builder.setInteractive( false ); - - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); - } + public void testSnapshotReleasePluginNonInteractive() throws Exception { + List reactorProjects = createDescriptorFromProjects("snapshot-release-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); + builder.setInteractive(false); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotReleasePluginInteractiveDeclined() - throws Exception - { + public void testSnapshotReleasePluginInteractiveDeclined() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "snapshot-release-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("snapshot-release-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompterWithSnapshotReleasePlugin( NO, NO ) ); + phase.setPrompter(createMockPrompterWithSnapshotReleasePlugin(NO, NO)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createMockPrompterWithSnapshotReleasePlugin( NO, NO ) ); + phase.setPrompter(createMockPrompterWithSnapshotReleasePlugin(NO, NO)); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotReleasePluginInteractiveAcceptedForExecution() - throws Exception - { + public void testSnapshotReleasePluginInteractiveAcceptedForExecution() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "snapshot-release-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("snapshot-release-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createYesMockPrompter() ); + phase.setPrompter(createYesMockPrompter()); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotReleasePluginInteractiveAcceptedForSimulation() - throws Exception - { + public void testSnapshotReleasePluginInteractiveAcceptedForSimulation() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "snapshot-release-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("snapshot-release-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createYesMockPrompter() ); + phase.setPrompter(createYesMockPrompter()); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotReleasePluginInteractiveInvalid() - throws Exception - { + public void testSnapshotReleasePluginInteractiveInvalid() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "snapshot-release-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("snapshot-release-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompterWithSnapshotReleasePlugin( "donkey", NO ) ); + phase.setPrompter(createMockPrompterWithSnapshotReleasePlugin("donkey", NO)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createMockPrompterWithSnapshotReleasePlugin( "donkey", NO ) ); + phase.setPrompter(createMockPrompterWithSnapshotReleasePlugin("donkey", NO)); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotReleasePluginInteractiveException() - throws Exception - { + public void testSnapshotReleasePluginInteractiveException() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "snapshot-release-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("snapshot-release-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - Prompter mockPrompter = mock( Prompter.class ); - when( mockPrompter.prompt( anyString(), eq( YES_NO_ARRAY ), - eq( NO ) ) ).thenThrow( new PrompterException( "..." ) ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = mock(Prompter.class); + when(mockPrompter.prompt(anyString(), eq(YES_NO_ARRAY), eq(NO))).thenThrow(new PrompterException("...")); + phase.setPrompter(mockPrompter); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", PrompterException.class, e.getCause().getClass() ); + fail("Should have failed execution"); + } catch (ReleaseExecutionException e) { + assertEquals("Check cause", PrompterException.class, e.getCause().getClass()); } - mockPrompter = mock( Prompter.class ); - when( mockPrompter.prompt( anyString(), eq( YES_NO_ARRAY ), - eq( NO ) ) ).thenThrow( new PrompterException( "..." ) ); + mockPrompter = mock(Prompter.class); + when(mockPrompter.prompt(anyString(), eq(YES_NO_ARRAY), eq(NO))).thenThrow(new PrompterException("...")); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", PrompterException.class, e.getCause().getClass() ); + fail("Should have failed execution"); + } catch (ReleaseExecutionException e) { + assertEquals("Check cause", PrompterException.class, e.getCause().getClass()); } } @Test - public void testSnapshotDependenciesInProjectOnlyMismatchedVersion() - throws Exception - { + public void testSnapshotDependenciesInProjectOnlyMismatchedVersion() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "internal-differing-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("internal-differing-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotManagedDependenciesInProjectOnly() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "internal-managed-snapshot-dependency" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotManagedDependenciesInProjectOnly() throws Exception { + List reactorProjects = createDescriptorFromProjects("internal-managed-snapshot-dependency"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotUnusedInternalManagedDependency() - throws Exception - { + public void testSnapshotUnusedInternalManagedDependency() throws Exception { List reactorProjects = - createDescriptorFromProjects( "unused-internal-managed-snapshot-dependency" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + createDescriptorFromProjects("unused-internal-managed-snapshot-dependency"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotUnusedExternalManagedDependency() - throws Exception - { + public void testSnapshotUnusedExternalManagedDependency() throws Exception { List reactorProjects = - createDescriptorFromProjects( "unused-external-managed-snapshot-dependency" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + createDescriptorFromProjects("unused-external-managed-snapshot-dependency"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotExternalManagedDependency() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "external-managed-snapshot-dependency" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotExternalManagedDependency() throws Exception { + List reactorProjects = createDescriptorFromProjects("external-managed-snapshot-dependency"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - builder.setInteractive( false ); + builder.setInteractive(false); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotDependenciesOutsideProjectOnlyNonInteractive() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotDependenciesOutsideProjectOnlyNonInteractive() throws Exception { + List reactorProjects = createDescriptorFromProjects("external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - builder.setInteractive( false ); + builder.setInteractive(false); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testRangeSnapshotDependenciesOutsideProjectOnlyNonInteractive() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "external-range-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testRangeSnapshotDependenciesOutsideProjectOnlyNonInteractive() throws Exception { + List reactorProjects = createDescriptorFromProjects("external-range-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - builder.setInteractive( false ); + builder.setInteractive(false); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotDependenciesOutsideProjectOnlyInteractiveWithSnapshotsResolved() - throws Exception - { + public void testSnapshotDependenciesOutsideProjectOnlyInteractiveWithSnapshotsResolved() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.0", "1.1-SNAPSHOT" ), - new VersionPair( "1.0", "1.0" ) ) ); + phase.setPrompter(createMockPrompter( + YES, DEFAULT_CHOICE, new VersionPair("1.0", "1.1-SNAPSHOT"), new VersionPair("1.0", "1.0"))); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // validate - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId" ) ); - assertEquals( "1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) ); + assertEquals("1.0", descriptor.getDependencyReleaseVersion("external:artifactId")); + assertEquals("1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion("external:artifactId")); - builder = createReleaseDescriptorBuilder( reactorProjects ); + builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.0", "1.1-SNAPSHOT" ) ) ); + phase.setPrompter(createMockPrompter(YES, DEFAULT_CHOICE, new VersionPair("1.0", "1.1-SNAPSHOT"))); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); } @Test - public void testSnapshotDependenciesSelectOlderRelease() - throws Exception - { + public void testSnapshotDependenciesSelectOlderRelease() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "0.9", "1.0-SNAPSHOT" ), - new VersionPair( "1.0", "1.0-SNAPSHOT" ) ) ); + phase.setPrompter(createMockPrompter( + YES, DEFAULT_CHOICE, new VersionPair("0.9", "1.0-SNAPSHOT"), new VersionPair("1.0", "1.0-SNAPSHOT"))); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // validate - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "0.9", descriptor.getDependencyReleaseVersion( "external:artifactId" ) ); - assertEquals( "1.0-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) ); + assertEquals("0.9", descriptor.getDependencyReleaseVersion("external:artifactId")); + assertEquals("1.0-SNAPSHOT", descriptor.getDependencyDevelopmentVersion("external:artifactId")); } @Test - public void testSnapshotDependenciesSelectDefaults() - throws Exception - { + public void testSnapshotDependenciesSelectDefaults() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.0", "1.0" ) ) ); + phase.setPrompter(createMockPrompter(YES, DEFAULT_CHOICE, new VersionPair("1.0", "1.0"))); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // validate - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId" ) ); - assertEquals( "1.0", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) ); + assertEquals("1.0", descriptor.getDependencyReleaseVersion("external:artifactId")); + assertEquals("1.0", descriptor.getDependencyDevelopmentVersion("external:artifactId")); } @Test - public void testSnapshotDependenciesUpdateAllOnlyDependenciesNeeded() - throws Exception - { + public void testSnapshotDependenciesUpdateAllOnlyDependenciesNeeded() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createMockPrompter( YES, "0", new VersionPair( "1.0", "1.0" ) ) ); + phase.setPrompter(createMockPrompter(YES, "0", new VersionPair("1.0", "1.0"))); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // validate - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId" ) ); - assertEquals( "1.0", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) ); + assertEquals("1.0", descriptor.getDependencyReleaseVersion("external:artifactId")); + assertEquals("1.0", descriptor.getDependencyDevelopmentVersion("external:artifactId")); } @Test - public void testSnapshotDependenciesUpdateAll() - throws Exception - { + public void testSnapshotDependenciesUpdateAll() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-all" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-all"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - Prompter mockPrompter = - createMockPrompter( YES, "0", - Arrays.asList( new VersionPair( "1.0", "1.0" ), new VersionPair( "1.1", "1.1" ), - new VersionPair( "1.2", "1.2" ), new VersionPair( "1.3", "1.3" ) ) ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = createMockPrompter( + YES, + "0", + Arrays.asList( + new VersionPair("1.0", "1.0"), new VersionPair("1.1", "1.1"), + new VersionPair("1.2", "1.2"), new VersionPair("1.3", "1.3"))); + phase.setPrompter(mockPrompter); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // validate - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId" ) ); - assertEquals( "1.0", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) ); + assertEquals("1.0", descriptor.getDependencyReleaseVersion("external:artifactId")); + assertEquals("1.0", descriptor.getDependencyDevelopmentVersion("external:artifactId")); } // MRELEASE-589 @Test public void testSnapshotDependenciesOutsideMultimoduleProjectOnlyInteractiveWithSnapshotsResolved() - throws Exception - { + throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = - createDescriptorFromProjects( "multimodule-external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("multimodule-external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - VersionPair pair = new VersionPair( "1.0", "1.1-SNAPSHOT" ); - VersionPair defaultPair = new VersionPair( "1.0", "1.0" ); + VersionPair pair = new VersionPair("1.0", "1.1-SNAPSHOT"); + VersionPair defaultPair = new VersionPair("1.0", "1.0"); Prompter mockPrompter = - createMockPrompter( "yes", "1", Arrays.asList( pair, pair ), Arrays.asList( defaultPair, defaultPair ) ); - phase.setPrompter( mockPrompter ); + createMockPrompter("yes", "1", Arrays.asList(pair, pair), Arrays.asList(defaultPair, defaultPair)); + phase.setPrompter(mockPrompter); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId" ) ); - assertEquals( "1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) ); + assertEquals("1.0", descriptor.getDependencyReleaseVersion("external:artifactId")); + assertEquals("1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion("external:artifactId")); - assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId2" ) ); - assertEquals( "1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( "external:artifactId2" ) ); + assertEquals("1.0", descriptor.getDependencyReleaseVersion("external:artifactId2")); + assertEquals("1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion("external:artifactId2")); } @Test - public void testSnapshotDependenciesInsideAndOutsideProject() - throws Exception - { + public void testSnapshotDependenciesInsideAndOutsideProject() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); List reactorProjects = - createDescriptorFromProjects( "internal-and-external-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + createDescriptorFromProjects("internal-and-external-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testNoSnapshotReportPlugins() - throws Exception - { - ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();; - List reactorProjects = createDescriptorFromProjects( "no-snapshot-report-plugins" ); + public void testNoSnapshotReportPlugins() throws Exception { + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); + ; + List reactorProjects = createDescriptorFromProjects("no-snapshot-report-plugins"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotReportPluginsInProjectOnly() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "internal-snapshot-report-plugins" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotReportPluginsInProjectOnly() throws Exception { + List reactorProjects = createDescriptorFromProjects("internal-snapshot-report-plugins"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotReportPluginsOutsideProjectOnly() - throws Exception - { + public void testSnapshotReportPluginsOutsideProjectOnly() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-report-plugins" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-report-plugins"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotReportPluginsInsideAndOutsideProject() - throws Exception - { + public void testSnapshotReportPluginsInsideAndOutsideProject() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); List reactorProjects = - createDescriptorFromProjects( "internal-and-external-snapshot-report-plugins" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + createDescriptorFromProjects("internal-and-external-snapshot-report-plugins"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testNoSnapshotPlugins() - throws Exception - { - ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();; - List reactorProjects = createDescriptorFromProjects( "no-snapshot-plugins" ); + public void testNoSnapshotPlugins() throws Exception { + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); + ; + List reactorProjects = createDescriptorFromProjects("no-snapshot-plugins"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotPluginsInProjectOnly() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "internal-snapshot-plugins" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotPluginsInProjectOnly() throws Exception { + List reactorProjects = createDescriptorFromProjects("internal-snapshot-plugins"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotManagedPluginInProjectOnly() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "internal-managed-snapshot-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotManagedPluginInProjectOnly() throws Exception { + List reactorProjects = createDescriptorFromProjects("internal-managed-snapshot-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotUnusedInternalManagedPlugin() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "unused-internal-managed-snapshot-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotUnusedInternalManagedPlugin() throws Exception { + List reactorProjects = createDescriptorFromProjects("unused-internal-managed-snapshot-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotUnusedExternalManagedPlugin() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "unused-external-managed-snapshot-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotUnusedExternalManagedPlugin() throws Exception { + List reactorProjects = createDescriptorFromProjects("unused-external-managed-snapshot-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotExternalManagedPlugin() - throws Exception - { + public void testSnapshotExternalManagedPlugin() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-managed-snapshot-plugin" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-managed-snapshot-plugin"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotPluginsOutsideProjectOnly() - throws Exception - { + public void testSnapshotPluginsOutsideProjectOnly() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-plugins" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-plugins"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotPluginsInsideAndOutsideProject() - throws Exception - { + public void testSnapshotPluginsInsideAndOutsideProject() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "internal-and-external-snapshot-plugins" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("internal-and-external-snapshot-plugins"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotExternalParent() - throws Exception - { + public void testSnapshotExternalParent() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-parent/child" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-parent/child"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotExternalParentAdjusted() - throws Exception - { + public void testSnapshotExternalParentAdjusted() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-parent/child" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-parent/child"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - Prompter mockPrompter = createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.0-test", "1.0-test" ), - new VersionPair( "1.0", "1.0-test" ) ); - phase.setPrompter( mockPrompter ); + Prompter mockPrompter = createMockPrompter( + YES, DEFAULT_CHOICE, new VersionPair("1.0-test", "1.0-test"), new VersionPair("1.0", "1.0-test")); + phase.setPrompter(mockPrompter); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // validate - ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor(builder); - assertEquals( "1.0-test", descriptor.getDependencyReleaseVersion( "groupId:parent-external" ) ); - assertEquals( "1.0-test", descriptor.getDependencyDevelopmentVersion( "groupId:parent-external" ) ); + assertEquals("1.0-test", descriptor.getDependencyReleaseVersion("groupId:parent-external")); + assertEquals("1.0-test", descriptor.getDependencyDevelopmentVersion("groupId:parent-external")); } @Test - public void testReleaseExternalParent() - throws Exception - { - ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();; - List reactorProjects = createDescriptorFromProjects( "external-parent/child" ); + public void testReleaseExternalParent() throws Exception { + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); + ; + List reactorProjects = createDescriptorFromProjects("external-parent/child"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testSnapshotExternalExtension() - throws Exception - { + public void testSnapshotExternalExtension() throws Exception { CheckDependencySnapshotsPhase phase = - (CheckDependencySnapshotsPhase) lookup( ReleasePhase.class, "check-dependency-snapshots" ); + (CheckDependencySnapshotsPhase) lookup(ReleasePhase.class, "check-dependency-snapshots"); - List reactorProjects = createDescriptorFromProjects( "external-snapshot-extension" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + List reactorProjects = createDescriptorFromProjects("external-snapshot-extension"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - phase.setPrompter( createNoMockPrompter() ); + phase.setPrompter(createNoMockPrompter()); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSnapshotInternalExtension() - throws Exception - { - List reactorProjects = createDescriptorFromProjects( "internal-snapshot-extension" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testSnapshotInternalExtension() throws Exception { + List reactorProjects = createDescriptorFromProjects("internal-snapshot-extension"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testReleaseExternalExtension() - throws Exception - { - ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();; - List reactorProjects = createDescriptorFromProjects( "external-extension" ); + public void testReleaseExternalExtension() throws Exception { + ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); + ; + List reactorProjects = createDescriptorFromProjects("external-extension"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testAllowTimestampedSnapshots() - throws Exception - { - List reactorProjects = - createDescriptorFromProjects( "external-timestamped-snapshot-dependencies" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects ); + public void testAllowTimestampedSnapshots() throws Exception { + List reactorProjects = createDescriptorFromProjects("external-timestamped-snapshot-dependencies"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(reactorProjects); - builder.setInteractive( false ); + builder.setInteractive(false); // confirm POM fails without allowTimestampedSnapshots - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Should have failed execution" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed execution"); + } catch (ReleaseFailureException e) { + assertTrue(true); } // check whether flag allows - builder.setAllowTimestampedSnapshots( true ); + builder.setAllowTimestampedSnapshots(true); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } - private List createDescriptorFromProjects( String path ) - throws Exception - { - String dir = "check-dependencies/" + Objects.toString( path, "" ); - return createReactorProjects( dir, dir, null ); + private List createDescriptorFromProjects(String path) throws Exception { + String dir = "check-dependencies/" + Objects.toString(path, ""); + return createReactorProjects(dir, dir, null); } - private Prompter createNoMockPrompter() - throws PrompterException - { - return createYesNoMockPrompter( false ); + private Prompter createNoMockPrompter() throws PrompterException { + return createYesNoMockPrompter(false); } - private Prompter createYesMockPrompter() - throws PrompterException - { - return createYesNoMockPrompter( true ); + private Prompter createYesMockPrompter() throws PrompterException { + return createYesNoMockPrompter(true); } - private Prompter createYesNoMockPrompter( boolean yes ) - throws PrompterException - { - Prompter mockPrompter = mock( Prompter.class ); + private Prompter createYesNoMockPrompter(boolean yes) throws PrompterException { + Prompter mockPrompter = mock(Prompter.class); - when( mockPrompter.prompt( anyString(), eq( YES_NO_ARRAY ), eq( NO ) ) ).thenReturn( yes ? YES : NO ); + when(mockPrompter.prompt(anyString(), eq(YES_NO_ARRAY), eq(NO))).thenReturn(yes ? YES : NO); return mockPrompter; } - private Prompter createMockPrompterWithSnapshotReleasePlugin( String useSnapshotReleasePlugin, - String resolveSnapshots ) - throws PrompterException - { - Prompter mockPrompter = mock( Prompter.class ); + private Prompter createMockPrompterWithSnapshotReleasePlugin( + String useSnapshotReleasePlugin, String resolveSnapshots) throws PrompterException { + Prompter mockPrompter = mock(Prompter.class); - when( mockPrompter.prompt( anyString(), eq( YES_NO_ARRAY ), eq( NO ) ) ).thenReturn( useSnapshotReleasePlugin ); - when( mockPrompter.prompt( anyString(), eq( YES_NO_ARRAY ), eq( NO ) ) ).thenReturn( resolveSnapshots ); + when(mockPrompter.prompt(anyString(), eq(YES_NO_ARRAY), eq(NO))).thenReturn(useSnapshotReleasePlugin); + when(mockPrompter.prompt(anyString(), eq(YES_NO_ARRAY), eq(NO))).thenReturn(resolveSnapshots); return mockPrompter; } - private Prompter createMockPrompter( String resolveSnapshots, String resolutionType, VersionPair resolvedVersions ) - throws PrompterException - { - return createMockPrompter( resolveSnapshots, resolutionType, resolvedVersions, resolvedVersions ); + private Prompter createMockPrompter(String resolveSnapshots, String resolutionType, VersionPair resolvedVersions) + throws PrompterException { + return createMockPrompter(resolveSnapshots, resolutionType, resolvedVersions, resolvedVersions); } - private Prompter createMockPrompter( String resolveSnapshots, String resolutionType, VersionPair resolvedVersions, - VersionPair defaultVersions ) - throws PrompterException - { - return createMockPrompter( resolveSnapshots, resolutionType, Collections.singletonList( resolvedVersions ), - Collections.singletonList( defaultVersions ) ); + private Prompter createMockPrompter( + String resolveSnapshots, String resolutionType, VersionPair resolvedVersions, VersionPair defaultVersions) + throws PrompterException { + return createMockPrompter( + resolveSnapshots, + resolutionType, + Collections.singletonList(resolvedVersions), + Collections.singletonList(defaultVersions)); } - private Prompter createMockPrompter( String resolveSnapshots, String resolutionType, - List resolvedVersions ) - throws PrompterException - { - return createMockPrompter( resolveSnapshots, resolutionType, resolvedVersions, resolvedVersions ); + private Prompter createMockPrompter( + String resolveSnapshots, String resolutionType, List resolvedVersions) + throws PrompterException { + return createMockPrompter(resolveSnapshots, resolutionType, resolvedVersions, resolvedVersions); } - private Prompter createMockPrompter( String resolveSnapshots, String resolutionType, - List resolvedVersions, List defaultVersions ) - throws PrompterException - { - Prompter mockPrompter = mock( Prompter.class ); - - when( mockPrompter.prompt( anyString(), eq( YES_NO_ARRAY ), eq( NO ) ) ).thenReturn( resolveSnapshots ); - when( mockPrompter.prompt( anyString(), eq( CHOICE_ARRAY ), - eq( DEFAULT_CHOICE ) ) ).thenReturn( resolutionType ); - - for ( int i = 0; i < resolvedVersions.size(); i++ ) - { - when( mockPrompter.prompt( "Which release version should it be set to?", - defaultVersions.get( i ).releaseVersion ) ).thenReturn( resolvedVersions.get( i ).releaseVersion ); - when( mockPrompter.prompt( "What version should the dependency be reset to for development?", - defaultVersions.get( i ).developmentVersion ) ).thenReturn( resolvedVersions.get( i ).developmentVersion ); + private Prompter createMockPrompter( + String resolveSnapshots, + String resolutionType, + List resolvedVersions, + List defaultVersions) + throws PrompterException { + Prompter mockPrompter = mock(Prompter.class); + + when(mockPrompter.prompt(anyString(), eq(YES_NO_ARRAY), eq(NO))).thenReturn(resolveSnapshots); + when(mockPrompter.prompt(anyString(), eq(CHOICE_ARRAY), eq(DEFAULT_CHOICE))) + .thenReturn(resolutionType); + + for (int i = 0; i < resolvedVersions.size(); i++) { + when(mockPrompter.prompt( + "Which release version should it be set to?", defaultVersions.get(i).releaseVersion)) + .thenReturn(resolvedVersions.get(i).releaseVersion); + when(mockPrompter.prompt( + "What version should the dependency be reset to for development?", + defaultVersions.get(i).developmentVersion)) + .thenReturn(resolvedVersions.get(i).developmentVersion); } return mockPrompter; } - private static class VersionPair - { + private static class VersionPair { String releaseVersion; String developmentVersion; - public VersionPair( String releaseVersion, String developmentVersion ) - { + public VersionPair(String releaseVersion, String developmentVersion) { this.releaseVersion = releaseVersion; this.developmentVersion = developmentVersion; } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckPomPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckPomPhaseTest.java index c93ed59ca..4e3cbebf0 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckPomPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckPomPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,9 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; + +import java.util.Collections; import com.google.inject.Module; import org.apache.maven.model.Model; @@ -31,8 +32,6 @@ import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException; import org.junit.Test; -import java.util.Collections; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -42,207 +41,213 @@ * * @author Brett Porter */ -public class CheckPomPhaseTest - extends PlexusJUnit4TestCase -{ +public class CheckPomPhaseTest extends PlexusJUnit4TestCase { private ReleasePhase phase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "check-poms" ); + phase = lookup(ReleasePhase.class, "check-poms"); } @Override - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[0]; // real SCM needed } @Test - public void testCorrectlyConfigured() - throws Exception - { + public void testCorrectlyConfigured() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/repo" ); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/repo"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(createProject("1.0-SNAPSHOT"))); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) ); + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(createProject("1.0-SNAPSHOT"))); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testGetUrlFromProjectConnection() - throws Exception - { + public void testGetUrlFromProjectConnection() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/repo" ); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/repo"); - MavenProject project = createProject( "1.0-SNAPSHOT" ); + MavenProject project = createProject("1.0-SNAPSHOT"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( project ) ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(project)); - assertEquals( "Check URL", "scm:svn:file://localhost/tmp/repo", ReleaseUtils.buildReleaseDescriptor( builder ).getScmSourceUrl() ); + assertEquals( + "Check URL", + "scm:svn:file://localhost/tmp/repo", + ReleaseUtils.buildReleaseDescriptor(builder).getScmSourceUrl()); } @Test - public void testGetUrlFromProjectConnectionSimulate() - throws Exception - { + public void testGetUrlFromProjectConnectionSimulate() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/repo" ); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/repo"); - MavenProject project = createProject( "1.0-SNAPSHOT" ); + MavenProject project = createProject("1.0-SNAPSHOT"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( project ) ); + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(project)); - assertEquals( "Check URL", "scm:svn:file://localhost/tmp/repo", ReleaseUtils.buildReleaseDescriptor( builder ).getScmSourceUrl() ); + assertEquals( + "Check URL", + "scm:svn:file://localhost/tmp/repo", + ReleaseUtils.buildReleaseDescriptor(builder).getScmSourceUrl()); } @Test - public void testGetUrlFromProjectDevConnection() - throws Exception - { + public void testGetUrlFromProjectDevConnection() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:https://localhost/tmp/repo" ); + builder.setScmSourceUrl("scm:svn:https://localhost/tmp/repo"); - MavenProject project = createProject( "1.0-SNAPSHOT" ); + MavenProject project = createProject("1.0-SNAPSHOT"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( project ) ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(project)); - assertEquals( "Check URL", "scm:svn:https://localhost/tmp/repo", ReleaseUtils.buildReleaseDescriptor( builder ).getScmSourceUrl() ); + assertEquals( + "Check URL", + "scm:svn:https://localhost/tmp/repo", + ReleaseUtils.buildReleaseDescriptor(builder).getScmSourceUrl()); } @Test - public void testGetUrlFromProjectDevConnectionSimulate() - throws Exception - { + public void testGetUrlFromProjectDevConnectionSimulate() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:https://localhost/tmp/repo" ); + builder.setScmSourceUrl("scm:svn:https://localhost/tmp/repo"); - MavenProject project = createProject( "1.0-SNAPSHOT" ); + MavenProject project = createProject("1.0-SNAPSHOT"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( project ) ); + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(project)); - assertEquals( "Check URL", "scm:svn:https://localhost/tmp/repo", ReleaseUtils.buildReleaseDescriptor( builder ).getScmSourceUrl() ); + assertEquals( + "Check URL", + "scm:svn:https://localhost/tmp/repo", + ReleaseUtils.buildReleaseDescriptor(builder).getScmSourceUrl()); } @Test - public void testGetInvalidUrl() - throws Exception - { + public void testGetInvalidUrl() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:" ); + builder.setScmSourceUrl("scm:svn:"); - MavenProject project = createProject( "1.0-SNAPSHOT" ); + MavenProject project = createProject("1.0-SNAPSHOT"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( project ) ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(project)); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseScmRepositoryException e ) - { - assertTrue( true ); + fail("Should have thrown an exception"); + } catch (ReleaseScmRepositoryException e) { + assertTrue(true); } } @Test - public void testGetInvalidProvider() - throws Exception - { + public void testGetInvalidProvider() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - MavenProject project = createProject( "1.0-SNAPSHOT" ); + MavenProject project = createProject("1.0-SNAPSHOT"); Scm scm = new Scm(); - scm.setConnection( "scm:foo:" ); - project.setScm( scm ); - - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( project ) ); - - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + scm.setConnection("scm:foo:"); + project.setScm(scm); + + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(project)); + + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testMissingUrl() - throws Exception - { + public void testMissingUrl() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(createProject("1.0-SNAPSHOT"))); - fail( "Should have failed to execute" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed to execute"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0-SNAPSHOT" ) ) ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(createProject("1.0-SNAPSHOT"))); - fail( "Should have failed to simulate" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed to simulate"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testReleasingNonSnapshot() - throws Exception - { + public void testReleasingNonSnapshot() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/repo" ); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/repo"); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0" ) ) ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(createProject("1.0"))); - fail( "Should have failed to execute" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed to execute"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), Collections.singletonList( createProject( "1.0" ) ) ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + Collections.singletonList(createProject("1.0"))); - fail( "Should have failed to simulate" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Should have failed to simulate"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } - private static MavenProject createProject( String version ) - { + private static MavenProject createProject(String version) { Model model = new Model(); - model.setArtifactId( "artifactId" ); - model.setGroupId( "groupId" ); - model.setVersion( version ); + model.setArtifactId("artifactId"); + model.setGroupId("groupId"); + model.setVersion(version); - return new MavenProject( model ); + return new MavenProject(model); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java index 998a62354..01936b772 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CheckoutProjectFromScmTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,16 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.List; @@ -51,209 +40,216 @@ import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * @author Brett Porter */ -public class CheckoutProjectFromScmTest - extends AbstractReleaseTestCase -{ +public class CheckoutProjectFromScmTest extends AbstractReleaseTestCase { @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "checkout-project-from-scm" ); + phase = lookup(ReleasePhase.class, "checkout-project-from-scm"); } @Test - public void testExecuteStandard() - throws Exception - { + public void testExecuteStandard() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - File checkoutDirectory = getTestFile( "target/checkout-test/standard" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); + File checkoutDirectory = getTestFile("target/checkout-test/standard"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); String sourceUrl = "file://localhost/tmp/scm-repo/trunk"; String scmUrl = "scm:svn:" + sourceUrl; - builder.setScmSourceUrl( scmUrl ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - when( scmProviderMock.checkOut( eq( repository ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ), - argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) ) - .thenReturn( new CheckOutScmResult( "", null ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( scmUrl, repository ); + builder.setScmSourceUrl(scmUrl); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(sourceUrl); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + when(scmProviderMock.checkOut( + eq(repository), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + argThat(new IsScmTagEquals(new ScmTag("release-label"))), + argThat(new HasCommandParameter(CommandParameter.SHALLOW, true)))) + .thenReturn(new CheckOutScmResult("", null)); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl(scmUrl, repository); String dir = "scm-commit/single-pom"; - List reactorProjects = createReactorProjects( dir, dir, null ); - builder.setWorkingDirectory( getWorkingDirectory( dir ).toString() ); + List reactorProjects = createReactorProjects(dir, dir, null); + builder.setWorkingDirectory(getWorkingDirectory(dir).toString()); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // prepare - assertEquals( "", ReleaseUtils.buildReleaseDescriptor( builder ).getScmRelativePathProjectDirectory() ); - - verify( scmProviderMock ).checkOut( eq( repository ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ), - argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + assertEquals("", ReleaseUtils.buildReleaseDescriptor(builder).getScmRelativePathProjectDirectory()); + + verify(scmProviderMock) + .checkOut( + eq(repository), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + argThat(new IsScmTagEquals(new ScmTag("release-label"))), + argThat(new HasCommandParameter(CommandParameter.SHALLOW, true))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testExecuteMultiModuleWithDeepSubprojects() - throws Exception - { + public void testExecuteMultiModuleWithDeepSubprojects() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - File checkoutDirectory = getTestFile( "target/checkout-test/multimodule-with-deep-subprojects" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); + File checkoutDirectory = getTestFile("target/checkout-test/multimodule-with-deep-subprojects"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); String sourceUrl = "file://localhost/tmp/scm-repo/trunk"; String scmUrl = "scm:svn:" + sourceUrl; - builder.setScmSourceUrl( scmUrl ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - when( scmProviderMock.checkOut( eq( repository ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ), - argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) ) - .thenReturn( new CheckOutScmResult( "", null ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( scmUrl, repository ); + builder.setScmSourceUrl(scmUrl); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(sourceUrl); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + when(scmProviderMock.checkOut( + eq(repository), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + argThat(new IsScmTagEquals(new ScmTag("release-label"))), + argThat(new HasCommandParameter(CommandParameter.SHALLOW, true)))) + .thenReturn(new CheckOutScmResult("", null)); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl(scmUrl, repository); String dir = "scm-commit/multimodule-with-deep-subprojects"; - List reactorProjects = createReactorProjects( dir, dir, null ); - builder.setWorkingDirectory( getWorkingDirectory( dir ).toString() ); + List reactorProjects = createReactorProjects(dir, dir, null); + builder.setWorkingDirectory(getWorkingDirectory(dir).toString()); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "", ReleaseUtils.buildReleaseDescriptor( builder ).getScmRelativePathProjectDirectory() ); - - verify( scmProviderMock ).checkOut( eq( repository ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ), - argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + assertEquals("", ReleaseUtils.buildReleaseDescriptor(builder).getScmRelativePathProjectDirectory()); + + verify(scmProviderMock) + .checkOut( + eq(repository), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + argThat(new IsScmTagEquals(new ScmTag("release-label"))), + argThat(new HasCommandParameter(CommandParameter.SHALLOW, true))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testExecuteFlatMultiModule() - throws Exception - { + public void testExecuteFlatMultiModule() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - File checkoutDirectory = getTestFile( "target/checkout-test/flat-multi-module" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); + File checkoutDirectory = getTestFile("target/checkout-test/flat-multi-module"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); String sourceUrl = "file://localhost/tmp/scm-repo/trunk/root-project"; String scmUrl = "scm:svn:" + sourceUrl; - builder.setScmSourceUrl( scmUrl ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - when( scmProviderMock.checkOut( eq( repository ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ), - argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ) ) - .thenReturn( new CheckOutScmResult( "", null ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( scmUrl, repository ); + builder.setScmSourceUrl(scmUrl); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(sourceUrl); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + when(scmProviderMock.checkOut( + eq(repository), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + argThat(new IsScmTagEquals(new ScmTag("release-label"))), + argThat(new HasCommandParameter(CommandParameter.SHALLOW, true)))) + .thenReturn(new CheckOutScmResult("", null)); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl(scmUrl, repository); List reactorProjects = - createReactorProjects( "rewrite-for-release/pom-with-parent-flat", "root-project" ); - builder.setWorkingDirectory( getWorkingDirectory( "rewrite-for-release/pom-with-parent-flat" ) .toString() ); + createReactorProjects("rewrite-for-release/pom-with-parent-flat", "root-project"); + builder.setWorkingDirectory( + getWorkingDirectory("rewrite-for-release/pom-with-parent-flat").toString()); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "not found root-project but " + ReleaseUtils.buildReleaseDescriptor( builder ).getScmRelativePathProjectDirectory(), "root-project", - ReleaseUtils.buildReleaseDescriptor( builder ).getScmRelativePathProjectDirectory() ); - - verify( scmProviderMock ).checkOut( eq( repository ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - argThat( new IsScmTagEquals( new ScmTag( "release-label" ) ) ), - argThat( new HasCommandParameter( CommandParameter.SHALLOW, true ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + assertEquals( + "not found root-project but " + + ReleaseUtils.buildReleaseDescriptor(builder).getScmRelativePathProjectDirectory(), + "root-project", + ReleaseUtils.buildReleaseDescriptor(builder).getScmRelativePathProjectDirectory()); + + verify(scmProviderMock) + .checkOut( + eq(repository), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + argThat(new IsScmTagEquals(new ScmTag("release-label"))), + argThat(new HasCommandParameter(CommandParameter.SHALLOW, true))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testNoSuchScmProviderExceptionThrown() - throws Exception - { + public void testNoSuchScmProviderExceptionThrown() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new NoSuchScmProviderException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new NoSuchScmProviderException("...")); String dir = "scm-commit/single-pom"; - List reactorProjects = createReactorProjects( dir, dir, null ); + List reactorProjects = createReactorProjects(dir, dir, null); // execute - try - { - builder.setUseReleaseProfile( false ); - - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - - fail( "commit should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + try { + builder.setUseReleaseProfile(false); + + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + + fail("commit should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals( + "check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } } @Test - public void testScmRepositoryExceptionThrown() - throws Exception - { + public void testScmRepositoryExceptionThrown() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new ScmRepositoryException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new ScmRepositoryException("...")); String dir = "scm-commit/single-pom"; - List reactorProjects = createReactorProjects( dir, dir, null ); + List reactorProjects = createReactorProjects(dir, dir, null); // execute - try - { - builder.setUseReleaseProfile( false ); + try { + builder.setUseReleaseProfile(false); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "commit should have failed" ); - } - catch ( ReleaseScmRepositoryException e ) - { - assertNull( "Check no additional cause", e.getCause() ); + fail("commit should have failed"); + } catch (ReleaseScmRepositoryException e) { + assertNull("Check no additional cause", e.getCause()); } } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhaseTest.java index 44e43ee59..898d58e6e 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/CreateBackupPomsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.Iterator; @@ -31,105 +27,88 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Edwin Punzalan */ -public class CreateBackupPomsPhaseTest - extends AbstractBackupPomsPhaseTest -{ +public class CreateBackupPomsPhaseTest extends AbstractBackupPomsPhaseTest { @Override - ReleasePhase getReleasePhase() - throws Exception - { - return (ReleasePhase) lookup( ReleasePhase.class, "create-backup-poms" ); + ReleasePhase getReleasePhase() throws Exception { + return (ReleasePhase) lookup(ReleasePhase.class, "create-backup-poms"); } @Test - public void testBasicPom() - throws Exception - { + public void testBasicPom() throws Exception { String projectPath = "target/test-classes/projects/create-backup-poms/basic-pom"; // should create backup files - runExecuteOnProjects( projectPath ); + runExecuteOnProjects(projectPath); // should delete backup files - runCleanOnProjects( projectPath ); + runCleanOnProjects(projectPath); // should re-create backup files - runSimulateOnProjects( projectPath ); + runSimulateOnProjects(projectPath); } @Test - public void testMultiModulePom() - throws Exception - { + public void testMultiModulePom() throws Exception { String projectPath = "target/test-classes/projects/create-backup-poms/pom-with-modules"; // should create backup files - runExecuteOnProjects( projectPath ); + runExecuteOnProjects(projectPath); // should delete backup files - runCleanOnProjects( projectPath ); + runCleanOnProjects(projectPath); // should re-create backup files - runSimulateOnProjects( projectPath ); + runSimulateOnProjects(projectPath); } - private void runExecuteOnProjects( String path ) - throws Exception - { - List projects = getReactorProjects( getTestPath( path ) ); + private void runExecuteOnProjects(String path) throws Exception { + List projects = getReactorProjects(getTestPath(path)); - phase.execute( null, new DefaultReleaseEnvironment(), projects ); + phase.execute(null, new DefaultReleaseEnvironment(), projects); - testProjectBackups( projects, true ); + testProjectBackups(projects, true); } - private void runSimulateOnProjects( String path ) - throws Exception - { - List projects = getReactorProjects( getTestPath( path ) ); + private void runSimulateOnProjects(String path) throws Exception { + List projects = getReactorProjects(getTestPath(path)); - phase.simulate( null, new DefaultReleaseEnvironment(), projects ); + phase.simulate(null, new DefaultReleaseEnvironment(), projects); - testProjectBackups( projects, true ); + testProjectBackups(projects, true); } - private void runCleanOnProjects( String path ) - throws Exception - { - List projects = getReactorProjects( getTestPath( path ) ); + private void runCleanOnProjects(String path) throws Exception { + List projects = getReactorProjects(getTestPath(path)); - ( (ResourceGenerator) phase ).clean( projects ); + ((ResourceGenerator) phase).clean(projects); - testProjectBackups( projects, false ); + testProjectBackups(projects, false); } - protected void testProjectBackups( List reactorProjects, boolean created ) - throws Exception - { - for( Iterator projects = reactorProjects.iterator(); projects.hasNext(); ) - { + protected void testProjectBackups(List reactorProjects, boolean created) throws Exception { + for (Iterator projects = reactorProjects.iterator(); projects.hasNext(); ) { MavenProject project = projects.next(); File pomFile = project.getFile(); - File backupFile = new File( pomFile.getAbsolutePath() + releaseBackupSuffix ); + File backupFile = new File(pomFile.getAbsolutePath() + releaseBackupSuffix); - if ( created ) - { - assertTrue( "Check if backup file was created.", backupFile.exists() ); + if (created) { + assertTrue("Check if backup file was created.", backupFile.exists()); - String pomContents = ReleaseUtil.readXmlFile( pomFile ); + String pomContents = ReleaseUtil.readXmlFile(pomFile); - String backupContents = ReleaseUtil.readXmlFile( backupFile ); + String backupContents = ReleaseUtil.readXmlFile(backupFile); - assertTrue( "Check if pom and backup files are identical", pomContents.equals( backupContents ) ); - } - else - { - assertFalse( "Check if backup file is not present", backupFile.exists() ); + assertTrue("Check if pom and backup files are identical", pomContents.equals(backupContents)); + } else { + assertFalse("Check if backup file is not present", backupFile.exists()); } } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/EndReleasePhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/EndReleasePhaseTest.java index 990bd4144..fa8d36ed7 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/EndReleasePhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/EndReleasePhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; +package org.apache.maven.shared.release.phase; import org.apache.maven.shared.release.PlexusJUnit4TestCase; import org.apache.maven.shared.release.ReleaseExecutionException; @@ -30,40 +27,40 @@ import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; import org.junit.Test; +import static org.junit.Assert.assertEquals; + /** * Test the the end release phase. Nothing to see here really, but we want to make sure it is configured. * * @author Brett Porter */ -public class EndReleasePhaseTest - extends PlexusJUnit4TestCase -{ +public class EndReleasePhaseTest extends PlexusJUnit4TestCase { private ReleasePhase phase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "end-release" ); + phase = lookup(ReleasePhase.class, "end-release"); } @Test - public void testExecute() - throws ReleaseExecutionException, ReleaseFailureException - { - ReleaseResult result = phase.execute( ReleaseUtils.buildReleaseDescriptor( new ReleaseDescriptorBuilder() ), new DefaultReleaseEnvironment(), null ); + public void testExecute() throws ReleaseExecutionException, ReleaseFailureException { + ReleaseResult result = phase.execute( + ReleaseUtils.buildReleaseDescriptor(new ReleaseDescriptorBuilder()), + new DefaultReleaseEnvironment(), + null); - assertEquals( ReleaseResult.SUCCESS, result.getResultCode() ); + assertEquals(ReleaseResult.SUCCESS, result.getResultCode()); } @Test - public void testSimulate() - throws ReleaseExecutionException, ReleaseFailureException - { - ReleaseResult result = phase.simulate( ReleaseUtils.buildReleaseDescriptor( new ReleaseDescriptorBuilder() ), new DefaultReleaseEnvironment(), null ); + public void testSimulate() throws ReleaseExecutionException, ReleaseFailureException { + ReleaseResult result = phase.simulate( + ReleaseUtils.buildReleaseDescriptor(new ReleaseDescriptorBuilder()), + new DefaultReleaseEnvironment(), + null); - assertEquals( ReleaseResult.SUCCESS, result.getResultCode() ); + assertEquals(ReleaseResult.SUCCESS, result.getResultCode()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhaseTest.java index d269eae42..74ac15834 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/GenerateReleasePomsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,18 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import javax.inject.Singleton; -import static org.junit.Assert.assertTrue; - -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -56,58 +46,57 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the generate release POMs phase. * * @author Mark Hobson */ -public class GenerateReleasePomsPhaseTest - extends AbstractRewritingReleasePhaseTestCase -{ +public class GenerateReleasePomsPhaseTest extends AbstractRewritingReleasePhaseTestCase { private static final String NEXT_VERSION = "1.0"; private static final String ALTERNATIVE_NEXT_VERSION = "2.0"; private ScmProvider scmProviderMock; - public GenerateReleasePomsPhaseTest( String modelETL ) - { - super( modelETL ); + public GenerateReleasePomsPhaseTest(String modelETL) { + super(modelETL); } @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); scmProviderMock = null; } @Override - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[] { - new AbstractModule() - { - @Override - protected void configure() - { - bind( ScmManager.class ) - .to( org.apache.maven.shared.release.stubs.ScmManagerStub.class ) - .in( Singleton.class ); - bind( ScmTranslator.class ) - .annotatedWith( Names.named( "stub-provider" ) ) - .to( org.apache.maven.shared.release.scm.SubversionScmTranslator.class ) - .in( Singleton.class ); - } + new AbstractModule() { + @Override + protected void configure() { + bind(ScmManager.class) + .to(org.apache.maven.shared.release.stubs.ScmManagerStub.class) + .in(Singleton.class); + bind(ScmTranslator.class) + .annotatedWith(Names.named("stub-provider")) + .to(org.apache.maven.shared.release.scm.SubversionScmTranslator.class) + .in(Singleton.class); } + } }; } @Override - protected String getRoleHint() - { + protected String getRoleHint() { return "generate-release-poms"; } @@ -123,68 +112,61 @@ protected String getRoleHint() // } @Test - public void testRewriteExternalRangeDependency() - throws Exception - { - List reactorProjects = createReactorProjects( "external-range-dependency" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "external-range-dependency" ); + public void testRewriteExternalRangeDependency() throws Exception { + List reactorProjects = createReactorProjects("external-range-dependency"); + ReleaseDescriptorBuilder builder = createMappedConfiguration(reactorProjects, "external-range-dependency"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - comparePomFiles( reactorProjects ); + comparePomFiles(reactorProjects); } // MRELEASE-787 @Test - public void testSuppressCommitBeforeTagOrBranch() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); + public void testSuppressCommitBeforeTagOrBranch() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setGenerateReleasePoms( true ); - builder.setSuppressCommitBeforeTagOrBranch( true ); - builder.setRemoteTagging( false ); - builder.setPinExternals( false ); - mapNextVersion( builder, "groupId:artifactId" ); + builder.setGenerateReleasePoms(true); + builder.setSuppressCommitBeforeTagOrBranch(true); + builder.setRemoteTagging(false); + builder.setPinExternals(false); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - verify( scmProviderMock ).add( isA( ScmRepository.class ), isA( ScmFileSet.class ) ); + verify(scmProviderMock).add(isA(ScmRepository.class), isA(ScmFileSet.class)); - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSuppressCommitBeforeTagOrBranchAndReomoteTagging() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); + public void testSuppressCommitBeforeTagOrBranchAndReomoteTagging() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setGenerateReleasePoms( true ); - builder.setSuppressCommitBeforeTagOrBranch( true ); - builder.setRemoteTagging( true ); - builder.setPinExternals( false ); - mapNextVersion( builder, "groupId:artifactId" ); + builder.setGenerateReleasePoms(true); + builder.setSuppressCommitBeforeTagOrBranch(true); + builder.setRemoteTagging(true); + builder.setPinExternals(false); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - verify( scmProviderMock ).add( isA( ScmRepository.class ), isA( ScmFileSet.class ) ); + verify(scmProviderMock).add(isA(ScmRepository.class), isA(ScmFileSet.class)); - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } // MRELEASE-808 @Test - public void testFinalName() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-finalname" ); - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, "pom-with-finalname" ); - builder.setGenerateReleasePoms( true ); + public void testFinalName() throws Exception { + List reactorProjects = createReactorProjects("pom-with-finalname"); + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, "pom-with-finalname"); + builder.setGenerateReleasePoms(true); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } /* @@ -193,11 +175,11 @@ public void testFinalName() * util.List) */ @Override - protected ReleaseDescriptorBuilder createDescriptorFromProjects( List reactorProjects, String workingDirectory ) - { - ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects( reactorProjects, workingDirectory ); - builder.setScmReleaseLabel( "release-label" ); - builder.setGenerateReleasePoms( true ); + protected ReleaseDescriptorBuilder createDescriptorFromProjects( + List reactorProjects, String workingDirectory) { + ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects(reactorProjects, workingDirectory); + builder.setScmReleaseLabel("release-label"); + builder.setGenerateReleasePoms(true); return builder; } @@ -206,61 +188,54 @@ protected ReleaseDescriptorBuilder createDescriptorFromProjects( List prepareReactorProjects( String path ) - throws Exception - { + protected List prepareReactorProjects(String path) throws Exception { String dir = "generate-release-poms/" + path; - List reactorProjects = createReactorProjects( dir, dir, null ); + List reactorProjects = createReactorProjects(dir, dir, null); - scmProviderMock = mock( ScmProvider.class ); + scmProviderMock = mock(ScmProvider.class); List releasePoms = new ArrayList<>(); - for ( MavenProject project : reactorProjects ) - { - releasePoms.add( ReleaseUtil.getReleasePom( project ) ); + for (MavenProject project : reactorProjects) { + releasePoms.add(ReleaseUtil.getReleasePom(project)); } - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), releasePoms ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), releasePoms); - when( scmProviderMock.add( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ) ) ).thenReturn( new AddScmResult( "...", - Collections.singletonList( new ScmFile( "pom.xml", ScmFileStatus.ADDED ) ) ) ); + when(scmProviderMock.add(isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)))) + .thenReturn(new AddScmResult( + "...", Collections.singletonList(new ScmFile("pom.xml", ScmFileStatus.ADDED)))); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); return reactorProjects; } @Override - protected void verifyReactorProjects( String path, boolean copyFiles ) - throws Exception - { - String dir = "generate-release-poms/"+ path; - List reactorProjects = createReactorProjects( dir, dir, null ); + protected void verifyReactorProjects(String path, boolean copyFiles) throws Exception { + String dir = "generate-release-poms/" + path; + List reactorProjects = createReactorProjects(dir, dir, null); List releasePoms = new ArrayList<>(); - for ( Iterator iterator = reactorProjects.iterator(); iterator.hasNext(); ) - { + for (Iterator iterator = reactorProjects.iterator(); iterator.hasNext(); ) { MavenProject project = iterator.next(); - releasePoms.add( ReleaseUtil.getReleasePom( project ) ); + releasePoms.add(ReleaseUtil.getReleasePom(project)); } - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), releasePoms ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), releasePoms); - verify( scmProviderMock ).add( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock).add(isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet))); + verifyNoMoreInteractions(scmProviderMock); } @Override - protected void mapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, NEXT_VERSION ); + protected void mapNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, NEXT_VERSION); } /* @@ -269,9 +244,8 @@ protected void mapNextVersion( ReleaseDescriptorBuilder config, String projectId * maven.shared.release.config.ReleaseDescriptor, java.lang.String) */ @Override - protected void mapAlternateNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, ALTERNATIVE_NEXT_VERSION ); + protected void mapAlternateNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, ALTERNATIVE_NEXT_VERSION); } /* @@ -280,8 +254,7 @@ protected void mapAlternateNextVersion( ReleaseDescriptorBuilder config, String * shared.release.config.ReleaseDescriptor, java.lang.String) */ @Override - protected void unmapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { + protected void unmapNextVersion(ReleaseDescriptorBuilder config, String projectId) { // nothing to do } @@ -290,13 +263,12 @@ protected void unmapNextVersion( ReleaseDescriptorBuilder config, String project * createConfigurationForPomWithParentAlternateNextVersion(java.util.List) */ @Override - protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); return builder; } @@ -306,13 +278,12 @@ protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateN * createConfigurationForWithParentNextVersion(java.util.List) */ @Override - protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", NEXT_VERSION); return builder; } @@ -322,11 +293,8 @@ protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( * org.apache.maven.shared.release.phase.AbstractRewritingReleasePhaseTestCase#readTestProjectFile(java.lang.String) */ @Override - protected String readTestProjectFile( String fileName ) - throws IOException - { - return ReleaseUtil.readXmlFile( getTestFile( "target/test-classes/projects/generate-release-poms/" - + fileName ) ); + protected String readTestProjectFile(String fileName) throws IOException { + return ReleaseUtil.readXmlFile(getTestFile("target/test-classes/projects/generate-release-poms/" + fileName)); } /* @@ -336,13 +304,11 @@ protected String readTestProjectFile( String fileName ) */ // @Override @Override - protected void comparePomFiles( MavenProject project, String expectedFileSuffix, boolean normalizeLineEndings ) - throws IOException - { - File actualFile = ReleaseUtil.getReleasePom( project ); - File expectedFile = - new File( actualFile.getParentFile(), "expected-release-pom" + expectedFileSuffix + ".xml" ); - - comparePomFiles( expectedFile, actualFile, normalizeLineEndings, true ); + protected void comparePomFiles(MavenProject project, String expectedFileSuffix, boolean normalizeLineEndings) + throws IOException { + File actualFile = ReleaseUtil.getReleasePom(project); + File expectedFile = new File(actualFile.getParentFile(), "expected-release-pom" + expectedFileSuffix + ".xml"); + + comparePomFiles(expectedFile, actualFile, normalizeLineEndings, true); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/HasCommandParameter.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/HasCommandParameter.java index 99c02fa65..a9fe36613 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/HasCommandParameter.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/HasCommandParameter.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.scm.CommandParameter; import org.apache.maven.scm.CommandParameters; @@ -29,32 +28,24 @@ * * @author Michael Cramer */ -public class HasCommandParameter implements ArgumentMatcher -{ +public class HasCommandParameter implements ArgumentMatcher { private final CommandParameter commandParameter; private final Object expected; - public HasCommandParameter( CommandParameter commandParameter, Object expected ) - { + public HasCommandParameter(CommandParameter commandParameter, Object expected) { this.commandParameter = commandParameter; this.expected = expected; } @Override - public boolean matches( CommandParameters argument ) - { + public boolean matches(CommandParameters argument) { CommandParameters commandParameters = (CommandParameters) argument; - try - { - return commandParameters.getString( this.commandParameter ).equals( String.valueOf( expected ) ); - } - catch ( ScmException e ) - { + try { + return commandParameters.getString(this.commandParameter).equals(String.valueOf(expected)); + } catch (ScmException e) { return false; } } - - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/InputVariablesPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/InputVariablesPhaseTest.java index e4f093843..345337cd8 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/InputVariablesPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/InputVariablesPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,17 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.Collections; import java.util.List; @@ -47,14 +35,24 @@ import org.codehaus.plexus.components.interactivity.PrompterException; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the variable input phase. * * @author Brett Porter */ -public class InputVariablesPhaseTest - extends PlexusJUnit4TestCase -{ +public class InputVariablesPhaseTest extends PlexusJUnit4TestCase { private InputVariablesPhase phase; private ScmRepositoryConfigurator scmRepositoryConfigurator; @@ -62,334 +60,340 @@ public class InputVariablesPhaseTest private Map namingPolicies; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - scmRepositoryConfigurator = lookup( ScmRepositoryConfigurator.class ); - namingPolicies = lookupMap( NamingPolicy.class ); + scmRepositoryConfigurator = lookup(ScmRepositoryConfigurator.class); + namingPolicies = lookupMap(NamingPolicy.class); } @Test - public void testInputVariablesInteractive() - throws Exception - { + public void testInputVariablesInteractive() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - when( mockPrompter.prompt( isA( String.class ), eq( "artifactId-1.0" ) ) ).thenReturn( "tag-value", - "simulated-tag-value" ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + when(mockPrompter.prompt(isA(String.class), eq("artifactId-1.0"))) + .thenReturn("tag-value", "simulated-tag-value"); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); - verify( mockPrompter, times( 2 ) ).prompt( isA( String.class ), eq( "artifactId-1.0" ) ); - verifyNoMoreInteractions( mockPrompter ); + verify(mockPrompter, times(2)).prompt(isA(String.class), eq("artifactId-1.0")); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testUnmappedVersion() - throws Exception - { - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + public void testUnmappedVersion() throws Exception { + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertNull( "check no cause", e.getCause() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertNull("check no cause", e.getCause()); } builder = new ReleaseDescriptorBuilder(); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertNull( "check no cause", e.getCause() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertNull("check no cause", e.getCause()); } } @Test - public void testInputVariablesNonInteractive() - throws Exception - { + public void testInputVariablesNonInteractive() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.setInteractive(false); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "artifactId-1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "artifactId-1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.setInteractive(false); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "artifactId-1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "artifactId-1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testInputVariablesNonInteractiveConfigured() - throws Exception - { + public void testInputVariablesNonInteractiveConfigured() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setScmReleaseLabel( "tag-value" ); + builder.setInteractive(false); + builder.setScmReleaseLabel("tag-value"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setScmReleaseLabel( "simulated-tag-value" ); + builder.setInteractive(false); + builder.setScmReleaseLabel("simulated-tag-value"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testInputVariablesInteractiveConfigured() - throws Exception - { + public void testInputVariablesInteractiveConfigured() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "tag-value" ); + builder.setScmReleaseLabel("tag-value"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "simulated-tag-value" ); + builder.setScmReleaseLabel("simulated-tag-value"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-tag-value", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-tag-value", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testPrompterException() - throws Exception - { + public void testPrompterException() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - when( mockPrompter.prompt( isA( String.class ), - isA( String.class ) ) ).thenThrow( new PrompterException( "..." ) ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + when(mockPrompter.prompt(isA(String.class), isA(String.class))).thenThrow(new PrompterException("...")); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", PrompterException.class, e.getCause().getClass() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", PrompterException.class, e.getCause().getClass()); } // prepare builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", PrompterException.class, e.getCause().getClass() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", PrompterException.class, e.getCause().getClass()); } // verify - verify( mockPrompter, times( 2 ) ).prompt( isA( String.class ), isA( String.class ) ); - verifyNoMoreInteractions( mockPrompter ); + verify(mockPrompter, times(2)).prompt(isA(String.class), isA(String.class)); + verifyNoMoreInteractions(mockPrompter); } // MRELEASE-110 @Test - public void testSvnTag() - throws Exception - { + public void testSvnTag() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:svn://localhost/repo" ); + builder.setInteractive(false); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:svn://localhost/repo"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "artifactId-1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "artifactId-1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:svn://localhost/repo" ); + builder.setInteractive(false); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:svn://localhost/repo"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "artifactId-1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "artifactId-1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } // MRELEASE-159 @Test - public void testCustomTagFormat() - throws Exception - { + public void testCustomTagFormat() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + builder.setInteractive(false); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "artifactId-1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "artifactId-1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addReleaseVersion( "groupId:artifactId", "1.0" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); - builder.setScmTagNameFormat( "simulated-@{artifactId}-@{version}" ); + builder.setInteractive(false); + builder.addReleaseVersion("groupId:artifactId", "1.0"); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); + builder.setScmTagNameFormat("simulated-@{artifactId}-@{version}"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check tag", "simulated-artifactId-1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getScmReleaseLabel() ); + assertEquals( + "Check tag", + "simulated-artifactId-1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getScmReleaseLabel()); // never use prompter - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testBranchOperation() - throws Exception - { + public void testBranchOperation() throws Exception { // prepare - Prompter mockPrompter = mock( Prompter.class ); - phase = new InputVariablesPhase( mockPrompter, scmRepositoryConfigurator, namingPolicies ); - assertFalse( phase.isBranchOperation() ); + Prompter mockPrompter = mock(Prompter.class); + phase = new InputVariablesPhase(mockPrompter, scmRepositoryConfigurator, namingPolicies); + assertFalse(phase.isBranchOperation()); } - private static MavenProject createProject( String artifactId, String version ) - { + private static MavenProject createProject(String artifactId, String version) { Model model = new Model(); - model.setGroupId( "groupId" ); - model.setArtifactId( artifactId ); - model.setVersion( version ); - return new MavenProject( model ); + model.setGroupId("groupId"); + model.setArtifactId(artifactId); + model.setVersion(version); + return new MavenProject(model); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchEquals.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchEquals.java index 31404a85f..c7e2b8393 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchEquals.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchEquals.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.scm.ScmBranch; import org.mockito.ArgumentMatcher; @@ -27,20 +26,17 @@ * * @author Brett Porter */ -public class IsScmBranchEquals implements ArgumentMatcher -{ +public class IsScmBranchEquals implements ArgumentMatcher { private final ScmBranch branch; - public IsScmBranchEquals( ScmBranch branch ) - { + public IsScmBranchEquals(ScmBranch branch) { this.branch = branch; } @Override - public boolean matches( ScmBranch argument ) - { + public boolean matches(ScmBranch argument) { ScmBranch sb = (ScmBranch) argument; - return sb.getName().equals( this.branch.getName() ); + return sb.getName().equals(this.branch.getName()); } -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchParametersEquals.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchParametersEquals.java index e6aea940f..104bf3562 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchParametersEquals.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmBranchParametersEquals.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,31 +16,28 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.scm.ScmBranchParameters; - import org.mockito.ArgumentMatcher; /** * Mockito constraint to compare tags since it has no equals method. - * + * * @author olamy */ -public class IsScmBranchParametersEquals implements ArgumentMatcher -{ +public class IsScmBranchParametersEquals implements ArgumentMatcher { private final ScmBranchParameters scmBranchParameters; - public IsScmBranchParametersEquals( ScmBranchParameters scmBranchParameters ) - { + public IsScmBranchParametersEquals(ScmBranchParameters scmBranchParameters) { this.scmBranchParameters = scmBranchParameters; } @Override - public boolean matches( ScmBranchParameters argument ) - { + public boolean matches(ScmBranchParameters argument) { ScmBranchParameters sbp = (ScmBranchParameters) argument; - return sbp.getMessage().equals( this.scmBranchParameters.getMessage() ) - && sbp.isRemoteBranching() == this.scmBranchParameters.isRemoteBranching() - && sbp.isPinExternals() == this.scmBranchParameters.isPinExternals(); + return sbp.getMessage().equals(this.scmBranchParameters.getMessage()) + && sbp.isRemoteBranching() == this.scmBranchParameters.isRemoteBranching() + && sbp.isPinExternals() == this.scmBranchParameters.isPinExternals(); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmFileSetEquals.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmFileSetEquals.java index 6f0a6b35f..d966c98fa 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmFileSetEquals.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmFileSetEquals.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.io.IOException; @@ -29,31 +28,25 @@ * * @author Brett Porter */ -public class IsScmFileSetEquals implements ArgumentMatcher -{ +public class IsScmFileSetEquals implements ArgumentMatcher { private final ScmFileSet fileSet; - public IsScmFileSetEquals( ScmFileSet fileSet ) - { + public IsScmFileSetEquals(ScmFileSet fileSet) { this.fileSet = fileSet; } @Override - public boolean matches( ScmFileSet argument ) - { + public boolean matches(ScmFileSet argument) { ScmFileSet fs = (ScmFileSet) argument; - try - { - return fs.getBasedir().getCanonicalPath().equals( fileSet.getBasedir().getCanonicalPath() ) - && fs.getFileList().equals( fileSet.getFileList() ); - } - catch ( IOException e ) - { + try { + return fs.getBasedir() + .getCanonicalPath() + .equals(fileSet.getBasedir().getCanonicalPath()) + && fs.getFileList().equals(fileSet.getFileList()); + } catch (IOException e) { // should not happened so RuntimeException throw new RuntimeException(e.getMessage(), e); } } - - -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagEquals.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagEquals.java index 6affb41f8..4e214c51a 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagEquals.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagEquals.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.scm.ScmTag; import org.mockito.ArgumentMatcher; @@ -27,22 +26,17 @@ * * @author Brett Porter */ -public class IsScmTagEquals implements ArgumentMatcher -{ +public class IsScmTagEquals implements ArgumentMatcher { private final ScmTag tag; - public IsScmTagEquals( ScmTag tag ) - { + public IsScmTagEquals(ScmTag tag) { this.tag = tag; } @Override - public boolean matches( ScmTag argument ) - { + public boolean matches(ScmTag argument) { ScmTag tag = (ScmTag) argument; - return tag.getName().equals( this.tag.getName() ); + return tag.getName().equals(this.tag.getName()); } - - -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagParametersEquals.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagParametersEquals.java index 629f7d63d..267e7493e 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagParametersEquals.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/IsScmTagParametersEquals.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,31 +16,29 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import org.apache.maven.scm.ScmTagParameters; import org.mockito.ArgumentMatcher; /** * Mockito constraint to compare tags since it has no equals method. - * + * * @author olamy */ -public class IsScmTagParametersEquals implements ArgumentMatcher -{ +public class IsScmTagParametersEquals implements ArgumentMatcher { private final ScmTagParameters scmTagParameters; - public IsScmTagParametersEquals( ScmTagParameters scmTagParameters ) - { + public IsScmTagParametersEquals(ScmTagParameters scmTagParameters) { this.scmTagParameters = scmTagParameters; } @Override - public boolean matches( ScmTagParameters argument ) - { + public boolean matches(ScmTagParameters argument) { ScmTagParameters stp = (ScmTagParameters) argument; - return stp.getMessage().equals( this.scmTagParameters.getMessage() ) - && stp.isRemoteTagging() == this.scmTagParameters.isRemoteTagging() - && stp.isPinExternals() == this.scmTagParameters.isPinExternals() - && stp.isSign() == this.scmTagParameters.isSign(); + return stp.getMessage().equals(this.scmTagParameters.getMessage()) + && stp.isRemoteTagging() == this.scmTagParameters.isRemoteTagging() + && stp.isPinExternals() == this.scmTagParameters.isPinExternals() + && stp.isSign() == this.scmTagParameters.isSign(); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java index d8943dc6b..6088a9b8f 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapDevelopmentVersionPhaseIT.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; import java.util.Collections; import java.util.List; @@ -32,38 +31,35 @@ import static org.junit.Assert.assertEquals; -public class MapDevelopmentVersionPhaseIT - extends PlexusJUnit4TestCase -{ +public class MapDevelopmentVersionPhaseIT extends PlexusJUnit4TestCase { private MapDevelopmentVersionsPhase mapDevelopmentVersionsPhase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - mapDevelopmentVersionsPhase = (MapDevelopmentVersionsPhase) lookup( ReleasePhase.class, "map-development-versions" ); + mapDevelopmentVersionsPhase = + (MapDevelopmentVersionsPhase) lookup(ReleasePhase.class, "map-development-versions"); } - private static MavenProject createProject( String artifactId, String version ) - { + private static MavenProject createProject(String artifactId, String version) { Model model = new Model(); - model.setGroupId( "groupId" ); - model.setArtifactId( artifactId ); - model.setVersion( version ); - return new MavenProject( model ); + model.setGroupId("groupId"); + model.setArtifactId(artifactId); + model.setVersion(version); + return new MavenProject(model); } @Test - public void testNoUpdateWorkingCopyVersions() throws Exception - { + public void testNoUpdateWorkingCopyVersions() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.setUpdateWorkingCopyVersions( false ); + builder.setInteractive(false); + builder.setUpdateWorkingCopyVersions(false); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); - mapDevelopmentVersionsPhase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); + mapDevelopmentVersionsPhase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertEquals( "1.0", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "1.0", ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java index 804a7629f..36baf5df2 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/MapVersionsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,19 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.startsWith; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.ArrayList; import java.util.Arrays; @@ -56,14 +42,25 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the version mapping phase. * * @author Brett Porter */ -public class MapVersionsPhaseTest - extends PlexusJUnit4TestCase -{ +public class MapVersionsPhaseTest extends PlexusJUnit4TestCase { @Mock private ScmRepositoryConfigurator scmRepositoryConfigurator; @@ -73,187 +70,194 @@ public class MapVersionsPhaseTest private Map versionPolicies; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - MockitoAnnotations.initMocks( this ); - versionPolicies = lookupMap( VersionPolicy.class ); + MockitoAnnotations.initMocks(this); + versionPolicies = lookupMap(VersionPolicy.class); } @Override - public void tearDown() - throws Exception - { + public void tearDown() throws Exception { super.tearDown(); - verifyNoMoreInteractions( mockPrompter ); + verifyNoMoreInteractions(mockPrompter); } @Test - public void testExecuteSnapshot_MapRelease() - throws Exception - { + public void testExecuteSnapshot_MapRelease() throws Exception { // prepare - MavenProject project = createProject( "artifactId", "1.0-SNAPSHOT" ); - when( mockPrompter.prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ) ).thenReturn( "2.0" ); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MavenProject project = createProject("artifactId", "1.0-SNAPSHOT"); + when(mockPrompter.prompt( + startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0"))) + .thenReturn("2.0"); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); - verify( mockPrompter ).prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ); + verify(mockPrompter) + .prompt(startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0")); } @Test - public void testSimulateSnapshot_MapReleaseVersions() - throws Exception - { + public void testSimulateSnapshot_MapReleaseVersions() throws Exception { // prepare - MavenProject project = createProject( "artifactId", "1.0-SNAPSHOT" ); - when( mockPrompter.prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ) ).thenReturn( "2.0" ); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MavenProject project = createProject("artifactId", "1.0-SNAPSHOT"); + when(mockPrompter.prompt( + startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0"))) + .thenReturn("2.0"); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - verify( mockPrompter ).prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + verify(mockPrompter) + .prompt(startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0")); } // MRELEASE-403: Release plugin ignores given version number @Test - public void testMapReleaseVersionsInteractiveAddZeroIncremental() - throws Exception - { + public void testMapReleaseVersionsInteractiveAddZeroIncremental() throws Exception { // prepare - MavenProject project = createProject( "artifactId", "1.0-SNAPSHOT" ); - when( mockPrompter.prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ) ).thenReturn( "1.0.0" ); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MavenProject project = createProject("artifactId", "1.0-SNAPSHOT"); + when(mockPrompter.prompt( + startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0"))) + .thenReturn("1.0.0"); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check mapped versions", + "1.0.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - verify( mockPrompter, - times( 2 ) ).prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ); + assertEquals( + "Check mapped versions", + "1.0.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + verify(mockPrompter, times(2)) + .prompt(startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0")); } /** * Test to release "SNAPSHOT" version MRELEASE-90 */ @Test - public void testMapReleaseVersionsInteractiveWithSnaphotVersion() - throws Exception - { + public void testMapReleaseVersionsInteractiveWithSnaphotVersion() throws Exception { // prepare - MavenProject project = createProject( "artifactId", "SNAPSHOT" ); - when( mockPrompter.prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ) ).thenReturn( "2.0" ); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MavenProject project = createProject("artifactId", "SNAPSHOT"); + when(mockPrompter.prompt( + startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0"))) + .thenReturn("2.0"); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); - verify( mockPrompter, - times( 2 ) ).prompt( startsWith( "What is the release version for \"" + project.getName() + "\"?" ), - eq( "1.0" ) ); + verify(mockPrompter, times(2)) + .prompt(startsWith("What is the release version for \"" + project.getName() + "\"?"), eq("1.0")); } /** * MRELEASE-524: ignores commandline versions in batch mode */ @Test - public void testMapReleaseVersionsNonInteractiveWithExplicitVersion() - throws Exception - { + public void testMapReleaseVersionsNonInteractiveWithExplicitVersion() throws Exception { // prepare - List reactorProjects = Collections.singletonList( createProject( "artifactId", "SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "SNAPSHOT")); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "2.0" ); + builder.addReleaseVersion("groupId:artifactId", "2.0"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); - builder.addReleaseVersion( "groupId:artifactId", "2.0" ); + builder.addReleaseVersion("groupId:artifactId", "2.0"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } /** * MRELEASE-1022: don't ignore command line (or release.properties) versions when auto-versioning sub-modules */ @Test - public void testMapReleaseVersionsForSubModuleWithExplicitVersion() - throws Exception - { + public void testMapReleaseVersionsForSubModuleWithExplicitVersion() throws Exception { // prepare MavenProject rootProject = createProject("rootArtifactId", "SNAPSHOT"); rootProject.setExecutionRoot(true); @@ -261,41 +265,48 @@ public void testMapReleaseVersionsForSubModuleWithExplicitVersion() final MavenProject moduleProject = createProject("artifactId", "SNAPSHOT"); moduleProject.setParent(rootProject); - List reactorProjects = Arrays.asList( rootProject, moduleProject ); + List reactorProjects = Arrays.asList(rootProject, moduleProject); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder() - .setInteractive(false) // batch mode - .setAutoVersionSubmodules( true ) - .addReleaseVersion( "groupId:artifactId", "2.0" ); + .setInteractive(false) // batch mode + .setAutoVersionSubmodules(true) + .addReleaseVersion("groupId:artifactId", "2.0"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:rootArtifactId") ); - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:rootArtifactId")); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:rootArtifactId") ); - assertEquals( "Check mapped versions", "2.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:rootArtifactId")); + assertEquals( + "Check mapped versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } /** * MRELEASE-1022: don't ignore command line (or release.properties) versions when auto-versioning sub-modules */ @Test - public void testMapDevelopmentVersionsForSubModuleWithExplicitVersion() - throws Exception - { + public void testMapDevelopmentVersionsForSubModuleWithExplicitVersion() throws Exception { // prepare MavenProject rootProject = createProject("rootArtifactId", "1.0"); rootProject.setExecutionRoot(true); @@ -303,925 +314,1028 @@ public void testMapDevelopmentVersionsForSubModuleWithExplicitVersion() final MavenProject moduleProject = createProject("artifactId", "1.0"); moduleProject.setParent(rootProject); - List reactorProjects = Arrays.asList( rootProject, moduleProject ); + List reactorProjects = Arrays.asList(rootProject, moduleProject); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder() - .setInteractive( false ) // batch mode - .setAutoVersionSubmodules( true ) - .setDefaultDevelopmentVersion( "1.1-SNAPSHOT" ) - .addDevelopmentVersion( "groupId:artifactId", "2.0-SNAPSHOT" ); + .setInteractive(false) // batch mode + .setAutoVersionSubmodules(true) + .setDefaultDevelopmentVersion("1.1-SNAPSHOT") + .addDevelopmentVersion("groupId:artifactId", "2.0-SNAPSHOT"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:rootArtifactId") ); - assertEquals( "Check mapped versions", "2.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:rootArtifactId")); + assertEquals( + "Check mapped versions", + "2.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:rootArtifactId") ); - assertEquals( "Check mapped versions", "2.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:rootArtifactId")); + assertEquals( + "Check mapped versions", + "2.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotNonInteractive_MapRelease() - throws Exception - { + public void testExecuteSnapshotNonInteractive_MapRelease() throws Exception { // prepare - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotNonInteractive_MapReleaseVersions() - throws Exception - { + public void testSimulateSnapshotNonInteractive_MapReleaseVersions() throws Exception { // prepare - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testMapDevVersionsInteractive() - throws Exception - { + public void testMapDevVersionsInteractive() throws Exception { // prepare - MavenProject project = createProject( "artifactId", "1.0" ); - when( mockPrompter.prompt( startsWith( "What is the new development version for \"" + project.getName() - + "\"?" ), eq( "1.1-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MavenProject project = createProject("artifactId", "1.0"); + when(mockPrompter.prompt( + startsWith("What is the new development version for \"" + project.getName() + "\"?"), + eq("1.1-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); - verify( mockPrompter, times( 2 ) ).prompt( startsWith( "What is the new development version for \"" - + project.getName() + "\"?" ), eq( "1.1-SNAPSHOT" ) ); + verify(mockPrompter, times(2)) + .prompt( + startsWith("What is the new development version for \"" + project.getName() + "\"?"), + eq("1.1-SNAPSHOT")); } /** * MRELEASE-760: updateWorkingCopyVersions=false still bumps up pom versions to next development version */ @Test - public void testMapDevVersionsInteractiveDoNotUpdateWorkingCopy() - throws Exception - { + public void testMapDevVersionsInteractiveDoNotUpdateWorkingCopy() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); - MavenProject project = createProject( "artifactId", "1.0" ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); + MavenProject project = createProject("artifactId", "1.0"); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setUpdateWorkingCopyVersions( false ); + builder.setUpdateWorkingCopyVersions(false); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setUpdateWorkingCopyVersions( false ); + builder.setUpdateWorkingCopyVersions(false); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.0" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testMapDevVersionsNonInteractive() - throws Exception - { + public void testMapDevVersionsNonInteractive() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "1.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } /** * MRELEASE-524: ignores commandline versions in batch mode */ @Test - public void testMapDevVersionsNonInteractiveWithExplicitVersion() - throws Exception - { + public void testMapDevVersionsNonInteractiveWithExplicitVersion() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addDevelopmentVersion( "groupId:artifactId", "2-SNAPSHOT" ); + builder.setInteractive(false); + builder.addDevelopmentVersion("groupId:artifactId", "2-SNAPSHOT"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); - builder.addDevelopmentVersion( "groupId:artifactId", "2-SNAPSHOT" ); + builder.setInteractive(false); + builder.addDevelopmentVersion("groupId:artifactId", "2-SNAPSHOT"); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testPrompterException() - throws Exception - { + public void testPrompterException() throws Exception { // prepare - when( mockPrompter.prompt( isA( String.class ), - isA( String.class ) ) ).thenThrow( new PrompterException( "..." ) ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(isA(String.class), isA(String.class))).thenThrow(new PrompterException("...")); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", PrompterException.class, e.getCause().getClass() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", PrompterException.class, e.getCause().getClass()); } // prepare builder = new ReleaseDescriptorBuilder(); // execute - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", PrompterException.class, e.getCause().getClass() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", PrompterException.class, e.getCause().getClass()); } // verify - verify( mockPrompter, times( 2 ) ).prompt( isA( String.class ), isA( String.class ) ); + verify(mockPrompter, times(2)).prompt(isA(String.class), isA(String.class)); } @Test - public void testAdjustVersionInteractive() - throws Exception - { + public void testAdjustVersionInteractive() throws Exception { // prepare - MavenProject project = createProject( "artifactId", "foo" ); + MavenProject project = createProject("artifactId", "foo"); - when( mockPrompter.prompt( startsWith( "What is the new development version for \"" + project.getName() - + "\"?" ), eq( "1.1-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt( + startsWith("What is the new development version for \"" + project.getName() + "\"?"), + eq("1.1-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( project ); + List reactorProjects = Collections.singletonList(project); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); // prepare builder = new ReleaseDescriptorBuilder(); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check mapped versions", "2.0-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertEquals( + "Check mapped versions", + "2.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); - verify( mockPrompter, times( 2 ) ).prompt( startsWith( "What is the new development version for \"" - + project.getName() + "\"?" ), eq( "1.1-SNAPSHOT" ) ); + verify(mockPrompter, times(2)) + .prompt( + startsWith("What is the new development version for \"" + project.getName() + "\"?"), + eq("1.1-SNAPSHOT")); } @Test - public void testAdjustVersionNonInteractive() - { - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + public void testAdjustVersionNonInteractive() { + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "foo" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "foo")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", VersionParseException.class, e.getCause().getClass() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "check cause", VersionParseException.class, e.getCause().getClass()); } builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Expected an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", VersionParseException.class, e.getCause().getClass() ); + fail("Expected an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "check cause", VersionParseException.class, e.getCause().getClass()); } } @Test - public void testExecuteSnapshotBranchCreation_DefaultDevelopmentVersion_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotBranchCreation_DefaultDevelopmentVersion_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); + builder.setBranchCreation(true); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotBranchCreation_DefaultDevelopmentVersion_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotBranchCreation_DefaultDevelopmentVersion_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); + builder.setBranchCreation(true); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testExecuteSnapshotBranchCreation_DefaultDevelopmentVersion_NonInteractive_MapDevelopment() - throws Exception - { + throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setBranchCreation(true); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testSimulateSnapshotBranchCreation_DefaultDevelopmentVersion_NonInteractive_MapDevelopment() - throws Exception - { + throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setBranchCreation(true); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotBranchCreation_NonInteractive_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotBranchCreation_NonInteractive_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.3-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotBranchCreation_NonInteractive_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotBranchCreation_NonInteractive_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.3-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotDefaultDevelopmentVersion_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotDefaultDevelopmentVersion_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotDefaultDevelopmentVersion_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotDefaultDevelopmentVersion_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotDefaultDevelopmentVersion_NonInteractive_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotDefaultDevelopmentVersion_NonInteractive_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotDefaultDevelopmentVersion_NonInteractive_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotDefaultDevelopmentVersion_NonInteractive_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultDevelopmentVersion( "1.1.1-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setDefaultDevelopmentVersion("1.1.1-SNAPSHOT"); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.1.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.1.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotNonInteractive_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotNonInteractive_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.3-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotNonInteractive_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotNonInteractive_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setInteractive( false ); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotAutoVersionSubmodules_NotInteractive_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotAutoVersionSubmodules_NotInteractive_MapDevelopment() throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotAutoVersionSubmodules_NotInteractive_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotAutoVersionSubmodules_NotInteractive_MapDevelopment() throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testExecuteReleaseAutoVersionSubmodules_NotInteractive_MapDevelopment() - throws Exception - { + public void testExecuteReleaseAutoVersionSubmodules_NotInteractive_MapDevelopment() throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseAutoVersionSubmodules_NotInteractive_MapDevelopment() - throws Exception - { + public void testSimulateReleaseAutoVersionSubmodules_NotInteractive_MapDevelopment() throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotAutoVersionSubmodules_NotInteractive_MapRelease() - throws Exception - { + public void testExecuteSnapshotAutoVersionSubmodules_NotInteractive_MapRelease() throws Exception { // verify - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotAutoVersionSubmodules_NotInteractive_MapRelease() - throws Exception - { + public void testSimulateSnapshotAutoVersionSubmodules_NotInteractive_MapRelease() throws Exception { // verify - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteReleaseAutoVersionSubmodules_NotInteractive_MapRelease() - throws Exception - { + public void testExecuteReleaseAutoVersionSubmodules_NotInteractive_MapRelease() throws Exception { // verify - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseAutoVersionSubmodules_NotInteractive_MapRelease() - throws Exception - { + public void testSimulateReleaseAutoVersionSubmodules_NotInteractive_MapRelease() throws Exception { // verify - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testExecuteSnapshotAutoVersionSubmodules_BranchCreation_NotInteractive_MapDevelopment() - throws Exception - { + throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test public void testSimulateSnapshotAutoVersionSubmodules_BranchCreation_NotInteractive_MapDevelopment() - throws Exception - { + throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test public void testExecuteReleaseAutoVersionSubmodules_BranchCreation_NotInteractive_MapDevelopment() - throws Exception - { + throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test public void testSimulateReleaseAutoVersionSubmodules_BranchCreation_NotInteractive_MapDevelopment() - throws Exception - { + throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() - throws Exception - { + public void testExecuteSnapshotAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() - throws Exception - { + public void testSimulateSnapshotAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteReleaseAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() - throws Exception - { + public void testExecuteReleaseAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify /* @@ -1229,28 +1343,30 @@ public void testExecuteReleaseAutoVersionSubmodules_BranchCreation_NotInteractiv * This is true for trunk, but when branching from a tag I would expect the next SNAPSHOT version. For now keep * '1.2' instead of '1.3-SNAPSHOT' until further investigation. */ - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() - throws Exception - { + public void testSimulateReleaseAutoVersionSubmodules_BranchCreation_NotInteractive_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setBranchCreation( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setBranchCreation(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify /* @@ -1258,352 +1374,374 @@ public void testSimulateReleaseAutoVersionSubmodules_BranchCreation_NotInteracti * This is true for trunk, but when branching from a tag I would expect the next SNAPSHOT version. For now keep * '1.2' instead of '1.3-SNAPSHOT' until further investigation. */ - assertEquals( "Check release versions", "1.2" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotBranchCreation_NonInteractive_UpdateBranchVersions_MapBranch() - throws Exception - { + public void testExecuteSnapshotBranchCreation_NonInteractive_UpdateBranchVersions_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setInteractive( false ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setInteractive(false); + builder.setUpdateBranchVersions(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - assertEquals( "Check release versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotBranchCreation_NonInteractive_UpdateBranchVersions_MapBranch() - throws Exception - { + public void testSimulateSnapshotBranchCreation_NonInteractive_UpdateBranchVersions_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setInteractive( false ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setInteractive(false); + builder.setUpdateBranchVersions(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - assertEquals( "Check release versions", "1.3-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testExecuteSnapshotBranchCreation_DefaultReleaseVersion_NonInteractive_UpdateBranchVersions_MapBranch() - throws Exception - { + throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultReleaseVersion( "2.1-SNAPSHOT" ); - builder.setInteractive( false ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setDefaultReleaseVersion("2.1-SNAPSHOT"); + builder.setInteractive(false); + builder.setUpdateBranchVersions(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "2.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "2.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testSimulateSnapshotBranchCreation_DefaultReleaseVersion_NonInteractive_UpdateBranchVersions_MapBranch() - throws Exception - { + throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultReleaseVersion( "2.1-SNAPSHOT" ); - builder.setInteractive( false ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setDefaultReleaseVersion("2.1-SNAPSHOT"); + builder.setInteractive(false); + builder.setUpdateBranchVersions(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "2.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "2.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testExecuteSnapshotBranchCreation_DefaultReleaseVersion_UpdateBranchVersions_MapBranch() - throws Exception - { + throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultReleaseVersion( "2.1-SNAPSHOT" ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setDefaultReleaseVersion("2.1-SNAPSHOT"); + builder.setUpdateBranchVersions(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "2.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "2.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testSimulateSnapshotBranchCreation_DefaultReleaseVersion_UpdateBranchVersions_MapBranch() - throws Exception - { + throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setDefaultReleaseVersion( "2.1-SNAPSHOT" ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setDefaultReleaseVersion("2.1-SNAPSHOT"); + builder.setUpdateBranchVersions(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "2.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "2.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotBranchCreation_UpdateBranchVersions_MapBranch() - throws Exception - { + public void testExecuteSnapshotBranchCreation_UpdateBranchVersions_MapBranch() throws Exception { // prepare // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - when( mockPrompter.prompt( startsWith( "What is the branch version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - verify( mockPrompter ).prompt( startsWith( "What is the branch version for" ), eq( "1.3-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT")); } @Test - public void testSimulateSnapshotBranchCreation_UpdateBranchVersions_MapBranch() - throws Exception - { + public void testSimulateSnapshotBranchCreation_UpdateBranchVersions_MapBranch() throws Exception { // prepare // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - when( mockPrompter.prompt( startsWith( "What is the branch version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - verify( mockPrompter ).prompt( startsWith( "What is the branch version for" ), eq( "1.3-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT")); } @Test public void testExecuteReleaseBranchCreation_UpdateBranchVersions_UpdateVersionsToSnapshot_MapBranch() - throws Exception - { + throws Exception { // prepare // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT (yes, one step back!) // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - when( mockPrompter.prompt( startsWith( "What is the branch version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.1-SNAPSHOT" ); - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.1-SNAPSHOT"); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); - builder.setUpdateVersionsToSnapshot( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); + builder.setUpdateVersionsToSnapshot(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT (yes, one step back!) // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - verify( mockPrompter ).prompt( startsWith( "What is the branch version for" ), eq( "1.3-SNAPSHOT" ) ); - assertEquals( "Check release versions", "2.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + verify(mockPrompter).prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT")); + assertEquals( + "Check release versions", + "2.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testSimulateReleaseBranchCreation_UpdateBranchVersions_UpdateVersionsToSnapshot_MapBranch() - throws Exception - { + throws Exception { // prepare // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT (yes, one step back!) // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - when( mockPrompter.prompt( startsWith( "What is the branch version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.1-SNAPSHOT" ); - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.1-SNAPSHOT"); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); - builder.setUpdateVersionsToSnapshot( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); + builder.setUpdateVersionsToSnapshot(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT (yes, one step back!) // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - verify( mockPrompter ).prompt( startsWith( "What is the branch version for" ), eq( "1.3-SNAPSHOT" ) ); - assertEquals( "Check release versions", "2.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + verify(mockPrompter).prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT")); + assertEquals( + "Check release versions", + "2.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test public void testExecuteSnapshotBranchCreation_UpdateBranchVersions_UpdateVersionsToSnapshot_MapBranch() - throws Exception - { + throws Exception { // prepare // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - when( mockPrompter.prompt( startsWith( "What is the branch version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); - builder.setUpdateVersionsToSnapshot( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); + builder.setUpdateVersionsToSnapshot(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - verify( mockPrompter ).prompt( startsWith( "What is the branch version for" ), eq( "1.3-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT")); } @Test public void testSimulateSnapshotBranchCreation_UpdateBranchVersions_UpdateVersionsToSnapshot_MapBranch() - throws Exception - { + throws Exception { // prepare // updateBranchVersions is set to true, so suggest the next snapshot version // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - when( mockPrompter.prompt( startsWith( "What is the branch version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); - builder.setUpdateVersionsToSnapshot( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); + builder.setUpdateVersionsToSnapshot(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // org.apache.maven.release:maven-release-manager:(,2.4) > 1.2-SNAPSHOT // org.apache.maven.release:maven-release-manager:[2.4,) > 1.3-SNAPSHOT - verify( mockPrompter ).prompt( startsWith( "What is the branch version for" ), eq( "1.3-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the branch version for"), eq("1.3-SNAPSHOT")); } @Test - public void testExecuteReleaseBranchCreation_MapBranch() - throws Exception - { + public void testExecuteReleaseBranchCreation_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); + builder.setBranchCreation(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify /* @@ -1611,26 +1749,28 @@ public void testExecuteReleaseBranchCreation_MapBranch() * This is true for trunk, but when branching from a tag I would expect the next SNAPSHOT version. For now keep * '1.2' instead of '1.3-SNAPSHOT' until further investigation. */ - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseBranchCreation_MapBranch() - throws Exception - { + public void testSimulateReleaseBranchCreation_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); + builder.setBranchCreation(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify /* @@ -1638,622 +1778,680 @@ public void testSimulateReleaseBranchCreation_MapBranch() * This is true for trunk, but when branching from a tag I would expect the next SNAPSHOT version. For now keep * '1.2' instead of '1.3-SNAPSHOT' until further investigation. */ - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteReleaseBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() - throws Exception - { + public void testExecuteReleaseBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateWorkingCopyVersions( false ); + builder.setBranchCreation(true); + builder.setUpdateWorkingCopyVersions(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() - throws Exception - { + public void testSimulateReleaseBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateWorkingCopyVersions( false ); + builder.setBranchCreation(true); + builder.setUpdateWorkingCopyVersions(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.2" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteReleaseBranchCreation_MapDevelopment() - throws Exception - { + public void testExecuteReleaseBranchCreation_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); + builder.setBranchCreation(true); // org.apache.maven.release:maven-release-manager:(,2.4) > true // org.apache.maven.release:maven-release-manager:[2.4,) > false - builder.setInteractive( false ); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + builder.setInteractive(false); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.2" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseBranchCreation_MapDevelopment() - throws Exception - { + public void testSimulateReleaseBranchCreation_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); + builder.setBranchCreation(true); // org.apache.maven.release:maven-release-manager:(,2.4) > true // org.apache.maven.release:maven-release-manager:[2.4,) > false - builder.setInteractive( false ); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotBranchCreation_MapBranch() - throws Exception - { + public void testExecuteSnapshotBranchCreation_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); + builder.setBranchCreation(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotBranchCreation_MapBranch() - throws Exception - { + public void testSimulateSnapshotBranchCreation_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); + builder.setBranchCreation(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateWorkingCopyVersions( false ); + builder.setBranchCreation(true); + builder.setUpdateWorkingCopyVersions(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateSnapshotBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotBranchCreation_NonUpdateWorkingCopyVersions_MapDevelopment() throws Exception { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateWorkingCopyVersions( false ); + builder.setBranchCreation(true); + builder.setUpdateWorkingCopyVersions(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "1.2-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "1.2-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteReleaseBranchCreation_UpdateBranchVersions_MapBranch() - throws Exception - { + public void testExecuteReleaseBranchCreation_UpdateBranchVersions_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); // org.apache.maven.release:maven-release-manager:(,2.4) > true // org.apache.maven.release:maven-release-manager:[2.4,) > false - builder.setInteractive( false ); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testSimulateReleaseBranchCreation_UpdateBranchVersions_MapBranch() - throws Exception - { + public void testSimulateReleaseBranchCreation_UpdateBranchVersions_MapBranch() throws Exception { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateBranchVersions( true ); + builder.setBranchCreation(true); + builder.setUpdateBranchVersions(true); // org.apache.maven.release:maven-release-manager:(,2.4) > true // org.apache.maven.release:maven-release-manager:[2.4,) > false - builder.setInteractive( false ); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check release versions", "1.2" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check development versions", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId" ) ); + assertEquals( + "Check release versions", + "1.2", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check development versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); } @Test - public void testExecuteSnapshotBranchCreation_UpdateWorkingCopyVersions_MapDevelopment() - throws Exception - { + public void testExecuteSnapshotBranchCreation_UpdateWorkingCopyVersions_MapDevelopment() throws Exception { // prepare - when( mockPrompter.prompt( startsWith( "What is the new working copy version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the new working copy version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateWorkingCopyVersions( true ); + builder.setBranchCreation(true); + builder.setUpdateWorkingCopyVersions(true); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( mockPrompter ).prompt( startsWith( "What is the new working copy version for" ), eq( "1.3-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the new working copy version for"), eq("1.3-SNAPSHOT")); } @Test - public void testSimulateSnapshotBranchCreation_UpdateWorkingCopyVersions_MapDevelopment() - throws Exception - { + public void testSimulateSnapshotBranchCreation_UpdateWorkingCopyVersions_MapDevelopment() throws Exception { // prepare - when( mockPrompter.prompt( startsWith( "What is the new working copy version for" ), - eq( "1.3-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the new working copy version for"), eq("1.3-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.2-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setBranchCreation( true ); - builder.setUpdateWorkingCopyVersions( true ); + builder.setBranchCreation(true); + builder.setUpdateWorkingCopyVersions(true); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( mockPrompter ).prompt( startsWith( "What is the new working copy version for" ), eq( "1.3-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the new working copy version for"), eq("1.3-SNAPSHOT")); } @Test - public void testExecuteMultiModuleAutoVersionSubmodules__MapDevelopment() - throws Exception - { + public void testExecuteMultiModuleAutoVersionSubmodules__MapDevelopment() throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); List reactorProjects = new ArrayList<>(); - Collections.addAll( reactorProjects, createProject( "artifactId", "1.2-SNAPSHOT" ), - createProject( "module1", "2.0" ) ); + Collections.addAll( + reactorProjects, createProject("artifactId", "1.2-SNAPSHOT"), createProject("module1", "2.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertEquals( "Check development versions", "2.0" , ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:module1") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:module1") ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:module1")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:module1")); } @Test - public void testSimulateMultiModuleAutoVersionSubmodules__MapDevelopment() - throws Exception - { + public void testSimulateMultiModuleAutoVersionSubmodules__MapDevelopment() throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); List reactorProjects = new ArrayList<>(); - Collections.addAll( reactorProjects, createProject( "artifactId", "1.2-SNAPSHOT" ), - createProject( "module1", "2.0" ) ); + Collections.addAll( + reactorProjects, createProject("artifactId", "1.2-SNAPSHOT"), createProject("module1", "2.0")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "1.3-SNAPSHOT", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion( "groupId:artifactId" ) ); - assertEquals( "Check development versions", "2.0", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:module1") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:module1") ); + assertEquals( + "Check development versions", + "1.3-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertEquals( + "Check development versions", + "2.0", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:module1")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:module1")); } @Test public void testExecuteSnapshotAutoVersionSubmodules_DefaultReleaseVersion_NonInteractive_MapDevelopment() - throws Exception - { + throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = - Collections.singletonList( createProject( "artifactId", "1.2.1-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2.1-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setDefaultReleaseVersion( "3.0" ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setDefaultReleaseVersion("3.0"); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "3.1-SNAPSHOT" , - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion("groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "3.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test public void testSimulateSnapshotAutoVersionSubmodules_DefaultReleaseVersion_NonInteractive_MapDevelopment() - throws Exception - { + throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = - Collections.singletonList( createProject( "artifactId", "1.2.1-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2.1-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setDefaultReleaseVersion( "3.0" ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setDefaultReleaseVersion("3.0"); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "3.1-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "3.1-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test public void testExecuteSnapshotAutoVersionSubmodules_DefaultDevelopmentVersion_NonInteractive_MapDevelopment() - throws Exception - { + throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = - Collections.singletonList( createProject( "artifactId", "1.2.1-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2.1-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setDefaultDevelopmentVersion( "3.0-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setDefaultDevelopmentVersion("3.0-SNAPSHOT"); + builder.setInteractive(false); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "3.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "3.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } @Test public void testSimulateSnapshotAutoVersionSubmodules_DefaultDevelopmentVersion_NonInteractive_MapDevelopment() - throws Exception - { + throws Exception { // verify - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = - Collections.singletonList( createProject( "artifactId", "1.2.1-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.2.1-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setAutoVersionSubmodules( true ); - builder.setDefaultDevelopmentVersion( "3.0-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setAutoVersionSubmodules(true); + builder.setDefaultDevelopmentVersion("3.0-SNAPSHOT"); + builder.setInteractive(false); // test - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", "3.0-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertNull( "Check release versions", ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "3.0-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertNull( + "Check release versions", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } // MRELEASE-511 @Test - public void testUnusualVersions1() - throws Exception - { - MapReleaseVersionsPhase mapReleasephase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); - MapDevelopmentVersionsPhase mapDevelopmentphase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + public void testUnusualVersions1() throws Exception { + MapReleaseVersionsPhase mapReleasephase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); + MapDevelopmentVersionsPhase mapDevelopmentphase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); List reactorProjects = - Collections.singletonList( createProject( "artifactId", "MYB_200909-SNAPSHOT" ) ); + Collections.singletonList(createProject("artifactId", "MYB_200909-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultReleaseVersion( "PPX" ); - builder.setDefaultDevelopmentVersion( "MYB_200909-SNAPSHOT" ); + builder.setDefaultReleaseVersion("PPX"); + builder.setDefaultDevelopmentVersion("MYB_200909-SNAPSHOT"); // test - mapReleasephase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - mapDevelopmentphase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + mapReleasephase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + mapDevelopmentphase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - assertEquals( "Check development versions", - "MYB_200909-SNAPSHOT", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectDevelopmentVersion("groupId:artifactId") ); - assertEquals( "Check release versions", "PPX", - ReleaseUtils.buildReleaseDescriptor( builder ).getProjectReleaseVersion( "groupId:artifactId" ) ); + assertEquals( + "Check development versions", + "MYB_200909-SNAPSHOT", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId")); + assertEquals( + "Check release versions", + "PPX", + ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId")); } // MRELEASE-269 @Test - public void testContinuousSnapshotCheck() - throws Exception - { + public void testContinuousSnapshotCheck() throws Exception { // prepare - when( mockPrompter.prompt( startsWith( "What is the new development version for " ), - eq( "1.12-SNAPSHOT" ) ) ).thenReturn( "2.0" ) // wrong, expected SNAPSHOT - .thenReturn( "2.0-SNAPSHOT" ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the new development version for "), eq("1.12-SNAPSHOT"))) + .thenReturn("2.0") // wrong, expected SNAPSHOT + .thenReturn("2.0-SNAPSHOT"); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "bar", "1.11-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("bar", "1.11-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( mockPrompter, times( 2 ) ).prompt( startsWith( "What is the new development version for " ), - eq( "1.12-SNAPSHOT" ) ); + verify(mockPrompter, times(2)) + .prompt(startsWith("What is the new development version for "), eq("1.12-SNAPSHOT")); } // MRELEASE-734 @Test - public void testEmptyDefaultDevelopmentVersion() - throws Exception - { + public void testEmptyDefaultDevelopmentVersion() throws Exception { // prepare - when( mockPrompter.prompt( startsWith( "What is the new development version for " ), - eq( "1.12-SNAPSHOT" ) ) ).thenReturn( "2.0-SNAPSHOT" ); - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the new development version for "), eq("1.12-SNAPSHOT"))) + .thenReturn("2.0-SNAPSHOT"); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "bar", "1.11-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("bar", "1.11-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultDevelopmentVersion( "" ); + builder.setDefaultDevelopmentVersion(""); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( mockPrompter ).prompt( startsWith( "What is the new development version for " ), - eq( "1.12-SNAPSHOT" ) ); + verify(mockPrompter).prompt(startsWith("What is the new development version for "), eq("1.12-SNAPSHOT")); } @Test - public void testEmptyDefaultReleaseVersion() - throws Exception - { + public void testEmptyDefaultReleaseVersion() throws Exception { // prepare - when( mockPrompter.prompt( startsWith( "What is the release version for " ), - eq( "1.11" ) ) ).thenReturn( "2.0" ); - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + when(mockPrompter.prompt(startsWith("What is the release version for "), eq("1.11"))) + .thenReturn("2.0"); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "bar", "1.11-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("bar", "1.11-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultReleaseVersion( "" ); + builder.setDefaultReleaseVersion(""); // test - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( mockPrompter ).prompt( startsWith( "What is the release version for " ), eq( "1.11" ) ); + verify(mockPrompter).prompt(startsWith("What is the release version for "), eq("1.11")); } /** * MRELEASE-975: Test that a PolicyException is thrown when using an unknown policy version hint. */ @Test - public void testNonExistentVersionPolicy() - { + public void testNonExistentVersionPolicy() { // prepare - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "artifactId", "1.0-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("artifactId", "1.0-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setProjectVersionPolicyId( "UNKNOWN" ); + builder.setProjectVersionPolicyId("UNKNOWN"); // test - ReleaseExecutionException e = assertThrows( ReleaseExecutionException.class, - () -> phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ) ); - assertThat( e.getCause(), CoreMatchers.instanceOf( PolicyException.class ) ); + ReleaseExecutionException e = assertThrows( + ReleaseExecutionException.class, + () -> phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + reactorProjects)); + assertThat(e.getCause(), CoreMatchers.instanceOf(PolicyException.class)); } @Test - public void testUpdateBranchInvalidDefaultReleaseVersion_NonInteractive() - { + public void testUpdateBranchInvalidDefaultReleaseVersion_NonInteractive() { // prepare - MapBranchVersionsPhase phase = new MapBranchVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapBranchVersionsPhase phase = + new MapBranchVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "bar", "1.11-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("bar", "1.11-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultReleaseVersion( "3.0" ); - builder.setInteractive( false ); - builder.setUpdateBranchVersions( true ); + builder.setDefaultReleaseVersion("3.0"); + builder.setInteractive(false); + builder.setUpdateBranchVersions(true); // test try { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should fail due to invalid version" ); - } - catch( ReleaseExecutionException e ) - { - assertEquals( "3.0 is invalid, expected a snapshot", e.getMessage() ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should fail due to invalid version"); + } catch (ReleaseExecutionException e) { + assertEquals("3.0 is invalid, expected a snapshot", e.getMessage()); } } @Test - public void testUpdateReleaseInvalidDefaultReleaseVersion_NonInteractive() - { + public void testUpdateReleaseInvalidDefaultReleaseVersion_NonInteractive() { // prepare - MapReleaseVersionsPhase phase = new MapReleaseVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapReleaseVersionsPhase phase = + new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "bar", "1.11-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("bar", "1.11-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultReleaseVersion( "3.0-SNAPSHOT" ); - builder.setInteractive( false ); + builder.setDefaultReleaseVersion("3.0-SNAPSHOT"); + builder.setInteractive(false); // test try { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should fail due to invalid version" ); - } - catch( ReleaseExecutionException e ) - { - assertEquals( "3.0-SNAPSHOT is invalid, expected a non-snapshot", e.getMessage() ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should fail due to invalid version"); + } catch (ReleaseExecutionException e) { + assertEquals("3.0-SNAPSHOT is invalid, expected a non-snapshot", e.getMessage()); } } @Test - public void testUpdateDevelopmentInvalidDefaultDevelopmentVersion_NonInteractive() - { + public void testUpdateDevelopmentInvalidDefaultDevelopmentVersion_NonInteractive() { // prepare - MapDevelopmentVersionsPhase phase = new MapDevelopmentVersionsPhase( scmRepositoryConfigurator, mockPrompter, versionPolicies ); + MapDevelopmentVersionsPhase phase = + new MapDevelopmentVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies); - List reactorProjects = Collections.singletonList( createProject( "bar", "1.11-SNAPSHOT" ) ); + List reactorProjects = Collections.singletonList(createProject("bar", "1.11-SNAPSHOT")); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setDefaultDevelopmentVersion( "3.0" ); - builder.setInteractive( false ); + builder.setDefaultDevelopmentVersion("3.0"); + builder.setInteractive(false); // test try { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should fail due to invalid version" ); - } - catch( ReleaseExecutionException e ) - { - assertEquals( "3.0 is invalid, expected a snapshot", e.getMessage() ); + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should fail due to invalid version"); + } catch (ReleaseExecutionException e) { + assertEquals("3.0 is invalid, expected a snapshot", e.getMessage()); } } - private static MavenProject createProject( String artifactId, String version ) - { + private static MavenProject createProject(String artifactId, String version) { Model model = new Model(); - model.setGroupId( "groupId" ); - model.setArtifactId( artifactId ); - model.setVersion( version ); - return new MavenProject( model ); + model.setGroupId("groupId"); + model.setArtifactId(artifactId); + model.setVersion(version); + return new MavenProject(model); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ReleasePhaseStub.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ReleasePhaseStub.java index 7d28bdf4a..9d55d47f7 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ReleasePhaseStub.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ReleasePhaseStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,22 +16,21 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.phase; + +import java.util.List; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.release.ReleaseResult; import org.apache.maven.shared.release.config.ReleaseDescriptor; import org.apache.maven.shared.release.env.ReleaseEnvironment; -import java.util.List; - /** * Test stub for testing if a phase is executed. * * @author Brett Porter */ -public class ReleasePhaseStub - implements ReleasePhase, ResourceGenerator -{ +public class ReleasePhaseStub implements ReleasePhase, ResourceGenerator { /** * Whether the phase was simulated. */ @@ -50,53 +47,53 @@ public class ReleasePhaseStub private boolean cleaned; @Override - public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, List reactorProjects ) - { + public ReleaseResult execute( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) { ReleaseResult result = new ReleaseResult(); executed = true; - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult simulate( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, List reactorProjects ) - { + public ReleaseResult simulate( + ReleaseDescriptor releaseDescriptor, + ReleaseEnvironment releaseEnvironment, + List reactorProjects) { ReleaseResult result = new ReleaseResult(); simulated = true; - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } @Override - public ReleaseResult clean( List reactorProjects ) - { + public ReleaseResult clean(List reactorProjects) { ReleaseResult result = new ReleaseResult(); cleaned = true; - result.setResultCode( ReleaseResult.SUCCESS ); + result.setResultCode(ReleaseResult.SUCCESS); return result; } - public boolean isExecuted() - { + public boolean isExecuted() { return executed; } - public boolean isSimulated() - { + public boolean isSimulated() { return simulated; } - public boolean isCleaned() - { + public boolean isCleaned() { return cleaned; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhaseTest.java index ce8396089..39934f58d 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveReleasePomsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,14 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.io.BufferedReader; import java.io.File; @@ -52,202 +43,187 @@ import org.codehaus.plexus.util.IOUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the remove release POMs phase. * * @author Mark Hobson */ -public class RemoveReleasePomsPhaseTest - extends AbstractReleaseTestCase -{ +public class RemoveReleasePomsPhaseTest extends AbstractReleaseTestCase { @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "remove-release-poms" ); + phase = lookup(ReleasePhase.class, "remove-release-poms"); } @Test - public void testExecuteBasicPom() - throws Exception - { + public void testExecuteBasicPom() throws Exception { // prepare - File workingDirectory = getTestFile( "target/test/checkout" ); - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( workingDirectory ); - MavenProject project = ReleaseUtil.getRootProject( reactorProjects ); + File workingDirectory = getTestFile("target/test/checkout"); + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(workingDirectory); + MavenProject project = ReleaseUtil.getRootProject(reactorProjects); - File releasePom = ReleaseUtil.getReleasePom( project ); - ScmFileSet fileSet = new ScmFileSet( workingDirectory, releasePom ); + File releasePom = ReleaseUtil.getReleasePom(project); + ScmFileSet fileSet = new ScmFileSet(workingDirectory, releasePom); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.remove( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isA( String.class ) ) ).thenReturn( new RemoveScmResult( "...", - Collections.singletonList( new ScmFile( "pom.xml", - ScmFileStatus.DELETED ) ) ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.remove( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), isA(String.class))) + .thenReturn(new RemoveScmResult( + "...", Collections.singletonList(new ScmFile("pom.xml", ScmFileStatus.DELETED)))); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).remove( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isA( String.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .remove(isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), isA(String.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testExecutePomWithModules() - throws Exception - { + public void testExecutePomWithModules() throws Exception { // prepare - File workingDirectory = getTestFile( "target/test/checkout" ); - List reactorProjects = createReactorProjects( "pom-with-modules" ); + File workingDirectory = getTestFile("target/test/checkout"); + List reactorProjects = createReactorProjects("pom-with-modules"); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); List releasePoms = new ArrayList<>(); - for ( Iterator iterator = reactorProjects.iterator(); iterator.hasNext(); ) - { + for (Iterator iterator = reactorProjects.iterator(); iterator.hasNext(); ) { MavenProject project = iterator.next(); - File releasePom = ReleaseUtil.getReleasePom( project ); - releasePoms.add( releasePom ); + File releasePom = ReleaseUtil.getReleasePom(project); + releasePoms.add(releasePom); } - ScmFileSet fileSet = new ScmFileSet( workingDirectory, releasePoms ); + ScmFileSet fileSet = new ScmFileSet(workingDirectory, releasePoms); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.remove( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isA( String.class ) ) ).thenReturn( new RemoveScmResult( "...", - Collections.singletonList( new ScmFile( "pom.xml", - ScmFileStatus.DELETED ) ) ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.remove( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), isA(String.class))) + .thenReturn(new RemoveScmResult( + "...", Collections.singletonList(new ScmFile("pom.xml", ScmFileStatus.DELETED)))); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).remove( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isA( String.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .remove(isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), isA(String.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSimulateBasicPom() - throws Exception - { + public void testSimulateBasicPom() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); + List reactorProjects = createReactorProjects("basic-pom"); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // never invoke scmProviderMock - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testExecuteWithSuppressCommitBeforeTag() - throws Exception - { + public void testExecuteWithSuppressCommitBeforeTag() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); + List reactorProjects = createReactorProjects("basic-pom"); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - builder.setSuppressCommitBeforeTagOrBranch( true ); - builder.setGenerateReleasePoms( true ); + builder.setSuppressCommitBeforeTagOrBranch(true); + builder.setGenerateReleasePoms(true); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - ReleaseResult result = phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult result = phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); BufferedReader reader = null; - try - { - reader = new BufferedReader( new StringReader( result.getOutput() ) ); + try { + reader = new BufferedReader(new StringReader(result.getOutput())); - assertEquals( "[INFO] Removing release POM for 'artifactId'...", - reader.readLine() ); - assertEquals( "Expected EOF", null, reader.readLine() ); - } - finally - { - IOUtil.close( reader ); + assertEquals("[INFO] Removing release POM for 'artifactId'...", reader.readLine()); + assertEquals("Expected EOF", null, reader.readLine()); + } finally { + IOUtil.close(reader); } // never invoke scmProviderMock - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSimulateWithSuppressCommitBeforeTag() - throws Exception - { + public void testSimulateWithSuppressCommitBeforeTag() throws Exception { // prepare - List reactorProjects = createReactorProjects( "basic-pom" ); + List reactorProjects = createReactorProjects("basic-pom"); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - builder.setSuppressCommitBeforeTagOrBranch( true ); - builder.setGenerateReleasePoms( true ); + builder.setSuppressCommitBeforeTagOrBranch(true); + builder.setGenerateReleasePoms(true); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - ReleaseResult result = phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult result = phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); BufferedReader reader = null; - try - { - reader = new BufferedReader( new StringReader( result.getOutput() ) ); - - assertEquals( "[INFO] Removing release POM for 'artifactId'...", - 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 ); + try { + reader = new BufferedReader(new StringReader(result.getOutput())); + + assertEquals("[INFO] Removing release POM for 'artifactId'...", 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 ); + verifyNoMoreInteractions(scmProviderMock); } - protected List createReactorProjects( String path ) - throws Exception - { + protected List createReactorProjects(String path) throws Exception { String dir = "remove-release-poms/" + path; - return createReactorProjects( dir, dir, null ); + return createReactorProjects(dir, dir, null); } - private ReleaseDescriptorBuilder createReleaseDescriptorBuilder() - { - return createReleaseDescriptorBuilder( getTestFile( "target/test/checkout" ) ); + private ReleaseDescriptorBuilder createReleaseDescriptorBuilder() { + return createReleaseDescriptorBuilder(getTestFile("target/test/checkout")); } - - private ReleaseDescriptorBuilder createReleaseDescriptorBuilder( File workingDirectory ) - { + + private ReleaseDescriptorBuilder createReleaseDescriptorBuilder(File workingDirectory) { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setGenerateReleasePoms( true ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); + builder.setGenerateReleasePoms(true); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); return builder; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveScmTagPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveScmTagPhaseTest.java index 5821d8c48..3af103ea1 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveScmTagPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RemoveScmTagPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,12 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertThrows; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.argThat; +package org.apache.maven.shared.release.phase; import java.util.List; @@ -46,196 +39,199 @@ import org.junit.Test; import org.mockito.Mockito; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertThrows; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.isA; + /** * Test the remove SCM tag phase. */ -public class RemoveScmTagPhaseTest extends AbstractReleaseTestCase -{ +public class RemoveScmTagPhaseTest extends AbstractReleaseTestCase { @Override - public void setUp() throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = ( ReleasePhase ) lookup( ReleasePhase.class, "remove-scm-tag" ); - + phase = (ReleasePhase) lookup(ReleasePhase.class, "remove-scm-tag"); } @Test - public void testExecuteOutput() throws Exception - { + public void testExecuteOutput() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmReleaseLabel("release-label"); + builder.setScmSourceUrl("scm-url"); List reactorProjects = createReactorProjects(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); // mock, only real matcher is the file set - ScmProvider scmProviderMock = Mockito.mock( ScmProvider.class ); - Mockito.when( scmProviderMock.untag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isA( CommandParameters.class ) ) ) - .thenReturn( new UntagScmResult( "...", "...", "...", true ) ); - ScmManagerStub stub = ( ScmManagerStub ) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmProvider scmProviderMock = Mockito.mock(ScmProvider.class); + Mockito.when(scmProviderMock.untag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isA(CommandParameters.class))) + .thenReturn(new UntagScmResult("...", "...", "...", true)); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - ReleaseResult actual = phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), - new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult actual = phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify, actual contains trailing newline - Assert.assertEquals( "[INFO] Removing tag with the label release-label ...", actual.getOutput().trim() ); - + Assert.assertEquals( + "[INFO] Removing tag with the label release-label ...", + actual.getOutput().trim()); } @Test - public void testExecuteResultCode() throws Exception - { + public void testExecuteResultCode() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmReleaseLabel("release-label"); + builder.setScmSourceUrl("scm-url"); List reactorProjects = createReactorProjects(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); // mock, only real matcher is the file set - ScmProvider scmProviderMock = Mockito.mock( ScmProvider.class ); - Mockito.when( scmProviderMock.untag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isA( CommandParameters.class ) ) ) - .thenReturn( new UntagScmResult( "...", "...", "...", true ) ); - ScmManagerStub stub = ( ScmManagerStub ) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmProvider scmProviderMock = Mockito.mock(ScmProvider.class); + Mockito.when(scmProviderMock.untag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isA(CommandParameters.class))) + .thenReturn(new UntagScmResult("...", "...", "...", true)); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - ReleaseResult actual = phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), - new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult actual = phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - Assert.assertEquals( 0, actual.getResultCode() ); - + Assert.assertEquals(0, actual.getResultCode()); } @Test - @Ignore( "We changed the behaviour to warning instead of error." ) - public void testExecuteError() throws Exception - { + @Ignore("We changed the behaviour to warning instead of error.") + public void testExecuteError() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmReleaseLabel("release-label"); + builder.setScmSourceUrl("scm-url"); List reactorProjects = createReactorProjects(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); // mock, only real matcher is the file set - ScmProvider scmProviderMock = Mockito.mock( ScmProvider.class ); - Mockito.when( scmProviderMock.untag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isA( CommandParameters.class ) ) ) - .thenReturn( new UntagScmResult( "command-line", "provider-message", "command-output", false ) ); - ScmManagerStub stub = ( ScmManagerStub ) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmProvider scmProviderMock = Mockito.mock(ScmProvider.class); + Mockito.when(scmProviderMock.untag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isA(CommandParameters.class))) + .thenReturn(new UntagScmResult("command-line", "provider-message", "command-output", false)); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - ReleaseScmCommandException e = assertThrows( ReleaseScmCommandException.class, - () -> phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ) ); - - assertThat( e.getMessage(), equalTo( "Unable to remove tag \nProvider message:\nprovider-message\nCommand output:\ncommand-output" ) ); + ReleaseScmCommandException e = assertThrows( + ReleaseScmCommandException.class, + () -> phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), + new DefaultReleaseEnvironment(), + reactorProjects)); + + assertThat( + e.getMessage(), + equalTo("Unable to remove tag \nProvider message:\nprovider-message\nCommand output:\ncommand-output")); } @Test - public void testExecuteNoError() throws Exception - { + public void testExecuteNoError() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmReleaseLabel("release-label"); + builder.setScmSourceUrl("scm-url"); List reactorProjects = createReactorProjects(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); // mock, only real matcher is the file set - ScmProvider scmProviderMock = Mockito.mock( ScmProvider.class ); - Mockito.when( scmProviderMock.untag( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( fileSet ) ), - isA( CommandParameters.class ) ) ) - .thenReturn( new UntagScmResult( "command-line", "provider-message", "command-output", false ) ); - ScmManagerStub stub = ( ScmManagerStub ) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmProvider scmProviderMock = Mockito.mock(ScmProvider.class); + Mockito.when(scmProviderMock.untag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isA(CommandParameters.class))) + .thenReturn(new UntagScmResult("command-line", "provider-message", "command-output", false)); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - ReleaseResult actual = phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), - new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult actual = phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - Assert.assertEquals( 0, actual.getResultCode() ); - - + Assert.assertEquals(0, actual.getResultCode()); } @Test - public void testSimulateOutput() throws Exception - { + public void testSimulateOutput() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmReleaseLabel("release-label"); + builder.setScmSourceUrl("scm-url"); List reactorProjects = createReactorProjects(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); // execute - ReleaseResult actual = phase.simulate(ReleaseUtils.buildReleaseDescriptor( builder ), - new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult actual = phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify, actual contains newline - Assert.assertEquals( "[INFO] Full run would remove tag with label: 'release-label'", - actual.getOutput().trim() ); - + Assert.assertEquals( + "[INFO] Full run would remove tag with label: 'release-label'", + actual.getOutput().trim()); } @Test - public void testSimulateResultCode() throws Exception - { + public void testSimulateResultCode() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmReleaseLabel("release-label"); + builder.setScmSourceUrl("scm-url"); List reactorProjects = createReactorProjects(); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); // execute - ReleaseResult actual = phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), - new DefaultReleaseEnvironment(), reactorProjects ); + ReleaseResult actual = phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - Assert.assertEquals( 0, actual.getResultCode() ); + Assert.assertEquals(0, actual.getResultCode()); } - private List createReactorProjects() throws Exception - { - return createReactorProjects( "scm-commit/single-pom", "" ); + private List createReactorProjects() throws Exception { + return createReactorProjects("scm-commit/single-pom", ""); } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhaseTest.java index dacb66a67..eea750c33 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RestoreBackupPomsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertTrue; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.List; @@ -32,81 +29,70 @@ import org.codehaus.plexus.util.FileUtils; import org.junit.Test; +import static org.junit.Assert.assertTrue; + /** * @author Edwin Punzalan */ -public class RestoreBackupPomsPhaseTest - extends AbstractBackupPomsPhaseTest -{ +public class RestoreBackupPomsPhaseTest extends AbstractBackupPomsPhaseTest { private String expectedPomFilename = "expected-pom.xml"; @Override - ReleasePhase getReleasePhase() - throws Exception - { - return lookup( ReleasePhase.class, "restore-backup-poms" ); + ReleasePhase getReleasePhase() throws Exception { + return lookup(ReleasePhase.class, "restore-backup-poms"); } @Test - public void testBasicPom() - throws Exception - { + public void testBasicPom() throws Exception { String projectPath = "/projects/restore-backup-poms/basic-pom"; // copy poms so tests are valid without clean - File sourceDir = getTestFile( "src/test/resources" + projectPath ); - File testDir = getTestFile( "target/test-classes" + projectPath ); - FileUtils.copyDirectoryStructure( sourceDir, testDir ); + File sourceDir = getTestFile("src/test/resources" + projectPath); + File testDir = getTestFile("target/test-classes" + projectPath); + FileUtils.copyDirectoryStructure(sourceDir, testDir); String testPath = "target/test-classes" + projectPath; - runExecuteOnProjects( testPath ); + runExecuteOnProjects(testPath); } @Test - public void testMultiModulePom() - throws Exception - { + public void testMultiModulePom() throws Exception { String projectPath = "/projects/restore-backup-poms/pom-with-modules"; // copy poms so tests are valid without clean - File sourceDir = getTestFile( "src/test/resources" + projectPath ); - File testDir = getTestFile( "target/test-classes" + projectPath ); - FileUtils.copyDirectoryStructure( sourceDir, testDir ); + File sourceDir = getTestFile("src/test/resources" + projectPath); + File testDir = getTestFile("target/test-classes" + projectPath); + FileUtils.copyDirectoryStructure(sourceDir, testDir); String testPath = "target/test-classes" + projectPath; - runExecuteOnProjects( testPath ); + runExecuteOnProjects(testPath); } - private void runExecuteOnProjects( String path ) - throws Exception - { - List projects = getReactorProjects( getTestPath( path ) ); + private void runExecuteOnProjects(String path) throws Exception { + List projects = getReactorProjects(getTestPath(path)); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:http://myhost/myrepo" ); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), projects ); + builder.setScmSourceUrl("scm:svn:http://myhost/myrepo"); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), projects); - testProjectIsRestored( projects ); + testProjectIsRestored(projects); } - private void testProjectIsRestored( List reactorProjects ) - throws Exception - { - for ( MavenProject project : reactorProjects ) - { + private void testProjectIsRestored(List reactorProjects) throws Exception { + for (MavenProject project : reactorProjects) { File pomFile = project.getFile(); - File expectedFile = new File( pomFile.getParentFile(), expectedPomFilename ); + File expectedFile = new File(pomFile.getParentFile(), expectedPomFilename); - assertTrue( "Check if expected file exists.", expectedFile.exists() ); + assertTrue("Check if expected file exists.", expectedFile.exists()); - String pomContents = ReleaseUtil.readXmlFile( pomFile ); + String pomContents = ReleaseUtil.readXmlFile(pomFile); - String expectedContents = ReleaseUtil.readXmlFile( expectedFile ); + String expectedContents = ReleaseUtil.readXmlFile(expectedFile); - assertTrue( "Check if pom and backup files are identical", pomContents.equals( expectedContents ) ); + assertTrue("Check if pom and backup files are identical", pomContents.equals(expectedContents)); } } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhaseTest.java index b62dc17d1..aacfc4269 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForBranchPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +package org.apache.maven.shared.release.phase; import java.io.File; import java.io.IOException; @@ -36,440 +31,397 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test the SCM modification check phase. * * @author Brett Porter */ -public class RewritePomsForBranchPhaseTest - extends AbstractEditModeRewritingReleasePhaseTestCase -{ +public class RewritePomsForBranchPhaseTest extends AbstractEditModeRewritingReleasePhaseTestCase { private static final String NEXT_VERSION = "1.0-SNAPSHOT"; private static final String ALTERNATIVE_NEXT_VERSION = "2.0-SNAPSHOT"; - public RewritePomsForBranchPhaseTest( String modelETL ) - { - super( modelETL ); + public RewritePomsForBranchPhaseTest(String modelETL) { + super(modelETL); } @Override - protected String getRoleHint() - { + protected String getRoleHint() { return "rewrite-poms-for-branch"; } @Override - protected Path getWorkingDirectory( String workingDir ) - { - return super.getWorkingDirectory( "rewrite-for-branch/" + workingDir ); + protected Path getWorkingDirectory(String workingDir) { + return super.getWorkingDirectory("rewrite-for-branch/" + workingDir); } @Override - protected List prepareReactorProjects( String path ) - throws Exception - { - String dir = "rewrite-for-branch/" + Objects.toString( path, "" ); - return createReactorProjects( dir, path, null ); + protected List prepareReactorProjects(String path) throws Exception { + String dir = "rewrite-for-branch/" + Objects.toString(path, ""); + return createReactorProjects(dir, path, null); } @Override - protected String readTestProjectFile( String fileName ) - throws IOException - { - return ReleaseUtil.readXmlFile( getTestFile( "target/test-classes/projects/rewrite-for-branch/" + fileName ) ); + protected String readTestProjectFile(String fileName) throws IOException { + return ReleaseUtil.readXmlFile(getTestFile("target/test-classes/projects/rewrite-for-branch/" + fileName)); } @Test - public void testSimulateRewrite() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); + public void testSimulateRewrite() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); - String expected = readTestProjectFile( "basic-pom/pom.xml" ); + String expected = readTestProjectFile("basic-pom/pom.xml"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - String actual = readTestProjectFile( "basic-pom/pom.xml" ); - assertEquals( "Check the original POM untouched", expected, actual ); + String actual = readTestProjectFile("basic-pom/pom.xml"); + assertEquals("Check the original POM untouched", expected, actual); - expected = readTestProjectFile( "basic-pom/expected-pom.xml" ); - actual = readTestProjectFile( "basic-pom/pom.xml.branch" ); - assertEquals( "Check the transformed POM", expected, actual ); + expected = readTestProjectFile("basic-pom/expected-pom.xml"); + actual = readTestProjectFile("basic-pom/pom.xml.branch"); + assertEquals("Check the transformed POM", expected, actual); } @Test - public void testRewriteWithDashedComments() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-dashes-in-comment" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom-with-dashes-in-comment" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); + public void testRewriteWithDashedComments() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-dashes-in-comment"); + ReleaseDescriptorBuilder builder = + createDescriptorFromBasicPom(reactorProjects, "basic-pom-with-dashes-in-comment"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); - String expected = readTestProjectFile( "basic-pom-with-dashes-in-comment/pom.xml" ); + String expected = readTestProjectFile("basic-pom-with-dashes-in-comment/pom.xml"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - String actual = readTestProjectFile( "basic-pom-with-dashes-in-comment/pom.xml" ); - assertEquals( "Check the original POM is untouched", expected, actual ); + String actual = readTestProjectFile("basic-pom-with-dashes-in-comment/pom.xml"); + assertEquals("Check the original POM is untouched", expected, actual); - expected = readTestProjectFile( "basic-pom-with-dashes-in-comment/expected-pom.xml" ); - actual = readTestProjectFile( "basic-pom-with-dashes-in-comment/pom.xml.branch" ); - assertEquals( "Check the transformed POM", expected, actual ); + expected = readTestProjectFile("basic-pom-with-dashes-in-comment/expected-pom.xml"); + actual = readTestProjectFile("basic-pom-with-dashes-in-comment/pom.xml.branch"); + assertEquals("Check the transformed POM", expected, actual); } @Test - public void testClean() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - - File testFile = getTestFile( "target/test-classes/projects/rewrite-for-branch/basic-pom/pom.xml.branch" ); + public void testClean() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + + File testFile = getTestFile("target/test-classes/projects/rewrite-for-branch/basic-pom/pom.xml.branch"); testFile.delete(); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( testFile.exists() ); + assertTrue(testFile.exists()); - ( (ResourceGenerator) phase ).clean( reactorProjects ); + ((ResourceGenerator) phase).clean(reactorProjects); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); } @Test - public void testCleanNotExists() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - - File testFile = getTestFile( "target/test-classes/projects/rewrite-for-branch/basic-pom/pom.xml.branch" ); + public void testCleanNotExists() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + + File testFile = getTestFile("target/test-classes/projects/rewrite-for-branch/basic-pom/pom.xml.branch"); testFile.delete(); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); - ( (ResourceGenerator) phase ).clean( reactorProjects ); + ((ResourceGenerator) phase).clean(reactorProjects); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); } // MRELEASE-116 @Test - public void testScmOverridden() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-overridden-scm" ); - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, "pom-with-overridden-scm" ); - builder.addReleaseVersion( "groupId:subsubproject", NEXT_VERSION ); + public void testScmOverridden() throws Exception { + List reactorProjects = createReactorProjects("pom-with-overridden-scm"); + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, "pom-with-overridden-scm"); + builder.addReleaseVersion("groupId:subsubproject", NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Override - protected void mapAlternateNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, ALTERNATIVE_NEXT_VERSION ); + protected void mapAlternateNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, ALTERNATIVE_NEXT_VERSION); } @Override - protected void mapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, NEXT_VERSION ); + protected void mapNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, NEXT_VERSION); } @Override - protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( List reactorProjects, String workingDirectory ) - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( + List reactorProjects, String workingDirectory) { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); return builder; } @Override - protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( List reactorProjects, String workingDirectory ) - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( + List reactorProjects, String workingDirectory) { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", NEXT_VERSION); return builder; } @Override - protected void unmapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { + protected void unmapNextVersion(ReleaseDescriptorBuilder config, String projectId) { // nothing to do } @Test - public void testRewriteBasicPomWithGit() - throws Exception - { + public void testRewriteBasicPomWithGit() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-git" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-git" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-git"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-git"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithScmExpression() - throws Exception - { + public void testRewriteBasicPomWithScmExpression() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-scm-expression" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-scm-expression" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-scm-expression"); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "basic-pom-with-scm-expression"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithTagBase() - throws Exception - { + public void testRewriteBasicPomWithTagBase() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-tag-base" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-tag-base" ); - builder.setScmBranchBase( "file://localhost/tmp/scm-repo/branches" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-tag-base"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-tag-base"); + builder.setScmBranchBase("file://localhost/tmp/scm-repo/branches"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithTagBaseAndVaryingScmUrls() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-tag-base-and-varying-scm-urls" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-tag-base-and-varying-scm-urls" ); - builder.setScmBranchBase( "file://localhost/tmp/scm-repo/allprojects/branches" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithTagBaseAndVaryingScmUrls() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-tag-base-and-varying-scm-urls"); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "basic-pom-with-tag-base-and-varying-scm-urls"); + builder.setScmBranchBase("file://localhost/tmp/scm-repo/allprojects/branches"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithGitFromTag() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-git-from-tag" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-git-from-tag" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithGitFromTag() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-git-from-tag"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-git-from-tag"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithEmptyScm() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-empty-scm" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-empty-scm" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithEmptyScm() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-empty-scm"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-empty-scm"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteInterpolatedVersions() - throws Exception - { - List reactorProjects = createReactorProjects( "interpolated-versions" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "interpolated-versions" ); + public void testRewriteInterpolatedVersions() throws Exception { + List reactorProjects = createReactorProjects("interpolated-versions"); + ReleaseDescriptorBuilder builder = createMappedConfiguration(reactorProjects, "interpolated-versions"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteInterpolatedVersionsDifferentVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "interpolated-versions" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "interpolated-versions" ); + public void testRewriteInterpolatedVersionsDifferentVersion() throws Exception { + List reactorProjects = createReactorProjects("interpolated-versions"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "interpolated-versions"); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject3", NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject3", NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - for ( MavenProject project : reactorProjects ) - { + for (MavenProject project : reactorProjects) { // skip subproject1 - we don't need to worry about its version mapping change, it has no deps of any kind - if ( !"groupId".equals( project.getGroupId() ) || !"subproject1".equals( project.getArtifactId() ) ) - { - comparePomFiles( project, "-different-version", true ); + if (!"groupId".equals(project.getGroupId()) || !"subproject1".equals(project.getArtifactId())) { + comparePomFiles(project, "-different-version", true); } } } @Test - public void testRewriteBasicPomWithInheritedScm() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-inherited-scm" ); - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, "basic-pom-inherited-scm" ); - builder.addReleaseVersion( "groupId:subsubproject", NEXT_VERSION ); + public void testRewriteBasicPomWithInheritedScm() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-inherited-scm"); + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, "basic-pom-inherited-scm"); + builder.addReleaseVersion("groupId:subsubproject", NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithParentAndProperties() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-parent-and-properties" ); + public void testRewritePomWithParentAndProperties() throws Exception { + List reactorProjects = createReactorProjects("pom-with-parent-and-properties"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-parent-and-properties" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-parent-and-properties"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-311 @Test - public void testRewritePomWithDependencyPropertyCoordinate() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-property-dependency-coordinate" ); + public void testRewritePomWithDependencyPropertyCoordinate() throws Exception { + List reactorProjects = createReactorProjects("pom-with-property-dependency-coordinate"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-property-dependency-coordinate" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1-3.4", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-property-dependency-coordinate"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1-3.4", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-305 @Test - public void testRewritePomWithScmOfParentEndingWithASlash() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-scm-of-parent-ending-with-a-slash" ); + public void testRewritePomWithScmOfParentEndingWithASlash() throws Exception { + List reactorProjects = createReactorProjects("pom-with-scm-of-parent-ending-with-a-slash"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-scm-of-parent-ending-with-a-slash" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-scm-of-parent-ending-with-a-slash"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithDeepSubprojects() - throws Exception - { - List reactorProjects = createReactorProjects( "multimodule-with-deep-subprojects" ); + public void testRewritePomWithDeepSubprojects() throws Exception { + List reactorProjects = createReactorProjects("multimodule-with-deep-subprojects"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "multimodule-with-deep-subprojects" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "multimodule-with-deep-subprojects"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomForFlatMultiModule() - throws Exception - { - List reactorProjects = - createReactorProjects( "rewrite-for-branch/pom-with-parent-flat", "pom-with-parent-flat", "root-project" ); + public void testRewritePomForFlatMultiModule() throws Exception { + List reactorProjects = createReactorProjects( + "rewrite-for-branch/pom-with-parent-flat", "pom-with-parent-flat", "root-project"); ReleaseDescriptorBuilder builder = - createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "pom-with-parent-flat" ); + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "pom-with-parent-flat"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-383 @Test - public void testRewritePomWithCDATASectionOnWindows() - throws Exception - { - List reactorProjects = createReactorProjects( "cdata-section" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "cdata-section" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewritePomWithCDATASectionOnWindows() throws Exception { + List reactorProjects = createReactorProjects("cdata-section"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "cdata-section"); + mapNextVersion(builder, "groupId:artifactId"); AbstractRewritePomsPhase phase = (AbstractRewritePomsPhase) this.phase; - ReleaseDescriptorBuilder.BuilderReleaseDescriptor builderReleaseDescriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptorBuilder.BuilderReleaseDescriptor builderReleaseDescriptor = + ReleaseUtils.buildReleaseDescriptor(builder); builderReleaseDescriptor.setLineSeparator("\r\n"); - phase.execute( builderReleaseDescriptor, new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(builderReleaseDescriptor, new DefaultReleaseEnvironment(), reactorProjects); // compare POMS without line ending normalization - assertTrue( comparePomFiles( reactorProjects, false ) ); + assertTrue(comparePomFiles(reactorProjects, false)); } - protected ReleaseDescriptorBuilder createDescriptorFromProjects( List reactorProjects, String workingDirectory ) - { - ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects( reactorProjects, workingDirectory ); - builder.setScmReleaseLabel( "release-label" ); + protected ReleaseDescriptorBuilder createDescriptorFromProjects( + List reactorProjects, String workingDirectory) { + ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects(reactorProjects, workingDirectory); + builder.setScmReleaseLabel("release-label"); return builder; } // MRELEASE-454 @Test - public void testRewritePomWithImportedDependencyManagementInReactor() - throws Exception - { - List reactorProjects = createReactorProjects( "imported-dependency-management-in-reactor" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "imported-dependency-management-in-reactor" ); + public void testRewritePomWithImportedDependencyManagementInReactor() throws Exception { + List reactorProjects = createReactorProjects("imported-dependency-management-in-reactor"); + ReleaseDescriptorBuilder builder = + createMappedConfiguration(reactorProjects, "imported-dependency-management-in-reactor"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithDifferentVersionsAcrossModules() - throws Exception - { - List reactorProjects = createReactorProjects( "modules-with-different-versions" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "modules-with-different-versions" ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + public void testRewritePomWithDifferentVersionsAcrossModules() throws Exception { + List reactorProjects = createReactorProjects("modules-with-different-versions"); + ReleaseDescriptorBuilder builder = + createMappedConfiguration(reactorProjects, "modules-with-different-versions"); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java index c96f583fd..b303a514f 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForDevelopmentPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +package org.apache.maven.shared.release.phase; import java.io.File; import java.io.IOException; @@ -38,14 +33,16 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test the SCM modification check phase. * * @author Brett Porter */ -public class RewritePomsForDevelopmentPhaseTest - extends AbstractEditModeRewritingReleasePhaseTestCase -{ +public class RewritePomsForDevelopmentPhaseTest extends AbstractEditModeRewritingReleasePhaseTestCase { private static final String NEXT_VERSION = "1.1-SNAPSHOT"; private static final String ALTERNATIVE_NEXT_VERSION = "2.1-SNAPSHOT"; @@ -54,397 +51,351 @@ public class RewritePomsForDevelopmentPhaseTest private static final String ALTERNATIVE_RELEASE_VERSION = "2.0"; - public RewritePomsForDevelopmentPhaseTest( String modelETL ) - { - super( modelETL ); + public RewritePomsForDevelopmentPhaseTest(String modelETL) { + super(modelETL); } @Override - protected String getRoleHint() - { + protected String getRoleHint() { return "rewrite-poms-for-development"; } @Override - protected Path getWorkingDirectory( String workingDir ) - { - return super.getWorkingDirectory( "rewrite-for-development/" + workingDir ); + protected Path getWorkingDirectory(String workingDir) { + return super.getWorkingDirectory("rewrite-for-development/" + workingDir); } @Test - public void testSimulateRewrite() - throws Exception - { - List reactorProjects = createReactorProjectsWhenSimulated( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); + public void testSimulateRewrite() throws Exception { + List reactorProjects = createReactorProjectsWhenSimulated("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); - String expected = readTestProjectFile( "basic-pom/pom.xml" ); + String expected = readTestProjectFile("basic-pom/pom.xml"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - String actual = readTestProjectFile( "basic-pom/pom.xml" ); - assertEquals( "Check the original POM untouched", expected, actual ); + String actual = readTestProjectFile("basic-pom/pom.xml"); + assertEquals("Check the original POM untouched", expected, actual); - expected = readTestProjectFile( "basic-pom/expected-pom.xml" ); - actual = readTestProjectFile( "basic-pom/pom.xml.next" ); - assertEquals( "Check the transformed POM", expected, actual ); + expected = readTestProjectFile("basic-pom/expected-pom.xml"); + actual = readTestProjectFile("basic-pom/pom.xml.next"); + assertEquals("Check the transformed POM", expected, actual); } - private List createReactorProjectsWhenSimulated( String name ) - throws Exception - { - return createReactorProjects( "rewrite-for-release/" + name, name, null ); + private List createReactorProjectsWhenSimulated(String name) throws Exception { + return createReactorProjects("rewrite-for-release/" + name, name, null); } @Test - public void testSimulateRewriteEjbClientDeps() - throws Exception - { + public void testSimulateRewriteEjbClientDeps() throws Exception { List reactorProjects = - new LinkedList<>( createReactorProjects( "basic-pom-ejb-client-dep/project" ) ); - reactorProjects.addAll( createReactorProjects( "basic-pom-ejb-client-dep/ejb" ) ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom-ejb-client-dep" ); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addDevelopmentVersion( ArtifactUtils.versionlessKey( "groupId", "artifactId1" ), NEXT_VERSION ); - builder.addReleaseVersion( ArtifactUtils.versionlessKey( "groupId", "artifactId1" ), RELEASE_VERSION ); + new LinkedList<>(createReactorProjects("basic-pom-ejb-client-dep/project")); + reactorProjects.addAll(createReactorProjects("basic-pom-ejb-client-dep/ejb")); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom-ejb-client-dep"); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addDevelopmentVersion(ArtifactUtils.versionlessKey("groupId", "artifactId1"), NEXT_VERSION); + builder.addReleaseVersion(ArtifactUtils.versionlessKey("groupId", "artifactId1"), RELEASE_VERSION); - String expected = readTestProjectFile( "basic-pom-ejb-client-dep/project/pom.xml" ); + String expected = readTestProjectFile("basic-pom-ejb-client-dep/project/pom.xml"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - String actual = readTestProjectFile( "basic-pom-ejb-client-dep/project/pom.xml" ); - assertEquals( "Check the original POM untouched", expected, actual ); + String actual = readTestProjectFile("basic-pom-ejb-client-dep/project/pom.xml"); + assertEquals("Check the original POM untouched", expected, actual); - expected = readTestProjectFile( "basic-pom-ejb-client-dep/project/expected-pom.xml" ); - actual = readTestProjectFile( "basic-pom-ejb-client-dep/project/pom.xml.next" ); - assertEquals( "Check the transformed POM", expected, actual ); + expected = readTestProjectFile("basic-pom-ejb-client-dep/project/expected-pom.xml"); + actual = readTestProjectFile("basic-pom-ejb-client-dep/project/pom.xml.next"); + assertEquals("Check the transformed POM", expected, actual); } @Test - public void testClean() - throws Exception - { - List reactorProjects = createReactorProjectsWhenSimulated( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - - File testFile = getTestFile( "target/test-classes/projects/rewrite-for-development/basic-pom/pom.xml.next" ); + public void testClean() throws Exception { + List reactorProjects = createReactorProjectsWhenSimulated("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + + File testFile = getTestFile("target/test-classes/projects/rewrite-for-development/basic-pom/pom.xml.next"); testFile.delete(); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( testFile.exists() ); + assertTrue(testFile.exists()); - ( (ResourceGenerator) phase ).clean( reactorProjects ); + ((ResourceGenerator) phase).clean(reactorProjects); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); } @Test - public void testCleanNotExists() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); + public void testCleanNotExists() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); - File testFile = getTestFile( "target/test-classes/projects/rewrite-for-development/basic-pom/pom.xml.next" ); + File testFile = getTestFile("target/test-classes/projects/rewrite-for-development/basic-pom/pom.xml.next"); testFile.delete(); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); - ( (ResourceGenerator) phase ).clean( reactorProjects ); + ((ResourceGenerator) phase).clean(reactorProjects); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); } @Override - protected String readTestProjectFile( String fileName ) - throws IOException - { - return readTestProjectFile( fileName, "rewrite-for-development/" ); + protected String readTestProjectFile(String fileName) throws IOException { + return readTestProjectFile(fileName, "rewrite-for-development/"); } - protected String readTestProjectFile( String fileName, String subpath ) - throws IOException - { - return ReleaseUtil.readXmlFile( getTestFile( "target/test-classes/projects/" + subpath + fileName ) ); + protected String readTestProjectFile(String fileName, String subpath) throws IOException { + return ReleaseUtil.readXmlFile(getTestFile("target/test-classes/projects/" + subpath + fileName)); } @Override - protected List prepareReactorProjects( String path ) - throws Exception - { + protected List prepareReactorProjects(String path) throws Exception { String dir = "rewrite-for-development/" + path; - return createReactorProjects( dir, path, null ); + return createReactorProjects(dir, path, null); } @Override - protected ReleaseDescriptorBuilder createDescriptorFromBasicPom( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createDescriptorFromBasicPom( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects(reactorProjects, workingDirectory); - mapScm( builder ); + mapScm(builder); return builder; } - private void mapScm( ReleaseDescriptorBuilder builder ) - { + private void mapScm(ReleaseDescriptorBuilder builder) { Scm scm = new Scm(); - scm.setConnection( "scm:svn:file://localhost/tmp/scm-repo/trunk" ); - scm.setDeveloperConnection( "scm:svn:file://localhost/tmp/scm-repo/trunk" ); - scm.setUrl( "file://localhost/tmp/scm-repo/trunk" ); - builder.addOriginalScmInfo( "groupId:artifactId", scm ); + scm.setConnection("scm:svn:file://localhost/tmp/scm-repo/trunk"); + scm.setDeveloperConnection("scm:svn:file://localhost/tmp/scm-repo/trunk"); + scm.setUrl("file://localhost/tmp/scm-repo/trunk"); + builder.addOriginalScmInfo("groupId:artifactId", scm); } @Override - protected void mapAlternateNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, ALTERNATIVE_RELEASE_VERSION ); - config.addDevelopmentVersion( projectId, ALTERNATIVE_NEXT_VERSION ); + protected void mapAlternateNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, ALTERNATIVE_RELEASE_VERSION); + config.addDevelopmentVersion(projectId, ALTERNATIVE_NEXT_VERSION); } @Override - protected void mapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, RELEASE_VERSION ); - config.addDevelopmentVersion( projectId, NEXT_VERSION ); + protected void mapNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, RELEASE_VERSION); + config.addDevelopmentVersion(projectId, NEXT_VERSION); } @Override - protected void unmapNextVersion( ReleaseDescriptorBuilder builder, String projectId ) - { - builder.addReleaseVersion( projectId, RELEASE_VERSION ); + protected void unmapNextVersion(ReleaseDescriptorBuilder builder, String projectId) { + builder.addReleaseVersion(projectId, RELEASE_VERSION); } @Override - protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - mapScm( builder ); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + mapScm(builder); return builder; } @Override - protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject1", NEXT_VERSION ); - mapScm( builder ); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject1", NEXT_VERSION); + mapScm(builder); return builder; } @Test - public void testRewriteBasicPomWithGit() - throws Exception - { + public void testRewriteBasicPomWithGit() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-git" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-git" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-git"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-git"); + mapNextVersion(builder, "groupId:artifactId"); Scm scm = new Scm(); - scm.setConnection( "${scm.base}:git://localhost/repo" ); - scm.setDeveloperConnection( "${scm.base}:git+ssh://${username}@localhost/tmp/repo" ); - scm.setUrl( "${baseUrl}/repo" ); - builder.addOriginalScmInfo( "groupId:artifactId", scm ); + scm.setConnection("${scm.base}:git://localhost/repo"); + scm.setDeveloperConnection("${scm.base}:git+ssh://${username}@localhost/tmp/repo"); + scm.setUrl("${baseUrl}/repo"); + builder.addOriginalScmInfo("groupId:artifactId", scm); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithGitFromTag() - throws Exception - { + public void testRewriteBasicPomWithGitFromTag() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-git-from-tag" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-git-from-tag" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-git-from-tag"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-git-from-tag"); + mapNextVersion(builder, "groupId:artifactId"); Scm scm = new Scm(); - scm.setConnection( "scm:git:git://localhost/repo" ); - scm.setDeveloperConnection( "scm:git:git+ssh://${username}@localhost/tmp/repo" ); - scm.setUrl( "http://localhost/viewgit.cgi/repo" ); - scm.setTag( "original-label" ); - builder.addOriginalScmInfo( "groupId:artifactId", scm ); + scm.setConnection("scm:git:git://localhost/repo"); + scm.setDeveloperConnection("scm:git:git+ssh://${username}@localhost/tmp/repo"); + scm.setUrl("http://localhost/viewgit.cgi/repo"); + scm.setTag("original-label"); + builder.addOriginalScmInfo("groupId:artifactId", scm); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithSvnFromTag() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-svn-from-tag" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-svn-from-tag" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithSvnFromTag() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-svn-from-tag"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-svn-from-tag"); + mapNextVersion(builder, "groupId:artifactId"); Scm scm = new Scm(); - scm.setConnection( "scm:svn:file://localhost/svnroot/trunk/" ); - scm.setDeveloperConnection( "scm:svn:file://localhost/svnroot/trunk/" ); - scm.setUrl( "http://localhost/svn" ); - scm.setTag( "trunk" ); - builder.addOriginalScmInfo( "groupId:artifactId", scm ); + scm.setConnection("scm:svn:file://localhost/svnroot/trunk/"); + scm.setDeveloperConnection("scm:svn:file://localhost/svnroot/trunk/"); + scm.setUrl("http://localhost/svn"); + scm.setTag("trunk"); + builder.addOriginalScmInfo("groupId:artifactId", scm); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithInheritedScm() - throws Exception - { - - List reactorProjects = createReactorProjects( "basic-pom-inherited-scm" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-inherited-scm" ); - - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject1", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subsubproject", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subsubproject", NEXT_VERSION ); + public void testRewriteBasicPomWithInheritedScm() throws Exception { + + List reactorProjects = createReactorProjects("basic-pom-inherited-scm"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-inherited-scm"); + + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject1", NEXT_VERSION); + builder.addReleaseVersion("groupId:subsubproject", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subsubproject", NEXT_VERSION); Scm scm = new Scm(); - scm.setConnection( "scm:svn:file://localhost/tmp/scm-repo/trunk/subproject1" ); - scm.setDeveloperConnection( "scm:svn:file://localhost/tmp/scm-repo/trunk/subproject1" ); + scm.setConnection("scm:svn:file://localhost/tmp/scm-repo/trunk/subproject1"); + scm.setDeveloperConnection("scm:svn:file://localhost/tmp/scm-repo/trunk/subproject1"); // MRELEASE-107 - scm.setUrl( "http://localhost/viewvc/mypath/trunk/subproject1" ); - builder.addOriginalScmInfo( "groupId:subproject1", scm ); - builder.addOriginalScmInfo( "groupId:subsubproject", null ); + scm.setUrl("http://localhost/viewvc/mypath/trunk/subproject1"); + builder.addOriginalScmInfo("groupId:subproject1", scm); + builder.addOriginalScmInfo("groupId:subsubproject", null); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithParentAndProperties() - throws Exception - { - performTestRewritePomWithParentAndProperties( "pom-with-parent-and-properties" ); + public void testRewritePomWithParentAndProperties() throws Exception { + performTestRewritePomWithParentAndProperties("pom-with-parent-and-properties"); } // MRELEASE-454 @Test - public void testRewritePomWithParentAndPropertiesInDependencyManagement() - throws Exception - { - performTestRewritePomWithParentAndProperties( "pom-with-parent-and-properties-in-dependency-management" ); + public void testRewritePomWithParentAndPropertiesInDependencyManagement() throws Exception { + performTestRewritePomWithParentAndProperties("pom-with-parent-and-properties-in-dependency-management"); } // MRELEASE-454 @Test - public void testRewritePomWithParentAndPropertiesInDependencyManagementImport() - throws Exception - { - performTestRewritePomWithParentAndProperties( "pom-with-parent-and-properties-in-dependency-management-import" ); + public void testRewritePomWithParentAndPropertiesInDependencyManagementImport() throws Exception { + performTestRewritePomWithParentAndProperties("pom-with-parent-and-properties-in-dependency-management-import"); } - private void performTestRewritePomWithParentAndProperties( String path ) - throws Exception - { - List reactorProjects = createReactorProjects( path ); + private void performTestRewritePomWithParentAndProperties(String path) throws Exception { + List reactorProjects = createReactorProjects(path); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, path ); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, path); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - mapScm( builder ); + mapScm(builder); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testSimulateRewritePomWithParentAndProperties() - throws Exception - { + public void testSimulateRewritePomWithParentAndProperties() throws Exception { // use the original ones since simulation didn't modify them - List reactorProjects = createReactorProjects( "pom-with-parent-and-properties-sim" ); + List reactorProjects = createReactorProjects("pom-with-parent-and-properties-sim"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-parent-and-properties-sim" ); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-parent-and-properties-sim"); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - mapScm( builder ); + mapScm(builder); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - for ( MavenProject project : reactorProjects ) - { + for (MavenProject project : reactorProjects) { File pomFile = project.getFile(); - File actualFile = new File( pomFile.getParentFile(), pomFile.getName() + ".next" ); - File expectedFile = new File( actualFile.getParentFile(), "expected-pom.xml" ); + File actualFile = new File(pomFile.getParentFile(), pomFile.getName() + ".next"); + File expectedFile = new File(actualFile.getParentFile(), "expected-pom.xml"); - comparePomFiles( expectedFile, actualFile, true, false ); + comparePomFiles(expectedFile, actualFile, true, false); } } // MRELEASE-311 @Test - public void testRewritePomWithDependencyPropertyCoordinate() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-property-dependency-coordinate" ); + public void testRewritePomWithDependencyPropertyCoordinate() throws Exception { + List reactorProjects = createReactorProjects("pom-with-property-dependency-coordinate"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-property-dependency-coordinate" ); - builder.addReleaseVersion( "groupId:artifactId", RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1-3.4", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject1-3.4", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_RELEASE_VERSION ); - builder.addDevelopmentVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-property-dependency-coordinate"); + builder.addReleaseVersion("groupId:artifactId", RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1-3.4", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject1-3.4", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_RELEASE_VERSION); + builder.addDevelopmentVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - mapScm( builder ); + mapScm(builder); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomDependenciesWithoutDependenciesVersionUpdate() - throws Exception - { + public void testRewritePomDependenciesWithoutDependenciesVersionUpdate() throws Exception { List reactorProjects = - createReactorProjects( "internal-snapshot-dependencies-without-dependencies-version-update" ); - ReleaseDescriptorBuilder builder = createDefaultConfiguration( reactorProjects, "internal-snapshot-dependencies-without-dependencies-version-update" ); - builder.setUpdateDependencies( false ); - mapNextVersion( builder, "groupId:subsubproject" ); + createReactorProjects("internal-snapshot-dependencies-without-dependencies-version-update"); + ReleaseDescriptorBuilder builder = createDefaultConfiguration( + reactorProjects, "internal-snapshot-dependencies-without-dependencies-version-update"); + builder.setUpdateDependencies(false); + mapNextVersion(builder, "groupId:subsubproject"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java index 4fb3367cb..138f4bfc1 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RewritePomsForReleasePhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +package org.apache.maven.shared.release.phase; import java.io.File; import java.io.IOException; @@ -30,469 +25,419 @@ import java.util.List; import java.util.Objects; -import com.google.inject.AbstractModule; -import com.google.inject.Module; import org.apache.maven.project.MavenProject; -import org.apache.maven.scm.manager.ScmManager; import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; import org.apache.maven.shared.release.config.ReleaseUtils; import org.apache.maven.shared.release.env.DefaultReleaseEnvironment; -import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test the SCM modification check phase. * * @author Brett Porter */ -public class RewritePomsForReleasePhaseTest - extends AbstractEditModeRewritingReleasePhaseTestCase -{ +public class RewritePomsForReleasePhaseTest extends AbstractEditModeRewritingReleasePhaseTestCase { private static final String NEXT_VERSION = "1.0"; private static final String ALTERNATIVE_NEXT_VERSION = "2.0"; - public RewritePomsForReleasePhaseTest( String modelETL ) - { - super( modelETL ); + public RewritePomsForReleasePhaseTest(String modelETL) { + super(modelETL); } @Override - protected String getRoleHint() - { + protected String getRoleHint() { return "rewrite-poms-for-release"; } @Override - protected Path getWorkingDirectory( String workingDir ) - { - return super.getWorkingDirectory( "rewrite-for-release/" + workingDir ); + protected Path getWorkingDirectory(String workingDir) { + return super.getWorkingDirectory("rewrite-for-release/" + workingDir); } - @Override - protected List prepareReactorProjects( String path ) - throws Exception - { - String dir = "rewrite-for-release/" + Objects.toString( path, "" ); - return createReactorProjects( dir, path, null ); + protected List prepareReactorProjects(String path) throws Exception { + String dir = "rewrite-for-release/" + Objects.toString(path, ""); + return createReactorProjects(dir, path, null); } @Override - protected String readTestProjectFile( String fileName ) - throws IOException - { - return ReleaseUtil.readXmlFile( getTestFile( "target/test-classes/projects/rewrite-for-release/" + fileName ) ); + protected String readTestProjectFile(String fileName) throws IOException { + return ReleaseUtil.readXmlFile(getTestFile("target/test-classes/projects/rewrite-for-release/" + fileName)); } @Test - public void testSimulateRewrite() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); + public void testSimulateRewrite() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); - String expected = readTestProjectFile( "basic-pom/pom.xml" ); + String expected = readTestProjectFile("basic-pom/pom.xml"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - String actual = readTestProjectFile( "basic-pom/pom.xml" ); - assertEquals( "Check the original POM untouched", expected, actual ); + String actual = readTestProjectFile("basic-pom/pom.xml"); + assertEquals("Check the original POM untouched", expected, actual); - expected = readTestProjectFile( "basic-pom/expected-pom.xml" ); - actual = readTestProjectFile( "basic-pom/pom.xml.tag" ); - assertEquals( "Check the transformed POM", expected, actual ); + expected = readTestProjectFile("basic-pom/expected-pom.xml"); + actual = readTestProjectFile("basic-pom/pom.xml.tag"); + assertEquals("Check the transformed POM", expected, actual); } @Test - public void testRewriteWithDashedComments() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-dashes-in-comment" ); - ReleaseDescriptorBuilder builder = createDescriptorFromBasicPom( reactorProjects, "basic-pom-with-dashes-in-comment" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); + public void testRewriteWithDashedComments() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-dashes-in-comment"); + ReleaseDescriptorBuilder builder = + createDescriptorFromBasicPom(reactorProjects, "basic-pom-with-dashes-in-comment"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); - String expected = readTestProjectFile( "basic-pom-with-dashes-in-comment/pom.xml" ); + String expected = readTestProjectFile("basic-pom-with-dashes-in-comment/pom.xml"); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - String actual = readTestProjectFile( "basic-pom-with-dashes-in-comment/pom.xml" ); - assertEquals( "Check the original POM is untouched", expected, actual ); + String actual = readTestProjectFile("basic-pom-with-dashes-in-comment/pom.xml"); + assertEquals("Check the original POM is untouched", expected, actual); - expected = readTestProjectFile( "basic-pom-with-dashes-in-comment/expected-pom.xml" ); - actual = readTestProjectFile( "basic-pom-with-dashes-in-comment/pom.xml.tag" ); - assertEquals( "Check the transformed POM", expected, actual ); + expected = readTestProjectFile("basic-pom-with-dashes-in-comment/expected-pom.xml"); + actual = readTestProjectFile("basic-pom-with-dashes-in-comment/pom.xml.tag"); + assertEquals("Check the transformed POM", expected, actual); } @Test - public void testClean() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - - File testFile = getTestFile( "target/test-classes/projects/rewrite-for-release/basic-pom/pom.xml.tag" ); + public void testClean() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + + File testFile = getTestFile("target/test-classes/projects/rewrite-for-release/basic-pom/pom.xml.tag"); testFile.delete(); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( testFile.exists() ); + assertTrue(testFile.exists()); - ( (ResourceGenerator) phase ).clean( reactorProjects ); + ((ResourceGenerator) phase).clean(reactorProjects); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); } @Test - public void testCleanNotExists() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom" ); + public void testCleanNotExists() throws Exception { + List reactorProjects = createReactorProjects("basic-pom"); - File testFile = getTestFile( "target/test-classes/projects/rewrite-for-release/basic-pom/pom.xml.tag" ); + File testFile = getTestFile("target/test-classes/projects/rewrite-for-release/basic-pom/pom.xml.tag"); testFile.delete(); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); - ( (ResourceGenerator) phase ).clean( reactorProjects ); + ((ResourceGenerator) phase).clean(reactorProjects); - assertFalse( testFile.exists() ); + assertFalse(testFile.exists()); } // MRELEASE-116 @Test - public void testScmOverridden() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-overridden-scm" ); - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, "pom-with-overridden-scm" ); - builder.addReleaseVersion( "groupId:subsubproject", NEXT_VERSION ); + public void testScmOverridden() throws Exception { + List reactorProjects = createReactorProjects("pom-with-overridden-scm"); + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, "pom-with-overridden-scm"); + builder.addReleaseVersion("groupId:subsubproject", NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Override - protected void mapAlternateNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, ALTERNATIVE_NEXT_VERSION ); + protected void mapAlternateNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, ALTERNATIVE_NEXT_VERSION); } @Override - protected void mapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { - config.addReleaseVersion( projectId, NEXT_VERSION ); + protected void mapNextVersion(ReleaseDescriptorBuilder config, String projectId) { + config.addReleaseVersion(projectId, NEXT_VERSION); } @Override - protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForPomWithParentAlternateNextVersion( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); return builder; } @Override - protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( List reactorProjects, String workingDirectory ) - throws Exception - { - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, workingDirectory ); + protected ReleaseDescriptorBuilder createConfigurationForWithParentNextVersion( + List reactorProjects, String workingDirectory) throws Exception { + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, workingDirectory); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", NEXT_VERSION); return builder; } @Override - protected void unmapNextVersion( ReleaseDescriptorBuilder config, String projectId ) - { + protected void unmapNextVersion(ReleaseDescriptorBuilder config, String projectId) { // nothing to do } @Test - public void testRewriteBasicPomWithGit() - throws Exception - { + public void testRewriteBasicPomWithGit() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-git" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-git" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-git"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-git"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithScmExpression() - throws Exception - { + public void testRewriteBasicPomWithScmExpression() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-scm-expression" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-scm-expression" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-scm-expression"); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "basic-pom-with-scm-expression"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithTagBase() - throws Exception - { + public void testRewriteBasicPomWithTagBase() throws Exception { - List reactorProjects = createReactorProjects( "basic-pom-with-tag-base" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-tag-base" ); - builder.setScmTagBase( "file://localhost/tmp/scm-repo/releases" ); - mapNextVersion( builder, "groupId:artifactId" ); + List reactorProjects = createReactorProjects("basic-pom-with-tag-base"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-tag-base"); + builder.setScmTagBase("file://localhost/tmp/scm-repo/releases"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithTagBaseAndVaryingScmUrls() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-tag-base-and-varying-scm-urls" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-tag-base-and-varying-scm-urls" ); - builder.setScmTagBase( "file://localhost/tmp/scm-repo/allprojects/releases" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithTagBaseAndVaryingScmUrls() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-tag-base-and-varying-scm-urls"); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "basic-pom-with-tag-base-and-varying-scm-urls"); + builder.setScmTagBase("file://localhost/tmp/scm-repo/allprojects/releases"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithGitFromTag() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-git-from-tag" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-git-from-tag" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithGitFromTag() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-git-from-tag"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-git-from-tag"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteBasicPomWithEmptyScm() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-with-empty-scm" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "basic-pom-with-empty-scm" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewriteBasicPomWithEmptyScm() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-with-empty-scm"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "basic-pom-with-empty-scm"); + mapNextVersion(builder, "groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteInterpolatedVersions() - throws Exception - { - List reactorProjects = createReactorProjects( "interpolated-versions" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "interpolated-versions" ); + public void testRewriteInterpolatedVersions() throws Exception { + List reactorProjects = createReactorProjects("interpolated-versions"); + ReleaseDescriptorBuilder builder = createMappedConfiguration(reactorProjects, "interpolated-versions"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewriteInterpolatedVersionsDifferentVersion() - throws Exception - { - List reactorProjects = createReactorProjects( "interpolated-versions" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "interpolated-versions" ); + public void testRewriteInterpolatedVersionsDifferentVersion() throws Exception { + List reactorProjects = createReactorProjects("interpolated-versions"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "interpolated-versions"); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject3", NEXT_VERSION ); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject3", NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - for ( Iterator i = reactorProjects.iterator(); i.hasNext(); ) - { + for (Iterator i = reactorProjects.iterator(); i.hasNext(); ) { MavenProject project = i.next(); // skip subproject1 - we don't need to worry about its version mapping change, it has no deps of any kind - if ( !"groupId".equals( project.getGroupId() ) || !"subproject1".equals( project.getArtifactId() ) ) - { - comparePomFiles( project, "-different-version", true ); + if (!"groupId".equals(project.getGroupId()) || !"subproject1".equals(project.getArtifactId())) { + comparePomFiles(project, "-different-version", true); } } } @Test - public void testRewriteBasicPomWithInheritedScm() - throws Exception - { - List reactorProjects = createReactorProjects( "basic-pom-inherited-scm" ); - ReleaseDescriptorBuilder builder = createConfigurationForWithParentNextVersion( reactorProjects, "basic-pom-inherited-scm" ); - builder.addReleaseVersion( "groupId:subsubproject", NEXT_VERSION ); + public void testRewriteBasicPomWithInheritedScm() throws Exception { + List reactorProjects = createReactorProjects("basic-pom-inherited-scm"); + ReleaseDescriptorBuilder builder = + createConfigurationForWithParentNextVersion(reactorProjects, "basic-pom-inherited-scm"); + builder.addReleaseVersion("groupId:subsubproject", NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithParentAndProperties() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-parent-and-properties" ); + public void testRewritePomWithParentAndProperties() throws Exception { + List reactorProjects = createReactorProjects("pom-with-parent-and-properties"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-parent-and-properties" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-parent-and-properties"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-311 @Test - public void testRewritePomWithDependencyPropertyCoordinate() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-property-dependency-coordinate" ); + public void testRewritePomWithDependencyPropertyCoordinate() throws Exception { + List reactorProjects = createReactorProjects("pom-with-property-dependency-coordinate"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-property-dependency-coordinate" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1-3.4", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-property-dependency-coordinate"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1-3.4", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-305 @Test - public void testRewritePomWithScmOfParentEndingWithASlash() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-scm-of-parent-ending-with-a-slash" ); + public void testRewritePomWithScmOfParentEndingWithASlash() throws Exception { + List reactorProjects = createReactorProjects("pom-with-scm-of-parent-ending-with-a-slash"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-scm-of-parent-ending-with-a-slash" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-scm-of-parent-ending-with-a-slash"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithDeepSubprojects() - throws Exception - { - List reactorProjects = createReactorProjects( "multimodule-with-deep-subprojects" ); + public void testRewritePomWithDeepSubprojects() throws Exception { + List reactorProjects = createReactorProjects("multimodule-with-deep-subprojects"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "multimodule-with-deep-subprojects" ); - builder.addReleaseVersion( "groupId:artifactId", NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "multimodule-with-deep-subprojects"); + builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomForFlatMultiModule() - throws Exception - { - List reactorProjects = - createReactorProjects( "rewrite-for-release/pom-with-parent-flat", "pom-with-parent-flat", "root-project" ); - ReleaseDescriptorBuilder builder = createConfigurationForPomWithParentAlternateNextVersion( reactorProjects, "pom-with-parent-flat" ); + public void testRewritePomForFlatMultiModule() throws Exception { + List reactorProjects = createReactorProjects( + "rewrite-for-release/pom-with-parent-flat", "pom-with-parent-flat", "root-project"); + ReleaseDescriptorBuilder builder = + createConfigurationForPomWithParentAlternateNextVersion(reactorProjects, "pom-with-parent-flat"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-383 @Test - public void testRewritePomWithCDATASectionOnWindows() - throws Exception - { - List reactorProjects = createReactorProjects( "cdata-section" ); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "cdata-section" ); - mapNextVersion( builder, "groupId:artifactId" ); + public void testRewritePomWithCDATASectionOnWindows() throws Exception { + List reactorProjects = createReactorProjects("cdata-section"); + ReleaseDescriptorBuilder builder = createDescriptorFromProjects(reactorProjects, "cdata-section"); + mapNextVersion(builder, "groupId:artifactId"); RewritePomsForReleasePhase phase = (RewritePomsForReleasePhase) this.phase; - ReleaseDescriptorBuilder.BuilderReleaseDescriptor builderReleaseDescriptor = ReleaseUtils.buildReleaseDescriptor( builder ); + ReleaseDescriptorBuilder.BuilderReleaseDescriptor builderReleaseDescriptor = + ReleaseUtils.buildReleaseDescriptor(builder); builderReleaseDescriptor.setLineSeparator("\r\n"); - phase.execute(builderReleaseDescriptor , new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(builderReleaseDescriptor, new DefaultReleaseEnvironment(), reactorProjects); // compare POMS without line ending normalization - assertTrue( comparePomFiles( reactorProjects, false ) ); + assertTrue(comparePomFiles(reactorProjects, false)); } - protected ReleaseDescriptorBuilder createDescriptorFromProjects( List reactorProjects, String workingDirectory ) - { - ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects( reactorProjects, workingDirectory ); - builder.setScmReleaseLabel( "release-label" ); + protected ReleaseDescriptorBuilder createDescriptorFromProjects( + List reactorProjects, String workingDirectory) { + ReleaseDescriptorBuilder builder = super.createDescriptorFromProjects(reactorProjects, workingDirectory); + builder.setScmReleaseLabel("release-label"); return builder; } @Test - public void testRewritePomWithExternallyReleasedParent() - throws Exception - { - List reactorProjects = createReactorProjects( "pom-with-externally-released-parent" ); + public void testRewritePomWithExternallyReleasedParent() throws Exception { + List reactorProjects = createReactorProjects("pom-with-externally-released-parent"); - ReleaseDescriptorBuilder builder = createDescriptorFromProjects( reactorProjects, "pom-with-externally-released-parent" ); - builder.addDependencyReleaseVersion( "external:parent-artifactId", "1" ); - builder.addDependencyDevelopmentVersion( "external:parent-artifactId", "2-SNAPSHOT" ); - builder.addReleaseVersion( "groupId:subproject1", ALTERNATIVE_NEXT_VERSION ); + ReleaseDescriptorBuilder builder = + createDescriptorFromProjects(reactorProjects, "pom-with-externally-released-parent"); + builder.addDependencyReleaseVersion("external:parent-artifactId", "1"); + builder.addDependencyDevelopmentVersion("external:parent-artifactId", "2-SNAPSHOT"); + builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } // MRELEASE-454 @Test - public void testRewritePomWithImportedDependencyManagementInReactor() - throws Exception - { - List reactorProjects = createReactorProjects( "imported-dependency-management-in-reactor" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "imported-dependency-management-in-reactor" ); + public void testRewritePomWithImportedDependencyManagementInReactor() throws Exception { + List reactorProjects = createReactorProjects("imported-dependency-management-in-reactor"); + ReleaseDescriptorBuilder builder = + createMappedConfiguration(reactorProjects, "imported-dependency-management-in-reactor"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } @Test - public void testRewritePomWithDifferentVersionsAcrossModules() - throws Exception - { - List reactorProjects = createReactorProjects( "modules-with-different-versions" ); - ReleaseDescriptorBuilder builder = createMappedConfiguration( reactorProjects, "modules-with-different-versions" ); - builder.addReleaseVersion( "groupId:subproject2", ALTERNATIVE_NEXT_VERSION ); + public void testRewritePomWithDifferentVersionsAcrossModules() throws Exception { + List reactorProjects = createReactorProjects("modules-with-different-versions"); + ReleaseDescriptorBuilder builder = + createMappedConfiguration(reactorProjects, "modules-with-different-versions"); + builder.addReleaseVersion("groupId:subproject2", ALTERNATIVE_NEXT_VERSION); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - assertTrue( comparePomFiles( reactorProjects ) ); + assertTrue(comparePomFiles(reactorProjects)); } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhaseTest.java index eb5e8ece4..bc33c4964 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunCompleteGoalsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,16 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Matchers.isNull; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.List; @@ -46,14 +35,22 @@ import org.apache.maven.shared.release.stubs.MavenExecutorWrapper; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + /** * Test the simple test running phase. * * @author Brett Porter */ -public class RunCompleteGoalsPhaseTest - extends PlexusJUnit4TestCase -{ +public class RunCompleteGoalsPhaseTest extends PlexusJUnit4TestCase { private RunCompleteGoalsPhase phase; private MavenExecutorWrapper mavenExecutorWrapper; @@ -61,173 +58,186 @@ public class RunCompleteGoalsPhaseTest private DefaultReleaseEnvironment releaseEnvironment; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (RunCompleteGoalsPhase) lookup( ReleasePhase.class, "run-completion-goals" ); + phase = (RunCompleteGoalsPhase) lookup(ReleasePhase.class, "run-completion-goals"); - mavenExecutorWrapper = (MavenExecutorWrapper) lookup( "org.apache.maven.shared.release.exec.MavenExecutor", "wrapper" ); + mavenExecutorWrapper = + (MavenExecutorWrapper) lookup("org.apache.maven.shared.release.exec.MavenExecutor", "wrapper"); releaseEnvironment = new DefaultReleaseEnvironment(); - releaseEnvironment.setMavenExecutorId( "wrapper" ); + releaseEnvironment.setMavenExecutorId("wrapper"); } @Test - public void testExecute() - throws ReleaseExecutionException, ReleaseFailureException, MavenExecutorException - { + public void testExecute() throws ReleaseExecutionException, ReleaseFailureException, MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletionGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); + builder.setCompletionGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testSimulate() - throws ReleaseExecutionException, MavenExecutorException - { + public void testSimulate() throws ReleaseExecutionException, MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletionGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); + builder.setCompletionGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, null ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, null); // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testExecuteException() - throws ReleaseFailureException, MavenExecutorException - { + public void testExecuteException() throws ReleaseFailureException, MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletionGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); - - MavenExecutor mock = mock( MavenExecutor.class ); - doThrow( new MavenExecutorException( "...", - new Exception() ) ).when( mock ).executeGoals( eq( testFile ), - eq( "clean integration-test" ), - isA( ReleaseEnvironment.class ), - eq( true ), - isNull(), - isNull(), - isA( ReleaseResult.class ) ); - - mavenExecutorWrapper.setMavenExecutor( mock ); + builder.setCompletionGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); + + MavenExecutor mock = mock(MavenExecutor.class); + doThrow(new MavenExecutorException("...", new Exception())) + .when(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + + mavenExecutorWrapper.setMavenExecutor(mock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "Check cause", MavenExecutorException.class, e.getCause().getClass()); } // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testSimulateException() - throws MavenExecutorException - { + public void testSimulateException() throws MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletionGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); - - MavenExecutor mock = mock( MavenExecutor.class ); - doThrow( new MavenExecutorException( "...", - new Exception() ) ).when( mock ).executeGoals( eq( testFile ), - eq( "clean integration-test" ), - isA( ReleaseEnvironment.class ), - eq( true ), - isNull(), - isNull(), - isA( ReleaseResult.class ) ); - - mavenExecutorWrapper.setMavenExecutor( mock ); + builder.setCompletionGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); + + MavenExecutor mock = mock(MavenExecutor.class); + doThrow(new MavenExecutorException("...", new Exception())) + .when(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + + mavenExecutorWrapper.setMavenExecutor(mock); // execute - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, null); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "Check cause", MavenExecutorException.class, e.getCause().getClass()); } // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testEmptyGoals() - throws Exception - { + public void testEmptyGoals() throws Exception { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setCompletionGoals( "" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); + builder.setCompletionGoals(""); + builder.setWorkingDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); // verify // never invoke mock - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhaseTest.java index b983e50a6..c0e12bfa5 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPerformGoalsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,18 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.Collections; @@ -57,12 +44,22 @@ import org.apache.maven.shared.release.stubs.MavenExecutorWrapper; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * @author Emmanuel Venisse */ -public class RunPerformGoalsPhaseTest - extends PlexusJUnit4TestCase -{ +public class RunPerformGoalsPhaseTest extends PlexusJUnit4TestCase { private RunPerformGoalsPhase phase; private MavenExecutorWrapper mavenExecutorWrapper; @@ -70,311 +67,326 @@ public class RunPerformGoalsPhaseTest private DefaultReleaseEnvironment releaseEnvironment; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (RunPerformGoalsPhase) lookup( ReleasePhase.class, "run-perform-goals" ); + phase = (RunPerformGoalsPhase) lookup(ReleasePhase.class, "run-perform-goals"); - mavenExecutorWrapper = (MavenExecutorWrapper) lookup( "org.apache.maven.shared.release.exec.MavenExecutor", "wrapper" ); + mavenExecutorWrapper = + (MavenExecutorWrapper) lookup("org.apache.maven.shared.release.exec.MavenExecutor", "wrapper"); releaseEnvironment = new DefaultReleaseEnvironment(); - releaseEnvironment.setMavenExecutorId( "wrapper" ); + releaseEnvironment.setMavenExecutorId("wrapper"); } @Test - public void testExecuteException() - throws Exception - { + public void testExecuteException() throws Exception { // prepare - File testFile = getTestFile( "target/checkout-directory" ); + File testFile = getTestFile("target/checkout-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPerformGoals( "goal1 goal2" ); - builder.setCheckoutDirectory( testFile.getAbsolutePath() ); + builder.setPerformGoals("goal1 goal2"); + builder.setCheckoutDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); - doThrow( new MavenExecutorException( "...", new Exception() ) ).when( mock ).executeGoals( eq( testFile ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-DperformRelease=true -f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); + doThrow(new MavenExecutorException("...", new Exception())) + .when(mock) + .executeGoals( + eq(testFile), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-DperformRelease=true -f pom.xml"), + isNull(), + isA(ReleaseResult.class)); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "Check cause", MavenExecutorException.class, e.getCause().getClass()); } - //verify - verify( mock ).executeGoals( eq( testFile ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-DperformRelease=true -f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + // verify + verify(mock) + .executeGoals( + eq(testFile), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-DperformRelease=true -f pom.xml"), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testCustomPomFile() throws Exception - { - //prepare - File testFile = getTestFile( "target/checkout-directory" ); + public void testCustomPomFile() throws Exception { + // prepare + File testFile = getTestFile("target/checkout-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPerformGoals( "goal1 goal2" ); - builder.setPomFileName( "pom1.xml" ); - builder.setCheckoutDirectory( testFile.getAbsolutePath() ); + builder.setPerformGoals("goal1 goal2"); + builder.setPomFileName("pom1.xml"); + builder.setCheckoutDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); - verify( mock ).executeGoals( eq( testFile ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-DperformRelease=true -f pom1.xml" ), - eq( "pom1.xml" ), - isA( ReleaseResult.class ) ); + verify(mock) + .executeGoals( + eq(testFile), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-DperformRelease=true -f pom1.xml"), + eq("pom1.xml"), + isA(ReleaseResult.class)); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - public void testReleasePerformWithArgumentsNoReleaseProfile() - throws Exception - { + public void testReleasePerformWithArgumentsNoReleaseProfile() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setAdditionalArguments( "-Dmaven.test.skip=true" ); - builder.setPerformGoals( "goal1 goal2" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setAdditionalArguments("-Dmaven.test.skip=true"); + builder.setPerformGoals("goal1 goal2"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); - mavenExecutorWrapper.setMavenExecutor( mock ); + MavenExecutor mock = mock(MavenExecutor.class); + mavenExecutorWrapper.setMavenExecutor(mock); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class ))) - .thenReturn( new CheckOutScmResult( "...", Collections.emptyList() ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class))) + .thenReturn(new CheckOutScmResult("...", Collections.emptyList())); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); - builder.setUseReleaseProfile( false ); + builder.setUseReleaseProfile(false); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, createReactorProjects() ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, createReactorProjects()); // verify - verify( mock ).executeGoals( eq( checkoutDirectory ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-Dmaven.test.skip=true -f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); - verify( scmProviderMock ).checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )); - verifyNoMoreInteractions( mock, scmProviderMock ); + verify(mock) + .executeGoals( + eq(checkoutDirectory), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-Dmaven.test.skip=true -f pom.xml"), + isNull(), + isA(ReleaseResult.class)); + verify(scmProviderMock) + .checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class)); + verifyNoMoreInteractions(mock, scmProviderMock); } - public void testReleasePerform() - throws Exception - { + public void testReleasePerform() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setPerformGoals( "goal1 goal2" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setPerformGoals("goal1 goal2"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); - mavenExecutorWrapper.setMavenExecutor( mock ); + MavenExecutor mock = mock(MavenExecutor.class); + mavenExecutorWrapper.setMavenExecutor(mock); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )) ) - .thenReturn( new CheckOutScmResult( "...", Collections.emptyList() ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class))) + .thenReturn(new CheckOutScmResult("...", Collections.emptyList())); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, createReactorProjects() ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, createReactorProjects()); // verify - verify( mock ).executeGoals( eq( checkoutDirectory ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-DperformRelease=true -f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); - verify( scmProviderMock ).checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )); - verifyNoMoreInteractions( mock, scmProviderMock ); + verify(mock) + .executeGoals( + eq(checkoutDirectory), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-DperformRelease=true -f pom.xml"), + isNull(), + isA(ReleaseResult.class)); + verify(scmProviderMock) + .checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class)); + verifyNoMoreInteractions(mock, scmProviderMock); } - public void testReleasePerformNoReleaseProfile() - throws Exception - { + public void testReleasePerformNoReleaseProfile() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setPerformGoals( "goal1 goal2" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setPerformGoals("goal1 goal2"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); - mavenExecutorWrapper.setMavenExecutor( mock ); + MavenExecutor mock = mock(MavenExecutor.class); + mavenExecutorWrapper.setMavenExecutor(mock); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )) ) - .thenReturn( new CheckOutScmResult( "...", Collections.emptyList() ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class))) + .thenReturn(new CheckOutScmResult("...", Collections.emptyList())); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); - builder.setUseReleaseProfile( false ); + builder.setUseReleaseProfile(false); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, createReactorProjects() ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, createReactorProjects()); // verify - verify( mock ).executeGoals( eq( checkoutDirectory ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); - verify( scmProviderMock ).checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )); - verifyNoMoreInteractions( mock, scmProviderMock ); + verify(mock) + .executeGoals( + eq(checkoutDirectory), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-f pom.xml"), + isNull(), + isA(ReleaseResult.class)); + verify(scmProviderMock) + .checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class)); + verifyNoMoreInteractions(mock, scmProviderMock); } - public void testReleasePerformWithArguments() - throws Exception - { + public void testReleasePerformWithArguments() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setAdditionalArguments( "-Dmaven.test.skip=true" ); - builder.setPerformGoals( "goal1 goal2" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - - MavenExecutor mock = mock( MavenExecutor.class ); - mavenExecutorWrapper.setMavenExecutor( mock ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )) ) - .thenReturn( new CheckOutScmResult( "...", Collections.emptyList() ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + builder.setScmSourceUrl("scm-url"); + builder.setAdditionalArguments("-Dmaven.test.skip=true"); + builder.setPerformGoals("goal1 goal2"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + + MavenExecutor mock = mock(MavenExecutor.class); + mavenExecutorWrapper.setMavenExecutor(mock); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class))) + .thenReturn(new CheckOutScmResult("...", Collections.emptyList())); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, createReactorProjects() ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, createReactorProjects()); // verify - verify( mock ).executeGoals( eq( checkoutDirectory ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class), - eq( true), - eq( "-Dmaven.test.skip=true -DperformRelease=true -f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); - verify( scmProviderMock ).checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )); - verifyNoMoreInteractions( mock, scmProviderMock ); + verify(mock) + .executeGoals( + eq(checkoutDirectory), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-Dmaven.test.skip=true -DperformRelease=true -f pom.xml"), + isNull(), + isA(ReleaseResult.class)); + verify(scmProviderMock) + .checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class)); + verifyNoMoreInteractions(mock, scmProviderMock); } - public void testReleasePerformWithReleasePropertiesCompleted() - throws Exception - { + public void testReleasePerformWithReleasePropertiesCompleted() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setPerformGoals( "goal1 goal2" ); - File checkoutDirectory = getTestFile( "target/checkout-directory" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setPerformGoals("goal1 goal2"); + File checkoutDirectory = getTestFile("target/checkout-directory"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); - mavenExecutorWrapper.setMavenExecutor( mock ); + MavenExecutor mock = mock(MavenExecutor.class); + mavenExecutorWrapper.setMavenExecutor(mock); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )) ) - .thenReturn( new CheckOutScmResult( "...", Collections.emptyList() ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class))) + .thenReturn(new CheckOutScmResult("...", Collections.emptyList())); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); - builder.setCompletedPhase( "end-release" ); + builder.setCompletedPhase("end-release"); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, createReactorProjects() ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, createReactorProjects()); // verify - verify( mock ).executeGoals( eq( checkoutDirectory ), - eq( "goal1 goal2" ), - isA( ReleaseEnvironment.class ), - eq( true ), - eq( "-DperformRelease=true -f pom.xml" ), - isNull(), - isA( ReleaseResult.class ) ); - verify( scmProviderMock ).checkOut( isA( ScmRepository.class ), - argThat( new IsScmFileSetEquals( new ScmFileSet( checkoutDirectory ) ) ), - isA( ScmTag.class ), - isA( CommandParameters.class )); - verifyNoMoreInteractions( mock, scmProviderMock ); + verify(mock) + .executeGoals( + eq(checkoutDirectory), + eq("goal1 goal2"), + isA(ReleaseEnvironment.class), + eq(true), + eq("-DperformRelease=true -f pom.xml"), + isNull(), + isA(ReleaseResult.class)); + verify(scmProviderMock) + .checkOut( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(new ScmFileSet(checkoutDirectory))), + isA(ScmTag.class), + isA(CommandParameters.class)); + verifyNoMoreInteractions(mock, scmProviderMock); } - private static List createReactorProjects() - { + private static List createReactorProjects() { MavenProject project = new MavenProject(); - project.setFile( getTestFile( "target/dummy-project/pom.xml" ) ); - return Collections.singletonList( project ); + project.setFile(getTestFile("target/dummy-project/pom.xml")); + return Collections.singletonList(project); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhaseTest.java index 5210ab96f..228069365 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/RunPrepareGoalsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,16 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Matchers.isNull; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.List; @@ -46,14 +35,22 @@ import org.apache.maven.shared.release.stubs.MavenExecutorWrapper; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + /** * Test the simple test running phase. * * @author Brett Porter */ -public class RunPrepareGoalsPhaseTest - extends PlexusJUnit4TestCase -{ +public class RunPrepareGoalsPhaseTest extends PlexusJUnit4TestCase { private RunPrepareGoalsPhase phase; private MavenExecutorWrapper mavenExecutorWrapper; @@ -61,174 +58,186 @@ public class RunPrepareGoalsPhaseTest private DefaultReleaseEnvironment releaseEnvironment; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (RunPrepareGoalsPhase) lookup( ReleasePhase.class, "run-preparation-goals" ); + phase = (RunPrepareGoalsPhase) lookup(ReleasePhase.class, "run-preparation-goals"); - mavenExecutorWrapper = (MavenExecutorWrapper) lookup( "org.apache.maven.shared.release.exec.MavenExecutor", "wrapper" ); + mavenExecutorWrapper = + (MavenExecutorWrapper) lookup("org.apache.maven.shared.release.exec.MavenExecutor", "wrapper"); releaseEnvironment = new DefaultReleaseEnvironment(); - releaseEnvironment.setMavenExecutorId( "wrapper" ); + releaseEnvironment.setMavenExecutorId("wrapper"); } @Test - public void testExecute() - throws ReleaseExecutionException, ReleaseFailureException, MavenExecutorException - { + public void testExecute() throws ReleaseExecutionException, ReleaseFailureException, MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPreparationGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); + builder.setPreparationGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testSimulate() - throws ReleaseExecutionException, MavenExecutorException - { + public void testSimulate() throws ReleaseExecutionException, MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPreparationGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); + builder.setPreparationGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, null ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, null); // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testExecuteException() - throws ReleaseFailureException, MavenExecutorException - { + public void testExecuteException() throws ReleaseFailureException, MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPreparationGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); - - MavenExecutor mock = mock( MavenExecutor.class ); - doThrow( new MavenExecutorException( "...", - new Exception() ) ).when( mock ).executeGoals( eq( testFile ), - eq( "clean integration-test" ), - isA( ReleaseEnvironment.class ), - eq( true ), - isNull(), - isNull(), - isA( ReleaseResult.class ) ); - - mavenExecutorWrapper.setMavenExecutor( mock ); + builder.setPreparationGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); + + MavenExecutor mock = mock(MavenExecutor.class); + doThrow(new MavenExecutorException("...", new Exception())) + .when(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + + mavenExecutorWrapper.setMavenExecutor(mock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "Check cause", MavenExecutorException.class, e.getCause().getClass()); } // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testSimulateException() - throws MavenExecutorException - { + public void testSimulateException() throws MavenExecutorException { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPreparationGoals( "clean integration-test" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); - - MavenExecutor mock = mock( MavenExecutor.class ); - doThrow( new MavenExecutorException( "...", - new Exception() ) ).when( mock ).executeGoals( eq( testFile ), - eq( "clean integration-test" ), - isA( ReleaseEnvironment.class ), - eq( true ), - isNull(), - isNull(), - isA( ReleaseResult.class ) ); - - mavenExecutorWrapper.setMavenExecutor( mock ); + builder.setPreparationGoals("clean integration-test"); + builder.setWorkingDirectory(testFile.getAbsolutePath()); + + MavenExecutor mock = mock(MavenExecutor.class); + doThrow(new MavenExecutorException("...", new Exception())) + .when(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + + mavenExecutorWrapper.setMavenExecutor(mock); // execute - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, null); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "Check cause", MavenExecutorException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (ReleaseExecutionException e) { + assertEquals( + "Check cause", MavenExecutorException.class, e.getCause().getClass()); } // verify - verify( mock ).executeGoals( eq( testFile ), eq( "clean integration-test" ), isA( ReleaseEnvironment.class ), - eq( true ), isNull(), isNull(), - isA( ReleaseResult.class ) ); - verifyNoMoreInteractions( mock ); - + verify(mock) + .executeGoals( + eq(testFile), + eq("clean integration-test"), + isA(ReleaseEnvironment.class), + eq(true), + isNull(), + isNull(), + isA(ReleaseResult.class)); + verifyNoMoreInteractions(mock); } @Test - public void testEmptyGoals() - throws Exception - { + public void testEmptyGoals() throws Exception { // prepare - File testFile = getTestFile( "target/working-directory" ); + File testFile = getTestFile("target/working-directory"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setPreparationGoals( "" ); - builder.setWorkingDirectory( testFile.getAbsolutePath() ); + builder.setPreparationGoals(""); + builder.setWorkingDirectory(testFile.getAbsolutePath()); - MavenExecutor mock = mock( MavenExecutor.class ); + MavenExecutor mock = mock(MavenExecutor.class); - mavenExecutorWrapper.setMavenExecutor( mock ); + mavenExecutorWrapper.setMavenExecutor(mock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), releaseEnvironment, (List) null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), releaseEnvironment, (List) null); // verify // no invocations of mock - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java index b4e8a3792..9a0e097b4 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmBranchPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,18 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.io.File; import java.io.IOException; @@ -62,381 +49,391 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the SCM branch phase. * * @author Brett Porter */ -public class ScmBranchPhaseTest - extends AbstractReleaseTestCase -{ +public class ScmBranchPhaseTest extends AbstractReleaseTestCase { @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "scm-branch" ); + phase = lookup(ReleasePhase.class, "scm-branch"); } - public static String getPath( File file ) - throws IOException - { - return file.toPath().toRealPath( LinkOption.NOFOLLOW_LINKS ).toString(); + public static String getPath(File file) throws IOException { + return file.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); } @Test - public void testBranch() - throws Exception - { + public void testBranch() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( "pom.xml" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName("pom.xml"); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.branch( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label"))))) + .thenReturn(new BranchScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .branch( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitMultiModuleDeepFolders() - throws Exception - { + public void testCommitMultiModuleDeepFolders() throws Exception { // prepare String dir = "scm-commit/multimodule-with-deep-subprojects"; - List reactorProjects = - createReactorProjects( dir, dir, null ); + List reactorProjects = createReactorProjects(dir, dir, null); String sourceUrl = "http://svn.example.com/repos/project/trunk/"; String scmUrl = "scm:svn:" + sourceUrl; ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( scmUrl ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( "pom.xml" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); - builder.setScmBranchBase( "http://svn.example.com/repos/project/branches/" ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); - - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl ); - scmProviderRepository.setBranchBase( "http://svn.example.com/repos/project/branches/" ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( scmUrl, repository ); + builder.setScmSourceUrl(scmUrl); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName("pom.xml"); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); + builder.setScmBranchBase("http://svn.example.com/repos/project/branches/"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); + + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(sourceUrl); + scmProviderRepository.setBranchBase("http://svn.example.com/repos/project/branches/"); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.branch( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label"))))) + .thenReturn(new BranchScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl(scmUrl, repository); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .branch( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitForFlatMultiModule() - throws Exception - { + public void testCommitForFlatMultiModule() throws Exception { // prepare List reactorProjects = - createReactorProjects( "rewrite-for-release/pom-with-parent-flat", "root-project" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); + createReactorProjects("rewrite-for-release/pom-with-parent-flat", "root-project"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( rootProject.getScm().getConnection() ); - builder.setWorkingDirectory( getWorkingDirectory( "rewrite-for-release/pom-with-parent-flat" ).toRealPath( LinkOption.NOFOLLOW_LINKS ).toString() ); - builder.setPomFileName( "root-project/pom.xml" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); + builder.setScmSourceUrl(rootProject.getScm().getConnection()); + builder.setWorkingDirectory(getWorkingDirectory("rewrite-for-release/pom-with-parent-flat") + .toRealPath(LinkOption.NOFOLLOW_LINKS) + .toString()); + builder.setPomFileName("root-project/pom.xml"); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); // one directory up from root project - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile().getParentFile() ); + ScmFileSet fileSet = + new ScmFileSet(rootProject.getFile().getParentFile().getParentFile()); String scmUrl = "file://localhost/tmp/scm-repo/trunk"; - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( scmUrl ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( "scm:svn:" + scmUrl, repository ); + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(scmUrl); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.branch( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label"))))) + .thenReturn(new BranchScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl("scm:svn:" + scmUrl, repository); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .branch( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitMultiModule() - throws Exception - { + public void testCommitMultiModule() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); String dir = "scm-commit/multiple-poms"; - List reactorProjects = createReactorProjects( dir, dir, null ); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( "pom.xml" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + List reactorProjects = createReactorProjects(dir, dir, null); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName("pom.xml"); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.branch( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label"))))) + .thenReturn(new BranchScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // exeucte - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .branch( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmBranchParametersEquals( + new ScmBranchParameters("[my prefix] copy for branch release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testBranchNoReleaseLabel() - throws Exception - { + public void testBranchNoReleaseLabel() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSimulateBranch() - throws Exception - { + public void testSimulateBranch() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( "pom.xml" ); - builder.setScmReleaseLabel( "release-label" ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName("pom.xml"); + builder.setScmReleaseLabel("release-label"); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // no scmProvider invocation - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSimulateBranchNoReleaseLabel() - throws Exception - { + public void testSimulateBranchNoReleaseLabel() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testNoSuchScmProviderExceptionThrown() - throws Exception - { + public void testNoSuchScmProviderExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new NoSuchScmProviderException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new NoSuchScmProviderException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { // verify - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } } @Test - public void testScmRepositoryExceptionThrown() - throws Exception - { + public void testScmRepositoryExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new ScmRepositoryException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new ScmRepositoryException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmRepositoryException e ) - { + fail("Status check should have failed"); + } catch (ReleaseScmRepositoryException e) { // verify - assertNull( "Check no additional cause", e.getCause() ); + assertNull("Check no additional cause", e.getCause()); } - } @Test - public void testScmExceptionThrown() - throws Exception - { + public void testScmExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.branch( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), - isA( ScmBranchParameters.class ) ) ).thenThrow( new ScmException( "..." ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.branch( + isA(ScmRepository.class), + isA(ScmFileSet.class), + isA(String.class), + isA(ScmBranchParameters.class))) + .thenThrow(new ScmException("...")); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause().getClass()); } // verify - verify( scmProviderMock ).branch( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), - isA( ScmBranchParameters.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .branch( + isA(ScmRepository.class), + isA(ScmFileSet.class), + isA(String.class), + isA(ScmBranchParameters.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testScmResultFailure() - throws Exception - { + public void testScmResultFailure() throws Exception { List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManager scmManager = lookup( ScmManager.class ); - ScmProviderStub providerStub = - (ScmProviderStub) scmManager.getProviderByUrl( "scm-url" ); + ScmManager scmManager = lookup(ScmManager.class); + ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl("scm-url"); - providerStub.setBranchScmResult( new BranchScmResult( "", "", "", false ) ); + providerStub.setBranchScmResult(new BranchScmResult("", "", "", false)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Commit should have failed" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("Commit should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } } - private List createReactorProjects() - throws Exception - { + private List createReactorProjects() throws Exception { String dir = "scm-commit/single-pom"; - return createReactorProjects( dir, dir, null ); + return createReactorProjects(dir, dir, null); } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() - throws IOException - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() throws IOException { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setScmReleaseLabel( "release-label" ); - - File workingDir = getTestFile( "target/test/checkout" ); - if ( !workingDir.exists() ) - { - assertTrue( "Failed to create the directory, along with all necessary parent directories", - workingDir.mkdirs() ); + builder.setScmSourceUrl("scm-url"); + builder.setScmReleaseLabel("release-label"); + + File workingDir = getTestFile("target/test/checkout"); + if (!workingDir.exists()) { + assertTrue( + "Failed to create the directory, along with all necessary parent directories", workingDir.mkdirs()); } - - builder.setWorkingDirectory( getPath( workingDir ) ); - builder.setPomFileName( "pom.xml" ); + + builder.setWorkingDirectory(getPath(workingDir)); + builder.setPomFileName("pom.xml"); return builder; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java index bff49da14..05c95c3b2 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,17 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.ArrayList; import java.util.Arrays; @@ -59,384 +47,346 @@ import org.apache.maven.shared.release.stubs.ScmManagerStub; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the SCM modification check phase. * * @author Brett Porter */ -public class ScmCheckModificationsPhaseTest - extends PlexusJUnit4TestCase -{ +public class ScmCheckModificationsPhaseTest extends PlexusJUnit4TestCase { private ReleasePhase phase; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (ReleasePhase) lookup( ReleasePhase.class, "scm-check-modifications" ); + phase = (ReleasePhase) lookup(ReleasePhase.class, "scm-check-modifications"); } @Test - public void testNoSuchScmProviderExceptionThrown() - throws Exception - { + public void testNoSuchScmProviderExceptionThrown() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new NoSuchScmProviderException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new NoSuchScmProviderException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); - - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); + + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals( + "check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { // verify - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } } @Test - public void testScmRepositoryExceptionThrown() - throws Exception - { + public void testScmRepositoryExceptionThrown() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new ScmRepositoryException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new ScmRepositoryException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmRepositoryException e ) - { - assertNull( "Check no additional cause", e.getCause() ); + fail("Status check should have failed"); + } catch (ReleaseScmRepositoryException e) { + assertNull("Check no additional cause", e.getCause()); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmRepositoryException e ) - { - assertNull( "Check no additional cause", e.getCause() ); + fail("Status check should have failed"); + } catch (ReleaseScmRepositoryException e) { + assertNull("Check no additional cause", e.getCause()); } } @Test - public void testScmExceptionThrown() - throws Exception - { + public void testScmExceptionThrown() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.status( isA( ScmRepository.class ), - isA( ScmFileSet.class ) ) ).thenThrow( new ScmException( "..." ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.status(isA(ScmRepository.class), isA(ScmFileSet.class))) + .thenThrow(new ScmException("...")); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause().getClass()); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause().getClass()); } // verify - verify( scmProviderMock, times( 2 ) ).status( isA( ScmRepository.class ), isA( ScmFileSet.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock, times(2)).status(isA(ScmRepository.class), isA(ScmFileSet.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testScmResultFailure() - throws Exception - { + public void testScmResultFailure() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManager scmManager = lookup( ScmManager.class ); + ScmManager scmManager = lookup(ScmManager.class); ScmProviderStub providerStub = - (ScmProviderStub) scmManager.getProviderByUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + (ScmProviderStub) scmManager.getProviderByUrl("scm:svn:file://localhost/tmp/scm-repo"); - providerStub.setStatusScmResult( new StatusScmResult( "", "", "", false ) ); + providerStub.setStatusScmResult(new StatusScmResult("", "", "", false)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("Status check should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("Status check should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } } @Test - public void testNoModifications() - throws Exception - { + public void testNoModifications() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - setChangedFiles( builder, Collections.emptyList() ); + setChangedFiles(builder, Collections.emptyList()); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } @Test - public void testModificationsToExcludedFilesOnly() - throws Exception - { + public void testModificationsToExcludedFilesOnly() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - setChangedFiles( builder, - Arrays.asList( "release.properties", "pom.xml.backup", "pom.xml.tag", "pom.xml.next" ) ); + setChangedFiles(builder, Arrays.asList("release.properties", "pom.xml.backup", "pom.xml.tag", "pom.xml.next")); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); // successful execution is verification enough - assertTrue( true ); + assertTrue(true); } // MRELEASE-645: Allow File/Directory Patterns for the checkModificationExcludes Option @Test - public void testModificationsToCustomExcludedFilesOnly() - throws Exception - { + public void testModificationsToCustomExcludedFilesOnly() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - builder.setCheckModificationExcludes( Collections.singletonList( "**/keep.me" ) ); - - setChangedFiles( builder, - Arrays.asList( "release.properties", "pom.xml.backup", "pom.xml.tag", "pom.xml.next", - "keep.me", "src/app/keep.me", "config\\keep.me" ) ); - - assertEquals( ReleaseResult.SUCCESS, - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ).getResultCode() ); - - assertEquals( ReleaseResult.SUCCESS, - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ).getResultCode() ); + builder.setCheckModificationExcludes(Collections.singletonList("**/keep.me")); + + setChangedFiles( + builder, + Arrays.asList( + "release.properties", + "pom.xml.backup", + "pom.xml.tag", + "pom.xml.next", + "keep.me", + "src/app/keep.me", + "config\\keep.me")); + + assertEquals( + ReleaseResult.SUCCESS, + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null) + .getResultCode()); + + assertEquals( + ReleaseResult.SUCCESS, + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null) + .getResultCode()); } @Test - public void testModificationsToPoms() - throws Exception - { + public void testModificationsToPoms() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - setChangedFiles( builder, Arrays.asList( "pom.xml", "module/pom.xml" ) ); + setChangedFiles(builder, Arrays.asList("pom.xml", "module/pom.xml")); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Status check should have failed"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Status check should have failed"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testModificationsToIncludedFilesOnly() - throws Exception - { + public void testModificationsToIncludedFilesOnly() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - setChangedFiles( builder, Collections.singletonList( "something.txt" ) ); + setChangedFiles(builder, Collections.singletonList("something.txt")); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Status check should have failed"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Status check should have failed"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testModificationsToIncludedAndExcludedFiles() - throws Exception - { + public void testModificationsToIncludedAndExcludedFiles() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - setChangedFiles( builder, Arrays.asList( "release.properties", "pom.xml.backup", "pom.xml.tag", - "pom.xml.release", "something.txt" ) ); + setChangedFiles( + builder, + Arrays.asList( + "release.properties", "pom.xml.backup", "pom.xml.tag", "pom.xml.release", "something.txt")); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Status check should have failed"); + } catch (ReleaseFailureException e) { + assertTrue(true); } - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ); + try { + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null); - fail( "Status check should have failed" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + fail("Status check should have failed"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testModificationsToAdditionalExcludedFiles() - throws Exception - { + public void testModificationsToAdditionalExcludedFiles() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - builder.setCheckModificationExcludes( Collections.singletonList( "something.*" ) ); + builder.setCheckModificationExcludes(Collections.singletonList("something.*")); - setChangedFiles( builder, Collections.singletonList( "something.txt" ) ); + setChangedFiles(builder, Collections.singletonList("something.txt")); - assertEquals( ReleaseResult.SUCCESS, - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ).getResultCode() ); + assertEquals( + ReleaseResult.SUCCESS, + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null) + .getResultCode()); - assertEquals( ReleaseResult.SUCCESS, - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ).getResultCode() ); + assertEquals( + ReleaseResult.SUCCESS, + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null) + .getResultCode()); } // MRELEASE-775 @Test - public void testMultipleExclusionPatternMatch() - throws Exception - { + public void testMultipleExclusionPatternMatch() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - builder.setCheckModificationExcludes( Collections.singletonList( "release.properties" ) ); + builder.setCheckModificationExcludes(Collections.singletonList("release.properties")); - setChangedFiles( builder, Arrays.asList( "release.properties" ) ); + setChangedFiles(builder, Arrays.asList("release.properties")); - assertEquals( ReleaseResult.SUCCESS, - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ).getResultCode() ); + assertEquals( + ReleaseResult.SUCCESS, + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null) + .getResultCode()); - assertEquals( ReleaseResult.SUCCESS, - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), null ).getResultCode() ); + assertEquals( + ReleaseResult.SUCCESS, + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), null) + .getResultCode()); } - private void setChangedFiles( ReleaseDescriptorBuilder builder, List changedFiles ) - throws Exception - { - ScmManager scmManager = (ScmManager) lookup( ScmManager.class ); + private void setChangedFiles(ReleaseDescriptorBuilder builder, List changedFiles) throws Exception { + ScmManager scmManager = (ScmManager) lookup(ScmManager.class); ScmProviderStub providerStub = - (ScmProviderStub) scmManager.getProviderByUrl( "scm:svn:file://localhost/tmp/scm-repo" ); + (ScmProviderStub) scmManager.getProviderByUrl("scm:svn:file://localhost/tmp/scm-repo"); - providerStub.setStatusScmResult( new StatusScmResult( "", createScmFiles( changedFiles ) ) ); + providerStub.setStatusScmResult(new StatusScmResult("", createScmFiles(changedFiles))); } - private static List createScmFiles( List changedFiles ) - { - List files = new ArrayList<>( changedFiles.size() ); - for ( Iterator i = changedFiles.iterator(); i.hasNext(); ) - { + private static List createScmFiles(List changedFiles) { + List files = new ArrayList<>(changedFiles.size()); + for (Iterator i = changedFiles.iterator(); i.hasNext(); ) { String fileName = i.next(); - files.add( new ScmFile( fileName, ScmFileStatus.MODIFIED ) ); + files.add(new ScmFile(fileName, ScmFileStatus.MODIFIED)); } return files; } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:file://localhost/tmp/scm-repo" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm:svn:file://localhost/tmp/scm-repo"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); return builder; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java index 837886929..81777f3fc 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitDevelopmentPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,16 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Matchers.isNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.util.Collections; import java.util.List; @@ -48,18 +37,26 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the SCM development commit phase. * * @author Lars Corneliussen */ -public class ScmCommitDevelopmentPhaseTest - extends AbstractReleaseTestCase -{ +public class ScmCommitDevelopmentPhaseTest extends AbstractReleaseTestCase { private static final String COMMIT_MESSAGE = "[maven-release-manager] prepare for next development iteration"; private static final String ROLLBACK_PREFIX = - "[maven-release-manager] rollback changes from release preparation of "; + "[maven-release-manager] rollback changes from release preparation of "; private List reactorProjects; @@ -70,135 +67,120 @@ public class ScmCommitDevelopmentPhaseTest private ScmProvider scmProviderMock; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (ReleasePhase) lookup( ReleasePhase.class, "scm-commit-development" ); + phase = (ReleasePhase) lookup(ReleasePhase.class, "scm-commit-development"); reactorProjects = createReactorProjects(); - rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder = createReleaseDescriptorBuilder( rootProject ); + rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder = createReleaseDescriptorBuilder(rootProject); } @Test - public void testIsCorrectImplementation() - { - assertEquals( ScmCommitDevelopmentPhase.class, phase.getClass() ); + public void testIsCorrectImplementation() { + assertEquals(ScmCommitDevelopmentPhase.class, phase.getClass()); } @Test - public void testNoCommitOrRollbackRequired() - throws Exception - { - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( rootProject ); + public void testNoCommitOrRollbackRequired() throws Exception { + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(rootProject); List reactorProjects = createReactorProjects(); - builder.setRemoteTagging( false ); - builder.setPinExternals( false ); - builder.setSuppressCommitBeforeTagOrBranch( true ); - builder.setUpdateWorkingCopyVersions( false ); + builder.setRemoteTagging(false); + builder.setPinExternals(false); + builder.setSuppressCommitBeforeTagOrBranch(true); + builder.setUpdateWorkingCopyVersions(false); prepareNoCheckin(); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); verifyNoCheckin(); } @Test - public void testCommitsNextVersions() - throws Exception - { - builder.setUpdateWorkingCopyVersions( true ); + public void testCommitsNextVersions() throws Exception { + builder.setUpdateWorkingCopyVersions(true); - prepareCheckin( COMMIT_MESSAGE ); + prepareCheckin(COMMIT_MESSAGE); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - verifyCheckin( COMMIT_MESSAGE ); + verifyCheckin(COMMIT_MESSAGE); } @Test - public void testCommitsNextVersionsAlternateMessage() - throws Exception - { - builder.setUpdateWorkingCopyVersions( true ); + public void testCommitsNextVersionsAlternateMessage() throws Exception { + builder.setUpdateWorkingCopyVersions(true); builder.setScmCommentPrefix("[release]"); builder.setScmDevelopmentCommitComment("@{prefix} Development of @{groupId}:@{artifactId}"); - prepareCheckin( "[release] Development of groupId:artifactId" ); + prepareCheckin("[release] Development of groupId:artifactId"); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - verifyCheckin( "[release] Development of groupId:artifactId" ); + verifyCheckin("[release] Development of groupId:artifactId"); } @Test - public void testCommitsRollbackPrepare() - throws Exception - { - builder.setUpdateWorkingCopyVersions( false ); + public void testCommitsRollbackPrepare() throws Exception { + builder.setUpdateWorkingCopyVersions(false); String message = ROLLBACK_PREFIX + "release-label"; - prepareCheckin( message ); + prepareCheckin(message); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - verifyCheckin( message ); + verifyCheckin(message); } - private void prepareCheckin( String message ) - throws Exception - { - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( message ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + private void prepareCheckin(String message) throws Exception { + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), rootProject.getFile()); + scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq(message))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); } - private void verifyCheckin( String message ) - throws Exception - { - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), eq( message ) ); - verifyNoMoreInteractions( scmProviderMock ); + private void verifyCheckin(String message) throws Exception { + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), rootProject.getFile()); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), eq(message)); + verifyNoMoreInteractions(scmProviderMock); } - private void prepareNoCheckin() - throws Exception - { - scmProviderMock = mock( ScmProvider.class ); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + private void prepareNoCheckin() throws Exception { + scmProviderMock = mock(ScmProvider.class); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); } - private void verifyNoCheckin() - { - verifyNoMoreInteractions( scmProviderMock ); + private void verifyNoCheckin() { + verifyNoMoreInteractions(scmProviderMock); } - private List createReactorProjects() - throws Exception - { + private List createReactorProjects() throws Exception { String dir = "scm-commit/single-pom"; - return createReactorProjects( dir, dir, null ); + return createReactorProjects(dir, dir, null); } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder( MavenProject rootProject ) - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder(MavenProject rootProject) { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setScmReleaseLabel("release-label"); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); return builder; } -} \ No newline at end of file +} diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java index f040bac22..d4e04cf84 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCommitPreparationPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,19 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.io.File; import java.util.ArrayList; @@ -62,490 +48,489 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the release or branch preparation SCM commit phase. * * @author Brett Porter */ -public class ScmCommitPreparationPhaseTest - extends AbstractReleaseTestCase -{ +public class ScmCommitPreparationPhaseTest extends AbstractReleaseTestCase { private static final String PREFIX = "[maven-release-manager] prepare release "; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = lookup( ReleasePhase.class, "scm-commit-release" ); + phase = lookup(ReleasePhase.class, "scm-commit-release"); } @Test - public void testIsCorrectImplementation() - { - assertEquals( ScmCommitReleasePhase.class, phase.getClass() ); + public void testIsCorrectImplementation() { + assertEquals(ScmCommitReleasePhase.class, phase.getClass()); } @Test - public void testResolvesCorrectBranchImplementation() - throws Exception - { - assertTrue( lookup( ReleasePhase.class, "scm-commit-branch" ) instanceof ScmCommitBranchPhase ); + public void testResolvesCorrectBranchImplementation() throws Exception { + assertTrue(lookup(ReleasePhase.class, "scm-commit-branch") instanceof ScmCommitBranchPhase); } @Test - public void testCommit() - throws Exception - { + public void testCommit() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX - + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), rootProject.getFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq(PREFIX + "release-label"))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), eq( PREFIX + "release-label" ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), eq(PREFIX + "release-label")); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitAlternateMessage() - throws Exception - { + public void testCommitAlternateMessage() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmSourceUrl("scm-url"); builder.setScmCommentPrefix("[release]"); builder.setScmReleaseCommitComment("@{prefix} Release of @{groupId}:@{artifactId} @{releaseLabel}"); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( "[release] Release of groupId:artifactId release-label" ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), rootProject.getFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq("[release] Release of groupId:artifactId release-label"))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), eq( "[release] Release of groupId:artifactId release-label" ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), eq("[release] Release of groupId:artifactId release-label")); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitMultiModule() - throws Exception - { + public void testCommitMultiModule() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); String dir = "scm-commit/multiple-poms"; - List reactorProjects = createReactorProjects( dir, dir, null ); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); + List reactorProjects = createReactorProjects(dir, dir, null); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); List poms = new ArrayList<>(); - for ( Iterator i = reactorProjects.iterator(); i.hasNext(); ) - { + for (Iterator i = reactorProjects.iterator(); i.hasNext(); ) { MavenProject project = i.next(); - poms.add( project.getFile() ); + poms.add(project.getFile()); } - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), poms ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX - + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), poms); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq(PREFIX + "release-label"))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), eq( PREFIX + "release-label" ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), eq(PREFIX + "release-label")); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitDevelopment() - throws Exception - { + public void testCommitDevelopment() throws Exception { // prepare - phase = (ReleasePhase) lookup( ReleasePhase.class, "scm-commit-development" ); + phase = (ReleasePhase) lookup(ReleasePhase.class, "scm-commit-development"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( "[maven-release-manager] prepare for next development iteration" ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), rootProject.getFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq("[maven-release-manager] prepare for next development iteration"))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( "[maven-release-manager] prepare for next development iteration" ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq("[maven-release-manager] prepare for next development iteration")); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitDevelopmentAlternateMessage() - throws Exception - { + public void testCommitDevelopmentAlternateMessage() throws Exception { // prepare - phase = (ReleasePhase) lookup( ReleasePhase.class, "scm-commit-development" ); + phase = (ReleasePhase) lookup(ReleasePhase.class, "scm-commit-development"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmSourceUrl("scm-url"); builder.setScmCommentPrefix("[release]"); - builder.setScmDevelopmentCommitComment("@{prefix} Bump version of @{groupId}:@{artifactId} after @{releaseLabel}"); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), rootProject.getFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( "[release] Bump version of groupId:artifactId after release-label" ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + builder.setScmDevelopmentCommitComment( + "@{prefix} Bump version of @{groupId}:@{artifactId} after @{releaseLabel}"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), rootProject.getFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq("[release] Bump version of groupId:artifactId after release-label"))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( "[release] Bump version of groupId:artifactId after release-label" ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq("[release] Bump version of groupId:artifactId after release-label")); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitNoReleaseLabel() - throws Exception - { + public void testCommitNoReleaseLabel() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testCommitGenerateReleasePoms() - throws Exception - { + public void testCommitGenerateReleasePoms() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setGenerateReleasePoms( true ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); + builder.setScmSourceUrl("scm-url"); + builder.setGenerateReleasePoms(true); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); List files = new ArrayList<>(); - files.add( rootProject.getFile() ); - files.add( ReleaseUtil.getReleasePom( rootProject ) ); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile(), files ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), - eq( PREFIX - + "release-label" ) ) ).thenReturn( new CheckInScmResult( "...", - Collections.singletonList( new ScmFile( rootProject.getFile().getPath(), - ScmFileStatus.CHECKED_IN ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + files.add(rootProject.getFile()); + files.add(ReleaseUtil.getReleasePom(rootProject)); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), files); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), + eq(PREFIX + "release-label"))) + .thenReturn(new CheckInScmResult( + "...", + Collections.singletonList( + new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - isNull( ScmVersion.class ), eq( PREFIX + "release-label" ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)), + isNull(ScmVersion.class), eq(PREFIX + "release-label")); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSimulateCommit() - throws Exception - { + public void testSimulateCommit() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() ); - builder.setScmReleaseLabel( "release-label" ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath()); + builder.setScmReleaseLabel("release-label"); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // never invoke scmProviderMock - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSimulateCommitNoReleaseLabel() - throws Exception - { + public void testSimulateCommitNoReleaseLabel() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testNoSuchScmProviderExceptionThrown() - throws Exception - { + public void testNoSuchScmProviderExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new NoSuchScmProviderException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new NoSuchScmProviderException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { // verify - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } } @Test - public void testScmRepositoryExceptionThrown() - throws Exception - { + public void testScmRepositoryExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new ScmRepositoryException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new ScmRepositoryException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmRepositoryException e ) - { + fail("Status check should have failed"); + } catch (ReleaseScmRepositoryException e) { // verify - assertNull( "Check no additional cause", e.getCause() ); + assertNull("Check no additional cause", e.getCause()); } } @Test - public void testScmExceptionThrown() - throws Exception - { + public void testScmExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.checkIn( isA( ScmRepository.class ), isA( ScmFileSet.class ), isNull( ScmVersion.class ), - isA( String.class ) ) ).thenThrow( new ScmException( "..." ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.checkIn( + isA(ScmRepository.class), isA(ScmFileSet.class), isNull(ScmVersion.class), isA(String.class))) + .thenThrow(new ScmException("...")); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause().getClass()); } // verify - verify( scmProviderMock ).checkIn( isA( ScmRepository.class ), isA( ScmFileSet.class ), - isNull( ScmVersion.class ), isA( String.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .checkIn( + isA(ScmRepository.class), isA(ScmFileSet.class), + isNull(ScmVersion.class), isA(String.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testScmResultFailure() - throws Exception - { + public void testScmResultFailure() throws Exception { List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManager scmManager = (ScmManager) lookup( ScmManager.class ); - ScmProviderStub providerStub = - (ScmProviderStub) scmManager.getProviderByUrl( "scm-url" ); + ScmManager scmManager = (ScmManager) lookup(ScmManager.class); + ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl("scm-url"); - providerStub.setCheckInScmResult( new CheckInScmResult( "", "", "", false ) ); + providerStub.setCheckInScmResult(new CheckInScmResult("", "", "", false)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Commit should have failed" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("Commit should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } } @Test - public void testSuppressCommitWithRemoteTaggingFails() - throws Exception - { + public void testSuppressCommitWithRemoteTaggingFails() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setRemoteTagging( true ); - builder.setPinExternals( false ); - builder.setSuppressCommitBeforeTagOrBranch( true ); + builder.setRemoteTagging(true); + builder.setPinExternals(false); + builder.setSuppressCommitBeforeTagOrBranch(true); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Commit should have failed with ReleaseFailureException" ); - } - catch ( ReleaseFailureException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("Commit should have failed with ReleaseFailureException"); + } catch (ReleaseFailureException e) { + assertNull("check no other cause", e.getCause()); } // never invoke scmProviderMock - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSuppressCommitAfterBranch() - throws Exception - { + public void testSuppressCommitAfterBranch() throws Exception { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setBranchCreation( true ); - builder.setRemoteTagging( false ); - builder.setSuppressCommitBeforeTagOrBranch( true ); + builder.setBranchCreation(true); + builder.setRemoteTagging(false); + builder.setSuppressCommitBeforeTagOrBranch(true); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // never invoke scmProviderMock - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } - private List createReactorProjects() - throws Exception - { + private List createReactorProjects() throws Exception { String dir = "scm-commit/single-pom"; - return createReactorProjects( dir, dir, null ); + return createReactorProjects(dir, dir, null); } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() ); + builder.setScmSourceUrl("scm-url"); + builder.setScmReleaseLabel("release-label"); + builder.setWorkingDirectory(getTestFile("target/test/checkout").getAbsolutePath()); return builder; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java index 4eea100c7..7e4098b1e 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmTagPhaseTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.phase; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,18 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.shared.release.phase; import java.io.File; import java.io.IOException; @@ -67,403 +54,402 @@ import org.apache.maven.shared.release.util.ReleaseUtil; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test the SCM tag phase. * * @author Brett Porter */ -public class ScmTagPhaseTest - extends AbstractReleaseTestCase -{ +public class ScmTagPhaseTest extends AbstractReleaseTestCase { @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - phase = (ReleasePhase) lookup( ReleasePhase.class, "scm-tag" ); + phase = (ReleasePhase) lookup(ReleasePhase.class, "scm-tag"); } @Override - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[] { - new AbstractModule() - { - @Override - protected void configure() - { - bind( ScmManager.class ).toInstance( new ScmManagerStub() ); - bind( ReleaseDescriptorStore.class ).toInstance( new ReleaseDescriptorStoreStub() ); - } + new AbstractModule() { + @Override + protected void configure() { + bind(ScmManager.class).toInstance(new ScmManagerStub()); + bind(ReleaseDescriptorStore.class).toInstance(new ReleaseDescriptorStoreStub()); } + } }; } - public static String getPath( File file ) - throws IOException - { - return file.toPath().toRealPath( LinkOption.NOFOLLOW_LINKS ).toString(); - } - - public static String getPath( String file ) - throws IOException - { - return Paths.get( file ).toRealPath( LinkOption.NOFOLLOW_LINKS ).toString(); + public static String getPath(File file) throws IOException { + return file.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); } + public static String getPath(String file) throws IOException { + return Paths.get(file).toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); + } @Test - public void testTag() - throws Exception - { + public void testTag() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); builder.setScmSignTags(true); - ScmTagParameters expectedTagParameters = new ScmTagParameters( "[my prefix] copy for tag release-label" ); + ScmTagParameters expectedTagParameters = new ScmTagParameters("[my prefix] copy for tag release-label"); expectedTagParameters.setSign(true); - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( expectedTagParameters ) ) ) ).thenReturn( new TagScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.tag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals(expectedTagParameters)))) + .thenReturn(new TagScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( expectedTagParameters ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .tag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals(expectedTagParameters))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitMultiModuleDeepFolders() - throws Exception - { + public void testCommitMultiModuleDeepFolders() throws Exception { // prepare - List reactorProjects = - createReactorProjects( "scm-commit/multimodule-with-deep-subprojects", "" ); + List reactorProjects = createReactorProjects("scm-commit/multimodule-with-deep-subprojects", ""); String sourceUrl = "http://svn.example.com/repos/project/trunk/"; String scmUrl = "scm:svn:" + sourceUrl; ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( scmUrl ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); - builder.setScmTagBase( "http://svn.example.com/repos/project/releases/" ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); - - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( sourceUrl ); - scmProviderRepository.setTagBase( "http://svn.example.com/repos/project/releases/" ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( scmUrl, repository ); + builder.setScmSourceUrl(scmUrl); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); + builder.setScmTagBase("http://svn.example.com/repos/project/releases/"); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); + + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(sourceUrl); + scmProviderRepository.setTagBase("http://svn.example.com/repos/project/releases/"); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.tag( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals( + new ScmTagParameters("[my prefix] copy for tag release-label"))))) + .thenReturn(new TagScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl(scmUrl, repository); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .tag( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals( + new ScmTagParameters("[my prefix] copy for tag release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitForFlatMultiModule() - throws Exception - { + public void testCommitForFlatMultiModule() throws Exception { // prepare List reactorProjects = - createReactorProjects( "rewrite-for-release/pom-with-parent-flat", "root-project" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); + createReactorProjects("rewrite-for-release/pom-with-parent-flat", "root-project"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( rootProject.getScm().getConnection() ); - builder.setWorkingDirectory( getWorkingDirectory( "rewrite-for-release/pom-with-parent-flat" ).toRealPath( LinkOption.NOFOLLOW_LINKS ).toString() ); - builder.setPomFileName( "root-project/pom.xml" ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); + builder.setScmSourceUrl(rootProject.getScm().getConnection()); + builder.setWorkingDirectory(getWorkingDirectory("rewrite-for-release/pom-with-parent-flat") + .toRealPath(LinkOption.NOFOLLOW_LINKS) + .toString()); + builder.setPomFileName("root-project/pom.xml"); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); // one directory up from root project - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile().getParentFile() ); + ScmFileSet fileSet = + new ScmFileSet(rootProject.getFile().getParentFile().getParentFile()); String scmUrl = "file://localhost/tmp/scm-repo/trunk"; - SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository( scmUrl ); - ScmRepository repository = new ScmRepository( "svn", scmProviderRepository ); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); - stub.addScmRepositoryForUrl( "scm:svn:" + scmUrl, repository ); + SvnScmProviderRepository scmProviderRepository = new SvnScmProviderRepository(scmUrl); + ScmRepository repository = new ScmRepository("svn", scmProviderRepository); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.tag( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals( + new ScmTagParameters("[my prefix] copy for tag release-label"))))) + .thenReturn(new TagScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); + stub.addScmRepositoryForUrl("scm:svn:" + scmUrl, repository); // execute - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).tag( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .tag( + eq(repository), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals( + new ScmTagParameters("[my prefix] copy for tag release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testCommitMultiModule() - throws Exception - { + public void testCommitMultiModule() throws Exception { // prepare ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); String dir = "scm-commit/multiple-poms"; - List reactorProjects = createReactorProjects( dir, dir, null ); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - builder.setScmReleaseLabel( "release-label" ); - builder.setScmCommentPrefix( "[my prefix] " ); - - ScmFileSet fileSet = new ScmFileSet( rootProject.getFile().getParentFile() ); - - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ) ).thenReturn( new TagScmResult( "...", - Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ), - ScmFileStatus.TAGGED ) ) ) ); - - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + List reactorProjects = createReactorProjects(dir, dir, null); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + builder.setScmReleaseLabel("release-label"); + builder.setScmCommentPrefix("[my prefix] "); + + ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile()); + + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.tag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals( + new ScmTagParameters("[my prefix] copy for tag release-label"))))) + .thenReturn(new TagScmResult( + "...", + Collections.singletonList(new ScmFile(getPath(rootProject.getFile()), ScmFileStatus.TAGGED)))); + + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // exeucte - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify - verify( scmProviderMock ).tag( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ), - eq( "release-label" ), - argThat( new IsScmTagParametersEquals( new ScmTagParameters( "[my prefix] copy for tag release-label" ) ) ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .tag( + isA(ScmRepository.class), + argThat(new IsScmFileSetEquals(fileSet)), + eq("release-label"), + argThat(new IsScmTagParametersEquals( + new ScmTagParameters("[my prefix] copy for tag release-label")))); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testTagNoReleaseLabel() - throws Exception - { + public void testTagNoReleaseLabel() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testSimulateTag() - throws Exception - { + public void testSimulateTag() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - builder.setScmSourceUrl( "scm-url" ); - MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects ); - builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) ); - builder.setPomFileName( rootProject.getFile().getName() ); - builder.setScmReleaseLabel( "release-label" ); + builder.setScmSourceUrl("scm-url"); + MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects); + builder.setWorkingDirectory(getPath(rootProject.getFile().getParentFile())); + builder.setPomFileName(rootProject.getFile().getName()); + builder.setScmReleaseLabel("release-label"); - ScmProvider scmProviderMock = mock( ScmProvider.class ); + ScmProvider scmProviderMock = mock(ScmProvider.class); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); // verify // no scmProvider invocation - verifyNoMoreInteractions( scmProviderMock ); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testSimulateTagNoReleaseLabel() - throws Exception - { + public void testSimulateTagNoReleaseLabel() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); List reactorProjects = createReactorProjects(); - try - { - phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); - fail( "Should have thrown an exception" ); - } - catch ( ReleaseFailureException e ) - { - assertTrue( true ); + try { + phase.simulate( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); + fail("Should have thrown an exception"); + } catch (ReleaseFailureException e) { + assertTrue(true); } } @Test - public void testNoSuchScmProviderExceptionThrown() - throws Exception - { + public void testNoSuchScmProviderExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new NoSuchScmProviderException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new NoSuchScmProviderException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { // verify - assertEquals( "check cause", NoSuchScmProviderException.class, e.getCause().getClass() ); + assertEquals( + "check cause", + NoSuchScmProviderException.class, + e.getCause().getClass()); } } @Test - public void testScmRepositoryExceptionThrown() - throws Exception - { + public void testScmRepositoryExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManagerStub scmManagerStub = (ScmManagerStub) lookup( ScmManager.class ); - scmManagerStub.setException( new ScmRepositoryException( "..." ) ); + ScmManagerStub scmManagerStub = (ScmManagerStub) lookup(ScmManager.class); + scmManagerStub.setException(new ScmRepositoryException("...")); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseScmRepositoryException e ) - { + fail("Status check should have failed"); + } catch (ReleaseScmRepositoryException e) { // verify - assertNull( "Check no additional cause", e.getCause() ); + assertNull("Check no additional cause", e.getCause()); } } @Test - public void testScmExceptionThrown() - throws Exception - { + public void testScmExceptionThrown() throws Exception { // prepare List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmProvider scmProviderMock = mock( ScmProvider.class ); - when( scmProviderMock.tag( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), - isA( ScmTagParameters.class ) ) ).thenThrow( new ScmException( "..." ) ); + ScmProvider scmProviderMock = mock(ScmProvider.class); + when(scmProviderMock.tag( + isA(ScmRepository.class), + isA(ScmFileSet.class), + isA(String.class), + isA(ScmTagParameters.class))) + .thenThrow(new ScmException("...")); - ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class ); - stub.setScmProvider( scmProviderMock ); + ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class); + stub.setScmProvider(scmProviderMock); // execute - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Status check should have failed" ); - } - catch ( ReleaseExecutionException e ) - { - assertEquals( "check cause", ScmException.class, e.getCause().getClass() ); + fail("Status check should have failed"); + } catch (ReleaseExecutionException e) { + assertEquals("check cause", ScmException.class, e.getCause().getClass()); } // verify - verify( scmProviderMock ).tag( isA( ScmRepository.class ), isA( ScmFileSet.class ), isA( String.class ), - isA( ScmTagParameters.class ) ); - verifyNoMoreInteractions( scmProviderMock ); + verify(scmProviderMock) + .tag(isA(ScmRepository.class), isA(ScmFileSet.class), isA(String.class), isA(ScmTagParameters.class)); + verifyNoMoreInteractions(scmProviderMock); } @Test - public void testScmResultFailure() - throws Exception - { + public void testScmResultFailure() throws Exception { List reactorProjects = createReactorProjects(); ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmManager scmManager = lookup( ScmManager.class ); - ScmProviderStub providerStub = - (ScmProviderStub) scmManager.getProviderByUrl( "scm-url" ); + ScmManager scmManager = lookup(ScmManager.class); + ScmProviderStub providerStub = (ScmProviderStub) scmManager.getProviderByUrl("scm-url"); - providerStub.setTagScmResult( new TagScmResult( "", "", "", false ) ); + providerStub.setTagScmResult(new TagScmResult("", "", "", false)); - try - { - phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects ); + try { + phase.execute( + ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects); - fail( "Commit should have failed" ); - } - catch ( ReleaseScmCommandException e ) - { - assertNull( "check no other cause", e.getCause() ); + fail("Commit should have failed"); + } catch (ReleaseScmCommandException e) { + assertNull("check no other cause", e.getCause()); } } - private List createReactorProjects() - throws Exception - { - return createReactorProjects( "scm-commit/single-pom", "" ); + private List createReactorProjects() throws Exception { + return createReactorProjects("scm-commit/single-pom", ""); } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() - throws IOException - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() throws IOException { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); - builder.setScmReleaseLabel( "release-label" ); - File workingDir = getTestFile( "target/test/checkout" ); - if ( !workingDir.exists() ) - { - assertTrue( "Failed to create the directory, along with all necessary parent directories", - workingDir.mkdirs() ); + builder.setScmSourceUrl("scm-url"); + builder.setScmReleaseLabel("release-label"); + File workingDir = getTestFile("target/test/checkout"); + if (!workingDir.exists()) { + assertTrue( + "Failed to create the directory, along with all necessary parent directories", workingDir.mkdirs()); } - builder.setWorkingDirectory( getPath( workingDir ) ); - builder.setPomFileName( "pom.xml" ); + builder.setWorkingDirectory(getPath(workingDir)); + builder.setPomFileName("pom.xml"); return builder; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java index 6c2764b22..111c56c67 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policies; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,27 +16,28 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; +package org.apache.maven.shared.release.policies; import org.apache.maven.shared.release.policy.naming.NamingPolicyRequest; import org.junit.Test; -public class DefaultNamingPolicyTest -{ +import static org.junit.Assert.assertEquals; + +public class DefaultNamingPolicyTest { private final DefaultNamingPolicy policy = new DefaultNamingPolicy(); @Test - public void testName() throws Exception - { - assertEquals( "ARTIFACTID-VERSION", - policy.getName( newNamingPolicyRequest( "ARTIFACTID", "VERSION" ) ).getName() ); - assertEquals( "ARTIFACTID-1.0-SNAPSHOT", - policy.getName( newNamingPolicyRequest( "ARTIFACTID", "1.0-SNAPSHOT" ) ).getName() ); + public void testName() throws Exception { + assertEquals( + "ARTIFACTID-VERSION", + policy.getName(newNamingPolicyRequest("ARTIFACTID", "VERSION")).getName()); + assertEquals( + "ARTIFACTID-1.0-SNAPSHOT", + policy.getName(newNamingPolicyRequest("ARTIFACTID", "1.0-SNAPSHOT")) + .getName()); } - private NamingPolicyRequest newNamingPolicyRequest( String artifactId, String version ) - { - return new NamingPolicyRequest().setArtifactId( artifactId ).setVersion( version ); + private NamingPolicyRequest newNamingPolicyRequest(String artifactId, String version) { + return new NamingPolicyRequest().setArtifactId(artifactId).setVersion(version); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultVersionPolicyTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultVersionPolicyTest.java index 3b7dd195d..2ea70328c 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultVersionPolicyTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultVersionPolicyTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policies; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,56 +16,50 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; +package org.apache.maven.shared.release.policies; import org.apache.maven.shared.release.policy.version.VersionPolicy; import org.apache.maven.shared.release.policy.version.VersionPolicyRequest; import org.junit.Test; -public class DefaultVersionPolicyTest -{ +import static org.junit.Assert.assertEquals; + +public class DefaultVersionPolicyTest { private final VersionPolicy policy = new DefaultVersionPolicy(); @Test - public void testOneDigitReleaseVersion() throws Exception - { - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( "1-SNAPSHOT" ); - assertEquals( "1", policy.getReleaseVersion( request ).getVersion() ); + public void testOneDigitReleaseVersion() throws Exception { + VersionPolicyRequest request = new VersionPolicyRequest().setVersion("1-SNAPSHOT"); + assertEquals("1", policy.getReleaseVersion(request).getVersion()); } @Test - public void testOneDigitDevelopmentVersion() throws Exception - { - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( "1" ); - assertEquals( "2-SNAPSHOT", policy.getDevelopmentVersion( request ).getVersion() ); + public void testOneDigitDevelopmentVersion() throws Exception { + VersionPolicyRequest request = new VersionPolicyRequest().setVersion("1"); + assertEquals("2-SNAPSHOT", policy.getDevelopmentVersion(request).getVersion()); } - + @Test - public void testTwoDigitsReleaseVersion() throws Exception - { - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( "1.0-SNAPSHOT" ); - assertEquals( "1.0", policy.getReleaseVersion( request ).getVersion() ); + public void testTwoDigitsReleaseVersion() throws Exception { + VersionPolicyRequest request = new VersionPolicyRequest().setVersion("1.0-SNAPSHOT"); + assertEquals("1.0", policy.getReleaseVersion(request).getVersion()); } - + @Test - public void testTwoDigitsDevelopmentVersion() throws Exception - { - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( "1.0" ); - assertEquals( "1.1-SNAPSHOT", policy.getDevelopmentVersion( request ).getVersion() ); + public void testTwoDigitsDevelopmentVersion() throws Exception { + VersionPolicyRequest request = new VersionPolicyRequest().setVersion("1.0"); + assertEquals("1.1-SNAPSHOT", policy.getDevelopmentVersion(request).getVersion()); } @Test - public void testThreeDigitsReleaseVersion() throws Exception - { - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( "1.0.0-SNAPSHOT" ); - assertEquals( "1.0.0", policy.getReleaseVersion( request ).getVersion() ); + public void testThreeDigitsReleaseVersion() throws Exception { + VersionPolicyRequest request = new VersionPolicyRequest().setVersion("1.0.0-SNAPSHOT"); + assertEquals("1.0.0", policy.getReleaseVersion(request).getVersion()); } - + @Test - public void testThreeDigitsDevelopmentVersion() throws Exception - { - VersionPolicyRequest request = new VersionPolicyRequest().setVersion( "1.0.0" ); - assertEquals( "1.0.1-SNAPSHOT", policy.getDevelopmentVersion( request ).getVersion() ); + public void testThreeDigitsDevelopmentVersion() throws Exception { + VersionPolicyRequest request = new VersionPolicyRequest().setVersion("1.0.0"); + assertEquals("1.0.1-SNAPSHOT", policy.getDevelopmentVersion(request).getVersion()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslatorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslatorTest.java index 5b9410b5e..a80ed3f55 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslatorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/ClearCaseScmTranslatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,43 +16,39 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class ClearCaseScmTranslatorTest -{ +public class ClearCaseScmTranslatorTest { private final ClearCaseScmTranslator scmTranslator = new ClearCaseScmTranslator(); /** * @see org.apache.maven.model.Scm#getTag() */ @Test - public void testResolveTag() - { + public void testResolveTag() { // with current implementation you can't call your tag 'HEAD' (which is the default) - assertEquals( null, scmTranslator.resolveTag( "HEAD" ) ); - assertEquals( "project-1.0", scmTranslator.resolveTag( "project-1.0" ) ); + assertEquals(null, scmTranslator.resolveTag("HEAD")); + assertEquals("project-1.0", scmTranslator.resolveTag("project-1.0")); } @Test - public void testTranslateTagUrl() - { - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", null ) ); - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", "tagBase" ) ); + public void testTranslateTagUrl() { + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", null)); + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", "tagBase")); } @Test - public void testTranslateBranchUrl() - { - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", null ) ); - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", "tagBase" ) ); + public void testTranslateBranchUrl() { + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", null)); + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", "tagBase")); } @Test - public void testGetRelativePath() - { - assertEquals( "a/b/c", "a/b/c" ); + public void testGetRelativePath() { + assertEquals("a/b/c", "a/b/c"); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/CvsScmTranslatorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/CvsScmTranslatorTest.java index 083284588..6e7021d52 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/CvsScmTranslatorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/CvsScmTranslatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,43 +16,39 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class CvsScmTranslatorTest -{ +public class CvsScmTranslatorTest { private final CvsScmTranslator scmTranslator = new CvsScmTranslator(); /** * @see org.apache.maven.model.Scm#getTag() */ @Test - public void testResolveTag() - { + public void testResolveTag() { // with current implementation you can't call your tag 'HEAD' (which is the default) - assertEquals( null, scmTranslator.resolveTag( "HEAD" ) ); - assertEquals( "project-1.0", scmTranslator.resolveTag( "project-1.0" ) ); + assertEquals(null, scmTranslator.resolveTag("HEAD")); + assertEquals("project-1.0", scmTranslator.resolveTag("project-1.0")); } @Test - public void testTranslateTagUrl() - { - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", null ) ); - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", "tagBase" ) ); + public void testTranslateTagUrl() { + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", null)); + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", "tagBase")); } @Test - public void testTranslateBranchUrl() - { - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", null ) ); - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", "tagBase" ) ); + public void testTranslateBranchUrl() { + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", null)); + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", "tagBase")); } @Test - public void testGetRelativePath() - { - assertEquals( "a/b/c", "a/b/c" ); + public void testGetRelativePath() { + assertEquals("a/b/c", "a/b/c"); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfiguratorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfiguratorTest.java index 9ecf89838..ed02af2df 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfiguratorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/DefaultScmRepositoryConfiguratorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import com.google.inject.Module; import org.apache.maven.scm.manager.NoSuchScmProviderException; @@ -42,198 +41,175 @@ * * @author Brett Porter */ -public class DefaultScmRepositoryConfiguratorTest extends PlexusJUnit4TestCase -{ +public class DefaultScmRepositoryConfiguratorTest extends PlexusJUnit4TestCase { private ScmRepositoryConfigurator scmRepositoryConfigurator; @Override - public void setUp() - throws Exception - { + public void setUp() throws Exception { super.setUp(); - scmRepositoryConfigurator = lookup( ScmRepositoryConfigurator.class ); + scmRepositoryConfigurator = lookup(ScmRepositoryConfigurator.class); } @Override - protected Module[] getCustomModules() - { + protected Module[] getCustomModules() { return new Module[0]; // real SCM needed } @Test - public void testGetConfiguredRepository() - throws ScmRepositoryException, NoSuchScmProviderException - { + public void testGetConfiguredRepository() throws ScmRepositoryException, NoSuchScmProviderException { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + ScmRepository repository = + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); - assertEquals( "check provider", "svn", repository.getProvider() ); - assertNull( "check username", repository.getProviderRepository().getUser() ); - assertNull( "check password", repository.getProviderRepository().getPassword() ); + assertEquals("check provider", "svn", repository.getProvider()); + assertNull("check username", repository.getProviderRepository().getUser()); + assertNull("check password", repository.getProviderRepository().getPassword()); } @Test public void testGetConfiguredRepositoryWithUsernameAndPassword() - throws ScmRepositoryException, NoSuchScmProviderException - { - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( "username", "password" ); + throws ScmRepositoryException, NoSuchScmProviderException { + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder("username", "password"); - ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + ScmRepository repository = + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); - assertEquals( "check username", "username", repository.getProviderRepository().getUser() ); - assertEquals( "check password", "password", repository.getProviderRepository().getPassword() ); + assertEquals( + "check username", "username", repository.getProviderRepository().getUser()); + assertEquals( + "check password", "password", repository.getProviderRepository().getPassword()); } @Test - public void testGetConfiguredRepositoryWithTagBase() - throws ScmRepositoryException, NoSuchScmProviderException - { + public void testGetConfiguredRepositoryWithTagBase() throws ScmRepositoryException, NoSuchScmProviderException { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:http://localhost/home/svn/module/trunk" ); - builder.setScmTagBase( "http://localhost/home/svn/module/tags" ); + builder.setScmSourceUrl("scm:svn:http://localhost/home/svn/module/trunk"); + builder.setScmTagBase("http://localhost/home/svn/module/tags"); - ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + ScmRepository repository = + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); SvnScmProviderRepository providerRepository = (SvnScmProviderRepository) repository.getProviderRepository(); - assertEquals( "check tag base", "http://localhost/home/svn/module/tags", providerRepository.getTagBase() ); + assertEquals("check tag base", "http://localhost/home/svn/module/tags", providerRepository.getTagBase()); } @Test - public void testGetConfiguredRepositoryWithHost() - throws ScmRepositoryException, NoSuchScmProviderException - { + public void testGetConfiguredRepositoryWithHost() throws ScmRepositoryException, NoSuchScmProviderException { Settings settings = new Settings(); Server server = new Server(); - server.setId( "localhost" ); - server.setUsername( "settings-username" ); - server.setPassword( "settings-password" ); - server.setPrivateKey( "settings-private-key" ); - server.setPassphrase( "settings-passphrase" ); - settings.addServer( server ); + server.setId("localhost"); + server.setUsername("settings-username"); + server.setPassword("settings-password"); + server.setPrivateKey("settings-private-key"); + server.setPassphrase("settings-passphrase"); + settings.addServer(server); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:http://localhost/repo" ); + builder.setScmSourceUrl("scm:svn:http://localhost/repo"); - ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), settings ); + ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( + ReleaseUtils.buildReleaseDescriptor(builder), settings); ScmProviderRepositoryWithHost providerRepository = - (ScmProviderRepositoryWithHost) repository.getProviderRepository(); - assertEquals( "check host", "localhost", providerRepository.getHost() ); - assertEquals( "check port", 0, providerRepository.getPort() ); - assertEquals( "check username", "settings-username", providerRepository.getUser() ); - assertEquals( "check password", "settings-password", providerRepository.getPassword() ); - assertEquals( "check private key", "settings-private-key", providerRepository.getPrivateKey() ); - assertEquals( "check passphrase", "settings-passphrase", providerRepository.getPassphrase() ); + (ScmProviderRepositoryWithHost) repository.getProviderRepository(); + assertEquals("check host", "localhost", providerRepository.getHost()); + assertEquals("check port", 0, providerRepository.getPort()); + assertEquals("check username", "settings-username", providerRepository.getUser()); + assertEquals("check password", "settings-password", providerRepository.getPassword()); + assertEquals("check private key", "settings-private-key", providerRepository.getPrivateKey()); + assertEquals("check passphrase", "settings-passphrase", providerRepository.getPassphrase()); } @Test public void testGetConfiguredRepositoryWithEncryptedPasswords() - throws ScmRepositoryException, NoSuchScmProviderException - { + throws ScmRepositoryException, NoSuchScmProviderException { Settings settings = new Settings(); Server server = new Server(); - server.setId( "localhost" ); - server.setUsername( "testuser" ); - server.setPassword( "{Ael0S2tnXv8H3X+gHKpZAvAA25D8+gmU2w2RrGaf5v8=}" ); - server.setPassphrase( "{7zK9P8hNVeUHbTsjiA/vnOs0zUXbND+9MBNPvdvl+x4=}" ); - settings.addServer( server ); + server.setId("localhost"); + server.setUsername("testuser"); + server.setPassword("{Ael0S2tnXv8H3X+gHKpZAvAA25D8+gmU2w2RrGaf5v8=}"); + server.setPassphrase("{7zK9P8hNVeUHbTsjiA/vnOs0zUXbND+9MBNPvdvl+x4=}"); + settings.addServer(server); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:svn://localhost/repo" ); + builder.setScmSourceUrl("scm:svn:svn://localhost/repo"); - ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), settings ); + ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( + ReleaseUtils.buildReleaseDescriptor(builder), settings); ScmProviderRepositoryWithHost providerRepository = - (ScmProviderRepositoryWithHost) repository.getProviderRepository(); - assertEquals( "check host", "localhost", providerRepository.getHost() ); - assertEquals( "check username", "testuser", providerRepository.getUser() ); - assertEquals( "check password", "testpass", providerRepository.getPassword() ); - assertEquals( "check passphrase", "testphrase", providerRepository.getPassphrase() ); + (ScmProviderRepositoryWithHost) repository.getProviderRepository(); + assertEquals("check host", "localhost", providerRepository.getHost()); + assertEquals("check username", "testuser", providerRepository.getUser()); + assertEquals("check password", "testpass", providerRepository.getPassword()); + assertEquals("check passphrase", "testphrase", providerRepository.getPassphrase()); } @Test - public void testGetConfiguredRepositoryInvalidScmUrl() - throws Exception - { + public void testGetConfiguredRepositoryInvalidScmUrl() throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm-url" ); + builder.setScmSourceUrl("scm-url"); - try - { - scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + try { + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); - fail( "Expected failure to get a repository with an invalid SCM URL" ); - } - catch ( IllegalArgumentException e ) - { + fail("Expected failure to get a repository with an invalid SCM URL"); + } catch (IllegalArgumentException e) { // expected } } @Test - public void testGetConfiguredRepositoryInvalidScmProvider() - throws ScmRepositoryException - { + public void testGetConfiguredRepositoryInvalidScmProvider() throws ScmRepositoryException { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:url:" ); + builder.setScmSourceUrl("scm:url:"); - try - { - scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + try { + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); - fail( "Expected failure to get a repository with an invalid SCM URL" ); - } - catch ( NoSuchScmProviderException e ) - { + fail("Expected failure to get a repository with an invalid SCM URL"); + } catch (NoSuchScmProviderException e) { // expected } } @Test - public void testGetConfiguredRepositoryInvalidScmUrlParameters() - throws NoSuchScmProviderException - { + public void testGetConfiguredRepositoryInvalidScmUrlParameters() throws NoSuchScmProviderException { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:" ); + builder.setScmSourceUrl("scm:svn:"); - try - { - scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + try { + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); - fail( "Expected failure to get a repository with an invalid SCM URL" ); - } - catch ( ScmRepositoryException e ) - { + fail("Expected failure to get a repository with an invalid SCM URL"); + } catch (ScmRepositoryException e) { // expected } } @Test - public void testGetRepositoryProvider() - throws ScmRepositoryException, NoSuchScmProviderException - { + public void testGetRepositoryProvider() throws ScmRepositoryException, NoSuchScmProviderException { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - ScmRepository repository = scmRepositoryConfigurator.getConfiguredRepository( ReleaseUtils.buildReleaseDescriptor( builder ), null ); + ScmRepository repository = + scmRepositoryConfigurator.getConfiguredRepository(ReleaseUtils.buildReleaseDescriptor(builder), null); - ScmProvider provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); - assertEquals( "Check SCM provider", "svn", provider.getScmType() ); + ScmProvider provider = scmRepositoryConfigurator.getRepositoryProvider(repository); + assertEquals("Check SCM provider", "svn", provider.getScmType()); } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder() { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setScmSourceUrl( "scm:svn:http://localhost/repo" ); + builder.setScmSourceUrl("scm:svn:http://localhost/repo"); return builder; } - private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder( String username, String password ) - { + private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder(String username, String password) { ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(); - builder.setScmUsername( username ); - builder.setScmPassword( password ); + builder.setScmUsername(username); + builder.setScmPassword(password); return builder; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/GitScmTranslatorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/GitScmTranslatorTest.java index 602504aa3..21b0898e8 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/GitScmTranslatorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/GitScmTranslatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,44 +16,39 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; -import junit.framework.TestCase; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class GitScmTranslatorTest -{ +public class GitScmTranslatorTest { - private final GitScmTranslator scmTranslator = new GitScmTranslator(); + private final GitScmTranslator scmTranslator = new GitScmTranslator(); /** * @see org.apache.maven.model.Scm#getTag() */ @Test - public void testResolveTag() - { - assertEquals( "HEAD", scmTranslator.resolveTag( "HEAD" ) ); - assertEquals( "project-1.0", scmTranslator.resolveTag( "project-1.0" ) ); + public void testResolveTag() { + assertEquals("HEAD", scmTranslator.resolveTag("HEAD")); + assertEquals("project-1.0", scmTranslator.resolveTag("project-1.0")); } @Test - public void testTranslateTagUrl() - { - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", null ) ); - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", "tagBase" ) ); + public void testTranslateTagUrl() { + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", null)); + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", "tagBase")); } @Test - public void testTranslateBranchUrl() - { - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", null ) ); - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", "tagBase" ) ); + public void testTranslateBranchUrl() { + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", null)); + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", "tagBase")); } @Test - public void testGetRelativePath() - { - assertEquals( "a/b/c", "a/b/c" ); + public void testGetRelativePath() { + assertEquals("a/b/c", "a/b/c"); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/HgScmTranslatorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/HgScmTranslatorTest.java index 9ada9b163..900b0cf9d 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/HgScmTranslatorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/HgScmTranslatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,42 +16,38 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.junit.Test; import static org.junit.Assert.assertEquals; -public class HgScmTranslatorTest -{ +public class HgScmTranslatorTest { private final HgScmTranslator scmTranslator = new HgScmTranslator(); /** * @see org.apache.maven.model.Scm#getTag() */ @Test - public void testResolveTag() - { - assertEquals( "HEAD", scmTranslator.resolveTag( "HEAD" ) ); - assertEquals( "project-1.0", scmTranslator.resolveTag( "project-1.0" ) ); + public void testResolveTag() { + assertEquals("HEAD", scmTranslator.resolveTag("HEAD")); + assertEquals("project-1.0", scmTranslator.resolveTag("project-1.0")); } @Test - public void testTranslateTagUrl() - { - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", null ) ); - assertEquals( "url", scmTranslator.translateTagUrl( "url", "tag", "tagBase" ) ); + public void testTranslateTagUrl() { + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", null)); + assertEquals("url", scmTranslator.translateTagUrl("url", "tag", "tagBase")); } @Test - public void testTranslateBranchUrl() - { - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", null ) ); - assertEquals( "url", scmTranslator.translateBranchUrl( "url", "branchName", "tagBase" ) ); + public void testTranslateBranchUrl() { + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", null)); + assertEquals("url", scmTranslator.translateBranchUrl("url", "branchName", "tagBase")); } @Test - public void testGetRelativePath() - { - assertEquals( "a/b/c", "a/b/c" ); + public void testGetRelativePath() { + assertEquals("a/b/c", "a/b/c"); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/JazzScmTranslatorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/JazzScmTranslatorTest.java index 2b38b7a34..67fe8e2fb 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/JazzScmTranslatorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/JazzScmTranslatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import java.io.File; @@ -26,41 +25,44 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -public class JazzScmTranslatorTest -{ +public class JazzScmTranslatorTest { - private final JazzScmTranslator scmTranslator = new JazzScmTranslator(); + private final JazzScmTranslator scmTranslator = new JazzScmTranslator(); /** * @see org.apache.maven.model.Scm#getTag() */ @Test - public void testResolveTag() - { - assertNull( scmTranslator.resolveTag( "HEAD" ) ); - assertNull( scmTranslator.resolveTag( "project-1.0" ) ); + public void testResolveTag() { + assertNull(scmTranslator.resolveTag("HEAD")); + assertNull(scmTranslator.resolveTag("project-1.0")); } @Test - public void testTranslateTagUrl() - { - assertEquals( "url:tag", scmTranslator.translateTagUrl( "url:module", "tag", null ) ); - assertEquals( "url:tag", scmTranslator.translateTagUrl( "url:module", "tag", "tagBase" ) ); + public void testTranslateTagUrl() { + assertEquals("url:tag", scmTranslator.translateTagUrl("url:module", "tag", null)); + assertEquals("url:tag", scmTranslator.translateTagUrl("url:module", "tag", "tagBase")); } @Test - public void testTranslateBranchUrl() - { - assertEquals( "url:branchName", scmTranslator.translateBranchUrl( "url:module", "branchName", null ) ); - assertEquals( "url:branchName", scmTranslator.translateBranchUrl( "url:module", "branchName", "tagBase" ) ); + public void testTranslateBranchUrl() { + assertEquals("url:branchName", scmTranslator.translateBranchUrl("url:module", "branchName", null)); + assertEquals("url:branchName", scmTranslator.translateBranchUrl("url:module", "branchName", "tagBase")); } @Test - public void testGetRelativePath() - { - assertEquals( "BogusTest" + File.separator + "release.properties", scmTranslator.toRelativePath( "BogusTest/release.properties" ) ); - assertEquals( "BogusTest" + File.separator + "release.properties", scmTranslator.toRelativePath( "/BogusTest/release.properties" ) ); - assertEquals( "BogusTest" + File.separator + "release.properties", scmTranslator.toRelativePath( "BogusTest\\release.properties" ) ); - assertEquals( "BogusTest" + File.separator + "release.properties", scmTranslator.toRelativePath( "\\BogusTest\\release.properties" ) ); + public void testGetRelativePath() { + assertEquals( + "BogusTest" + File.separator + "release.properties", + scmTranslator.toRelativePath("BogusTest/release.properties")); + assertEquals( + "BogusTest" + File.separator + "release.properties", + scmTranslator.toRelativePath("/BogusTest/release.properties")); + assertEquals( + "BogusTest" + File.separator + "release.properties", + scmTranslator.toRelativePath("BogusTest\\release.properties")); + assertEquals( + "BogusTest" + File.separator + "release.properties", + scmTranslator.toRelativePath("\\BogusTest\\release.properties")); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/SubversionScmTranslatorTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/SubversionScmTranslatorTest.java index 161623b70..7d75a823b 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/SubversionScmTranslatorTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/scm/SubversionScmTranslatorTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.scm; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,45 +16,41 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.scm; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -public class SubversionScmTranslatorTest -{ +public class SubversionScmTranslatorTest { - private final SubversionScmTranslator scmTranslator = new SubversionScmTranslator(); + private final SubversionScmTranslator scmTranslator = new SubversionScmTranslator(); /** * @see org.apache.maven.model.Scm#getTag() */ @Test - public void testResolveTag() - { + public void testResolveTag() { // "HEAD"is default - assertNull( scmTranslator.resolveTag( "HEAD" ) ); - assertNull( scmTranslator.resolveTag( "project-1.0" ) ); + assertNull(scmTranslator.resolveTag("HEAD")); + assertNull(scmTranslator.resolveTag("project-1.0")); } @Test - public void testTranslateTagUrl() - { - assertEquals( "url/tags/tag", scmTranslator.translateTagUrl( "url", "tag", null ) ); - assertEquals( "tagBase/tag", scmTranslator.translateTagUrl( "url", "tag", "tagBase" ) ); + public void testTranslateTagUrl() { + assertEquals("url/tags/tag", scmTranslator.translateTagUrl("url", "tag", null)); + assertEquals("tagBase/tag", scmTranslator.translateTagUrl("url", "tag", "tagBase")); } @Test - public void testTranslateBranchUrl() - { - assertEquals( "url/branches/branchName", scmTranslator.translateBranchUrl( "url", "branchName", null ) ); - assertEquals( "tagBase/branchName", scmTranslator.translateBranchUrl( "url", "branchName", "tagBase" ) ); + public void testTranslateBranchUrl() { + assertEquals("url/branches/branchName", scmTranslator.translateBranchUrl("url", "branchName", null)); + assertEquals("tagBase/branchName", scmTranslator.translateBranchUrl("url", "branchName", "tagBase")); } @Test - public void testGetRelativePath() - { - assertEquals( "a/b/c", "a/b/c" ); + public void testGetRelativePath() { + assertEquals("a/b/c", "a/b/c"); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/MavenExecutorWrapper.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/MavenExecutorWrapper.java index 9fa4535ea..1eeeab9f1 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/MavenExecutorWrapper.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/MavenExecutorWrapper.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.stubs; import javax.inject.Named; import javax.inject.Singleton; @@ -30,23 +29,25 @@ import org.apache.maven.shared.release.exec.MavenExecutorException; @Singleton -@Named( "wrapper" ) -public class MavenExecutorWrapper implements MavenExecutor -{ +@Named("wrapper") +public class MavenExecutorWrapper implements MavenExecutor { private MavenExecutor executor; - public void setMavenExecutor( MavenExecutor executor ) - { + public void setMavenExecutor(MavenExecutor executor) { this.executor = executor; } @Override - public void executeGoals( File workingDirectory, String goals, ReleaseEnvironment releaseEnvironment, - boolean interactive, String additionalArguments, String pomFileName, - ReleaseResult result ) - throws MavenExecutorException - { - executor.executeGoals( workingDirectory, goals, releaseEnvironment, interactive, additionalArguments, - pomFileName, result ); + public void executeGoals( + File workingDirectory, + String goals, + ReleaseEnvironment releaseEnvironment, + boolean interactive, + String additionalArguments, + String pomFileName, + ReleaseResult result) + throws MavenExecutorException { + executor.executeGoals( + workingDirectory, goals, releaseEnvironment, interactive, additionalArguments, pomFileName, result); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/NamingPolicyStub.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/NamingPolicyStub.java index 2d94c578b..0446f501d 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/NamingPolicyStub.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/NamingPolicyStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.stubs; import javax.inject.Named; import javax.inject.Singleton; @@ -33,13 +32,10 @@ * */ @Singleton -@Named( "stub" ) -public class NamingPolicyStub implements NamingPolicy -{ +@Named("stub") +public class NamingPolicyStub implements NamingPolicy { @Override - public NamingPolicyResult getName( NamingPolicyRequest request ) - throws PolicyException - { - return new NamingPolicyResult().setName( "STUB" ); + public NamingPolicyResult getName(NamingPolicyRequest request) throws PolicyException { + return new NamingPolicyResult().setName("STUB"); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/ScmManagerStub.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/ScmManagerStub.java index 99d6b389a..7085b32a1 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/ScmManagerStub.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/stubs/ScmManagerStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.stubs; import javax.inject.Singleton; @@ -33,55 +32,41 @@ * Override the makeRepository methods to honour the URL passed in. */ @Singleton -@Priority( 100 ) -public class ScmManagerStub - extends org.apache.maven.scm.manager.ScmManagerStub -{ +@Priority(100) +public class ScmManagerStub extends org.apache.maven.scm.manager.ScmManagerStub { private Exception e; private Map scmRepositoriesForUrl = new HashMap<>(); @Override - public ScmRepository makeScmRepository( String scmUrl ) - throws ScmRepositoryException, NoSuchScmProviderException - { - if ( e != null ) - { - if ( e instanceof ScmRepositoryException ) - { + public ScmRepository makeScmRepository(String scmUrl) throws ScmRepositoryException, NoSuchScmProviderException { + if (e != null) { + if (e instanceof ScmRepositoryException) { throw (ScmRepositoryException) e; - } - else if ( e instanceof NoSuchScmProviderException ) - { + } else if (e instanceof NoSuchScmProviderException) { throw (NoSuchScmProviderException) e; - } - else - { - throw new RuntimeException( e ); + } else { + throw new RuntimeException(e); } } - if ( scmRepositoriesForUrl.isEmpty() ) - { + if (scmRepositoriesForUrl.isEmpty()) { // we didn't configure any for URLs, return the preset one return getScmRepository(); } - ScmRepository repository = scmRepositoriesForUrl.get( scmUrl ); - if ( repository == null ) - { - throw new ScmRepositoryException( "Unexpected URL: " + scmUrl ); + ScmRepository repository = scmRepositoriesForUrl.get(scmUrl); + if (repository == null) { + throw new ScmRepositoryException("Unexpected URL: " + scmUrl); } return repository; } - public void addScmRepositoryForUrl( String url, ScmRepository repository ) - { - scmRepositoriesForUrl.put( url, repository ); + public void addScmRepositoryForUrl(String url, ScmRepository repository) { + scmRepositoriesForUrl.put(url, repository); } - public void setException( Exception e ) - { + public void setException(Exception e) { this.e = e; } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomBuildTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomBuildTest.java index 30789320d..4db65a163 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomBuildTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomBuildTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -29,278 +24,242 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomBuildTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class JDomBuildTest { private SAXBuilder builder = new SAXBuilder(); @Test - public void testGetExtensions() throws Exception - { + public void testGetExtensions() throws Exception { String content = ""; - Document document = builder.build( new StringReader( content ) ); - assertNotNull( new JDomBuild( document.getRootElement() ).getExtensions() ); - assertEquals( 0, new JDomBuild( document.getRootElement() ).getExtensions().size() ); + Document document = builder.build(new StringReader(content)); + assertNotNull(new JDomBuild(document.getRootElement()).getExtensions()); + assertEquals(0, new JDomBuild(document.getRootElement()).getExtensions().size()); content = ""; - document = builder.build( new StringReader( content ) ); - assertEquals( 0, new JDomBuild( document.getRootElement() ).getExtensions().size() ); + document = builder.build(new StringReader(content)); + assertEquals(0, new JDomBuild(document.getRootElement()).getExtensions().size()); content = ""; - document = builder.build( new StringReader( content ) ); - assertEquals( 1, new JDomBuild( document.getRootElement() ).getExtensions().size() ); - + document = builder.build(new StringReader(content)); + assertEquals(1, new JDomBuild(document.getRootElement()).getExtensions().size()); } @Test - public void testGetPluginManagement() throws Exception - { + public void testGetPluginManagement() throws Exception { String content = ""; - Document document = builder.build( new StringReader( content ) ); - assertNull( new JDomBuild( document.getRootElement() ).getPluginManagement() ); + Document document = builder.build(new StringReader(content)); + assertNull(new JDomBuild(document.getRootElement()).getPluginManagement()); content = ""; - document = builder.build( new StringReader( content ) ); - assertNotNull( new JDomBuild( document.getRootElement() ).getPluginManagement() ); + document = builder.build(new StringReader(content)); + assertNotNull(new JDomBuild(document.getRootElement()).getPluginManagement()); } @Test - public void testGetPlugins() throws Exception - { + public void testGetPlugins() throws Exception { String content = ""; - Document document = builder.build( new StringReader( content ) ); - assertNotNull( new JDomBuild( document.getRootElement() ).getPlugins() ); - assertEquals( 0, new JDomBuild( document.getRootElement() ).getPlugins().size() ); + Document document = builder.build(new StringReader(content)); + assertNotNull(new JDomBuild(document.getRootElement()).getPlugins()); + assertEquals(0, new JDomBuild(document.getRootElement()).getPlugins().size()); content = ""; - document = builder.build( new StringReader( content ) ); - assertEquals( 0, new JDomBuild( document.getRootElement() ).getPlugins().size() ); + document = builder.build(new StringReader(content)); + assertEquals(0, new JDomBuild(document.getRootElement()).getPlugins().size()); content = ""; - document = builder.build( new StringReader( content ) ); - assertEquals( 1, new JDomBuild( document.getRootElement() ).getPlugins().size() ); + document = builder.build(new StringReader(content)); + assertEquals(1, new JDomBuild(document.getRootElement()).getPlugins().size()); } // All other methods throw UnsupportedOperationException - @Test( expected = UnsupportedOperationException.class ) - public void testFlushPluginMap() - { - new JDomBuild( null ).flushPluginMap(); + @Test(expected = UnsupportedOperationException.class) + public void testFlushPluginMap() { + new JDomBuild(null).flushPluginMap(); } - @Test( expected = UnsupportedOperationException.class ) - public void testAddExtension() - { - new JDomBuild( null ).addExtension( null );; + @Test(expected = UnsupportedOperationException.class) + public void testAddExtension() { + new JDomBuild(null).addExtension(null); + ; } - @Test( expected = UnsupportedOperationException.class ) - public void testGetOutputDirectory() - { - new JDomBuild( null ).getOutputDirectory(); + @Test(expected = UnsupportedOperationException.class) + public void testGetOutputDirectory() { + new JDomBuild(null).getOutputDirectory(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetScriptSourceDirectory() - { - new JDomBuild( null ).getScriptSourceDirectory(); + @Test(expected = UnsupportedOperationException.class) + public void testGetScriptSourceDirectory() { + new JDomBuild(null).getScriptSourceDirectory(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetSourceDirectory() - { - new JDomBuild( null ).getSourceDirectory(); + @Test(expected = UnsupportedOperationException.class) + public void testGetSourceDirectory() { + new JDomBuild(null).getSourceDirectory(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetTestOutputDirectory() - { - new JDomBuild( null ).getTestOutputDirectory(); + @Test(expected = UnsupportedOperationException.class) + public void testGetTestOutputDirectory() { + new JDomBuild(null).getTestOutputDirectory(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetTestSourceDirectory() - { - new JDomBuild( null ).getTestSourceDirectory(); + @Test(expected = UnsupportedOperationException.class) + public void testGetTestSourceDirectory() { + new JDomBuild(null).getTestSourceDirectory(); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemoveExtension() - { - new JDomBuild( null ).removeExtension( null ); + @Test(expected = UnsupportedOperationException.class) + public void testRemoveExtension() { + new JDomBuild(null).removeExtension(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetExtensions() - { - new JDomBuild( null ).setExtensions( null );; + @Test(expected = UnsupportedOperationException.class) + public void testSetExtensions() { + new JDomBuild(null).setExtensions(null); + ; } - @Test( expected = UnsupportedOperationException.class ) - public void testSetOutputDirectory() - { - new JDomBuild( null ).setOutputDirectory( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetOutputDirectory() { + new JDomBuild(null).setOutputDirectory(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetScriptSourceDirectory() - { - new JDomBuild( null ).setScriptSourceDirectory( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetScriptSourceDirectory() { + new JDomBuild(null).setScriptSourceDirectory(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetSourceDirectory() - { - new JDomBuild( null ).setSourceDirectory( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetSourceDirectory() { + new JDomBuild(null).setSourceDirectory(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetTestOutputDirectoryString() - { - new JDomBuild( null ).setTestOutputDirectory( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetTestOutputDirectoryString() { + new JDomBuild(null).setTestOutputDirectory(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetTestSourceDirectory() - { - new JDomBuild( null ).setTestSourceDirectory( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetTestSourceDirectory() { + new JDomBuild(null).setTestSourceDirectory(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testAddFilter() - { - new JDomBuild( null ).addFilter( null ); + @Test(expected = UnsupportedOperationException.class) + public void testAddFilter() { + new JDomBuild(null).addFilter(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testAddResource() - { - new JDomBuild( null ).addResource( null ); + @Test(expected = UnsupportedOperationException.class) + public void testAddResource() { + new JDomBuild(null).addResource(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testAddTestResource() - { - new JDomBuild( null ).addTestResource( null ); + @Test(expected = UnsupportedOperationException.class) + public void testAddTestResource() { + new JDomBuild(null).addTestResource(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetDefaultGoal() - { - new JDomBuild( null ).getDefaultGoal(); + @Test(expected = UnsupportedOperationException.class) + public void testGetDefaultGoal() { + new JDomBuild(null).getDefaultGoal(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetDirectory() - { - new JDomBuild( null ).getDirectory(); + @Test(expected = UnsupportedOperationException.class) + public void testGetDirectory() { + new JDomBuild(null).getDirectory(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetFilters() - { - new JDomBuild( null ).getFilters(); + @Test(expected = UnsupportedOperationException.class) + public void testGetFilters() { + new JDomBuild(null).getFilters(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetFinalName() - { - new JDomBuild( null ).getFinalName(); + @Test(expected = UnsupportedOperationException.class) + public void testGetFinalName() { + new JDomBuild(null).getFinalName(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetResources() - { - new JDomBuild( null ).getResources(); + @Test(expected = UnsupportedOperationException.class) + public void testGetResources() { + new JDomBuild(null).getResources(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetTestResources() - { - new JDomBuild( null ).getTestResources(); + @Test(expected = UnsupportedOperationException.class) + public void testGetTestResources() { + new JDomBuild(null).getTestResources(); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemoveFilter() - { - new JDomBuild( null ).removeFilter( null ); + @Test(expected = UnsupportedOperationException.class) + public void testRemoveFilter() { + new JDomBuild(null).removeFilter(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemoveResource() - { - new JDomBuild( null ).removeResource( null ); + @Test(expected = UnsupportedOperationException.class) + public void testRemoveResource() { + new JDomBuild(null).removeResource(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemoveTestResource() - { - new JDomBuild( null ).removeTestResource( null ); + @Test(expected = UnsupportedOperationException.class) + public void testRemoveTestResource() { + new JDomBuild(null).removeTestResource(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetDefaultGoal() - { - new JDomBuild( null ).setDefaultGoal( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetDefaultGoal() { + new JDomBuild(null).setDefaultGoal(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetDirectory() - { - new JDomBuild( null ).setDirectory( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetDirectory() { + new JDomBuild(null).setDirectory(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetFilters() - { - new JDomBuild( null ).setFilters( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetFilters() { + new JDomBuild(null).setFilters(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetFinalName() - { - new JDomBuild( null ).setFinalName( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetFinalName() { + new JDomBuild(null).setFinalName(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetResources() - { - new JDomBuild( null ).setResources( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetResources() { + new JDomBuild(null).setResources(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetTestResources() - { - new JDomBuild( null ).setTestResources( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetTestResources() { + new JDomBuild(null).setTestResources(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetPluginManagement() - { - new JDomBuild( null ).setPluginManagement( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetPluginManagement() { + new JDomBuild(null).setPluginManagement(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testAddPlugin() - { - new JDomBuild( null ).addPlugin( null ); + @Test(expected = UnsupportedOperationException.class) + public void testAddPlugin() { + new JDomBuild(null).addPlugin(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemovePlugin() - { - new JDomBuild( null ).removePlugin( null ); + @Test(expected = UnsupportedOperationException.class) + public void testRemovePlugin() { + new JDomBuild(null).removePlugin(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetPlugins() - { - new JDomBuild( null ).setPlugins( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetPlugins() { + new JDomBuild(null).setPlugins(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetPluginsAsMap() - { - new JDomBuild( null ).getPluginsAsMap(); + @Test(expected = UnsupportedOperationException.class) + public void testGetPluginsAsMap() { + new JDomBuild(null).getPluginsAsMap(); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagementTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagementTest.java index c0052b5be..ebb9d829d 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagementTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyManagementTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -28,44 +24,54 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomDependencyManagementTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class JDomDependencyManagementTest { private SAXBuilder builder = new SAXBuilder(); @Test - public void testGetDependencies() throws Exception - { + public void testGetDependencies() throws Exception { String content = ""; - Document document = builder.build( new StringReader( content ) ); - assertNotNull( new JDomDependencyManagement( document.getRootElement() ).getDependencies() ); - assertEquals( 0, new JDomDependencyManagement( document.getRootElement() ).getDependencies().size() ); + Document document = builder.build(new StringReader(content)); + assertNotNull(new JDomDependencyManagement(document.getRootElement()).getDependencies()); + assertEquals( + 0, + new JDomDependencyManagement(document.getRootElement()) + .getDependencies() + .size()); content = ""; - document = builder.build( new StringReader( content ) ); - assertEquals( 0, new JDomDependencyManagement( document.getRootElement() ).getDependencies().size() ); + document = builder.build(new StringReader(content)); + assertEquals( + 0, + new JDomDependencyManagement(document.getRootElement()) + .getDependencies() + .size()); content = ""; - document = builder.build( new StringReader( content ) ); - assertEquals( 1, new JDomDependencyManagement( document.getRootElement() ).getDependencies().size() ); + document = builder.build(new StringReader(content)); + assertEquals( + 1, + new JDomDependencyManagement(document.getRootElement()) + .getDependencies() + .size()); } // All other methods throw UnsupportedOperationException - @Test( expected = UnsupportedOperationException.class ) - public void testAddDependency() - { - new JDomDependencyManagement( null ).addDependency( null ); + @Test(expected = UnsupportedOperationException.class) + public void testAddDependency() { + new JDomDependencyManagement(null).addDependency(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemoveDependency() - { - new JDomDependencyManagement( null ).addDependency( null ); + @Test(expected = UnsupportedOperationException.class) + public void testRemoveDependency() { + new JDomDependencyManagement(null).addDependency(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetDependenciesListOfDependency() - { - new JDomDependencyManagement( null ).setDependencies( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetDependenciesListOfDependency() { + new JDomDependencyManagement(null).setDependencies(null); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyTest.java index eadfcf338..5745d27be 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomDependencyTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -28,159 +24,143 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomDependencyTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class JDomDependencyTest { private SAXBuilder builder = new SAXBuilder(); - @Test( expected = UnsupportedOperationException.class ) - public void testIsOptional() - { - new JDomDependency( null ).isOptional(); + @Test(expected = UnsupportedOperationException.class) + public void testIsOptional() { + new JDomDependency(null).isOptional(); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetOptional() - { - new JDomDependency( null ).setOptional( true ); + @Test(expected = UnsupportedOperationException.class) + public void testSetOptional() { + new JDomDependency(null).setOptional(true); } - @Test( expected = UnsupportedOperationException.class ) - public void testAddExclusion() - { - new JDomDependency( null ).addExclusion( null ); + @Test(expected = UnsupportedOperationException.class) + public void testAddExclusion() { + new JDomDependency(null).addExclusion(null); } @Test - public void testGetArtifactId() throws Exception - { + public void testGetArtifactId() throws Exception { String content = ""; - Element dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomDependency( dependencyElm ).getArtifactId() ); + Element dependencyElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomDependency(dependencyElm).getArtifactId()); content = "ARTIFACTID"; - dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "ARTIFACTID", new JDomDependency( dependencyElm ).getArtifactId() ); + dependencyElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("ARTIFACTID", new JDomDependency(dependencyElm).getArtifactId()); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetClassifier() - { - new JDomDependency( null ).getClassifier(); + @Test(expected = UnsupportedOperationException.class) + public void testGetClassifier() { + new JDomDependency(null).getClassifier(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetExclusions() - { - new JDomDependency( null ).getExclusions(); + @Test(expected = UnsupportedOperationException.class) + public void testGetExclusions() { + new JDomDependency(null).getExclusions(); } @Test - public void testGetGroupId() throws Exception - { + public void testGetGroupId() throws Exception { String content = ""; - Element dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomDependency( dependencyElm ).getGroupId() ); + Element dependencyElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomDependency(dependencyElm).getGroupId()); content = "GROUPID"; - dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "GROUPID", new JDomDependency( dependencyElm ).getGroupId() ); + dependencyElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("GROUPID", new JDomDependency(dependencyElm).getGroupId()); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetScope() - { - new JDomDependency( null ).getScope(); + @Test(expected = UnsupportedOperationException.class) + public void testGetScope() { + new JDomDependency(null).getScope(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetSystemPath() - { - new JDomDependency( null ).getSystemPath(); + @Test(expected = UnsupportedOperationException.class) + public void testGetSystemPath() { + new JDomDependency(null).getSystemPath(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetType() - { - new JDomDependency( null ).getType(); + @Test(expected = UnsupportedOperationException.class) + public void testGetType() { + new JDomDependency(null).getType(); } @Test - public void testGetVersion() throws Exception - { + public void testGetVersion() throws Exception { String content = ""; - Element dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomDependency( dependencyElm ).getVersion() ); + Element dependencyElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomDependency(dependencyElm).getVersion()); content = "VERSION"; - dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "VERSION", new JDomDependency( dependencyElm ).getVersion() ); + dependencyElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("VERSION", new JDomDependency(dependencyElm).getVersion()); } - @Test( expected = UnsupportedOperationException.class ) - public void testRemoveExclusion() - { - new JDomDependency( null ).removeExclusion( null );; + @Test(expected = UnsupportedOperationException.class) + public void testRemoveExclusion() { + new JDomDependency(null).removeExclusion(null); + ; } - @Test( expected = UnsupportedOperationException.class ) - public void testSetArtifactIdString() - { - new JDomDependency( null ).setArtifactId( null );; + @Test(expected = UnsupportedOperationException.class) + public void testSetArtifactIdString() { + new JDomDependency(null).setArtifactId(null); + ; } - @Test( expected = UnsupportedOperationException.class ) - public void testSetClassifierString() - { - new JDomDependency( null ).setClassifier( null );; + @Test(expected = UnsupportedOperationException.class) + public void testSetClassifierString() { + new JDomDependency(null).setClassifier(null); + ; } - @Test( expected = UnsupportedOperationException.class ) - public void testSetExclusions() - { - new JDomDependency( null ).setExclusions( null );; + @Test(expected = UnsupportedOperationException.class) + public void testSetExclusions() { + new JDomDependency(null).setExclusions(null); + ; } - @Test( expected = UnsupportedOperationException.class ) - public void testSetGroupIdString() - { - new JDomDependency( null ).setGroupId( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetGroupIdString() { + new JDomDependency(null).setGroupId(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetScopeString() - { - new JDomDependency( null ).setScope( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetScopeString() { + new JDomDependency(null).setScope(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetSystemPathString() - { - new JDomDependency( null ).setSystemPath( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetSystemPathString() { + new JDomDependency(null).setSystemPath(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetTypeString() - { - new JDomDependency( null ).setType( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetTypeString() { + new JDomDependency(null).setType(null); } @Test - public void testSetVersionString() throws Exception - { + public void testSetVersionString() throws Exception { String content = "OLD_VERSION"; - Element dependencyElm = builder.build( new StringReader( content ) ).getRootElement(); - new JDomDependency( dependencyElm ).setVersion( "NEW_VERSION" ); - assertEquals( "NEW_VERSION", getVersion( dependencyElm ) ); + Element dependencyElm = builder.build(new StringReader(content)).getRootElement(); + new JDomDependency(dependencyElm).setVersion("NEW_VERSION"); + assertEquals("NEW_VERSION", getVersion(dependencyElm)); } @Test - public void testGetName() - { - assertEquals( "dependency", new JDomDependency( null ).getName() ); + public void testGetName() { + assertEquals("dependency", new JDomDependency(null).getName()); } - private String getVersion( Element dependencyElm ) - { - return dependencyElm.getChildTextTrim( "version", dependencyElm.getNamespace() ); + private String getVersion(Element dependencyElm) { + return dependencyElm.getChildTextTrim("version", dependencyElm.getNamespace()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomExtensionTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomExtensionTest.java index 336487b14..6a5eee142 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomExtensionTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomExtensionTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -28,75 +24,69 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomExtensionTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class JDomExtensionTest { private SAXBuilder builder = new SAXBuilder(); @Test - public void testGetArtifactId() throws Exception - { + public void testGetArtifactId() throws Exception { String content = ""; - Element extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomExtension( extensionElm ).getArtifactId() ); + Element extensionElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomExtension(extensionElm).getArtifactId()); content = "ARTIFACTID"; - extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "ARTIFACTID", new JDomExtension( extensionElm ).getArtifactId() ); + extensionElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("ARTIFACTID", new JDomExtension(extensionElm).getArtifactId()); } @Test - public void testGetGroupId() throws Exception - { + public void testGetGroupId() throws Exception { String content = ""; - Element extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomExtension( extensionElm ).getGroupId() ); + Element extensionElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomExtension(extensionElm).getGroupId()); content = "GROUPID"; - extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "GROUPID", new JDomExtension( extensionElm ).getGroupId() ); + extensionElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("GROUPID", new JDomExtension(extensionElm).getGroupId()); } @Test - public void testGetVersion() throws Exception - { + public void testGetVersion() throws Exception { String content = ""; - Element extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomExtension( extensionElm ).getVersion() ); + Element extensionElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomExtension(extensionElm).getVersion()); content = "VERSION"; - extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "VERSION", new JDomExtension( extensionElm ).getVersion() ); + extensionElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("VERSION", new JDomExtension(extensionElm).getVersion()); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetArtifactId() - { - new JDomExtension( null ).setArtifactId( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetArtifactId() { + new JDomExtension(null).setArtifactId(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetGroupId() - { - new JDomExtension( null ).setGroupId( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetGroupId() { + new JDomExtension(null).setGroupId(null); } @Test - public void testSetVersion() throws Exception - { + public void testSetVersion() throws Exception { String content = "OLD_VERSION"; - Element extensionElm = builder.build( new StringReader( content ) ).getRootElement(); - new JDomExtension( extensionElm ).setVersion( "NEW_VERSION" ); - assertEquals( "NEW_VERSION", getVersion( extensionElm ) ); + Element extensionElm = builder.build(new StringReader(content)).getRootElement(); + new JDomExtension(extensionElm).setVersion("NEW_VERSION"); + assertEquals("NEW_VERSION", getVersion(extensionElm)); } @Test - public void testGetName() - { - assertEquals( "extension", new JDomExtension( null ).getName() ); + public void testGetName() { + assertEquals("extension", new JDomExtension(null).getName()); } - private String getVersion( Element extensionElm ) - { - return extensionElm.getChildTextTrim( "version", extensionElm.getNamespace() ); + private String getVersion(Element extensionElm) { + return extensionElm.getChildTextTrim("version", extensionElm.getNamespace()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java index 6d45a62dd..43dec7e06 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomModelTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -32,67 +27,65 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomModelTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class JDomModelTest { private SAXBuilder builder = new SAXBuilder(); @Test - public void testGetScm() throws Exception - { + public void testGetScm() throws Exception { String content = ""; - Document document = builder.build( new StringReader( content ) ); - assertNull( new JDomModel( document ).getScm() ); + Document document = builder.build(new StringReader(content)); + assertNull(new JDomModel(document).getScm()); } @Test - public void testSetScm() throws Exception - { + public void testSetScm() throws Exception { String content = ""; - Document document = builder.build( new StringReader( content ) ); - Model model = new JDomModel( document ); - assertNull( model.getScm() ); + Document document = builder.build(new StringReader(content)); + Model model = new JDomModel(document); + assertNull(model.getScm()); - model.setScm( new Scm() ); - assertNotNull( model.getScm() ); + model.setScm(new Scm()); + assertNotNull(model.getScm()); - model.setScm( null ); - assertNull( model.getScm() ); + model.setScm(null); + assertNull(model.getScm()); } @Test - public void testSetVersion() throws Exception - { + public void testSetVersion() throws Exception { String content = ""; - Element projectElm = builder.build( new StringReader( content ) ).getRootElement(); - Model model = new JDomModel( projectElm ); - assertNull( model.getVersion() ); + Element projectElm = builder.build(new StringReader(content)).getRootElement(); + Model model = new JDomModel(projectElm); + assertNull(model.getVersion()); - model.setVersion( "VERSION" ); - assertEquals( "VERSION", getVersion( projectElm ) ); + model.setVersion("VERSION"); + assertEquals("VERSION", getVersion(projectElm)); - model.setVersion( null ); - assertNull( model.getVersion() ); + model.setVersion(null); + assertNull(model.getVersion()); // inherit from parent // this business logic might need to moved. content = "PARENT_VERSION"; - projectElm = builder.build( new StringReader( content ) ).getRootElement(); - model = new JDomModel( projectElm ); - assertNull( model.getVersion() ); + projectElm = builder.build(new StringReader(content)).getRootElement(); + model = new JDomModel(projectElm); + assertNull(model.getVersion()); - model.setVersion( "PARENT_VERSION" ); - assertNull( getVersion( projectElm ) ); + model.setVersion("PARENT_VERSION"); + assertNull(getVersion(projectElm)); - model.setVersion( "VERSION" ); - assertEquals( "VERSION", getVersion( projectElm ) ); + model.setVersion("VERSION"); + assertEquals("VERSION", getVersion(projectElm)); - model.setVersion( null ); - assertNull( model.getVersion() ); + model.setVersion(null); + assertNull(model.getVersion()); } - private String getVersion( Element projectElm ) - { - return projectElm.getChildText( "version", projectElm.getNamespace() ); + private String getVersion(Element projectElm) { + return projectElm.getChildText("version", projectElm.getNamespace()); } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomParentTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomParentTest.java index b9624e157..5f2c88ee4 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomParentTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomParentTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.*; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -27,75 +24,66 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomParentTest -{ +import static org.junit.Assert.*; + +public class JDomParentTest { private SAXBuilder builder = new SAXBuilder(); - @Test( expected = UnsupportedOperationException.class ) - public void testGetArtifactId() - { - new JDomParent( null ).getArtifactId(); + @Test(expected = UnsupportedOperationException.class) + public void testGetArtifactId() { + new JDomParent(null).getArtifactId(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetGroupId() - { - new JDomParent( null ).getGroupId(); + @Test(expected = UnsupportedOperationException.class) + public void testGetGroupId() { + new JDomParent(null).getGroupId(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetRelativePath() - { - new JDomParent( null ).getRelativePath(); + @Test(expected = UnsupportedOperationException.class) + public void testGetRelativePath() { + new JDomParent(null).getRelativePath(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetVersion() - { - new JDomParent( null ).getVersion(); + @Test(expected = UnsupportedOperationException.class) + public void testGetVersion() { + new JDomParent(null).getVersion(); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetArtifactId() - { - new JDomParent( null ).setArtifactId( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetArtifactId() { + new JDomParent(null).setArtifactId(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetGroupId() - { - new JDomParent( null ).setGroupId( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetGroupId() { + new JDomParent(null).setGroupId(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSetRelativePath() - { - new JDomParent( null ).setRelativePath( null ); + @Test(expected = UnsupportedOperationException.class) + public void testSetRelativePath() { + new JDomParent(null).setRelativePath(null); } @Test - public void testSetVersionString() throws Exception - { + public void testSetVersionString() throws Exception { String content = ""; - Element parentElm = builder.build( new StringReader( content ) ).getRootElement(); + Element parentElm = builder.build(new StringReader(content)).getRootElement(); - assertNull( getVersion( parentElm ) ); + assertNull(getVersion(parentElm)); - new JDomParent( parentElm ).setVersion( "VERSION" ); - assertEquals( "VERSION", getVersion( parentElm ) ); + new JDomParent(parentElm).setVersion("VERSION"); + assertEquals("VERSION", getVersion(parentElm)); - new JDomParent( parentElm ).setVersion( null ); - assertNull( getVersion( parentElm ) ); + new JDomParent(parentElm).setVersion(null); + assertNull(getVersion(parentElm)); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetId() - { - new JDomParent( null ).getId(); + @Test(expected = UnsupportedOperationException.class) + public void testGetId() { + new JDomParent(null).getId(); } - private String getVersion( Element parentElm ) - { - return parentElm.getChildText( "version", parentElm.getNamespace() ); + private String getVersion(Element parentElm) { + return parentElm.getChildText("version", parentElm.getNamespace()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java index 06673cfda..fa9f48d99 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomPropertiesTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.InputStream; import java.io.OutputStream; @@ -34,124 +30,103 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomPropertiesTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class JDomPropertiesTest { private SAXBuilder builder = new SAXBuilder(); @Test - public void testSetProperty() throws Exception - { + public void testSetProperty() throws Exception { String content = ""; - Element propertiesElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( getProperty( propertiesElm, "KEY" ) ); + Element propertiesElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(getProperty(propertiesElm, "KEY")); // Adding not allowed, prepare properties content = "OLD_VALUE"; - propertiesElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "OLD_VALUE", getProperty( propertiesElm, "KEY" ) ); - new JDomProperties( propertiesElm ).setProperty( "KEY", "NEW_VALUE" ); - assertEquals( "NEW_VALUE", getProperty( propertiesElm, "KEY" ) ); + propertiesElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("OLD_VALUE", getProperty(propertiesElm, "KEY")); + new JDomProperties(propertiesElm).setProperty("KEY", "NEW_VALUE"); + assertEquals("NEW_VALUE", getProperty(propertiesElm, "KEY")); } - @Test( expected = UnsupportedOperationException.class ) - public void testLoadReader() - throws Exception - { - new JDomProperties( null ).load( (Reader) null ); + @Test(expected = UnsupportedOperationException.class) + public void testLoadReader() throws Exception { + new JDomProperties(null).load((Reader) null); } - @Test( expected = UnsupportedOperationException.class ) - public void testLoadInputStream() - throws Exception - { - new JDomProperties( null ).load( (InputStream) null ); + @Test(expected = UnsupportedOperationException.class) + public void testLoadInputStream() throws Exception { + new JDomProperties(null).load((InputStream) null); } - @Test( expected = UnsupportedOperationException.class ) - public void testSave() - { - new JDomProperties( null ).save( null, null ); + @Test(expected = UnsupportedOperationException.class) + public void testSave() { + new JDomProperties(null).save(null, null); } - @Test( expected = UnsupportedOperationException.class ) - public void testStoreWriter() - throws Exception - { - new JDomProperties( null ).store( (Writer) null, null ); + @Test(expected = UnsupportedOperationException.class) + public void testStoreWriter() throws Exception { + new JDomProperties(null).store((Writer) null, null); } - @Test( expected = UnsupportedOperationException.class ) - public void testStoreOutputStream() - throws Exception - { - new JDomProperties( null ).store( (OutputStream) null, null ); + @Test(expected = UnsupportedOperationException.class) + public void testStoreOutputStream() throws Exception { + new JDomProperties(null).store((OutputStream) null, null); } - @Test( expected = UnsupportedOperationException.class ) - public void testLoadFromXML() - throws Exception - { - new JDomProperties( null ).loadFromXML( null ); + @Test(expected = UnsupportedOperationException.class) + public void testLoadFromXML() throws Exception { + new JDomProperties(null).loadFromXML(null); } - @Test( expected = UnsupportedOperationException.class ) - public void testStoreToXML() - throws Exception - { - new JDomProperties( null ).storeToXML( null, null ); + @Test(expected = UnsupportedOperationException.class) + public void testStoreToXML() throws Exception { + new JDomProperties(null).storeToXML(null, null); } - @Test( expected = UnsupportedOperationException.class ) - public void testStoreToXMLEncoded() - throws Exception - { - new JDomProperties( null ).storeToXML( (OutputStream) null, null, (String) null ); + @Test(expected = UnsupportedOperationException.class) + public void testStoreToXMLEncoded() throws Exception { + new JDomProperties(null).storeToXML((OutputStream) null, null, (String) null); } @Test - public void testGetProperty() throws Exception - { + public void testGetProperty() throws Exception { String content = ""; - Element propertiesElm = builder.build( new StringReader( content ) ).getRootElement(); - assertNull( new JDomProperties( propertiesElm ).getProperty( "KEY" ) ); + Element propertiesElm = builder.build(new StringReader(content)).getRootElement(); + assertNull(new JDomProperties(propertiesElm).getProperty("KEY")); content = "VALUE"; - propertiesElm = builder.build( new StringReader( content ) ).getRootElement(); - assertEquals( "VALUE", new JDomProperties( propertiesElm ).getProperty( "KEY" ) ); + propertiesElm = builder.build(new StringReader(content)).getRootElement(); + assertEquals("VALUE", new JDomProperties(propertiesElm).getProperty("KEY")); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetPropertyDefault() - { - new JDomProperties( null ).getProperty( null, null ); + @Test(expected = UnsupportedOperationException.class) + public void testGetPropertyDefault() { + new JDomProperties(null).getProperty(null, null); } - @Test( expected = UnsupportedOperationException.class ) - public void testPropertyNames() - { - new JDomProperties( null ).propertyNames(); + @Test(expected = UnsupportedOperationException.class) + public void testPropertyNames() { + new JDomProperties(null).propertyNames(); } - @Test( expected = UnsupportedOperationException.class ) - public void testStringPropertyNames() - { - new JDomProperties( null ).stringPropertyNames(); + @Test(expected = UnsupportedOperationException.class) + public void testStringPropertyNames() { + new JDomProperties(null).stringPropertyNames(); } - @Test( expected = UnsupportedOperationException.class ) - public void testListPrintStream() - { - new JDomProperties( null ).list( (PrintStream) null ); + @Test(expected = UnsupportedOperationException.class) + public void testListPrintStream() { + new JDomProperties(null).list((PrintStream) null); } - @Test( expected = UnsupportedOperationException.class ) - public void testListPrintWriter() - { - new JDomProperties( null ).list( (PrintWriter) null ); + @Test(expected = UnsupportedOperationException.class) + public void testListPrintWriter() { + new JDomProperties(null).list((PrintWriter) null); } - private String getProperty( Element propertiesElm, String key ) - { - return propertiesElm.getChildText( key, propertiesElm.getNamespace() ); + private String getProperty(Element propertiesElm, String key) { + return propertiesElm.getChildText(key, propertiesElm.getNamespace()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomScmTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomScmTest.java index ccd8b6b54..bb12fc891 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomScmTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/transform/jdom2/JDomScmTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.transform.jdom2; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +package org.apache.maven.shared.release.transform.jdom2; import java.io.StringReader; @@ -28,111 +24,101 @@ import org.jdom2.input.SAXBuilder; import org.junit.Test; -public class JDomScmTest -{ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class JDomScmTest { private SAXBuilder builder = new SAXBuilder(); - @Test( expected = UnsupportedOperationException.class ) - public void testGetConnection() - { - new JDomScm( null ).getConnection(); + @Test(expected = UnsupportedOperationException.class) + public void testGetConnection() { + new JDomScm(null).getConnection(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetDeveloperConnection() - { - new JDomScm( null ).getDeveloperConnection(); + @Test(expected = UnsupportedOperationException.class) + public void testGetDeveloperConnection() { + new JDomScm(null).getDeveloperConnection(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetTag() - { - new JDomScm( null ).getTag(); + @Test(expected = UnsupportedOperationException.class) + public void testGetTag() { + new JDomScm(null).getTag(); } - @Test( expected = UnsupportedOperationException.class ) - public void testGetUrl() - { - new JDomScm( null ).getUrl(); + @Test(expected = UnsupportedOperationException.class) + public void testGetUrl() { + new JDomScm(null).getUrl(); } @Test - public void testSetConnectionString() throws Exception - { + public void testSetConnectionString() throws Exception { String content = ""; - Element scmElm = builder.build( new StringReader( content ) ).getRootElement(); + Element scmElm = builder.build(new StringReader(content)).getRootElement(); - assertNull( getConnection( scmElm ) ); + assertNull(getConnection(scmElm)); - new JDomScm( scmElm ).setConnection( "CONNECTION" ); - assertEquals( "CONNECTION", getConnection( scmElm ) ); + new JDomScm(scmElm).setConnection("CONNECTION"); + assertEquals("CONNECTION", getConnection(scmElm)); - new JDomScm( scmElm ).setConnection( null ); - assertNull( getConnection( scmElm ) ); + new JDomScm(scmElm).setConnection(null); + assertNull(getConnection(scmElm)); } @Test - public void testSetDeveloperConnectionString() throws Exception - { + public void testSetDeveloperConnectionString() throws Exception { String content = ""; - Element scmElm = builder.build( new StringReader( content ) ).getRootElement(); + Element scmElm = builder.build(new StringReader(content)).getRootElement(); - assertNull( getDeveloperConnection( scmElm ) ); + assertNull(getDeveloperConnection(scmElm)); - new JDomScm( scmElm ).setDeveloperConnection( "DEVELOPERCONNECTION" ); - assertEquals( "DEVELOPERCONNECTION", getDeveloperConnection( scmElm ) ); + new JDomScm(scmElm).setDeveloperConnection("DEVELOPERCONNECTION"); + assertEquals("DEVELOPERCONNECTION", getDeveloperConnection(scmElm)); - new JDomScm( scmElm ).setDeveloperConnection( null ); - assertNull( getDeveloperConnection( scmElm ) ); + new JDomScm(scmElm).setDeveloperConnection(null); + assertNull(getDeveloperConnection(scmElm)); } @Test - public void testSetTagString() throws Exception - { + public void testSetTagString() throws Exception { String content = ""; - Element scmElm = builder.build( new StringReader( content ) ).getRootElement(); + Element scmElm = builder.build(new StringReader(content)).getRootElement(); - assertNull( getUrl( scmElm ) ); + assertNull(getUrl(scmElm)); - new JDomScm( scmElm ).setUrl( "URL" ); - assertEquals( "URL", getUrl( scmElm ) ); + new JDomScm(scmElm).setUrl("URL"); + assertEquals("URL", getUrl(scmElm)); - new JDomScm( scmElm ).setUrl( null ); - assertNull( getUrl( scmElm ) ); + new JDomScm(scmElm).setUrl(null); + assertNull(getUrl(scmElm)); } @Test - public void testSetUrlString() throws Exception - { + public void testSetUrlString() throws Exception { String content = ""; - Element scmElm = builder.build( new StringReader( content ) ).getRootElement(); + Element scmElm = builder.build(new StringReader(content)).getRootElement(); - assertNull( getTag( scmElm ) ); + assertNull(getTag(scmElm)); - new JDomScm( scmElm ).setTag( "TAG" ); - assertEquals( "TAG", getTag( scmElm ) ); + new JDomScm(scmElm).setTag("TAG"); + assertEquals("TAG", getTag(scmElm)); - new JDomScm( scmElm ).setTag( null ); - assertNull( getTag( scmElm ) ); + new JDomScm(scmElm).setTag(null); + assertNull(getTag(scmElm)); } - private String getConnection( Element scmElm ) - { - return scmElm.getChildText( "connection", scmElm.getNamespace() ); + private String getConnection(Element scmElm) { + return scmElm.getChildText("connection", scmElm.getNamespace()); } - private String getDeveloperConnection( Element scmElm ) - { - return scmElm.getChildText( "developerConnection", scmElm.getNamespace() ); + private String getDeveloperConnection(Element scmElm) { + return scmElm.getChildText("developerConnection", scmElm.getNamespace()); } - private String getTag( Element scmElm ) - { - return scmElm.getChildText( "tag", scmElm.getNamespace() ); + private String getTag(Element scmElm) { + return scmElm.getChildText("tag", scmElm.getNamespace()); } - private String getUrl( Element scmElm ) - { - return scmElm.getChildText( "url", scmElm.getNamespace() ); + private String getUrl(Element scmElm) { + return scmElm.getChildText("url", scmElm.getNamespace()); } } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/PomFinderTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/PomFinderTest.java index 488233c4d..863f640d4 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/PomFinderTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/PomFinderTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.util; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,53 +16,50 @@ * specific language governing permissions and limitations * under the License. */ - -import org.junit.Test; -import org.slf4j.LoggerFactory; +package org.apache.maven.shared.release.util; import java.io.File; import java.net.URL; +import org.junit.Test; +import org.slf4j.LoggerFactory; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - /** * @author Mark Struberg */ -public class PomFinderTest -{ +public class PomFinderTest { @Test - public void testPomFinderParser() - { - PomFinder pf = new PomFinder( LoggerFactory.getLogger( "test" ) ); + public void testPomFinderParser() { + PomFinder pf = new PomFinder(LoggerFactory.getLogger("test")); - boolean found = pf.parsePom( new File( "src/test/resources/pomfinder/pomNothere.xml" ) ); - assertFalse( found ); + boolean found = pf.parsePom(new File("src/test/resources/pomfinder/pomNothere.xml")); + assertFalse(found); URL pomUrl = getClass().getClassLoader().getResource("pomfinder/pom1.xml"); - assertNotNull( pomUrl ); + assertNotNull(pomUrl); - File pomFile = new File( pomUrl.getFile() ); - found = pf.parsePom( pomFile ); - assertTrue("pomFile not found pomUrl " + pomUrl + ", pomFile " + pomFile.getPath() , found ); + File pomFile = new File(pomUrl.getFile()); + found = pf.parsePom(pomFile); + assertTrue("pomFile not found pomUrl " + pomUrl + ", pomFile " + pomFile.getPath(), found); { - File foundPom = pf.findMatchingPom( pomFile.getParentFile() ); - assertNotNull( foundPom ); + File foundPom = pf.findMatchingPom(pomFile.getParentFile()); + assertNotNull(foundPom); - assertEquals( pomFile.getAbsolutePath(), foundPom.getAbsolutePath() ); + assertEquals(pomFile.getAbsolutePath(), foundPom.getAbsolutePath()); } { // try from 1 directory higher - File foundPom = pf.findMatchingPom( pomFile.getParentFile().getParentFile() ); - assertNotNull( foundPom ); + File foundPom = pf.findMatchingPom(pomFile.getParentFile().getParentFile()); + assertNotNull(foundPom); - assertEquals( pomFile.getAbsolutePath(), foundPom.getAbsolutePath() ); + assertEquals(pomFile.getAbsolutePath(), foundPom.getAbsolutePath()); } } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java index 738898787..e1ba6dc89 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/util/ReleaseUtilTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.util; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,11 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; +package org.apache.maven.shared.release.util; import java.nio.file.Path; import java.nio.file.Paths; @@ -30,196 +24,196 @@ import org.codehaus.plexus.util.Os; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + /** * Tests for ReleaseUtil methods */ -public class ReleaseUtilTest -{ +public class ReleaseUtilTest { /** * MRELEASE-273 : Tests if there no pom passed as parameter */ @Test - public void testProjectIsNull() - { - assertNull( ReleaseUtil.getReleasePom( null ) ); - assertNull( ReleaseUtil.getStandardPom( null ) ); + public void testProjectIsNull() { + assertNull(ReleaseUtil.getReleasePom(null)); + assertNull(ReleaseUtil.getStandardPom(null)); } @Test - public void testGetBaseScmUrlSingleLevel() - throws Exception - { - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk" ) ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk/", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/" ) ); + public void testGetBaseScmUrlSingleLevel() throws Exception { + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/trunk", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk")); + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/trunk/", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/")); } @Test - public void testGetBaseScmUrlSingleLevelDotCharacter() - throws Exception - { - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/." ) ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk/", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/./" ) ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk/project", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/./project" ) ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/.." ) ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/../" ) ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/branches", - ReleaseUtil.realignScmUrl( 0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/../branches" ) ); + public void testGetBaseScmUrlSingleLevelDotCharacter() throws Exception { + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/trunk", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/.")); + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/trunk/", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/./")); + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/trunk/project", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/./project")); + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/..")); + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/../")); + assertEquals( + "scm:svn:http://svn.repo.com/flat-multi-module/branches", + ReleaseUtil.realignScmUrl(0, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/../branches")); } @Test - public void testGetBaseScmUrlReturnOriginal() - throws Exception - { - assertEquals( "no-path-elements", ReleaseUtil.realignScmUrl( 1, "no-path-elements" ) ); - assertEquals( "no-path-elements", ReleaseUtil.realignScmUrl( 15, "no-path-elements" ) ); + public void testGetBaseScmUrlReturnOriginal() throws Exception { + assertEquals("no-path-elements", ReleaseUtil.realignScmUrl(1, "no-path-elements")); + assertEquals("no-path-elements", ReleaseUtil.realignScmUrl(15, "no-path-elements")); } @Test - public void testGetBaseScmUrlOfFlatMultiModule() - throws Exception - { + public void testGetBaseScmUrlOfFlatMultiModule() throws Exception { String actual = - ReleaseUtil.realignScmUrl( 1, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project" ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk", actual ); + ReleaseUtil.realignScmUrl(1, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project"); + assertEquals("scm:svn:http://svn.repo.com/flat-multi-module/trunk", actual); - actual = ReleaseUtil.realignScmUrl( 1, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project/" ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk/", actual ); + actual = ReleaseUtil.realignScmUrl(1, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project/"); + assertEquals("scm:svn:http://svn.repo.com/flat-multi-module/trunk/", actual); } @Test - public void testGetBaseScmUrlOfFlatMultiModuleMultipleLevels() - throws Exception - { + public void testGetBaseScmUrlOfFlatMultiModuleMultipleLevels() throws Exception { String actual = - ReleaseUtil.realignScmUrl( 3, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project/1/2" ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk", actual ); + ReleaseUtil.realignScmUrl(3, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project/1/2"); + assertEquals("scm:svn:http://svn.repo.com/flat-multi-module/trunk", actual); - actual = - ReleaseUtil.realignScmUrl( 3, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project/1/2/" ); - assertEquals( "scm:svn:http://svn.repo.com/flat-multi-module/trunk/", actual ); + actual = ReleaseUtil.realignScmUrl(3, "scm:svn:http://svn.repo.com/flat-multi-module/trunk/root-project/1/2/"); + assertEquals("scm:svn:http://svn.repo.com/flat-multi-module/trunk/", actual); } @Test - public void testGetBaseWorkingDirectoryParentCountSameDirectory() - { - Path workingDirectory = Paths.get( "/working/directory/maven/release" ); - Path basedir = Paths.get( "/working/directory/maven/release" ); - assertEquals( 0, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountSameDirectory() { + Path workingDirectory = Paths.get("/working/directory/maven/release"); + Path basedir = Paths.get("/working/directory/maven/release"); + assertEquals(0, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountSameDirectoryDotCharacter() - { - Path workingDirectory = Paths.get( "/working/directory/maven/release/." ).toAbsolutePath(); - assertTrue( workingDirectory.toString().contains( "." ) ); - Path basedir = Paths.get( "/working/directory/maven/release" ).toAbsolutePath(); - assertEquals( 0, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountSameDirectoryDotCharacter() { + Path workingDirectory = Paths.get("/working/directory/maven/release/.").toAbsolutePath(); + assertTrue(workingDirectory.toString().contains(".")); + Path basedir = Paths.get("/working/directory/maven/release").toAbsolutePath(); + assertEquals(0, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); // finish with slash - workingDirectory = Paths.get( "/working/directory/maven/release/./" ).toAbsolutePath(); - assertTrue( workingDirectory.toString().contains( "." ) ); - basedir = Paths.get( "/working/directory/maven/release" ).toAbsolutePath(); - assertEquals( 0, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + workingDirectory = Paths.get("/working/directory/maven/release/./").toAbsolutePath(); + assertTrue(workingDirectory.toString().contains(".")); + basedir = Paths.get("/working/directory/maven/release").toAbsolutePath(); + assertEquals(0, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountSubdirectory() - { - Path workingDirectory = Paths.get( "/working/directory/maven/release" ).toAbsolutePath(); - Path basedir = Paths.get( "/working/directory/maven/release/maven-release-manager" ).toAbsolutePath(); - assertEquals( 0, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountSubdirectory() { + Path workingDirectory = Paths.get("/working/directory/maven/release").toAbsolutePath(); + Path basedir = Paths.get("/working/directory/maven/release/maven-release-manager") + .toAbsolutePath(); + assertEquals(0, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountParentDirectory() - { - Path workingDirectory = - Paths.get( "/working/directory/maven/release/maven-release-manager" ).toAbsolutePath(); - Path basedir = Paths.get( "/working/directory/maven/release" ).toAbsolutePath(); - assertEquals( 1, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountParentDirectory() { + Path workingDirectory = Paths.get("/working/directory/maven/release/maven-release-manager") + .toAbsolutePath(); + Path basedir = Paths.get("/working/directory/maven/release").toAbsolutePath(); + assertEquals(1, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountParentDirectoryDotCharacter() - { - Path workingDirectory = - Paths.get( "/working/directory/maven/release/maven-release-manager/." ).toAbsolutePath(); - assertTrue( workingDirectory.toString().contains( "." ) ); - Path basedir = Paths.get( "/working/directory/maven/release" ).toAbsolutePath(); - assertEquals( 1, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountParentDirectoryDotCharacter() { + Path workingDirectory = Paths.get("/working/directory/maven/release/maven-release-manager/.") + .toAbsolutePath(); + assertTrue(workingDirectory.toString().contains(".")); + Path basedir = Paths.get("/working/directory/maven/release").toAbsolutePath(); + assertEquals(1, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); // finish with slash - workingDirectory = Paths.get( "/working/directory/maven/release/maven-release-manager/./" ).toAbsolutePath(); - assertTrue( workingDirectory.toString().contains( "." ) ); - basedir = Paths.get( "/working/directory/maven/release" ).toAbsolutePath(); - assertEquals( 1, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + workingDirectory = Paths.get("/working/directory/maven/release/maven-release-manager/./") + .toAbsolutePath(); + assertTrue(workingDirectory.toString().contains(".")); + basedir = Paths.get("/working/directory/maven/release").toAbsolutePath(); + assertEquals(1, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountParentDirectoryMultiple() - { - Path workingDirectory = - Paths.get( "/working/directory/maven/release/maven-release-manager" ).toAbsolutePath(); - Path basedir = Paths.get( "/working/directory" ).toAbsolutePath(); - assertEquals( 3, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountParentDirectoryMultiple() { + Path workingDirectory = Paths.get("/working/directory/maven/release/maven-release-manager") + .toAbsolutePath(); + Path basedir = Paths.get("/working/directory").toAbsolutePath(); + assertEquals(3, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountParentDirectoryMultipleDotCharacter() - { - Path workingDirectory = - Paths.get( "/working/directory/maven/release/maven-release-manager/./." ).toAbsolutePath(); - assertTrue( workingDirectory.toString().contains( "." ) ); - Path basedir = Paths.get( "/working/directory" ).toAbsolutePath(); - assertEquals( 3, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountParentDirectoryMultipleDotCharacter() { + Path workingDirectory = Paths.get("/working/directory/maven/release/maven-release-manager/./.") + .toAbsolutePath(); + assertTrue(workingDirectory.toString().contains(".")); + Path basedir = Paths.get("/working/directory").toAbsolutePath(); + assertEquals(3, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); // finish with slash - workingDirectory = Paths.get( "/working/directory/maven/release/maven-release-manager/././" ).toAbsolutePath(); - assertTrue( workingDirectory.toString().contains( "." ) ); - basedir = Paths.get( "/working/directory" ).toAbsolutePath(); - assertEquals( 3, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + workingDirectory = Paths.get("/working/directory/maven/release/maven-release-manager/././") + .toAbsolutePath(); + assertTrue(workingDirectory.toString().contains(".")); + basedir = Paths.get("/working/directory").toAbsolutePath(); + assertEquals(3, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } @Test - public void testGetBaseWorkingDirectoryParentCountDifferentCase() - { - Path workingDirectory = - Paths.get( "/Working/Directory/maven/release/maven-release-manager" ).toAbsolutePath(); - Path basedir = Paths.get( "/working/directory" ).toAbsolutePath(); - assertEquals( 3, ReleaseUtil.getBaseWorkingDirectoryParentCount( basedir, workingDirectory ) ); + public void testGetBaseWorkingDirectoryParentCountDifferentCase() { + Path workingDirectory = Paths.get("/Working/Directory/maven/release/maven-release-manager") + .toAbsolutePath(); + Path basedir = Paths.get("/working/directory").toAbsolutePath(); + assertEquals(3, ReleaseUtil.getBaseWorkingDirectoryParentCount(basedir, workingDirectory)); } /** * MRELEASE-663 */ @Test - public void testGetWindowsRootBaseWorkingDirectoryParentCountDifferentCase() - { - assumeTrue( Os.isFamily( Os.FAMILY_WINDOWS ) ); - - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "C:" ), - Paths.get( "C:\\working\\directory" ) ) ); - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "C:" ), - Paths.get( "C:\\working\\directory\\" ) ) ); - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "C:\\" ), - Paths.get( "C:\\working\\directory" ) ) ); - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "C:\\" ), - Paths.get( "C:\\working\\directory\\" ) ) ); - - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "c:" ), - Paths.get( "C:\\working\\directory" ) ) ); - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "C:" ), - Paths.get( "c:\\working\\directory" ) ) ); - assertEquals( 2, ReleaseUtil.getBaseWorkingDirectoryParentCount( Paths.get( "c:" ), - Paths.get( "c:\\working\\directory" ) ) ); - + public void testGetWindowsRootBaseWorkingDirectoryParentCountDifferentCase() { + assumeTrue(Os.isFamily(Os.FAMILY_WINDOWS)); + + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount(Paths.get("C:"), Paths.get("C:\\working\\directory"))); + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount(Paths.get("C:"), Paths.get("C:\\working\\directory\\"))); + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount(Paths.get("C:\\"), Paths.get("C:\\working\\directory"))); + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount( + Paths.get("C:\\"), Paths.get("C:\\working\\directory\\"))); + + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount(Paths.get("c:"), Paths.get("C:\\working\\directory"))); + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount(Paths.get("C:"), Paths.get("c:\\working\\directory"))); + assertEquals( + 2, + ReleaseUtil.getBaseWorkingDirectoryParentCount(Paths.get("c:"), Paths.get("c:\\working\\directory"))); } - } diff --git a/maven-release-manager/src/test/java/org/apache/maven/shared/release/versions/DefaultVersionInfoTest.java b/maven-release-manager/src/test/java/org/apache/maven/shared/release/versions/DefaultVersionInfoTest.java index 6c7324c11..8ed6e09d6 100644 --- a/maven-release-manager/src/test/java/org/apache/maven/shared/release/versions/DefaultVersionInfoTest.java +++ b/maven-release-manager/src/test/java/org/apache/maven/shared/release/versions/DefaultVersionInfoTest.java @@ -1,9 +1,3 @@ -package org.apache.maven.shared.release.versions; - -import java.util.Properties; - -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -22,7 +16,11 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.versions; + +import java.util.Properties; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.junit.Before; import org.junit.Test; @@ -33,370 +31,304 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -public class DefaultVersionInfoTest -{ +public class DefaultVersionInfoTest { private String mavenVersion; @Before - public void setUp() - throws Exception - { + public void setUp() throws Exception { Properties pomProperties = new Properties(); - pomProperties.load( DefaultArtifactVersion.class.getResourceAsStream( "/META-INF/maven/org.apache.maven/maven-artifact/pom.properties" ) ); - mavenVersion = pomProperties.getProperty( "version" ); + pomProperties.load(DefaultArtifactVersion.class.getResourceAsStream( + "/META-INF/maven/org.apache.maven/maven-artifact/pom.properties")); + mavenVersion = pomProperties.getProperty("version"); } @Test - public void testParse() - throws Exception - { - checkParsing( "1.0", "1.0", null, null, null ); + public void testParse() throws Exception { + checkParsing("1.0", "1.0", null, null, null); } @Test - public void testParseWithBadVersion() - throws Exception - { - try - { - checkParsing( "foo", null, null, null, "foo" ); - fail( "version is incorrect, must fail." ); - } - catch ( VersionParseException e ) - { + public void testParseWithBadVersion() throws Exception { + try { + checkParsing("foo", null, null, null, "foo"); + fail("version is incorrect, must fail."); + } catch (VersionParseException e) { } } @Test - public void testParseMultiDigit() - throws Exception - { - checkParsing( "99.99", "99.99", null, null, null ); - checkParsing( "990.990.990", "990.990.990", null, null, null ); + public void testParseMultiDigit() throws Exception { + checkParsing("99.99", "99.99", null, null, null); + checkParsing("990.990.990", "990.990.990", null, null, null); } @Test - public void testParseSnapshotVersion() - throws Exception - { - checkParsing( "SNAPSHOT", null, null, null, "SNAPSHOT" ); - checkParsing( "1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" ); - checkParsing( "1.0-beta-4_SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" ); + public void testParseSnapshotVersion() throws Exception { + checkParsing("SNAPSHOT", null, null, null, "SNAPSHOT"); + checkParsing("1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT"); + checkParsing("1.0-beta-4_SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT"); } @Test - public void testParseAnnotationVersion() - throws Exception - { - checkParsing( "1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" ); - checkParsing( "1.0-beta-4", "1.0", "beta", "4", null ); - checkParsing( "1.2.3-beta-99", "1.2.3", "beta", "99", null ); - checkParsing( "1.2.3-beta99", "1.2.3", "beta", "99", null ); - checkParsing( "1.2.3-beta99-SNAPSHOT", "1.2.3", "beta", "99", "SNAPSHOT" ); - checkParsing( "1.2.3-RC4", "1.2.3", "RC", "4", null ); + public void testParseAnnotationVersion() throws Exception { + checkParsing("1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT"); + checkParsing("1.0-beta-4", "1.0", "beta", "4", null); + checkParsing("1.2.3-beta-99", "1.2.3", "beta", "99", null); + checkParsing("1.2.3-beta99", "1.2.3", "beta", "99", null); + checkParsing("1.2.3-beta99-SNAPSHOT", "1.2.3", "beta", "99", "SNAPSHOT"); + checkParsing("1.2.3-RC4", "1.2.3", "RC", "4", null); } @Test - public void testParseSeparators() - throws Exception - { - checkParsing( "1.2.9-beta-9-SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" ); - checkParsing( "1.2.9beta9SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" ); - checkParsing( "1.2.9beta-9SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" ); - checkParsing( "1.2.9_beta_9_SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT" ); + public void testParseSeparators() throws Exception { + checkParsing("1.2.9-beta-9-SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT"); + checkParsing("1.2.9beta9SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT"); + checkParsing("1.2.9beta-9SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT"); + checkParsing("1.2.9_beta_9_SNAPSHOT", "1.2.9", "beta", "9", "SNAPSHOT"); } @Test - public void testParseAnnotationNoVersionButSnapshot() - throws Exception - { - checkParsing( "1.0-beta-SNAPSHOT", "1.0", "beta", null, "SNAPSHOT" ); - checkParsing( "1.2.3-beta99", "1.2.3", "beta", "99", null ); - checkParsing( "1.2.3-RC4-SNAPSHOT", "1.2.3", "RC", "4", "SNAPSHOT" ); + public void testParseAnnotationNoVersionButSnapshot() throws Exception { + checkParsing("1.0-beta-SNAPSHOT", "1.0", "beta", null, "SNAPSHOT"); + checkParsing("1.2.3-beta99", "1.2.3", "beta", "99", null); + checkParsing("1.2.3-RC4-SNAPSHOT", "1.2.3", "RC", "4", "SNAPSHOT"); } @Test - public void testParseAnnotationVersionWithRevision() - throws Exception - { - checkParsing( "1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT" ); - checkParsing( "1.0-beta-4", "1.0", "beta", "4", null ); - checkParsing( "1.2.3-beta-99", "1.2.3", "beta", "99", null ); - checkParsing( "1.2.3-beta99", "1.2.3", "beta", "99", null ); - checkParsing( "1.2.3-RC4", "1.2.3", "RC", "4", null ); - - checkParsing( "1.2.9", "1.2.9", null, null, null ); + public void testParseAnnotationVersionWithRevision() throws Exception { + checkParsing("1.0-beta-4-SNAPSHOT", "1.0", "beta", "4", "SNAPSHOT"); + checkParsing("1.0-beta-4", "1.0", "beta", "4", null); + checkParsing("1.2.3-beta-99", "1.2.3", "beta", "99", null); + checkParsing("1.2.3-beta99", "1.2.3", "beta", "99", null); + checkParsing("1.2.3-RC4", "1.2.3", "RC", "4", null); + + checkParsing("1.2.9", "1.2.9", null, null, null); } @Test - public void testParseAnnotationVersionWithoutRevision() - throws Exception - { - checkParsing( "1.0-beta", "1.0", "beta", null, null ); - checkParsing( "1.0-beta-SNAPSHOT", "1.0", "beta", null, "SNAPSHOT" ); + public void testParseAnnotationVersionWithoutRevision() throws Exception { + checkParsing("1.0-beta", "1.0", "beta", null, null); + checkParsing("1.0-beta-SNAPSHOT", "1.0", "beta", null, "SNAPSHOT"); } @Test - public void testParseAnnotationRevisionOnly() - throws Exception - { - checkParsing( "1.0-4", "1.0", null, "4", null ); + public void testParseAnnotationRevisionOnly() throws Exception { + checkParsing("1.0-4", "1.0", null, "4", null); } @Test - public void testParseLeadingZeros() - throws Exception - { - checkParsing( "1.01-beta-04-SNAPSHOT", "1.01", "beta", "04", "SNAPSHOT" ); - checkParsing( "01.01.001-beta-04-SNAPSHOT", "01.01.001", "beta", "04", "SNAPSHOT" ); + public void testParseLeadingZeros() throws Exception { + checkParsing("1.01-beta-04-SNAPSHOT", "1.01", "beta", "04", "SNAPSHOT"); + checkParsing("01.01.001-beta-04-SNAPSHOT", "01.01.001", "beta", "04", "SNAPSHOT"); } @Test - public void testParseBuildNumber() - throws Exception - { - checkParsing( "1.0-alpha-2-20051013.095555-2", "1.0", "alpha", "2", "20051013.095555-2" ); + public void testParseBuildNumber() throws Exception { + checkParsing("1.0-alpha-2-20051013.095555-2", "1.0", "alpha", "2", "20051013.095555-2"); } @Test - public void testNextVersion() - throws Exception - { - VersionInfo v = new DefaultVersionInfo( "SNAPSHOT" ); - assertNull( v.getNextVersion() ); - - checkNextVersion( "1", "2" ); - checkNextVersion( "1.01", "1.02" ); - checkNextVersion( "1.9", "1.10" ); - checkNextVersion( "1.09", "1.10" ); - checkNextVersion( "1.009", "1.010" ); - - checkNextVersion( "1.99", "1.100" ); - - //MRELEASE-623 SNAPSHOT is case-insensitive - checkNextVersion( "2.2-SNAPshot", "2.3-SNAPshot" ); + public void testNextVersion() throws Exception { + VersionInfo v = new DefaultVersionInfo("SNAPSHOT"); + assertNull(v.getNextVersion()); + + checkNextVersion("1", "2"); + checkNextVersion("1.01", "1.02"); + checkNextVersion("1.9", "1.10"); + checkNextVersion("1.09", "1.10"); + checkNextVersion("1.009", "1.010"); + + checkNextVersion("1.99", "1.100"); + + // MRELEASE-623 SNAPSHOT is case-insensitive + checkNextVersion("2.2-SNAPshot", "2.3-SNAPshot"); } @Test - public void testNextAnnotationRevision() - throws Exception - { - checkNextVersion( "1.01-beta-04", "1.01-beta-05" ); - checkNextVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT" ); - checkNextVersion( "9.99.999-beta-9-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT" ); - checkNextVersion( "9.99.999-beta-09-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT" ); - checkNextVersion( "9.99.999-beta-009-SNAPSHOT", "9.99.999-beta-010-SNAPSHOT" ); - checkNextVersion( "9.99.999-beta9-SNAPSHOT", "9.99.999-beta10-SNAPSHOT" ); + public void testNextAnnotationRevision() throws Exception { + checkNextVersion("1.01-beta-04", "1.01-beta-05"); + checkNextVersion("1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT"); + checkNextVersion("9.99.999-beta-9-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT"); + checkNextVersion("9.99.999-beta-09-SNAPSHOT", "9.99.999-beta-10-SNAPSHOT"); + checkNextVersion("9.99.999-beta-009-SNAPSHOT", "9.99.999-beta-010-SNAPSHOT"); + checkNextVersion("9.99.999-beta9-SNAPSHOT", "9.99.999-beta10-SNAPSHOT"); } @Test - public void testCompareToDigitsOnly() - throws Exception - { - checkVersionLessThanVersion( "1.01", "1.02" ); + public void testCompareToDigitsOnly() throws Exception { + checkVersionLessThanVersion("1.01", "1.02"); // M2.2.1 // checkVersionLessThanVersion( "1.00009", "1.01" ); // M3.0, because prefix 0's are ignored, hence 1 < 9 - checkVersionLessThanVersion( "1.01", "1.00009" ); + checkVersionLessThanVersion("1.01", "1.00009"); - checkVersionLessThanVersion( "1.01", "1.01.01" ); + checkVersionLessThanVersion("1.01", "1.01.01"); // M2.2.1 // checkVersionLessThanVersion( "1.01", "1.1" ); // M3.0, because prefix 0's are ignored, hence 1 == 1 - checkVersionEqualVersion( "1.01", "1.1" ); + checkVersionEqualVersion("1.01", "1.1"); - checkVersionEqualVersion( "1.01", "1.01" ); + checkVersionEqualVersion("1.01", "1.01"); // M2.2.1 // checkVersionLessThanVersion( "1.001", "1.01" ); // M3.0, because prefix 0's are ignored, hence 1 == 1 - checkVersionEqualVersion( "1.001", "1.01" ); + checkVersionEqualVersion("1.001", "1.01"); } @Test - public void testCompareToAnnotation() - throws Exception - { - checkVersionLessThanVersion( "1.01-alpha", "1.01" ); - checkVersionLessThanVersion( "1.01-alpha", "1.01-beta" ); - checkVersionLessThanVersion( "1.01-beta", "1.01-RC1" ); - checkVersionLessThanVersion( "1.01-beta", "1.01-RC" ); - checkVersionLessThanVersion( "1.01-alpha-4", "1.01.1-beta-1" ); - checkVersionLessThanVersion( "1.01-alpha-4-SNAPSHOT", "1.01-beta" ); - checkVersionLessThanVersion( "1.01-alpha-4-SNAPSHOT", "1.01-alpha-4" ); - checkVersionLessThanVersion( "1.01-alpha-4", "1.01-alpha-5-SNAPSHOT" ); + public void testCompareToAnnotation() throws Exception { + checkVersionLessThanVersion("1.01-alpha", "1.01"); + checkVersionLessThanVersion("1.01-alpha", "1.01-beta"); + checkVersionLessThanVersion("1.01-beta", "1.01-RC1"); + checkVersionLessThanVersion("1.01-beta", "1.01-RC"); + checkVersionLessThanVersion("1.01-alpha-4", "1.01.1-beta-1"); + checkVersionLessThanVersion("1.01-alpha-4-SNAPSHOT", "1.01-beta"); + checkVersionLessThanVersion("1.01-alpha-4-SNAPSHOT", "1.01-alpha-4"); + checkVersionLessThanVersion("1.01-alpha-4", "1.01-alpha-5-SNAPSHOT"); // M2.2.1 // checkVersionLessThanVersion( "1.01-alpha-004-SNAPSHOT", "1.01-alpha-4-SNAPSHOT" ); // M3.0, because prefix 0's are ignored, hence 4 == 4 - checkVersionEqualVersion( "1.01-alpha-004-SNAPSHOT", "1.01-alpha-4-SNAPSHOT" ); + checkVersionEqualVersion("1.01-alpha-004-SNAPSHOT", "1.01-alpha-4-SNAPSHOT"); } @Test - public void testCompareToAnnotationRevision() - throws Exception - { - checkVersionLessThanVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT" ); - checkVersionLessThanVersion( "1.01-beta-0004-SNAPSHOT", "1.01-beta-5-SNAPSHOT" ); - checkVersionLessThanVersion( "1.01-beta-4-SNAPSHOT", "1.01.1-beta-4-SNAPSHOT" ); + public void testCompareToAnnotationRevision() throws Exception { + checkVersionLessThanVersion("1.01-beta-04-SNAPSHOT", "1.01-beta-05-SNAPSHOT"); + checkVersionLessThanVersion("1.01-beta-0004-SNAPSHOT", "1.01-beta-5-SNAPSHOT"); + checkVersionLessThanVersion("1.01-beta-4-SNAPSHOT", "1.01.1-beta-4-SNAPSHOT"); // M2.2.1 // checkVersionLessThanVersion( "1.01-beta-0004-SNAPSHOT", "1.01-beta-4-SNAPSHOT" ); // M3.0, because prefix 0's are ignored, hence 4 == 4 - checkVersionEqualVersion( "1.01-beta-0004-SNAPSHOT", "1.01-beta-4-SNAPSHOT" ); + checkVersionEqualVersion("1.01-beta-0004-SNAPSHOT", "1.01-beta-4-SNAPSHOT"); } @Test - public void testCompareToBuildSpecifier() - throws Exception - { - checkVersionLessThanVersion( "1.01-SNAPSHOT", "1.01" ); - checkVersionLessThanVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04" ); + public void testCompareToBuildSpecifier() throws Exception { + checkVersionLessThanVersion("1.01-SNAPSHOT", "1.01"); + checkVersionLessThanVersion("1.01-beta-04-SNAPSHOT", "1.01-beta-04"); - checkVersionEqualVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT" ); + checkVersionEqualVersion("1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT"); - if ( !"3.0".equals( mavenVersion ) ) - { + if (!"3.0".equals(mavenVersion)) { // TODO: bug?? // checkVersionLessThanVersion( "1.01-beta-04-20051112.134500-2", "1.01-beta-04-SNAPSHOT" ); } - checkVersionLessThanVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051112.134500-2" ); - checkVersionLessThanVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051113.134500-1" ); + checkVersionLessThanVersion("1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051112.134500-2"); + checkVersionLessThanVersion("1.01-beta-04-20051112.134500-1", "1.01-beta-04-20051113.134500-1"); } @Test - public void testGetReleaseVersion() - throws Exception - { - checkGetReleaseVersion( "1-SNAPSHOT", "1" ); - checkGetReleaseVersion( "1", "1" ); - - checkGetReleaseVersion( "1.01", "1.01" ); - checkGetReleaseVersion( "1.01-beta", "1.01-beta" ); - checkGetReleaseVersion( "1.01-beta-04", "1.01-beta-04" ); - - checkGetReleaseVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04" ); - checkGetReleaseVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04" ); + public void testGetReleaseVersion() throws Exception { + checkGetReleaseVersion("1-SNAPSHOT", "1"); + checkGetReleaseVersion("1", "1"); + + checkGetReleaseVersion("1.01", "1.01"); + checkGetReleaseVersion("1.01-beta", "1.01-beta"); + checkGetReleaseVersion("1.01-beta-04", "1.01-beta-04"); + + checkGetReleaseVersion("1.01-beta-04-SNAPSHOT", "1.01-beta-04"); + checkGetReleaseVersion("1.01-beta-04-20051112.134500-1", "1.01-beta-04"); } @Test - public void testGetSnapshotVersion() - throws Exception - { - checkGetSnapshotVersion( "1", "1-SNAPSHOT" ); - checkGetSnapshotVersion( "1.01", "1.01-SNAPSHOT" ); - checkGetSnapshotVersion( "1.01-beta", "1.01-beta-SNAPSHOT" ); - checkGetSnapshotVersion( "1.01-beta-04", "1.01-beta-04-SNAPSHOT" ); - - checkGetSnapshotVersion( "SNAPSHOT", "SNAPSHOT" ); + public void testGetSnapshotVersion() throws Exception { + checkGetSnapshotVersion("1", "1-SNAPSHOT"); + checkGetSnapshotVersion("1.01", "1.01-SNAPSHOT"); + checkGetSnapshotVersion("1.01-beta", "1.01-beta-SNAPSHOT"); + checkGetSnapshotVersion("1.01-beta-04", "1.01-beta-04-SNAPSHOT"); + + checkGetSnapshotVersion("SNAPSHOT", "SNAPSHOT"); // TODO: bug in Artifact pattern -// checkGetSnapshotVersion( "20051112.134500-1", "SNAPSHOT" ); - checkGetSnapshotVersion( "1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT" ); - checkGetSnapshotVersion( "1.01-beta-04-20051112.134500-1", "1.01-beta-04-SNAPSHOT" ); - checkGetSnapshotVersion( "1.01-beta-04_20051112.134500-1", "1.01-beta-04_20051112.134500-1-SNAPSHOT" ); + // checkGetSnapshotVersion( "20051112.134500-1", "SNAPSHOT" ); + checkGetSnapshotVersion("1.01-beta-04-SNAPSHOT", "1.01-beta-04-SNAPSHOT"); + checkGetSnapshotVersion("1.01-beta-04-20051112.134500-1", "1.01-beta-04-SNAPSHOT"); + checkGetSnapshotVersion("1.01-beta-04_20051112.134500-1", "1.01-beta-04_20051112.134500-1-SNAPSHOT"); } @Test - public void testSnapshot() - throws VersionParseException - { - assertFalse( new DefaultVersionInfo( "1.01" ).isSnapshot() ); - assertFalse( new DefaultVersionInfo( "1.01-beta" ).isSnapshot() ); - assertFalse( new DefaultVersionInfo( "1.01-beta-04" ).isSnapshot() ); - - assertTrue( new DefaultVersionInfo( "1.01-beta-04-SNAPSHOT" ).isSnapshot() ); - assertTrue( new DefaultVersionInfo( "1.01-beta-04-20051112.134500-1" ).isSnapshot() ); - assertFalse( new DefaultVersionInfo( "1.01-beta-04_20051112.134500-1" ).isSnapshot() ); - + public void testSnapshot() throws VersionParseException { + assertFalse(new DefaultVersionInfo("1.01").isSnapshot()); + assertFalse(new DefaultVersionInfo("1.01-beta").isSnapshot()); + assertFalse(new DefaultVersionInfo("1.01-beta-04").isSnapshot()); + + assertTrue(new DefaultVersionInfo("1.01-beta-04-SNAPSHOT").isSnapshot()); + assertTrue(new DefaultVersionInfo("1.01-beta-04-20051112.134500-1").isSnapshot()); + assertFalse(new DefaultVersionInfo("1.01-beta-04_20051112.134500-1").isSnapshot()); } - //MRELEASE-623 SNAPSHOT is case-insensitive + // MRELEASE-623 SNAPSHOT is case-insensitive @Test - public void testCaseInsensitiveSnapshot() throws VersionParseException - { - DefaultVersionInfo currentVersionInfo = new DefaultVersionInfo( "2.2-SNAPshot" ); - assertTrue( currentVersionInfo.isSnapshot() ); - assertEquals( "2.2", currentVersionInfo.getReleaseVersionString() ); + public void testCaseInsensitiveSnapshot() throws VersionParseException { + DefaultVersionInfo currentVersionInfo = new DefaultVersionInfo("2.2-SNAPshot"); + assertTrue(currentVersionInfo.isSnapshot()); + assertEquals("2.2", currentVersionInfo.getReleaseVersionString()); VersionInfo nextVersionInfo = currentVersionInfo.getNextVersion(); - assertEquals( "2.3-SNAPSHOT", nextVersionInfo.getSnapshotVersionString() ); + assertEquals("2.3-SNAPSHOT", nextVersionInfo.getSnapshotVersionString()); } -// Ignore, new DefaultVersionInfo( "LATEST") throws VersionParseException -// public void testLatest() throws VersionParseException -// { -// assertTrue( new DefaultVersionInfo( "LATEST") .isSnapshot() ); -// } - - private static void checkGetReleaseVersion( String strVersion, String expected ) - throws Exception - { - VersionInfo v = new DefaultVersionInfo( strVersion ); - assertEquals( expected, v.getReleaseVersionString() ); + // Ignore, new DefaultVersionInfo( "LATEST") throws VersionParseException + // public void testLatest() throws VersionParseException + // { + // assertTrue( new DefaultVersionInfo( "LATEST") .isSnapshot() ); + // } + + private static void checkGetReleaseVersion(String strVersion, String expected) throws Exception { + VersionInfo v = new DefaultVersionInfo(strVersion); + assertEquals(expected, v.getReleaseVersionString()); } - private static void checkGetSnapshotVersion( String strVersion, String expected ) - throws Exception - { - VersionInfo v = new DefaultVersionInfo( strVersion ); - assertEquals( expected, v.getSnapshotVersionString() ); + private static void checkGetSnapshotVersion(String strVersion, String expected) throws Exception { + VersionInfo v = new DefaultVersionInfo(strVersion); + assertEquals(expected, v.getSnapshotVersionString()); } - private static void checkParsing( String strVersion, String digits, String annotation, String annotationRevision, - String buildSpecifier ) - throws Exception - { - DefaultVersionInfo v = new DefaultVersionInfo( strVersion ); - - assertEquals( strVersion, v.toString() ); - assertEquals( digits, DefaultVersionInfo.joinDigitString( v.getDigits() ) ); - assertEquals( annotation, v.getAnnotation() ); - assertEquals( annotationRevision, v.getAnnotationRevision() ); - assertEquals( buildSpecifier, v.getBuildSpecifier() ); + private static void checkParsing( + String strVersion, String digits, String annotation, String annotationRevision, String buildSpecifier) + throws Exception { + DefaultVersionInfo v = new DefaultVersionInfo(strVersion); + + assertEquals(strVersion, v.toString()); + assertEquals(digits, DefaultVersionInfo.joinDigitString(v.getDigits())); + assertEquals(annotation, v.getAnnotation()); + assertEquals(annotationRevision, v.getAnnotationRevision()); + assertEquals(buildSpecifier, v.getBuildSpecifier()); } - private static void checkNextVersion( String strVersion, String nextVersion ) - throws Exception - { - VersionInfo v = new DefaultVersionInfo( strVersion ); + private static void checkNextVersion(String strVersion, String nextVersion) throws Exception { + VersionInfo v = new DefaultVersionInfo(strVersion); VersionInfo nextV = v.getNextVersion(); - assertNotNull( nextV ); - assertEquals( nextVersion, nextV.toString() ); + assertNotNull(nextV); + assertEquals(nextVersion, nextV.toString()); } - private static void checkVersionLessThanVersion( String lesserVersion, String greaterVersion ) - throws VersionParseException - { - checkCompareTo( lesserVersion, greaterVersion, -1 ); - checkCompareTo( greaterVersion, lesserVersion, +1 ); + private static void checkVersionLessThanVersion(String lesserVersion, String greaterVersion) + throws VersionParseException { + checkCompareTo(lesserVersion, greaterVersion, -1); + checkCompareTo(greaterVersion, lesserVersion, +1); } - private static void checkVersionEqualVersion( String version1, String version2 ) - throws Exception - { - checkCompareTo( version1, version2, 0 ); + private static void checkVersionEqualVersion(String version1, String version2) throws Exception { + checkCompareTo(version1, version2, 0); } - private static void checkCompareTo( String lesserVersion, String greaterVersion, int comparison ) - throws VersionParseException - { - VersionInfo lesserV = new DefaultVersionInfo( lesserVersion ); - VersionInfo greaterV = new DefaultVersionInfo( greaterVersion ); - - if ( comparison == 0 ) - { - assertEquals( 0, lesserV.compareTo( greaterV ) ); - assertEquals( lesserV, greaterV ); - } - else if ( comparison < 0 ) - { - assertTrue( "Expected less but was " + lesserV.compareTo( greaterV ), lesserV.compareTo( greaterV ) < 0 ); - } - else if ( comparison > 0 ) - { - assertTrue( "Expected more but was " + lesserV.compareTo( greaterV ), lesserV.compareTo( greaterV ) > 0 ); + private static void checkCompareTo(String lesserVersion, String greaterVersion, int comparison) + throws VersionParseException { + VersionInfo lesserV = new DefaultVersionInfo(lesserVersion); + VersionInfo greaterV = new DefaultVersionInfo(greaterVersion); + + if (comparison == 0) { + assertEquals(0, lesserV.compareTo(greaterV)); + assertEquals(lesserV, greaterV); + } else if (comparison < 0) { + assertTrue("Expected less but was " + lesserV.compareTo(greaterV), lesserV.compareTo(greaterV) < 0); + } else if (comparison > 0) { + assertTrue("Expected more but was " + lesserV.compareTo(greaterV), lesserV.compareTo(greaterV) > 0); } } } diff --git a/maven-release-plugin/pom.xml b/maven-release-plugin/pom.xml index aa20fa24f..61553b868 100644 --- a/maven-release-plugin/pom.xml +++ b/maven-release-plugin/pom.xml @@ -17,7 +17,6 @@ ~ specific language governing permissions and limitations ~ under the License. --> - 4.0.0 @@ -117,11 +116,11 @@ 3.3.0 test - - org.slf4j - slf4j-simple - test - + + org.slf4j + slf4j-simple + test + @@ -149,19 +148,17 @@ maven-enforcer-plugin + ensure-no-container-api enforce - ensure-no-container-api org.codehaus.plexus:plexus-component-api - - The new containers are not supported. You probably added a dependency that is missing the exclusions. - + The new containers are not supported. You probably added a dependency that is missing the exclusions. true @@ -192,16 +189,6 @@ org.apache.maven.plugins maven-invoker-plugin - - - integration-test-prepare - - install - integration-test - verify - - - src/it ${project.build.directory}/it @@ -235,19 +222,21 @@ true - - - org.codehaus.mojo - mrm-maven-plugin - 1.4.1 + integration-test-prepare - start - stop + install + integration-test + verify + + + org.codehaus.mojo + mrm-maven-plugin + 1.4.1 @@ -256,6 +245,14 @@ + + + + start + stop + + + diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java index 9f5192a4d..825f441e8 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import java.io.File; import java.io.IOException; @@ -44,22 +43,20 @@ * * @author Brett Porter */ -public abstract class AbstractReleaseMojo - extends AbstractMojo -{ +public abstract class AbstractReleaseMojo extends AbstractMojo { /** */ - @Parameter( defaultValue = "${basedir}", readonly = true, required = true ) + @Parameter(defaultValue = "${basedir}", readonly = true, required = true) private File basedir; /** */ - @Parameter( defaultValue = "${settings}", readonly = true, required = true ) + @Parameter(defaultValue = "${settings}", readonly = true, required = true) private Settings settings; /** */ - @Parameter( defaultValue = "${project}", readonly = true, required = true ) + @Parameter(defaultValue = "${project}", readonly = true, required = true) protected MavenProject project; /** @@ -70,19 +67,19 @@ public abstract class AbstractReleaseMojo /** * Additional arguments to pass to the Maven executions, separated by spaces. */ - @Parameter( alias = "prepareVerifyArgs", property = "arguments" ) + @Parameter(alias = "prepareVerifyArgs", property = "arguments") private String arguments; /** * The file name of the POM to execute any goals against. As of version 3.0.0, this defaults to the name of * POM file of the project being built. */ - @Parameter( property = "pomFileName", defaultValue = "${project.file.name}" ) + @Parameter(property = "pomFileName", defaultValue = "${project.file.name}") private String pomFileName; /** */ - @Parameter( defaultValue = "${reactorProjects}", readonly = true, required = true ) + @Parameter(defaultValue = "${reactorProjects}", readonly = true, required = true) private List reactorProjects; /** @@ -90,7 +87,7 @@ public abstract class AbstractReleaseMojo * * @since 2.0-beta-8 */ - @Parameter( defaultValue = "${maven.home}" ) + @Parameter(defaultValue = "${maven.home}") private File mavenHome; /** @@ -98,7 +95,7 @@ public abstract class AbstractReleaseMojo * * @since 2.0-beta-8 */ - @Parameter( defaultValue = "${java.home}" ) + @Parameter(defaultValue = "${java.home}") private File javaHome; /** @@ -106,7 +103,7 @@ public abstract class AbstractReleaseMojo * * @since 2.0-beta-8 */ - @Parameter ( defaultValue = "${maven.repo.local}" ) + @Parameter(defaultValue = "${maven.repo.local}") private File localRepoDirectory; /** @@ -114,13 +111,13 @@ public abstract class AbstractReleaseMojo * * @since 2.0-beta-8 */ - @Parameter( defaultValue = "invoker", property = "mavenExecutorId" ) + @Parameter(defaultValue = "invoker", property = "mavenExecutorId") private String mavenExecutorId; /** * @since 2.0 */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) protected MavenSession session; /** @@ -130,7 +127,7 @@ public abstract class AbstractReleaseMojo * @since 3.0.0-M5 * @see org.apache.maven.shared.release.strategies.DefaultStrategy */ - @Parameter( defaultValue = "default", property = "releaseStrategyId" ) + @Parameter(defaultValue = "default", property = "releaseStrategyId") private String releaseStrategyId; /** @@ -138,13 +135,13 @@ public abstract class AbstractReleaseMojo * * @return The release environment, never null. */ - protected ReleaseEnvironment getReleaseEnvironment() - { - return new DefaultReleaseEnvironment().setSettings( settings ) - .setJavaHome( javaHome ) - .setMavenHome( mavenHome ) - .setLocalRepositoryDirectory( localRepoDirectory ) - .setMavenExecutorId( mavenExecutorId ); + protected ReleaseEnvironment getReleaseEnvironment() { + return new DefaultReleaseEnvironment() + .setSettings(settings) + .setJavaHome(javaHome) + .setMavenHome(mavenHome) + .setLocalRepositoryDirectory(localRepoDirectory) + .setMavenExecutorId(mavenExecutorId); } /** @@ -152,57 +149,50 @@ protected ReleaseEnvironment getReleaseEnvironment() * * @return The release descriptor, never null. */ - protected ReleaseDescriptorBuilder createReleaseDescriptor() - { + protected ReleaseDescriptorBuilder createReleaseDescriptor() { ReleaseDescriptorBuilder descriptor = new ReleaseDescriptorBuilder(); - descriptor.setInteractive( settings.isInteractiveMode() ); + descriptor.setInteractive(settings.isInteractiveMode()); Path workingDirectory; - try - { - workingDirectory = getCommonBasedir( reactorProjects ); + try { + workingDirectory = getCommonBasedir(reactorProjects); + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); } - catch ( IOException e ) - { - throw new RuntimeException( e.getMessage() ); - } - descriptor.setWorkingDirectory( workingDirectory.toFile().getAbsolutePath() ); + descriptor.setWorkingDirectory(workingDirectory.toFile().getAbsolutePath()); Path rootBasedir = basedir.toPath(); - if ( rootBasedir.equals( workingDirectory ) ) - { - descriptor.setPomFileName( pomFileName ); - } - else - { - descriptor.setPomFileName( workingDirectory.relativize( rootBasedir ).resolve( pomFileName ).toString() ); + if (rootBasedir.equals(workingDirectory)) { + descriptor.setPomFileName(pomFileName); + } else { + descriptor.setPomFileName(workingDirectory + .relativize(rootBasedir) + .resolve(pomFileName) + .toString()); } - for ( MavenProject project : reactorProjects ) - { - String versionlessKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); - descriptor.putOriginalVersion( versionlessKey, project.getVersion() ); + for (MavenProject project : reactorProjects) { + String versionlessKey = ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()); + descriptor.putOriginalVersion(versionlessKey, project.getVersion()); } - descriptor.setAdditionalArguments( this.arguments ); + descriptor.setAdditionalArguments(this.arguments); List profileIds = session.getRequest().getActiveProfiles(); String additionalProfiles = getAdditionalProfiles(); - if ( !profileIds.isEmpty() || StringUtils.isNotBlank( additionalProfiles ) ) - { - List profiles = new ArrayList<>( profileIds ); + if (!profileIds.isEmpty() || StringUtils.isNotBlank(additionalProfiles)) { + List profiles = new ArrayList<>(profileIds); - if ( additionalProfiles != null ) - { - profiles.addAll( Arrays.asList( additionalProfiles.split( "," ) ) ); + if (additionalProfiles != null) { + profiles.addAll(Arrays.asList(additionalProfiles.split(","))); } - descriptor.setActivateProfiles( profiles ); + descriptor.setActivateProfiles(profiles); } - descriptor.setReleaseStrategyId( releaseStrategyId ); + descriptor.setReleaseStrategyId(releaseStrategyId); return descriptor; } @@ -212,8 +202,7 @@ protected ReleaseDescriptorBuilder createReleaseDescriptor() * * @return additional profiles to enable during release */ - protected String getAdditionalProfiles() - { + protected String getAdditionalProfiles() { return null; } @@ -222,8 +211,7 @@ protected String getAdditionalProfiles() * * @param releaseManager The release manager implementation to use, must not be null. */ - void setReleaseManager( ReleaseManager releaseManager ) - { + void setReleaseManager(ReleaseManager releaseManager) { this.releaseManager = releaseManager; } @@ -232,13 +220,11 @@ void setReleaseManager( ReleaseManager releaseManager ) * * @return The effective settings for this build, never null. */ - Settings getSettings() - { + Settings getSettings() { return settings; } - protected final File getBasedir() - { + protected final File getBasedir() { return basedir; } @@ -247,21 +233,18 @@ protected final File getBasedir() * * @param basedir The build's base directory, must not be null. */ - public void setBasedir( File basedir ) - { + public void setBasedir(File basedir) { this.basedir = basedir; } - public void setPomFileName( String pomFileName ) - { + public void setPomFileName(String pomFileName) { this.pomFileName = pomFileName; } /** * only used for unit tests in which some required values of the project would be null */ - protected MavenProject getProject() - { + protected MavenProject getProject() { return this.project; } @@ -270,8 +253,7 @@ protected MavenProject getProject() * * @return The list of reactor project, never null. */ - public List getReactorProjects() - { + public List getReactorProjects() { return reactorProjects; } @@ -280,28 +262,20 @@ public List getReactorProjects() * * @param argument The argument to add, must not be null. */ - protected void addArgument( String argument ) - { - if ( arguments != null ) - { + protected void addArgument(String argument) { + if (arguments != null) { arguments += " " + argument; - } - else - { + } else { arguments = argument; } } - static Path getCommonBasedir( List reactorProjects ) - throws IOException - { - Path basePath = reactorProjects.get( 0 ).getBasedir().toPath(); + static Path getCommonBasedir(List reactorProjects) throws IOException { + Path basePath = reactorProjects.get(0).getBasedir().toPath(); - for ( MavenProject reactorProject : reactorProjects ) - { + for (MavenProject reactorProject : reactorProjects) { Path matchPath = reactorProject.getBasedir().toPath(); - while ( !basePath.startsWith( matchPath ) ) - { + while (!basePath.startsWith(matchPath)) { matchPath = matchPath.getParent(); } basePath = matchPath; diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractScmReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractScmReleaseMojo.java index fcdda10b0..5b0f4434e 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractScmReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/AbstractScmReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import java.util.Map; @@ -37,25 +36,23 @@ * @author Robert Scholte */ // Extra layer since 2.4. Don't use @since doclet, these would be inherited by the subclasses -public abstract class AbstractScmReleaseMojo - extends AbstractReleaseMojo -{ +public abstract class AbstractScmReleaseMojo extends AbstractReleaseMojo { /** * The SCM username to use. */ - @Parameter( property = "username" ) + @Parameter(property = "username") private String username; /** * The SCM password to use. */ - @Parameter( property = "password" ) + @Parameter(property = "password") private String password; /** * The SCM tag to use. */ - @Parameter( alias = "releaseLabel", property = "tag" ) + @Parameter(alias = "releaseLabel", property = "tag") private String tag; /** @@ -70,7 +67,7 @@ public abstract class AbstractScmReleaseMojo * * @since 2.2.0 */ - @Parameter( defaultValue = "@{project.artifactId}-@{project.version}", property = "tagNameFormat" ) + @Parameter(defaultValue = "@{project.artifactId}-@{project.version}", property = "tagNameFormat") private String tagNameFormat; /** @@ -78,7 +75,7 @@ public abstract class AbstractScmReleaseMojo * For example, http://svn.apache.org/repos/asf/maven/plugins/tags. The URL is an SVN URL and does not * include the SCM provider and protocol. */ - @Parameter( property = "tagBase" ) + @Parameter(property = "tagBase") private String tagBase; /** @@ -86,13 +83,13 @@ public abstract class AbstractScmReleaseMojo * * @since 2.0-beta-5 */ - @Parameter( defaultValue = "[maven-release-plugin] ", property = "scmCommentPrefix" ) + @Parameter(defaultValue = "[maven-release-plugin] ", property = "scmCommentPrefix") private String scmCommentPrefix; /** * When cloning a repository if it should be a shallow clone or a full clone. */ - @Parameter( defaultValue = "true", property = "scmShallowClone" ) + @Parameter(defaultValue = "true", property = "scmShallowClone") private boolean scmShallowClone = true; /** @@ -100,7 +97,7 @@ public abstract class AbstractScmReleaseMojo * true by default to preserve backward compatibility. * @since 2.1 */ - @Parameter( defaultValue = "true", property = "pushChanges" ) + @Parameter(defaultValue = "true", property = "pushChanges") private boolean pushChanges = true; /** @@ -109,11 +106,11 @@ public abstract class AbstractScmReleaseMojo * * @since 3.0.0-M5 */ - @Parameter( property = "workItem" ) + @Parameter(property = "workItem") private String workItem; /** - * Add a new or overwrite the default implementation per provider. + * Add a new or overwrite the default implementation per provider. * The key is the scm prefix and the value is the role hint of the * {@link org.apache.maven.scm.provider.ScmProvider}. * @@ -130,85 +127,70 @@ public abstract class AbstractScmReleaseMojo private ScmManager scmManager; @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( providerImplementations != null ) - { - for ( Map.Entry providerEntry : providerImplementations.entrySet() ) - { - getLog().info( "Change the default '" + providerEntry.getKey() + "' provider implementation to '" - + providerEntry.getValue() + "'." ); - scmManager.setScmProviderImplementation( providerEntry.getKey(), providerEntry.getValue() ); + public void execute() throws MojoExecutionException, MojoFailureException { + if (providerImplementations != null) { + for (Map.Entry providerEntry : providerImplementations.entrySet()) { + getLog().info("Change the default '" + providerEntry.getKey() + "' provider implementation to '" + + providerEntry.getValue() + "'."); + scmManager.setScmProviderImplementation(providerEntry.getKey(), providerEntry.getValue()); } } } @Override - protected ReleaseDescriptorBuilder createReleaseDescriptor() - { + protected ReleaseDescriptorBuilder createReleaseDescriptor() { ReleaseDescriptorBuilder descriptor = super.createReleaseDescriptor(); - descriptor.setScmPassword( password ); - descriptor.setScmReleaseLabel( tag ); - descriptor.setScmTagNameFormat( tagNameFormat ); - descriptor.setScmTagBase( tagBase ); - descriptor.setScmUsername( username ); - descriptor.setScmCommentPrefix( scmCommentPrefix ); - descriptor.setScmShallowClone( scmShallowClone ); - - descriptor.setPushChanges( pushChanges ); - descriptor.setWorkItem( workItem ); - - if ( project.getScm() != null ) - { - if ( project.getScm().getDeveloperConnection() != null ) - { - descriptor.setScmSourceUrl( project.getScm().getDeveloperConnection() ); - } - else if ( project.getScm().getConnection() != null ) - { - descriptor.setScmSourceUrl( project.getScm().getConnection() ); + descriptor.setScmPassword(password); + descriptor.setScmReleaseLabel(tag); + descriptor.setScmTagNameFormat(tagNameFormat); + descriptor.setScmTagBase(tagBase); + descriptor.setScmUsername(username); + descriptor.setScmCommentPrefix(scmCommentPrefix); + descriptor.setScmShallowClone(scmShallowClone); + + descriptor.setPushChanges(pushChanges); + descriptor.setWorkItem(workItem); + + if (project.getScm() != null) { + if (project.getScm().getDeveloperConnection() != null) { + descriptor.setScmSourceUrl(project.getScm().getDeveloperConnection()); + } else if (project.getScm().getConnection() != null) { + descriptor.setScmSourceUrl(project.getScm().getConnection()); } } - + // As long as Scm.getId() does not exist, read it as a property - descriptor.setScmId( project.getProperties().getProperty( "project.scm.id" ) ); - - for ( MavenProject reactorProject : session.getProjects() ) - { - if ( reactorProject.getScm() != null ) - { + descriptor.setScmId(project.getProperties().getProperty("project.scm.id")); + + for (MavenProject reactorProject : session.getProjects()) { + if (reactorProject.getScm() != null) { String projectId = - ArtifactUtils.versionlessKey( reactorProject.getGroupId(), reactorProject.getArtifactId() ); - - descriptor.addOriginalScmInfo( projectId, buildScm( reactorProject ) ); + ArtifactUtils.versionlessKey(reactorProject.getGroupId(), reactorProject.getArtifactId()); + + descriptor.addOriginalScmInfo(projectId, buildScm(reactorProject)); } } return descriptor; } - + /** *

buildScm.

* * @param project a {@link org.apache.maven.project.MavenProject} object * @return a {@link org.apache.maven.model.Scm} object */ - protected Scm buildScm( MavenProject project ) - { + protected Scm buildScm(MavenProject project) { Scm scm; - if ( project.getOriginalModel().getScm() == null ) - { + if (project.getOriginalModel().getScm() == null) { scm = null; - } - else - { + } else { scm = new Scm(); - scm.setConnection( project.getOriginalModel().getScm().getConnection() ); - scm.setDeveloperConnection( project.getOriginalModel().getScm().getDeveloperConnection() ); - scm.setTag( project.getOriginalModel().getScm().getTag() ); - scm.setUrl( project.getOriginalModel().getScm().getUrl() ); + scm.setConnection(project.getOriginalModel().getScm().getConnection()); + scm.setDeveloperConnection(project.getOriginalModel().getScm().getDeveloperConnection()); + scm.setTag(project.getOriginalModel().getScm().getTag()); + scm.setUrl(project.getOriginalModel().getScm().getUrl()); } return scm; } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java index 05b51f1b3..2da7df115 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import java.util.Arrays; @@ -40,16 +39,14 @@ * @author Emmanuel Venisse * @since 2.0-beta-6 */ -@Mojo( name = "branch", aggregator = true ) -public class BranchReleaseMojo - extends AbstractScmReleaseMojo -{ +@Mojo(name = "branch", aggregator = true) +public class BranchReleaseMojo extends AbstractScmReleaseMojo { /** * The branch name to use. * * @since 2.0-beta-6 */ - @Parameter( property = "branchName" ) + @Parameter(property = "branchName") private String branchName; /** @@ -59,7 +56,7 @@ public class BranchReleaseMojo * * @since 2.0 */ - @Parameter( property = "branchBase" ) + @Parameter(property = "branchBase") private String branchBase; /** @@ -67,7 +64,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "false", property = "updateBranchVersions" ) + @Parameter(defaultValue = "false", property = "updateBranchVersions") private boolean updateBranchVersions; /** @@ -75,7 +72,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "true", property = "updateWorkingCopyVersions" ) + @Parameter(defaultValue = "true", property = "updateWorkingCopyVersions") private boolean updateWorkingCopyVersions; /** @@ -90,7 +87,7 @@ public class BranchReleaseMojo * * @since 2.1 */ - @Parameter( defaultValue = "false", property = "suppressCommitBeforeBranch" ) + @Parameter(defaultValue = "false", property = "suppressCommitBeforeBranch") private boolean suppressCommitBeforeBranch; /** @@ -98,7 +95,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "true", property = "updateVersionsToSnapshot" ) + @Parameter(defaultValue = "true", property = "updateVersionsToSnapshot") private boolean updateVersionsToSnapshot; /** @@ -106,7 +103,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "false", property = "useEditMode" ) + @Parameter(defaultValue = "false", property = "useEditMode") private boolean useEditMode; /** @@ -114,7 +111,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "true", property = "updateDependencies" ) + @Parameter(defaultValue = "true", property = "updateDependencies") private boolean updateDependencies; /** @@ -123,7 +120,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "false", property = "autoVersionSubmodules" ) + @Parameter(defaultValue = "false", property = "autoVersionSubmodules") private boolean autoVersionSubmodules; /** @@ -134,7 +131,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "false", property = "dryRun" ) + @Parameter(defaultValue = "false", property = "dryRun") private boolean dryRun; /** @@ -142,7 +139,7 @@ public class BranchReleaseMojo * * @since 2.0-beta-6 */ - @Parameter( defaultValue = "true", property = "addSchema" ) + @Parameter(defaultValue = "true", property = "addSchema") private boolean addSchema; /** @@ -151,10 +148,10 @@ public class BranchReleaseMojo * * @since 2.0 */ - @Parameter( defaultValue = "true", property = "remoteTagging" ) + @Parameter(defaultValue = "true", property = "remoteTagging") private boolean remoteTagging; - /** + /** * A list of additional exclude filters that will be skipped when checking for * modifications on the working copy. * @@ -170,7 +167,7 @@ public class BranchReleaseMojo * * @since 2.1 */ - @Parameter( property = "checkModificationExcludeList" ) + @Parameter(property = "checkModificationExcludeList") private String checkModificationExcludeList; /** @@ -179,7 +176,7 @@ public class BranchReleaseMojo * * @since 2.0 */ - @Parameter( property = "releaseVersion" ) + @Parameter(property = "releaseVersion") private String releaseVersion; /** @@ -188,7 +185,7 @@ public class BranchReleaseMojo * * @since 2.0 */ - @Parameter( property = "developmentVersion" ) + @Parameter(property = "developmentVersion") private String developmentVersion; /** @@ -198,7 +195,7 @@ public class BranchReleaseMojo * @since 3.0.0-M5 * @see org.apache.maven.shared.release.policies.DefaultVersionPolicy */ - @Parameter( defaultValue = "default", property = "projectVersionPolicyId" ) + @Parameter(defaultValue = "default", property = "projectVersionPolicyId") private String projectVersionPolicyId; /** @@ -206,7 +203,7 @@ public class BranchReleaseMojo * * @since 3.0.0-M8 */ - @Parameter( property = "projectVersionPolicyConfig" ) + @Parameter(property = "projectVersionPolicyConfig") private XmlPlexusConfiguration projectVersionPolicyConfig; /** @@ -216,7 +213,7 @@ public class BranchReleaseMojo * @since 3.0.0-M5 * @see org.apache.maven.shared.release.policies.DefaultNamingPolicy */ - @Parameter( property = "projectNamingPolicyId" ) + @Parameter(property = "projectNamingPolicyId") private String projectBranchNamingPolicyId; /** @@ -235,7 +232,7 @@ public class BranchReleaseMojo * * @since 3.0.0-M1 */ - @Parameter( defaultValue = "@{prefix} prepare branch @{releaseLabel}", property = "scmBranchCommitComment" ) + @Parameter(defaultValue = "@{prefix} prepare branch @{releaseLabel}", property = "scmBranchCommitComment") private String scmBranchCommitComment = "@{prefix} prepare branch @{releaseLabel}"; /** @@ -244,68 +241,59 @@ public class BranchReleaseMojo * * @since 3.0.0-M5 */ - @Parameter( defaultValue = "false", property = "pinExternals" ) + @Parameter(defaultValue = "false", property = "pinExternals") private boolean pinExternals; @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); final ReleaseDescriptorBuilder config = createReleaseDescriptor(); - config.setAddSchema( addSchema ); - config.setScmUseEditMode( useEditMode ); - config.setUpdateDependencies( updateDependencies ); - config.setAutoVersionSubmodules( autoVersionSubmodules ); - config.setScmReleaseLabel( branchName ); - config.setScmBranchBase( branchBase ); - config.setBranchCreation( true ); - config.setUpdateBranchVersions( updateBranchVersions ); - config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); - config.setUpdateVersionsToSnapshot( updateVersionsToSnapshot ); - config.setRemoteTagging( remoteTagging ); - config.setDefaultReleaseVersion( releaseVersion ); - config.setDefaultDevelopmentVersion( developmentVersion ); - config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeBranch ); - config.setProjectVersionPolicyId( projectVersionPolicyId ); - if ( projectVersionPolicyConfig != null ) - { - config.setProjectVersionPolicyConfig( projectVersionPolicyConfig.toString() ); + config.setAddSchema(addSchema); + config.setScmUseEditMode(useEditMode); + config.setUpdateDependencies(updateDependencies); + config.setAutoVersionSubmodules(autoVersionSubmodules); + config.setScmReleaseLabel(branchName); + config.setScmBranchBase(branchBase); + config.setBranchCreation(true); + config.setUpdateBranchVersions(updateBranchVersions); + config.setUpdateWorkingCopyVersions(updateWorkingCopyVersions); + config.setUpdateVersionsToSnapshot(updateVersionsToSnapshot); + config.setRemoteTagging(remoteTagging); + config.setDefaultReleaseVersion(releaseVersion); + config.setDefaultDevelopmentVersion(developmentVersion); + config.setSuppressCommitBeforeTagOrBranch(suppressCommitBeforeBranch); + config.setProjectVersionPolicyId(projectVersionPolicyId); + if (projectVersionPolicyConfig != null) { + config.setProjectVersionPolicyConfig(projectVersionPolicyConfig.toString()); } - config.setProjectNamingPolicyId( projectBranchNamingPolicyId ); - config.setScmBranchCommitComment( scmBranchCommitComment ); - config.setPinExternals( pinExternals ); + config.setProjectNamingPolicyId(projectBranchNamingPolicyId); + config.setScmBranchCommitComment(scmBranchCommitComment); + config.setPinExternals(pinExternals); - if ( checkModificationExcludeList != null ) - { - checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," ); + if (checkModificationExcludeList != null) { + checkModificationExcludes = + checkModificationExcludeList.replaceAll("\\s", "").split(","); } - if ( checkModificationExcludes != null ) - { - config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) ); + if (checkModificationExcludes != null) { + config.setCheckModificationExcludes(Arrays.asList(checkModificationExcludes)); } - try - { + try { ReleaseBranchRequest branchRequest = new ReleaseBranchRequest(); - branchRequest.setReleaseDescriptorBuilder( config ); - branchRequest.setReleaseEnvironment( getReleaseEnvironment() ); - branchRequest.setReactorProjects( getReactorProjects() ); - branchRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) ); - branchRequest.setDryRun( dryRun ); - branchRequest.setUserProperties( session.getUserProperties() ); + branchRequest.setReleaseDescriptorBuilder(config); + branchRequest.setReleaseEnvironment(getReleaseEnvironment()); + branchRequest.setReactorProjects(getReactorProjects()); + branchRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog(), dryRun)); + branchRequest.setDryRun(dryRun); + branchRequest.setUserProperties(session.getUserProperties()); - releaseManager.branch( branchRequest ); - } - catch ( ReleaseExecutionException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( ReleaseFailureException e ) - { - throw new MojoFailureException( e.getMessage(), e ); + releaseManager.branch(branchRequest); + } catch (ReleaseExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } catch (ReleaseFailureException e) { + throw new MojoFailureException(e.getMessage(), e); } } } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java index 62eeee526..0221d7602 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/CleanReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -36,30 +35,22 @@ * * @author Brett Porter */ -@Mojo( name = "clean", aggregator = true ) -public class CleanReleaseMojo - extends AbstractReleaseMojo -{ +@Mojo(name = "clean", aggregator = true) +public class CleanReleaseMojo extends AbstractReleaseMojo { @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { ReleaseDescriptorBuilder releaseDescriptor = new ReleaseDescriptorBuilder(); - releaseDescriptor.setWorkingDirectory( getBasedir().getAbsolutePath() ); + releaseDescriptor.setWorkingDirectory(getBasedir().getAbsolutePath()); ReleaseCleanRequest cleanRequest = new ReleaseCleanRequest(); - cleanRequest.setReleaseDescriptorBuilder( releaseDescriptor ); - cleanRequest.setReactorProjects( getReactorProjects() ); - cleanRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog() ) ); - - try - { - releaseManager.clean( cleanRequest ); - } - catch ( ReleaseFailureException e ) - { - throw new MojoFailureException( e.getMessage() ); + cleanRequest.setReleaseDescriptorBuilder(releaseDescriptor); + cleanRequest.setReactorProjects(getReactorProjects()); + cleanRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog())); + + try { + releaseManager.clean(cleanRequest); + } catch (ReleaseFailureException e) { + throw new MojoFailureException(e.getMessage()); } } - } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java index c06332223..2dbf89812 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PerformReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import java.io.File; import java.util.Map; @@ -44,15 +43,13 @@ * @author Emmanuel Venisse * @author Brett Porter */ -@Mojo( name = "perform", aggregator = true, requiresProject = false ) -public class PerformReleaseMojo - extends AbstractReleaseMojo -{ +@Mojo(name = "perform", aggregator = true, requiresProject = false) +public class PerformReleaseMojo extends AbstractReleaseMojo { /** * A space separated list of goals to execute on release perform. Default value is either deploy or * deploy site-deploy, if the project has a <distributionManagement>/<site> element. */ - @Parameter( property = "goals" ) + @Parameter(property = "goals") String goals; /** @@ -60,20 +57,20 @@ public class PerformReleaseMojo * * @since 2.0-beta-8 */ - @Parameter( property = "releaseProfiles" ) + @Parameter(property = "releaseProfiles") private String releaseProfiles; /** * The checkout directory. */ - @Parameter( defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true ) + @Parameter(defaultValue = "${project.build.directory}/checkout", property = "workingDirectory", required = true) private File workingDirectory; /** * The SCM URL to checkout from. If omitted, the one from the release.properties file is used, followed * by the URL from the current POM. */ - @Parameter( property = "connectionUrl" ) + @Parameter(property = "connectionUrl") private String connectionUrl; /** @@ -85,25 +82,25 @@ public class PerformReleaseMojo * * @since 2.0 for release:perform and 2.5.2 for release:stage */ - @Parameter( defaultValue = "false", property = "localCheckout" ) + @Parameter(defaultValue = "false", property = "localCheckout") private boolean localCheckout; /** * The SCM username to use. */ - @Parameter( property = "username" ) + @Parameter(property = "username") private String username; /** * The SCM password to use. */ - @Parameter( property = "password" ) + @Parameter(property = "password") private String password; /** * When cloning a repository if it should be a shallow clone or a full clone. */ - @Parameter( defaultValue = "true", property = "scmShallowClone" ) + @Parameter(defaultValue = "true", property = "scmShallowClone") private boolean scmShallowClone = true; /** @@ -114,7 +111,7 @@ public class PerformReleaseMojo * * @deprecated The release-profile profile will be removed from future versions of the super POM */ - @Parameter( defaultValue = "false", property = "useReleaseProfile" ) + @Parameter(defaultValue = "false", property = "useReleaseProfile") @Deprecated private boolean useReleaseProfile; @@ -122,7 +119,7 @@ public class PerformReleaseMojo * Dry run: don't checkout anything from the scm repository, or modify the checkout. * The goals (by default at least {@code deploy}) will not be executed. */ - @Parameter( defaultValue = "false", property = "dryRun" ) + @Parameter(defaultValue = "false", property = "dryRun") private boolean dryRun; /** @@ -143,96 +140,77 @@ public class PerformReleaseMojo private ScmManager scmManager; @Override - protected String getAdditionalProfiles() - { + protected String getAdditionalProfiles() { return releaseProfiles; } @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( providerImplementations != null ) - { - for ( Map.Entry providerEntry : providerImplementations.entrySet() ) - { - getLog().info( "Change the default '" + providerEntry.getKey() + "' provider implementation to '" - + providerEntry.getValue() + "'." ); - scmManager.setScmProviderImplementation( providerEntry.getKey(), providerEntry.getValue() ); + public void execute() throws MojoExecutionException, MojoFailureException { + if (providerImplementations != null) { + for (Map.Entry providerEntry : providerImplementations.entrySet()) { + getLog().info("Change the default '" + providerEntry.getKey() + "' provider implementation to '" + + providerEntry.getValue() + "'."); + scmManager.setScmProviderImplementation(providerEntry.getKey(), providerEntry.getValue()); } } // goals may be splitted into multiple line in configuration. // Let's build a single line command - if ( goals != null ) - { - goals = StringUtils.join( StringUtils.split( goals ), " " ); + if (goals != null) { + goals = StringUtils.join(StringUtils.split(goals), " "); } - try - { + try { setDeploymentRepository(); // Note that the working directory here is not the same as in the release configuration, so don't reuse that ReleaseDescriptorBuilder releaseDescriptor = createReleaseDescriptor(); - if ( connectionUrl != null ) - { - releaseDescriptor.setScmSourceUrl( connectionUrl ); + if (connectionUrl != null) { + releaseDescriptor.setScmSourceUrl(connectionUrl); } - if ( username != null ) - { - releaseDescriptor.setScmUsername( username ); + if (username != null) { + releaseDescriptor.setScmUsername(username); } - if ( password != null ) - { - releaseDescriptor.setScmPassword( password ); + if (password != null) { + releaseDescriptor.setScmPassword(password); } - releaseDescriptor.setScmShallowClone( scmShallowClone ); + releaseDescriptor.setScmShallowClone(scmShallowClone); - releaseDescriptor.setLocalCheckout( localCheckout ); + releaseDescriptor.setLocalCheckout(localCheckout); - releaseDescriptor.setCheckoutDirectory( workingDirectory.getAbsolutePath() ); - releaseDescriptor.setUseReleaseProfile( useReleaseProfile ); + releaseDescriptor.setCheckoutDirectory(workingDirectory.getAbsolutePath()); + releaseDescriptor.setUseReleaseProfile(useReleaseProfile); createGoals(); - releaseDescriptor.setPerformGoals( goals ); - - ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( releaseDescriptor ); - performRequest.setReleaseEnvironment( getReleaseEnvironment() ); - performRequest.setReactorProjects( getReactorProjects() ); - performRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) ); - performRequest.setDryRun( dryRun ); - - releaseManager.perform( performRequest ); - } - catch ( ReleaseExecutionException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( ReleaseFailureException e ) - { - throw new MojoFailureException( e.getMessage(), e ); + releaseDescriptor.setPerformGoals(goals); + + ReleasePerformRequest performRequest = new ReleasePerformRequest(); + performRequest.setReleaseDescriptorBuilder(releaseDescriptor); + performRequest.setReleaseEnvironment(getReleaseEnvironment()); + performRequest.setReactorProjects(getReactorProjects()); + performRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog(), dryRun)); + performRequest.setDryRun(dryRun); + + releaseManager.perform(performRequest); + } catch (ReleaseExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } catch (ReleaseFailureException e) { + throw new MojoFailureException(e.getMessage(), e); } } /** Just here so it may be overridden by StageReleaseMojo */ - void setDeploymentRepository() - { - } + void setDeploymentRepository() {} /** Just here so it may be overridden by StageReleaseMojo */ - void createGoals() - { - if ( goals == null ) - { + void createGoals() { + if (goals == null) { // set default goals = "deploy"; - if ( project.getDistributionManagement() != null - && project.getDistributionManagement().getSite() != null ) - { + if (project.getDistributionManagement() != null + && project.getDistributionManagement().getSite() != null) { goals += " site-deploy"; } } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java index f02f050e9..e7403b998 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import java.io.FileInputStream; import java.io.IOException; @@ -49,28 +48,26 @@ * @author Brett Porter */ // TODO [!] check how this works with version ranges -@Mojo( name = "prepare", aggregator = true, requiresDependencyCollection = ResolutionScope.TEST ) -public class PrepareReleaseMojo - extends AbstractScmReleaseMojo -{ +@Mojo(name = "prepare", aggregator = true, requiresDependencyCollection = ResolutionScope.TEST) +public class PrepareReleaseMojo extends AbstractScmReleaseMojo { /** * Resume a previous release attempt from the point where it was stopped. */ - @Parameter( defaultValue = "true", property = "resume" ) + @Parameter(defaultValue = "true", property = "resume") private boolean resume; /** * @deprecated Please use release:prepare-with-pom instead. */ @Deprecated - @Parameter( defaultValue = "false", property = "generateReleasePoms" ) + @Parameter(defaultValue = "false", property = "generateReleasePoms") private boolean generateReleasePoms; /** * Whether to use "edit" mode on the SCM, to lock the file for editing during SCM operations. */ - @Parameter( defaultValue = "false", property = "useEditMode" ) + @Parameter(defaultValue = "false", property = "useEditMode") private boolean useEditMode; /** @@ -78,7 +75,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-5 */ - @Parameter( defaultValue = "true", property = "updateDependencies" ) + @Parameter(defaultValue = "true", property = "updateDependencies") private boolean updateDependencies; /** @@ -87,7 +84,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-5 */ - @Parameter( defaultValue = "false", property = "autoVersionSubmodules" ) + @Parameter(defaultValue = "false", property = "autoVersionSubmodules") private boolean autoVersionSubmodules; /** @@ -96,19 +93,19 @@ public class PrepareReleaseMojo * operations (only listed on the console) are working as expected. Modified POMs are written alongside the * originals without modifying them. */ - @Parameter( defaultValue = "false", property = "dryRun" ) + @Parameter(defaultValue = "false", property = "dryRun") private boolean dryRun; /** * Whether to add a schema to the POM if it was previously missing on release. */ - @Parameter( defaultValue = "true", property = "addSchema" ) + @Parameter(defaultValue = "true", property = "addSchema") private boolean addSchema; /** * Goals to run as part of the preparation step, after transformation but before committing. Space delimited. */ - @Parameter( defaultValue = "clean verify", property = "preparationGoals" ) + @Parameter(defaultValue = "clean verify", property = "preparationGoals") private String preparationGoals; /** @@ -117,7 +114,7 @@ public class PrepareReleaseMojo * * @since 2.2 */ - @Parameter( defaultValue = "", property = "completionGoals" ) + @Parameter(defaultValue = "", property = "completionGoals") private String completionGoals; /** @@ -125,7 +122,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-5 */ - @Parameter( defaultValue = "false", property = "commitByProject" ) + @Parameter(defaultValue = "false", property = "commitByProject") private boolean commitByProject; /** @@ -133,7 +130,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-7 */ - @Parameter( defaultValue = "false", property = "ignoreSnapshots" ) + @Parameter(defaultValue = "false", property = "ignoreSnapshots") private boolean allowTimestampedSnapshots; /** @@ -142,7 +139,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-9 */ - @Parameter( defaultValue = "false", property = "allowReleasePluginSnapshot", readonly = true ) + @Parameter(defaultValue = "false", property = "allowReleasePluginSnapshot", readonly = true) private boolean allowReleasePluginSnapshot; /** @@ -159,7 +156,7 @@ public class PrepareReleaseMojo * * @since 2.1 */ - @Parameter( property = "checkModificationExcludeList" ) + @Parameter(property = "checkModificationExcludeList") private String checkModificationExcludeList; /** @@ -167,7 +164,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-8 */ - @Parameter( property = "releaseVersion" ) + @Parameter(property = "releaseVersion") private String releaseVersion; /** @@ -175,7 +172,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-8 */ - @Parameter( property = "developmentVersion" ) + @Parameter(property = "developmentVersion") private String developmentVersion; /** @@ -189,7 +186,7 @@ public class PrepareReleaseMojo * * @since 2.0-beta-9 */ - @Parameter( defaultValue = "true", property = "remoteTagging" ) + @Parameter(defaultValue = "true", property = "remoteTagging") private boolean remoteTagging; /** @@ -197,7 +194,7 @@ public class PrepareReleaseMojo * * @since 3.0.0-M4 */ - @Parameter( property = "signTag" ) + @Parameter(property = "signTag") private boolean signTag = false; /** @@ -205,7 +202,7 @@ public class PrepareReleaseMojo * * @since 2.1 */ - @Parameter( defaultValue = "true", property = "updateWorkingCopyVersions" ) + @Parameter(defaultValue = "true", property = "updateWorkingCopyVersions") private boolean updateWorkingCopyVersions; /** @@ -218,7 +215,7 @@ public class PrepareReleaseMojo * * @since 2.1 */ - @Parameter( defaultValue = "false", property = "suppressCommitBeforeTag" ) + @Parameter(defaultValue = "false", property = "suppressCommitBeforeTag") private boolean suppressCommitBeforeTag; /** @@ -228,7 +225,7 @@ public class PrepareReleaseMojo * * @since 2.2 */ - @Parameter( defaultValue = "0", property = "waitBeforeTagging" ) + @Parameter(defaultValue = "0", property = "waitBeforeTagging") private int waitBeforeTagging; /** @@ -238,7 +235,7 @@ public class PrepareReleaseMojo * @since 2.5.1 * @see org.apache.maven.shared.release.policies.DefaultVersionPolicy */ - @Parameter( defaultValue = "default", property = "projectVersionPolicyId" ) + @Parameter(defaultValue = "default", property = "projectVersionPolicyId") private String projectVersionPolicyId; /** @@ -246,7 +243,7 @@ public class PrepareReleaseMojo * * @since 3.0.0-M8 */ - @Parameter( property = "projectVersionPolicyConfig" ) + @Parameter(property = "projectVersionPolicyConfig") private XmlPlexusConfiguration projectVersionPolicyConfig; /** @@ -256,7 +253,7 @@ public class PrepareReleaseMojo * @since 3.0.0-M1 * @see org.apache.maven.shared.release.policies.DefaultNamingPolicy */ - @Parameter( property = "projectNamingPolicyId" ) + @Parameter(property = "projectNamingPolicyId") private String projectTagNamingPolicyId; /** @@ -275,7 +272,7 @@ public class PrepareReleaseMojo * * @since 3.0.0-M1 */ - @Parameter( defaultValue = "@{prefix} prepare release @{releaseLabel}", property = "scmReleaseCommitComment" ) + @Parameter(defaultValue = "@{prefix} prepare release @{releaseLabel}", property = "scmReleaseCommitComment") private String scmReleaseCommitComment = "@{prefix} prepare release @{releaseLabel}"; /** @@ -296,7 +293,7 @@ public class PrepareReleaseMojo */ @Parameter( defaultValue = "@{prefix} prepare for next development iteration", - property = "scmDevelopmentCommitComment" ) + property = "scmDevelopmentCommitComment") private String scmDevelopmentCommitComment = "@{prefix} prepare for next development iteration"; /** @@ -314,7 +311,7 @@ public class PrepareReleaseMojo * * @since 3.0.0-M4 */ - @Parameter( property = "autoResolveSnapshots" ) + @Parameter(property = "autoResolveSnapshots") private String autoResolveSnapshots; /** @@ -323,7 +320,7 @@ public class PrepareReleaseMojo * * @since 3.0.0-M4 */ - @Parameter( defaultValue = "false", property = "pinExternals" ) + @Parameter(defaultValue = "false", property = "pinExternals") private boolean pinExternals; /** @@ -339,23 +336,20 @@ public class PrepareReleaseMojo * * @since 3.0.0-M6 */ - @Parameter( defaultValue = "source", property = "lineSeparator" ) + @Parameter(defaultValue = "source", property = "lineSeparator") private String lineSeparator; /** * {@inheritDoc} */ @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - if ( generateReleasePoms ) - { - throw new MojoFailureException( "Generating release POMs is no longer supported in release:prepare. " - + "Please run release:prepare-with-pom instead." ); + public void execute() throws MojoExecutionException, MojoFailureException { + if (generateReleasePoms) { + throw new MojoFailureException("Generating release POMs is no longer supported in release:prepare. " + + "Please run release:prepare-with-pom instead."); } - prepareRelease( generateReleasePoms ); + prepareRelease(generateReleasePoms); } /** @@ -365,85 +359,73 @@ public void execute() * @throws org.apache.maven.plugin.MojoExecutionException if any. * @throws org.apache.maven.plugin.MojoFailureException if any. */ - protected void prepareRelease( boolean generateReleasePoms ) - throws MojoExecutionException, MojoFailureException - { + protected void prepareRelease(boolean generateReleasePoms) throws MojoExecutionException, MojoFailureException { // this is here so the subclass can call it without getting the extra generateReleasePoms check in execute() // above super.execute(); final ReleaseDescriptorBuilder config = createReleaseDescriptor(); - config.setAddSchema( addSchema ); - config.setGenerateReleasePoms( generateReleasePoms ); - config.setScmUseEditMode( useEditMode ); - config.setPreparationGoals( preparationGoals ); - config.setCompletionGoals( completionGoals ); - config.setCommitByProject( commitByProject ); - config.setUpdateDependencies( updateDependencies ); - config.setAutoVersionSubmodules( autoVersionSubmodules ); - config.setAllowTimestampedSnapshots( allowTimestampedSnapshots ); - config.setSnapshotReleasePluginAllowed( allowReleasePluginSnapshot ); - config.setDefaultReleaseVersion( releaseVersion ); - config.setDefaultDevelopmentVersion( developmentVersion ); - config.setRemoteTagging( remoteTagging ); - config.setScmSignTags( signTag ); - config.setUpdateWorkingCopyVersions( updateWorkingCopyVersions ); - config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag ); - config.setWaitBeforeTagging( waitBeforeTagging ); - config.setProjectVersionPolicyId( projectVersionPolicyId ); - if ( projectVersionPolicyConfig != null ) - { - config.setProjectVersionPolicyConfig( projectVersionPolicyConfig.toString() ); + config.setAddSchema(addSchema); + config.setGenerateReleasePoms(generateReleasePoms); + config.setScmUseEditMode(useEditMode); + config.setPreparationGoals(preparationGoals); + config.setCompletionGoals(completionGoals); + config.setCommitByProject(commitByProject); + config.setUpdateDependencies(updateDependencies); + config.setAutoVersionSubmodules(autoVersionSubmodules); + config.setAllowTimestampedSnapshots(allowTimestampedSnapshots); + config.setSnapshotReleasePluginAllowed(allowReleasePluginSnapshot); + config.setDefaultReleaseVersion(releaseVersion); + config.setDefaultDevelopmentVersion(developmentVersion); + config.setRemoteTagging(remoteTagging); + config.setScmSignTags(signTag); + config.setUpdateWorkingCopyVersions(updateWorkingCopyVersions); + config.setSuppressCommitBeforeTagOrBranch(suppressCommitBeforeTag); + config.setWaitBeforeTagging(waitBeforeTagging); + config.setProjectVersionPolicyId(projectVersionPolicyId); + if (projectVersionPolicyConfig != null) { + config.setProjectVersionPolicyConfig(projectVersionPolicyConfig.toString()); } - config.setProjectNamingPolicyId( projectTagNamingPolicyId ); - config.setScmDevelopmentCommitComment( scmDevelopmentCommitComment ); - config.setScmReleaseCommitComment( scmReleaseCommitComment ); - config.setAutoResolveSnapshots( autoResolveSnapshots ); - config.setPinExternals( pinExternals ); - config.setLineSeparator( resolveLineSeparator() ); - - if ( checkModificationExcludeList != null ) - { - checkModificationExcludes = checkModificationExcludeList.replaceAll( "\\s", "" ).split( "," ); + config.setProjectNamingPolicyId(projectTagNamingPolicyId); + config.setScmDevelopmentCommitComment(scmDevelopmentCommitComment); + config.setScmReleaseCommitComment(scmReleaseCommitComment); + config.setAutoResolveSnapshots(autoResolveSnapshots); + config.setPinExternals(pinExternals); + config.setLineSeparator(resolveLineSeparator()); + + if (checkModificationExcludeList != null) { + checkModificationExcludes = + checkModificationExcludeList.replaceAll("\\s", "").split(","); } - if ( checkModificationExcludes != null ) - { - config.setCheckModificationExcludes( Arrays.asList( checkModificationExcludes ) ); + if (checkModificationExcludes != null) { + config.setCheckModificationExcludes(Arrays.asList(checkModificationExcludes)); } ReleasePrepareRequest prepareRequest = new ReleasePrepareRequest(); - prepareRequest.setReleaseDescriptorBuilder( config ); - prepareRequest.setReleaseEnvironment( getReleaseEnvironment() ); - prepareRequest.setReactorProjects( getReactorProjects() ); - prepareRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog(), dryRun ) ); - prepareRequest.setResume( resume ); - prepareRequest.setDryRun( dryRun ); - prepareRequest.setUserProperties( session.getUserProperties() ); - - try - { - releaseManager.prepare( prepareRequest ); - } - catch ( ReleaseExecutionException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( ReleaseFailureException e ) - { - throw new MojoFailureException( e.getMessage(), e ); + prepareRequest.setReleaseDescriptorBuilder(config); + prepareRequest.setReleaseEnvironment(getReleaseEnvironment()); + prepareRequest.setReactorProjects(getReactorProjects()); + prepareRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog(), dryRun)); + prepareRequest.setResume(resume); + prepareRequest.setDryRun(dryRun); + prepareRequest.setUserProperties(session.getUserProperties()); + + try { + releaseManager.prepare(prepareRequest); + } catch (ReleaseExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } catch (ReleaseFailureException e) { + throw new MojoFailureException(e.getMessage(), e); } } - private String resolveLineSeparator() throws MojoExecutionException - { - if ( lineSeparator == null ) - { + private String resolveLineSeparator() throws MojoExecutionException { + if (lineSeparator == null) { return getLineSeparatorFromPom(); } - switch ( lineSeparator ) - { + switch (lineSeparator) { case "lf": return "\n"; case "cr": @@ -455,43 +437,34 @@ private String resolveLineSeparator() throws MojoExecutionException case "source": return getLineSeparatorFromPom(); default: - throw new IllegalArgumentException( String.format( "Unknown property lineSeparator: '%s'. Use one of" - + " the following: 'source', 'system', 'lf', 'cr', 'crlf'.", lineSeparator ) ); + throw new IllegalArgumentException(String.format( + "Unknown property lineSeparator: '%s'. Use one of" + + " the following: 'source', 'system', 'lf', 'cr', 'crlf'.", + lineSeparator)); } } - private String getLineSeparatorFromPom() - throws MojoExecutionException - { + private String getLineSeparatorFromPom() throws MojoExecutionException { char current; String lineSeparator = ""; - try ( InputStream is = new FileInputStream( this.project.getFile() ) ) - { - while ( is.available() > 0 ) - { - current = ( char ) is.read(); - if ( ( current == '\n' ) || ( current == '\r' ) ) - { + try (InputStream is = new FileInputStream(this.project.getFile())) { + while (is.available() > 0) { + current = (char) is.read(); + if ((current == '\n') || (current == '\r')) { lineSeparator += current; - if ( is.available() > 0 ) - { - char next = ( char ) is.read(); - if ( ( next != current ) - && ( ( next == '\r' ) || ( next == '\n' ) ) ) - { + if (is.available() > 0) { + char next = (char) is.read(); + if ((next != current) && ((next == '\r') || (next == '\n'))) { lineSeparator += next; } } return lineSeparator; } } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Failed to detect line separator of " + this.project.getFile(), e ); + } catch (IOException e) { + throw new MojoExecutionException("Failed to detect line separator of " + this.project.getFile(), e); } return lineSeparator; } - } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareWithPomReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareWithPomReleaseMojo.java index b56eb0d25..91531cbd2 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareWithPomReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareWithPomReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -31,20 +30,16 @@ * @author Brett Porter * @since 2.0 */ -@Mojo( name = "prepare-with-pom", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST ) -public class PrepareWithPomReleaseMojo - extends PrepareReleaseMojo -{ +@Mojo(name = "prepare-with-pom", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST) +public class PrepareWithPomReleaseMojo extends PrepareReleaseMojo { /** * Whether to generate release-pom.xml files that contain resolved information about the project. */ - @Parameter( defaultValue = "true", property = "generateReleasePoms" ) + @Parameter(defaultValue = "true", property = "generateReleasePoms") private boolean generateReleasePoms; @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - prepareRelease( generateReleasePoms ); + public void execute() throws MojoExecutionException, MojoFailureException { + prepareRelease(generateReleasePoms); } } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java index 5c17de459..60f250d91 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/RollbackReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -38,10 +37,8 @@ * @since 2.0-beta-5 * @author Edwin Punzalan */ -@Mojo( name = "rollback", aggregator = true ) -public class RollbackReleaseMojo - extends AbstractScmReleaseMojo -{ +@Mojo(name = "rollback", aggregator = true) +public class RollbackReleaseMojo extends AbstractScmReleaseMojo { /** * The SCM commit comment when rolling back. @@ -60,37 +57,29 @@ public class RollbackReleaseMojo * @since 3.0.0-M5 */ @Parameter( - defaultValue = "@{prefix} rollback the release of @{releaseLabel}", - property = "scmRollbackCommitComment" ) + defaultValue = "@{prefix} rollback the release of @{releaseLabel}", + property = "scmRollbackCommitComment") private String scmRollbackCommitComment = "@{prefix} rollback the release of @{releaseLabel}"; @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); final ReleaseDescriptorBuilder config = createReleaseDescriptor(); - config.setScmRollbackCommitComment( scmRollbackCommitComment ); + config.setScmRollbackCommitComment(scmRollbackCommitComment); - try - { + try { ReleaseRollbackRequest rollbackRequest = new ReleaseRollbackRequest(); - rollbackRequest.setReleaseDescriptorBuilder( config ); - rollbackRequest.setReleaseEnvironment( getReleaseEnvironment() ); - rollbackRequest.setReactorProjects( getReactorProjects() ); - rollbackRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog() ) ); - - releaseManager.rollback( rollbackRequest ); - } - catch ( ReleaseExecutionException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( ReleaseFailureException e ) - { - throw new MojoFailureException( e.getMessage(), e ); + rollbackRequest.setReleaseDescriptorBuilder(config); + rollbackRequest.setReleaseEnvironment(getReleaseEnvironment()); + rollbackRequest.setReactorProjects(getReactorProjects()); + rollbackRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog())); + + releaseManager.rollback(rollbackRequest); + } catch (ReleaseExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } catch (ReleaseFailureException e) { + throw new MojoFailureException(e.getMessage(), e); } } - } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/StageReleaseMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/StageReleaseMojo.java index a32b9907c..50613accd 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/StageReleaseMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/StageReleaseMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -35,39 +34,33 @@ * @author Nicolas De Loof * @since 2.0-beta-8 */ -@Mojo( name = "stage", aggregator = true, requiresProject = false ) -public class StageReleaseMojo - extends PerformReleaseMojo -{ +@Mojo(name = "stage", aggregator = true, requiresProject = false) +public class StageReleaseMojo extends PerformReleaseMojo { /** * URL of the staging repository to use. * * @since 2.0-beta-8 */ - @Parameter( property = "stagingRepository", required = true ) + @Parameter(property = "stagingRepository", required = true) private String stagingRepository; @Override - void createGoals() - { - if ( goals == null ) - { + void createGoals() { + if (goals == null) { // set default goals = "deploy"; - if ( project.getDistributionManagement() != null - && project.getDistributionManagement().getSite() != null ) - { + if (project.getDistributionManagement() != null + && project.getDistributionManagement().getSite() != null) { goals += " site:stage-deploy"; } } - goals = StringUtils.replace( goals, "site-deploy", "site:stage-deploy" ); - goals = StringUtils.replace( goals, "site:deploy", "site:stage-deploy" ); + goals = StringUtils.replace(goals, "site-deploy", "site:stage-deploy"); + goals = StringUtils.replace(goals, "site:deploy", "site:stage-deploy"); } @Override - void setDeploymentRepository() - { - addArgument( "-DaltDeploymentRepository=\"" + stagingRepository + "\"" ); + void setDeploymentRepository() { + addArgument("-DaltDeploymentRepository=\"" + stagingRepository + "\""); } } diff --git a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java index 801db127b..b1c8b1938 100644 --- a/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java +++ b/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/UpdateVersionsMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.plugin.MojoExecutionException; @@ -40,10 +39,8 @@ * @author Paul Gier * @since 2.0 */ -@Mojo( name = "update-versions", aggregator = true ) -public class UpdateVersionsMojo - extends AbstractReleaseMojo -{ +@Mojo(name = "update-versions", aggregator = true) +public class UpdateVersionsMojo extends AbstractReleaseMojo { /** * Whether to automatically assign submodules the parent version. If set to false, the user will be prompted for the @@ -51,7 +48,7 @@ public class UpdateVersionsMojo * * @since 2.0 */ - @Parameter( defaultValue = "false", property = "autoVersionSubmodules" ) + @Parameter(defaultValue = "false", property = "autoVersionSubmodules") private boolean autoVersionSubmodules; /** @@ -59,7 +56,7 @@ public class UpdateVersionsMojo * * @since 2.0 */ - @Parameter( defaultValue = "true", property = "addSchema" ) + @Parameter(defaultValue = "true", property = "addSchema") private boolean addSchema; /** @@ -67,7 +64,7 @@ public class UpdateVersionsMojo * * @since 2.0 */ - @Parameter( property = "developmentVersion" ) + @Parameter(property = "developmentVersion") private String developmentVersion; /** @@ -75,7 +72,7 @@ public class UpdateVersionsMojo * * @since 2.5.2 */ - @Parameter( defaultValue = "true", property = "updateDependencies" ) + @Parameter(defaultValue = "true", property = "updateDependencies") private boolean updateDependencies; /** @@ -83,7 +80,7 @@ public class UpdateVersionsMojo * * @since 2.5.2 */ - @Parameter( defaultValue = "false", property = "useEditMode" ) + @Parameter(defaultValue = "false", property = "useEditMode") private boolean useEditMode; /** @@ -91,7 +88,7 @@ public class UpdateVersionsMojo * * @since 3.0.0-M5 */ - @Parameter( defaultValue = "default", property = "projectVersionPolicyId" ) + @Parameter(defaultValue = "default", property = "projectVersionPolicyId") private String projectVersionPolicyId; /** @@ -99,45 +96,37 @@ public class UpdateVersionsMojo * * @since 3.0.0-M8 */ - @Parameter( property = "projectVersionPolicyConfig" ) + @Parameter(property = "projectVersionPolicyConfig") private XmlPlexusConfiguration projectVersionPolicyConfig; @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { + public void execute() throws MojoExecutionException, MojoFailureException { final ReleaseDescriptorBuilder config = createReleaseDescriptor(); - config.setAddSchema( addSchema ); - config.setAutoVersionSubmodules( autoVersionSubmodules ); - config.setDefaultDevelopmentVersion( developmentVersion ); - config.setScmUseEditMode( useEditMode ); - config.setUpdateDependencies( updateDependencies ); - config.setProjectVersionPolicyId( projectVersionPolicyId ); - if ( projectVersionPolicyConfig != null ) - { - config.setProjectVersionPolicyConfig( projectVersionPolicyConfig.toString() ); + config.setAddSchema(addSchema); + config.setAutoVersionSubmodules(autoVersionSubmodules); + config.setDefaultDevelopmentVersion(developmentVersion); + config.setScmUseEditMode(useEditMode); + config.setUpdateDependencies(updateDependencies); + config.setProjectVersionPolicyId(projectVersionPolicyId); + if (projectVersionPolicyConfig != null) { + config.setProjectVersionPolicyConfig(projectVersionPolicyConfig.toString()); } - config.addOriginalScmInfo( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ), - project.getScm() ); + config.addOriginalScmInfo( + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()), project.getScm()); - try - { + try { ReleaseUpdateVersionsRequest updateVersionsRequest = new ReleaseUpdateVersionsRequest(); - updateVersionsRequest.setReleaseDescriptorBuilder( config ); - updateVersionsRequest.setReleaseEnvironment( getReleaseEnvironment() ); - updateVersionsRequest.setReactorProjects( getReactorProjects() ); - updateVersionsRequest.setReleaseManagerListener( new DefaultReleaseManagerListener( getLog() ) ); - updateVersionsRequest.setUserProperties( session.getUserProperties() ); + updateVersionsRequest.setReleaseDescriptorBuilder(config); + updateVersionsRequest.setReleaseEnvironment(getReleaseEnvironment()); + updateVersionsRequest.setReactorProjects(getReactorProjects()); + updateVersionsRequest.setReleaseManagerListener(new DefaultReleaseManagerListener(getLog())); + updateVersionsRequest.setUserProperties(session.getUserProperties()); - releaseManager.updateVersions( updateVersionsRequest ); - } - catch ( ReleaseExecutionException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( ReleaseFailureException e ) - { - throw new MojoFailureException( e.getMessage(), e ); + releaseManager.updateVersions(updateVersionsRequest); + } catch (ReleaseExecutionException e) { + throw new MojoExecutionException(e.getMessage(), e); + } catch (ReleaseFailureException e) { + throw new MojoFailureException(e.getMessage(), e); } } } diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/CleanReleaseMojoTest.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/CleanReleaseMojoTest.java index d80848a54..0e87abb4f 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/CleanReleaseMojoTest.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/CleanReleaseMojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +package org.apache.maven.plugins.release; import java.io.File; @@ -30,46 +25,44 @@ import org.apache.maven.shared.release.ReleaseManager; import org.mockito.ArgumentCaptor; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + /** * Test release:clean. * * @author Brett Porter */ -public class CleanReleaseMojoTest - extends AbstractMojoTestCase -{ +public class CleanReleaseMojoTest extends AbstractMojoTestCase { protected CleanReleaseMojo mojo; private File workingDirectory; - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - File testFile = getTestFile( "target/test-classes/mojos/clean/clean.xml" ); - mojo = (CleanReleaseMojo) lookupMojo( "clean", testFile ); + File testFile = getTestFile("target/test-classes/mojos/clean/clean.xml"); + mojo = (CleanReleaseMojo) lookupMojo("clean", testFile); workingDirectory = testFile.getParentFile(); - mojo.setBasedir( workingDirectory ); + mojo.setBasedir(workingDirectory); } - public void testClean() - throws Exception - { + public void testClean() throws Exception { // prepare - ArgumentCaptor request = ArgumentCaptor.forClass( ReleaseCleanRequest.class ); - - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ArgumentCaptor request = ArgumentCaptor.forClass(ReleaseCleanRequest.class); + + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); // verify - verify( mock ).clean( request.capture() ); - - assertEquals( mojo.getReactorProjects(), request.getValue().getReactorProjects() ); - - verifyNoMoreInteractions( mock ); + verify(mock).clean(request.capture()); + + assertEquals(mojo.getReactorProjects(), request.getValue().getReactorProjects()); + + verifyNoMoreInteractions(mock); } -} \ No newline at end of file +} diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PerformReleaseMojoTest.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PerformReleaseMojoTest.java index c423c405a..05f912cab 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PerformReleaseMojoTest.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PerformReleaseMojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,12 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +package org.apache.maven.plugins.release; import java.io.File; import java.util.Arrays; @@ -44,353 +37,327 @@ import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; import org.mockito.ArgumentCaptor; +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + /** * Test release:perform. * * @author Brett Porter */ -public class PerformReleaseMojoTest - extends AbstractMojoTestCase -{ +public class PerformReleaseMojoTest extends AbstractMojoTestCase { private File workingDirectory; - public void testPerform() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform.xml" ); + public void testPerform() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); + + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); - // execute mojo.execute(); - + // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); - verifyNoMoreInteractions( mock ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); + verifyNoMoreInteractions(mock); } - public void testPerformWithFlatStructure() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform-with-flat-structure.xml" ); + public void testPerformWithFlatStructure() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform-with-flat-structure.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy" ); - builder.setScmSourceUrl( "scm:svn:file://localhost/target/svnroot/flat-multi-module/trunk/root-project" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy"); + builder.setScmSourceUrl("scm:svn:file://localhost/target/svnroot/flat-multi-module/trunk/root-project"); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); - + // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); - verifyNoMoreInteractions( mock ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); + verifyNoMoreInteractions(mock); } - - public void testPerformWithoutSite() - throws Exception - { - File testFileDirectory = getTestFile( "target/test-classes/mojos/perform/" ); + public void testPerformWithoutSite() throws Exception { + File testFileDirectory = getTestFile("target/test-classes/mojos/perform/"); PerformReleaseMojo mojo = - (PerformReleaseMojo) lookupMojo( "perform", new File( testFileDirectory, "perform-without-site.xml" ) ); - mojo.setBasedir( testFileDirectory ); - mojo.setPomFileName( "pom.xml" ); - - MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); - setVariableValueToObject( mojo, "session", newMavenSession( project ) ); - - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy" ); - - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + (PerformReleaseMojo) lookupMojo("perform", new File(testFileDirectory, "perform-without-site.xml")); + mojo.setBasedir(testFileDirectory); + mojo.setPomFileName("pom.xml"); + + MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project"); + setVariableValueToObject(mojo, "session", newMavenSession(project)); + + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy"); + + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); - verifyNoMoreInteractions( mock ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); + verifyNoMoreInteractions(mock); } - private PerformReleaseMojo getMojoWithProjectSite( String fileName ) - throws Exception - { - PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", new File( workingDirectory, fileName ) ); - mojo.setBasedir( workingDirectory ); - mojo.setPomFileName( fileName ); + private PerformReleaseMojo getMojoWithProjectSite(String fileName) throws Exception { + PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo("perform", new File(workingDirectory, fileName)); + mojo.setBasedir(workingDirectory); + mojo.setPomFileName(fileName); - MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); + MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project"); DistributionManagement distributionManagement = new DistributionManagement(); - distributionManagement.setSite( new Site() ); - project.setDistributionManagement( distributionManagement ); - - setVariableValueToObject( mojo, "session", newMavenSession( project ) ); + distributionManagement.setSite(new Site()); + project.setDistributionManagement(distributionManagement); + + setVariableValueToObject(mojo, "session", newMavenSession(project)); return mojo; } - public void testPerformWithExecutionException() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform.xml" ); + public void testPerformWithExecutionException() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); - ReleaseManager mock = mock( ReleaseManager.class ); - doThrow( new ReleaseExecutionException( "..." ) ).when( mock ).perform( isA( ReleasePerformRequest.class ) ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + doThrow(new ReleaseExecutionException("...")).when(mock).perform(isA(ReleasePerformRequest.class)); + mojo.setReleaseManager(mock); // execute - try - { + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoExecutionException e ) - { - assertEquals( "Check cause", ReleaseExecutionException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (MojoExecutionException e) { + assertEquals( + "Check cause", ReleaseExecutionException.class, e.getCause().getClass()); } - + // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - public void testPerformWithExecutionFailure() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform.xml" ); + public void testPerformWithExecutionFailure() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); - ReleaseManager mock = mock( ReleaseManager.class ); - ReleaseFailureException cause = new ReleaseFailureException( "..." ); - doThrow( cause ).when( mock ).perform( isA( ReleasePerformRequest.class ) ); + ReleaseManager mock = mock(ReleaseManager.class); + ReleaseFailureException cause = new ReleaseFailureException("..."); + doThrow(cause).when(mock).perform(isA(ReleasePerformRequest.class)); - mojo.setReleaseManager( mock ); + mojo.setReleaseManager(mock); // execute - try - { + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoFailureException e ) - { - assertEquals( "Check cause exists", cause, e.getCause() ); + fail("Should have thrown an exception"); + } catch (MojoFailureException e) { + assertEquals("Check cause exists", cause, e.getCause()); } - + // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - public void testPerformWithScm() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform-with-scm.xml" ); + public void testPerformWithScm() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform-with-scm.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); - builder.setScmSourceUrl( "scm-url" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); + builder.setScmSourceUrl("scm-url"); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); - + // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - public void testPerformWithProfiles() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform.xml" ); + public void testPerformWithProfiles() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); - builder.setAdditionalArguments( "-P prof1,2prof" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); + builder.setAdditionalArguments("-P prof1,2prof"); - MavenSession session = (MavenSession) getVariableValueFromObject( mojo, "session"); + MavenSession session = (MavenSession) getVariableValueFromObject(mojo, "session"); Profile profile1 = new Profile(); - profile1.setId( "prof1" ); - session.getRequest().addProfile( profile1 ); + profile1.setId("prof1"); + session.getRequest().addProfile(profile1); Profile profile2 = new Profile(); - profile2.setId( "2prof" ); - session.getRequest().addProfile( profile2 ); - session.getRequest().setActiveProfiles( Arrays.asList( "prof1", "2prof" ) ); + profile2.setId("2prof"); + session.getRequest().addProfile(profile2); + session.getRequest().setActiveProfiles(Arrays.asList("prof1", "2prof")); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - public void testPerformWithProfilesAndArguments() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform-with-args.xml" ); + public void testPerformWithProfilesAndArguments() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform-with-args.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); - builder.setAdditionalArguments( "-Dmaven.test.skip=true -P prof1,2prof" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); + builder.setAdditionalArguments("-Dmaven.test.skip=true -P prof1,2prof"); - MavenSession session = (MavenSession) getVariableValueFromObject( mojo, "session"); + MavenSession session = (MavenSession) getVariableValueFromObject(mojo, "session"); Profile profile1 = new Profile(); - profile1.setId( "prof1" ); - session.getRequest().addProfile( profile1 ); + profile1.setId("prof1"); + session.getRequest().addProfile(profile1); Profile profile2 = new Profile(); - profile2.setId( "2prof" ); - session.getRequest().addProfile( profile2 ); - session.getRequest().setActiveProfiles( Arrays.asList( "prof1", "2prof" ) ); + profile2.setId("2prof"); + session.getRequest().addProfile(profile2); + session.getRequest().setActiveProfiles(Arrays.asList("prof1", "2prof")); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - public void testPerformWithMultilineGoals() - throws Exception - { - PerformReleaseMojo mojo = getMojoWithProjectSite( "perform-with-multiline-goals.xml" ); + public void testPerformWithMultilineGoals() throws Exception { + PerformReleaseMojo mojo = getMojoWithProjectSite("perform-with-multiline-goals.xml"); - ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( mojo ); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site-deploy" ); + ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder(mojo); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site-deploy"); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); // execute mojo.execute(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); - verifyNoMoreInteractions( mock ); + verifyNoMoreInteractions(mock); } - private ReleaseDescriptorBuilder createReleaseDescriptorBuilder( PerformReleaseMojo mojo ) throws Exception - { + private ReleaseDescriptorBuilder createReleaseDescriptorBuilder(PerformReleaseMojo mojo) throws Exception { ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - - @SuppressWarnings( "unchecked" ) - List reactorProjects = (List) getVariableValueFromObject( mojo, "reactorProjects" ); - - for ( MavenProject project : reactorProjects ) - { - builder.putOriginalVersion( project.getGroupId() + ':' + project.getArtifactId(), project.getVersion() ); + + @SuppressWarnings("unchecked") + List reactorProjects = (List) getVariableValueFromObject(mojo, "reactorProjects"); + + for (MavenProject project : reactorProjects) { + builder.putOriginalVersion(project.getGroupId() + ':' + project.getArtifactId(), project.getVersion()); } - + return builder; } - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - workingDirectory = getTestFile( "target/test-classes/mojos/perform" ); + workingDirectory = getTestFile("target/test-classes/mojos/perform"); } -} \ No newline at end of file +} diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java index 4b087daf6..1dd461f93 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/PrepareReleaseMojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,20 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; +package org.apache.maven.plugins.release; import java.io.File; import java.util.Collections; @@ -50,53 +35,57 @@ import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; import org.apache.maven.shared.release.env.ReleaseEnvironment; import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + /** * Test release:prepare. * * @author Brett Porter */ -public class PrepareReleaseMojoTest - extends AbstractMojoTestCase -{ - private void setDefaults( PrepareReleaseMojo mojo ) - throws IllegalAccessException - { - setVariableValueToObject( mojo, "updateWorkingCopyVersions", Boolean.TRUE ); +public class PrepareReleaseMojoTest extends AbstractMojoTestCase { + private void setDefaults(PrepareReleaseMojo mojo) throws IllegalAccessException { + setVariableValueToObject(mojo, "updateWorkingCopyVersions", Boolean.TRUE); } - public void testPrepare() - throws Exception - { - File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" ); - final PrepareReleaseMojo mojo = spy((PrepareReleaseMojo) lookupMojo( "prepare", testFile )); + public void testPrepare() throws Exception { + File testFile = getTestFile("target/test-classes/mojos/prepare/prepare.xml"); + final PrepareReleaseMojo mojo = spy((PrepareReleaseMojo) lookupMojo("prepare", testFile)); mojo.getProject().setFile(testFile); - setDefaults( mojo ); - mojo.setBasedir( testFile.getParentFile() ); - mojo.setPomFileName( "pom.xml" ); - mojo.session = new MavenSession( null, null, null, null, null, null, null, null, null ) - { - public Properties getExecutionProperties() - { + setDefaults(mojo); + mojo.setBasedir(testFile.getParentFile()); + mojo.setPomFileName("pom.xml"); + mojo.session = new MavenSession(null, null, null, null, null, null, null, null, null) { + public Properties getExecutionProperties() { return new Properties(); - }; + } + ; @Override - public List getProjects() - { - return Collections.singletonList( mojo.project ); + public List getProjects() { + return Collections.singletonList(mojo.project); } }; ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setWorkingDirectory( testFile.getParentFile().getAbsolutePath() ); - builder.setUpdateDependencies( false ); + builder.setWorkingDirectory(testFile.getParentFile().getAbsolutePath()); + builder.setUpdateDependencies(false); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); when(mojo.createReleaseDescriptor()).thenAnswer(new Answer() { @Override @@ -109,134 +98,120 @@ public ReleaseDescriptorBuilder answer(InvocationOnMock invocationOnMock) throws // execute mojo.execute(); - ArgumentCaptor prepareRequest = ArgumentCaptor.forClass( ReleasePrepareRequest.class ); + ArgumentCaptor prepareRequest = ArgumentCaptor.forClass(ReleasePrepareRequest.class); // verify - verify( mock ).prepare( prepareRequest.capture() ); + verify(mock).prepare(prepareRequest.capture()); - assertThat( prepareRequest.getValue().getReleaseDescriptorBuilder(), - is( instanceOf( ReleaseDescriptorBuilder.class ) ) ); - assertThat( prepareRequest.getValue().getReleaseEnvironment(), is( instanceOf( ReleaseEnvironment.class ) ) ); - assertThat( prepareRequest.getValue().getReactorProjects(), is( notNullValue() ) ); - assertThat( prepareRequest.getValue().getResume(), is( true ) ); - assertThat( prepareRequest.getValue().getDryRun(), is( false ) ); + assertThat( + prepareRequest.getValue().getReleaseDescriptorBuilder(), + is(instanceOf(ReleaseDescriptorBuilder.class))); + assertThat(prepareRequest.getValue().getReleaseEnvironment(), is(instanceOf(ReleaseEnvironment.class))); + assertThat(prepareRequest.getValue().getReactorProjects(), is(notNullValue())); + assertThat(prepareRequest.getValue().getResume(), is(true)); + assertThat(prepareRequest.getValue().getDryRun(), is(false)); verify(prepareRequest.getValue().getReleaseDescriptorBuilder()).setScmSignTags(false); } - public void testPrepareWithExecutionException() - throws Exception - { - File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" ); - final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile ); + public void testPrepareWithExecutionException() throws Exception { + File testFile = getTestFile("target/test-classes/mojos/prepare/prepare.xml"); + final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo("prepare", testFile); mojo.getProject().setFile(testFile); - setDefaults( mojo ); - mojo.setBasedir( testFile.getParentFile() ); - mojo.setPomFileName( "pom.xml" ); - mojo.session = new MavenSession( null, null, null, null, null, null, null, null, null ) - { - public Properties getExecutionProperties(){ - return new Properties(); - }; - - @Override - public List getProjects() - { - return Collections.singletonList( mojo.project ); - } + setDefaults(mojo); + mojo.setBasedir(testFile.getParentFile()); + mojo.setPomFileName("pom.xml"); + mojo.session = new MavenSession(null, null, null, null, null, null, null, null, null) { + public Properties getExecutionProperties() { + return new Properties(); + } + ; + + @Override + public List getProjects() { + return Collections.singletonList(mojo.project); + } }; - ReleaseManager mock = mock( ReleaseManager.class ); - doThrow( new ReleaseExecutionException( "..." ) ).when( mock ).prepare( isA( ReleasePrepareRequest.class ) ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + doThrow(new ReleaseExecutionException("...")).when(mock).prepare(isA(ReleasePrepareRequest.class)); + mojo.setReleaseManager(mock); - //execute - try - { + // execute + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoExecutionException e ) - { - assertEquals( "Check cause", ReleaseExecutionException.class, e.getCause().getClass() ); + fail("Should have thrown an exception"); + } catch (MojoExecutionException e) { + assertEquals( + "Check cause", ReleaseExecutionException.class, e.getCause().getClass()); } // verify - verify( mock ).prepare( isA( ReleasePrepareRequest.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock).prepare(isA(ReleasePrepareRequest.class)); + verifyNoMoreInteractions(mock); } - public void testPrepareWithExecutionFailure() - throws Exception - { - File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" ); - final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile ); + public void testPrepareWithExecutionFailure() throws Exception { + File testFile = getTestFile("target/test-classes/mojos/prepare/prepare.xml"); + final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo("prepare", testFile); mojo.getProject().setFile(testFile); - setDefaults( mojo ); - mojo.setBasedir( testFile.getParentFile() ); - mojo.setPomFileName( "pom.xml" ); - mojo.session = new MavenSession( null, null, null, null, null, null, null, null, null ) - { - public Properties getExecutionProperties(){ - return new Properties(); - }; - - @Override - public List getProjects() - { - return Collections.singletonList( mojo.project ); - } + setDefaults(mojo); + mojo.setBasedir(testFile.getParentFile()); + mojo.setPomFileName("pom.xml"); + mojo.session = new MavenSession(null, null, null, null, null, null, null, null, null) { + public Properties getExecutionProperties() { + return new Properties(); + } + ; + + @Override + public List getProjects() { + return Collections.singletonList(mojo.project); + } }; - ReleaseManager mock = mock( ReleaseManager.class ); - ReleaseFailureException cause = new ReleaseFailureException( "..." ); - doThrow( cause ).when( mock ).prepare( isA( ReleasePrepareRequest.class ) ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + ReleaseFailureException cause = new ReleaseFailureException("..."); + doThrow(cause).when(mock).prepare(isA(ReleasePrepareRequest.class)); + mojo.setReleaseManager(mock); // execute - try - { + try { mojo.execute(); - fail( "Should have thrown an exception" ); - } - catch ( MojoFailureException e ) - { - assertEquals( "Check cause exists", cause, e.getCause() ); + fail("Should have thrown an exception"); + } catch (MojoFailureException e) { + assertEquals("Check cause exists", cause, e.getCause()); } // verify - verify( mock ).prepare( isA( ReleasePrepareRequest.class ) ); - verifyNoMoreInteractions( mock ); + verify(mock).prepare(isA(ReleasePrepareRequest.class)); + verifyNoMoreInteractions(mock); } - public void testLineSeparatorInPrepareWithPom() - throws Exception - { - File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" ); - final PrepareWithPomReleaseMojo mojo = (PrepareWithPomReleaseMojo) lookupMojo( "prepare-with-pom", testFile ); + public void testLineSeparatorInPrepareWithPom() throws Exception { + File testFile = getTestFile("target/test-classes/mojos/prepare/prepare.xml"); + final PrepareWithPomReleaseMojo mojo = (PrepareWithPomReleaseMojo) lookupMojo("prepare-with-pom", testFile); mojo.getProject().setFile(testFile); - setDefaults( mojo ); - setVariableValueToObject( mojo, "generateReleasePoms", Boolean.TRUE ); - mojo.setBasedir( testFile.getParentFile() ); - mojo.setPomFileName( "pom.xml" ); - mojo.project.setFile( testFile ); - mojo.session = new MavenSession( null, null, null, null, null, null, null, null, null ) - { - public Properties getExecutionProperties() - { + setDefaults(mojo); + setVariableValueToObject(mojo, "generateReleasePoms", Boolean.TRUE); + mojo.setBasedir(testFile.getParentFile()); + mojo.setPomFileName("pom.xml"); + mojo.project.setFile(testFile); + mojo.session = new MavenSession(null, null, null, null, null, null, null, null, null) { + public Properties getExecutionProperties() { return new Properties(); - }; + } + ; @Override - public List getProjects() - { - return Collections.singletonList( mojo.project ); + public List getProjects() { + return Collections.singletonList(mojo.project); } }; - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); int times = 1; testLineSeparator(null, "\n", mojo, mock, times++); @@ -247,32 +222,28 @@ public List getProjects() testLineSeparator("system", System.lineSeparator(), mojo, mock, times++); } - public void testLineSeparatorInPrepare() - throws Exception - { - File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" ); - final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile ); + public void testLineSeparatorInPrepare() throws Exception { + File testFile = getTestFile("target/test-classes/mojos/prepare/prepare.xml"); + final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo("prepare", testFile); mojo.getProject().setFile(testFile); - setDefaults( mojo ); - mojo.setBasedir( testFile.getParentFile() ); - mojo.setPomFileName( "pom.xml" ); - mojo.project.setFile( testFile ); - mojo.session = new MavenSession( null, null, null, null, null, null, null, null, null ) - { - public Properties getExecutionProperties() - { + setDefaults(mojo); + mojo.setBasedir(testFile.getParentFile()); + mojo.setPomFileName("pom.xml"); + mojo.project.setFile(testFile); + mojo.session = new MavenSession(null, null, null, null, null, null, null, null, null) { + public Properties getExecutionProperties() { return new Properties(); - }; + } + ; @Override - public List getProjects() - { - return Collections.singletonList( mojo.project ); + public List getProjects() { + return Collections.singletonList(mojo.project); } }; - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); int times = 1; testLineSeparator(null, "\n", mojo, mock, times++); @@ -283,100 +254,101 @@ public List getProjects() testLineSeparator("system", System.lineSeparator(), mojo, mock, times++); } - private void testLineSeparator( String lineSeparator, String expected, PrepareReleaseMojo mojo, - ReleaseManager releaseManager, int times ) - throws Exception - { + private void testLineSeparator( + String lineSeparator, String expected, PrepareReleaseMojo mojo, ReleaseManager releaseManager, int times) + throws Exception { - setVariableValueToObject( mojo, "lineSeparator", lineSeparator ); + setVariableValueToObject(mojo, "lineSeparator", lineSeparator); mojo.execute(); - ArgumentCaptor prepareRequest = ArgumentCaptor.forClass( ReleasePrepareRequest.class ); - verify( releaseManager , times( times ) ).prepare( prepareRequest.capture() ); + ArgumentCaptor prepareRequest = ArgumentCaptor.forClass(ReleasePrepareRequest.class); + verify(releaseManager, times(times)).prepare(prepareRequest.capture()); - assertEquals( expected, prepareRequest.getValue().getReleaseDescriptorBuilder().build().getLineSeparator() ); + assertEquals( + expected, + prepareRequest.getValue().getReleaseDescriptorBuilder().build().getLineSeparator()); } -/* - public void testPerformWithScm() - throws Exception - { - PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", getTestFile( - "target/test-classes/mojos/perform/perform-with-scm.xml" ) ); - - ReleaseDescriptor releaseConfiguration = new ReleaseDescriptor(); - releaseConfiguration.setSettings( mojo.getSettings() ); - releaseConfiguration.setUrl( "scm-url" ); - - Mock mock = new Mock( ReleaseManager.class ); - Constraint[] constraints = new Constraint[]{new IsEqual( releaseConfiguration ), - new IsEqual( new File( getBasedir(), "target/checkout" ) ), new IsEqual( "deploy site-deploy" ), - new IsEqual( Boolean.TRUE )}; - mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints ); - mojo.setReleaseManager( (ReleaseManager) mock.proxy() ); + /* + public void testPerformWithScm() + throws Exception + { + PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", getTestFile( + "target/test-classes/mojos/perform/perform-with-scm.xml" ) ); - mojo.execute(); + ReleaseDescriptor releaseConfiguration = new ReleaseDescriptor(); + releaseConfiguration.setSettings( mojo.getSettings() ); + releaseConfiguration.setUrl( "scm-url" ); - assertTrue( true ); - } + Mock mock = new Mock( ReleaseManager.class ); + Constraint[] constraints = new Constraint[]{new IsEqual( releaseConfiguration ), + new IsEqual( new File( getBasedir(), "target/checkout" ) ), new IsEqual( "deploy site-deploy" ), + new IsEqual( Boolean.TRUE )}; + mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints ); + mojo.setReleaseManager( (ReleaseManager) mock.proxy() ); - public void testPerformWithProfiles() - throws Exception - { - PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", getTestFile( - "target/test-classes/mojos/perform/perform.xml" ) ); - - ReleaseDescriptor releaseConfiguration = new ReleaseDescriptor(); - releaseConfiguration.setSettings( mojo.getSettings() ); - releaseConfiguration.setAdditionalArguments( "-P prof1,2prof" ); - - MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); - Profile profile1 = new Profile(); - profile1.setId( "prof1" ); - Profile profile2 = new Profile(); - profile2.setId( "2prof" ); - project.setActiveProfiles( Arrays.asList( new Profile[]{profile1, profile2} ) ); - - Mock mock = new Mock( ReleaseManager.class ); - Constraint[] constraints = new Constraint[]{new IsEqual( releaseConfiguration ), - new IsEqual( new File( getBasedir(), "target/checkout" ) ), new IsEqual( "deploy site-deploy" ), - new IsEqual( Boolean.TRUE )}; - mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints ); - mojo.setReleaseManager( (ReleaseManager) mock.proxy() ); + mojo.execute(); - mojo.execute(); + assertTrue( true ); + } - assertTrue( true ); - } + public void testPerformWithProfiles() + throws Exception + { + PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", getTestFile( + "target/test-classes/mojos/perform/perform.xml" ) ); + + ReleaseDescriptor releaseConfiguration = new ReleaseDescriptor(); + releaseConfiguration.setSettings( mojo.getSettings() ); + releaseConfiguration.setAdditionalArguments( "-P prof1,2prof" ); + + MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); + Profile profile1 = new Profile(); + profile1.setId( "prof1" ); + Profile profile2 = new Profile(); + profile2.setId( "2prof" ); + project.setActiveProfiles( Arrays.asList( new Profile[]{profile1, profile2} ) ); + + Mock mock = new Mock( ReleaseManager.class ); + Constraint[] constraints = new Constraint[]{new IsEqual( releaseConfiguration ), + new IsEqual( new File( getBasedir(), "target/checkout" ) ), new IsEqual( "deploy site-deploy" ), + new IsEqual( Boolean.TRUE )}; + mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints ); + mojo.setReleaseManager( (ReleaseManager) mock.proxy() ); - public void testPerformWithProfilesAndArguments() - throws Exception - { - PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", getTestFile( - "target/test-classes/mojos/perform/perform-with-args.xml" ) ); - - ReleaseDescriptor releaseConfiguration = new ReleaseDescriptor(); - releaseConfiguration.setSettings( mojo.getSettings() ); - releaseConfiguration.setAdditionalArguments( "-Dmaven.test.skip=true -P prof1,2prof" ); - - MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); - Profile profile1 = new Profile(); - profile1.setId( "prof1" ); - Profile profile2 = new Profile(); - profile2.setId( "2prof" ); - project.setActiveProfiles( Arrays.asList( new Profile[]{profile1, profile2} ) ); - - Mock mock = new Mock( ReleaseManager.class ); - Constraint[] constraints = new Constraint[]{new IsEqual( releaseConfiguration ), - new IsEqual( new File( getBasedir(), "target/checkout" ) ), new IsEqual( "deploy site-deploy" ), - new IsEqual( Boolean.TRUE )}; - mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints ); - mojo.setReleaseManager( (ReleaseManager) mock.proxy() ); + mojo.execute(); - mojo.execute(); + assertTrue( true ); + } - assertTrue( true ); - } -*/ + public void testPerformWithProfilesAndArguments() + throws Exception + { + PerformReleaseMojo mojo = (PerformReleaseMojo) lookupMojo( "perform", getTestFile( + "target/test-classes/mojos/perform/perform-with-args.xml" ) ); + + ReleaseDescriptor releaseConfiguration = new ReleaseDescriptor(); + releaseConfiguration.setSettings( mojo.getSettings() ); + releaseConfiguration.setAdditionalArguments( "-Dmaven.test.skip=true -P prof1,2prof" ); + + MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); + Profile profile1 = new Profile(); + profile1.setId( "prof1" ); + Profile profile2 = new Profile(); + profile2.setId( "2prof" ); + project.setActiveProfiles( Arrays.asList( new Profile[]{profile1, profile2} ) ); + + Mock mock = new Mock( ReleaseManager.class ); + Constraint[] constraints = new Constraint[]{new IsEqual( releaseConfiguration ), + new IsEqual( new File( getBasedir(), "target/checkout" ) ), new IsEqual( "deploy site-deploy" ), + new IsEqual( Boolean.TRUE )}; + mock.expects( new InvokeOnceMatcher() ).method( "perform" ).with( constraints ); + mojo.setReleaseManager( (ReleaseManager) mock.proxy() ); + + mojo.execute(); + + assertTrue( true ); + } + */ } diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/StageReleaseMojoTest.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/StageReleaseMojoTest.java index e16b52225..2a6bcaf65 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/StageReleaseMojoTest.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/StageReleaseMojoTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,10 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +package org.apache.maven.plugins.release; import java.io.File; @@ -34,91 +29,83 @@ import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder; import org.mockito.ArgumentCaptor; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + /** * Test release:stage. * * @author Brett Porter */ -public class StageReleaseMojoTest - extends AbstractMojoTestCase -{ +public class StageReleaseMojoTest extends AbstractMojoTestCase { private File workingDirectory; - public void testStage() - throws Exception - { - StageReleaseMojo mojo = getMojoWithProjectSite( "stage.xml" ); + public void testStage() throws Exception { + StageReleaseMojo mojo = getMojoWithProjectSite("stage.xml"); ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder(); - builder.setWorkingDirectory( workingDirectory.getAbsolutePath() ); - File checkoutDirectory = getTestFile( "target/checkout" ); - builder.setCheckoutDirectory( checkoutDirectory.getAbsolutePath() ); - builder.setPerformGoals( "deploy site:stage-deploy" ); - builder.setAdditionalArguments( "-DaltDeploymentRepository=\"staging\"" ); + builder.setWorkingDirectory(workingDirectory.getAbsolutePath()); + File checkoutDirectory = getTestFile("target/checkout"); + builder.setCheckoutDirectory(checkoutDirectory.getAbsolutePath()); + builder.setPerformGoals("deploy site:stage-deploy"); + builder.setAdditionalArguments("-DaltDeploymentRepository=\"staging\""); ReleasePerformRequest performRequest = new ReleasePerformRequest(); - performRequest.setReleaseDescriptorBuilder( builder ); - performRequest.setReleaseEnvironment( mojo.getReleaseEnvironment() ); - performRequest.setReactorProjects( mojo.getReactorProjects() ); - performRequest.setDryRun( false ); + performRequest.setReleaseDescriptorBuilder(builder); + performRequest.setReleaseEnvironment(mojo.getReleaseEnvironment()); + performRequest.setReactorProjects(mojo.getReactorProjects()); + performRequest.setDryRun(false); - ReleaseManager mock = mock( ReleaseManager.class ); - mojo.setReleaseManager( mock ); + ReleaseManager mock = mock(ReleaseManager.class); + mojo.setReleaseManager(mock); mojo.execute(); // verify ArgumentCaptor argument = ArgumentCaptor.forClass(ReleasePerformRequest.class); - verify( mock ).perform( argument.capture() ); - assertNotNull( argument.getValue().getReleaseDescriptorBuilder() ); - assertNotNull( argument.getValue().getReleaseEnvironment() ); - assertNotNull( argument.getValue().getReactorProjects() ); - assertEquals( Boolean.FALSE, argument.getValue().getDryRun() ); - verifyNoMoreInteractions( mock ); + verify(mock).perform(argument.capture()); + assertNotNull(argument.getValue().getReleaseDescriptorBuilder()); + assertNotNull(argument.getValue().getReleaseEnvironment()); + assertNotNull(argument.getValue().getReactorProjects()); + assertEquals(Boolean.FALSE, argument.getValue().getDryRun()); + verifyNoMoreInteractions(mock); } - public void testCreateGoals() - throws Exception - { - StageReleaseMojo mojo = getMojoWithProjectSite( "stage.xml" ); + public void testCreateGoals() throws Exception { + StageReleaseMojo mojo = getMojoWithProjectSite("stage.xml"); mojo.createGoals(); - assertEquals( "deploy site:stage-deploy", mojo.goals ); + assertEquals("deploy site:stage-deploy", mojo.goals); mojo.goals = "deploy site:deploy"; mojo.createGoals(); - assertEquals( "deploy site:stage-deploy", mojo.goals ); + assertEquals("deploy site:stage-deploy", mojo.goals); } - public void testCreateArguments() - throws Exception - { - StageReleaseMojo mojo = getMojoWithProjectSite( "stage.xml" ); + public void testCreateArguments() throws Exception { + StageReleaseMojo mojo = getMojoWithProjectSite("stage.xml"); mojo.setDeploymentRepository(); - ReleaseDescriptorBuilder.BuilderReleaseDescriptor releaseDescriptor = mojo.createReleaseDescriptor().build(); - assertEquals( "-DskipTests -DaltDeploymentRepository=\"staging\"", releaseDescriptor.getAdditionalArguments() ); + ReleaseDescriptorBuilder.BuilderReleaseDescriptor releaseDescriptor = + mojo.createReleaseDescriptor().build(); + assertEquals("-DskipTests -DaltDeploymentRepository=\"staging\"", releaseDescriptor.getAdditionalArguments()); } + private StageReleaseMojo getMojoWithProjectSite(String fileName) throws Exception { + StageReleaseMojo mojo = (StageReleaseMojo) lookupMojo("stage", new File(workingDirectory, fileName)); + mojo.setBasedir(workingDirectory); + mojo.setPomFileName("pom.xml"); - private StageReleaseMojo getMojoWithProjectSite( String fileName ) - throws Exception - { - StageReleaseMojo mojo = (StageReleaseMojo) lookupMojo( "stage", new File( workingDirectory, fileName ) ); - mojo.setBasedir( workingDirectory ); - mojo.setPomFileName( "pom.xml" ); - - MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" ); + MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project"); DistributionManagement distributionManagement = new DistributionManagement(); - distributionManagement.setSite( new Site() ); - project.setDistributionManagement( distributionManagement ); + distributionManagement.setSite(new Site()); + project.setDistributionManagement(distributionManagement); - setVariableValueToObject( mojo, "session", newMavenSession( project ) ); + setVariableValueToObject(mojo, "session", newMavenSession(project)); return mojo; } - protected void setUp() - throws Exception - { + protected void setUp() throws Exception { super.setUp(); - workingDirectory = getTestFile( "target/test-classes/mojos/stage" ); + workingDirectory = getTestFile("target/test-classes/mojos/stage"); } } diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java index 44ff46869..0b10b37d7 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/FlatMultiModuleMavenProjectStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release.stubs; import java.io.File; import java.util.ArrayList; @@ -29,7 +28,7 @@ /** *

Stub for a MavenProject with a flat structure.

- * + * *

TODO: shouldn't need to do this, but the "stub" in the harness just throws away values you set. * Just overriding the ones I need for this plugin.

* @@ -38,68 +37,56 @@ /* * @noinspection ClassNameSameAsAncestorName */ -public class FlatMultiModuleMavenProjectStub - extends org.apache.maven.plugin.testing.stubs.MavenProjectStub -{ - public void setDistributionManagement( DistributionManagement distributionManagement ) - { - getModel().setDistributionManagement( distributionManagement ); +public class FlatMultiModuleMavenProjectStub extends org.apache.maven.plugin.testing.stubs.MavenProjectStub { + public void setDistributionManagement(DistributionManagement distributionManagement) { + getModel().setDistributionManagement(distributionManagement); } - public Model getModel() - { + public Model getModel() { Model model = super.getModel(); - if ( model == null ) - { + if (model == null) { model = new Model(); - setModel( model ); + setModel(model); } return model; } - public DistributionManagement getDistributionManagement() - { + public DistributionManagement getDistributionManagement() { return getModel().getDistributionManagement(); } - - public List getModules() - { + + public List getModules() { List modules = new ArrayList(); - modules.add( "../core" ); - modules.add( "../webapp" ); - modules.add( "../commons" ); - + modules.add("../core"); + modules.add("../webapp"); + modules.add("../commons"); + return modules; } - - public File getBasedir() - { - return new File( "/flat-multi-module/root-project" ).getAbsoluteFile(); + + public File getBasedir() { + return new File("/flat-multi-module/root-project").getAbsoluteFile(); } - - public Scm getScm() - { + + public Scm getScm() { Scm scm = new Scm(); - scm.setConnection( "scm:svn:file://localhost/target/svnroot/flat-multi-module/trunk/root-project" ); - + scm.setConnection("scm:svn:file://localhost/target/svnroot/flat-multi-module/trunk/root-project"); + return scm; } - + @Override - public String getGroupId() - { + public String getGroupId() { return "GROUPID"; } - + @Override - public String getArtifactId() - { + public String getArtifactId() { return "ARTIFACTID"; } - + @Override - public String getVersion() - { + public String getVersion() { return "VERSION"; } } diff --git a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/MavenProjectStub.java b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/MavenProjectStub.java index 8e377b798..f50f9ec42 100644 --- a/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/MavenProjectStub.java +++ b/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/stubs/MavenProjectStub.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.release.stubs; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,57 +16,49 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.release.stubs; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Model; /** *

Stub for MavenProject.

- * + * *

TODO: shouldn't need to do this, but the "stub" in the harness just throws away values you set. * Just overriding the ones I need for this plugin.

* * @author Brett Porter */ -public class MavenProjectStub - extends org.apache.maven.plugin.testing.stubs.MavenProjectStub -{ - public void setDistributionManagement( DistributionManagement distributionManagement ) - { - getModel().setDistributionManagement( distributionManagement ); +public class MavenProjectStub extends org.apache.maven.plugin.testing.stubs.MavenProjectStub { + public void setDistributionManagement(DistributionManagement distributionManagement) { + getModel().setDistributionManagement(distributionManagement); } - public Model getModel() - { + public Model getModel() { Model model = super.getModel(); - if ( model == null ) - { + if (model == null) { model = new Model(); - setModel( model ); + setModel(model); } return model; } - public DistributionManagement getDistributionManagement() - { + public DistributionManagement getDistributionManagement() { return getModel().getDistributionManagement(); } - + @Override - public String getGroupId() - { + public String getGroupId() { return "GROUPID"; } - + @Override - public String getArtifactId() - { + public String getArtifactId() { return "ARTIFACTID"; } - + @Override - public String getVersion() - { + public String getVersion() { return "VERSION"; } } diff --git a/maven-release-policies/maven-release-oddeven-policy/pom.xml b/maven-release-policies/maven-release-oddeven-policy/pom.xml index 89432c4f4..1612c5796 100644 --- a/maven-release-policies/maven-release-oddeven-policy/pom.xml +++ b/maven-release-policies/maven-release-oddeven-policy/pom.xml @@ -17,7 +17,6 @@ ~ specific language governing permissions and limitations ~ under the License. --> - 4.0.0 @@ -31,12 +30,11 @@ maven-release-oddeven-policy Maven Release Odd-Even Policy - - A version policy that proposes even version numbers only for releases and odd numbers for development - + A version policy that proposes even version numbers only for releases and odd numbers for development - true diff --git a/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicy.java b/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicy.java index 0c33f4b70..35640f51e 100644 --- a/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicy.java +++ b/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.oddeven; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.oddeven; import javax.inject.Named; import javax.inject.Singleton; @@ -44,99 +43,75 @@ * */ @Singleton -@Named( "OddEvenVersionPolicy" ) -@Description( "A VersionPolicy implementation that selects even version numbers only for releases" ) -public final class OddEvenVersionPolicy - implements VersionPolicy -{ +@Named("OddEvenVersionPolicy") +@Description("A VersionPolicy implementation that selects even version numbers only for releases") +public final class OddEvenVersionPolicy implements VersionPolicy { @Override - public VersionPolicyResult getReleaseVersion( VersionPolicyRequest request ) - throws PolicyException - { - return calculateNextVersion( request, false ); + public VersionPolicyResult getReleaseVersion(VersionPolicyRequest request) throws PolicyException { + return calculateNextVersion(request, false); } @Override - public VersionPolicyResult getDevelopmentVersion( VersionPolicyRequest request ) - throws PolicyException - { - return calculateNextVersion( request, true ); + public VersionPolicyResult getDevelopmentVersion(VersionPolicyRequest request) throws PolicyException { + return calculateNextVersion(request, true); } - private VersionPolicyResult calculateNextVersion( VersionPolicyRequest request, boolean development ) - { + private VersionPolicyResult calculateNextVersion(VersionPolicyRequest request, boolean development) { Version defaultVersionInfo = null; - try - { - defaultVersionInfo = new Version( request.getVersion() ); - } - catch ( VersionParseException e ) - { - throw new IllegalArgumentException( "Can't tell if version with no digits is even: " + e.getMessage(), e ); + try { + defaultVersionInfo = new Version(request.getVersion()); + } catch (VersionParseException e) { + throw new IllegalArgumentException("Can't tell if version with no digits is even: " + e.getMessage(), e); } - Version newVersion = newVersion( defaultVersionInfo, development ); + Version newVersion = newVersion(defaultVersionInfo, development); - return new VersionPolicyResult().setVersion( newVersion.toString() ); + return new VersionPolicyResult().setVersion(newVersion.toString()); } - private Version newVersion( Version defaultVersionInfo, boolean development ) - { + private Version newVersion(Version defaultVersionInfo, boolean development) { Version newVersion; int mostSignificantSegment; - if ( StringUtils.isNumeric( defaultVersionInfo.getAnnotationRevision() ) ) - { - mostSignificantSegment = Integer.parseInt( defaultVersionInfo.getAnnotationRevision() ); + if (StringUtils.isNumeric(defaultVersionInfo.getAnnotationRevision())) { + mostSignificantSegment = Integer.parseInt(defaultVersionInfo.getAnnotationRevision()); - int skip = getVersionIncrements( development, mostSignificantSegment % 2 == 0 ); + int skip = getVersionIncrements(development, mostSignificantSegment % 2 == 0); - newVersion = defaultVersionInfo.setAnnotationRevision( String.valueOf( mostSignificantSegment + skip ) ); - } - else - { + newVersion = defaultVersionInfo.setAnnotationRevision(String.valueOf(mostSignificantSegment + skip)); + } else { List digits = defaultVersionInfo.getDigits(); - if ( digits == null ) - { - throw new IllegalArgumentException( "Can't tell if version with no digits is even." ); + if (digits == null) { + throw new IllegalArgumentException("Can't tell if version with no digits is even."); } - mostSignificantSegment = Integer.parseInt( digits.get( digits.size() - 1 ) ); + mostSignificantSegment = Integer.parseInt(digits.get(digits.size() - 1)); - int skip = getVersionIncrements( development, mostSignificantSegment % 2 == 0 ); + int skip = getVersionIncrements(development, mostSignificantSegment % 2 == 0); - digits.set( digits.size() - 1, String.valueOf( String.valueOf( mostSignificantSegment + skip ) ) ); + digits.set(digits.size() - 1, String.valueOf(String.valueOf(mostSignificantSegment + skip))); - newVersion = defaultVersionInfo.setDigits( digits ); + newVersion = defaultVersionInfo.setDigits(digits); } - if ( development ) - { - return newVersion.setBuildSpecifier( Artifact.SNAPSHOT_VERSION ); - } - else - { - return newVersion.setBuildSpecifier( null ); + if (development) { + return newVersion.setBuildSpecifier(Artifact.SNAPSHOT_VERSION); + } else { + return newVersion.setBuildSpecifier(null); } } - private int getVersionIncrements( boolean development, boolean isEven ) - { - if ( development && !isEven ) - { + private int getVersionIncrements(boolean development, boolean isEven) { + if (development && !isEven) { // do we need a snapshot? make sure the version info is odd return 2; - } - else if ( !development && isEven ) - { + } else if (!development && isEven) { // do we need a release? make sure the version info is even return 0; - } - else - { + } else { // by default, never reuse revisions return 1; } diff --git a/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/package-info.java b/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/package-info.java index 4f0063539..874afa955 100644 --- a/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/package-info.java +++ b/maven-release-policies/maven-release-oddeven-policy/src/main/java/org/apache/maven/shared/release/policy/oddeven/package-info.java @@ -18,8 +18,4 @@ * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ diff --git a/maven-release-policies/maven-release-oddeven-policy/src/test/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicyTestCase.java b/maven-release-policies/maven-release-oddeven-policy/src/test/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicyTestCase.java index edee8a3f8..85c13167c 100644 --- a/maven-release-policies/maven-release-oddeven-policy/src/test/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicyTestCase.java +++ b/maven-release-policies/maven-release-oddeven-policy/src/test/java/org/apache/maven/shared/release/policy/oddeven/OddEvenVersionPolicyTestCase.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.oddeven; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,51 +16,46 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.assertEquals; +package org.apache.maven.shared.release.policy.oddeven; import org.apache.maven.shared.release.policy.version.VersionPolicy; import org.apache.maven.shared.release.policy.version.VersionPolicyRequest; import org.junit.Test; -public final class OddEvenVersionPolicyTestCase -{ +import static org.junit.Assert.assertEquals; + +public final class OddEvenVersionPolicyTestCase { private final VersionPolicy versionPolicy = new OddEvenVersionPolicy(); @Test - public void testConvertToSnapshot() - throws Exception - { - String suggestedVersion = versionPolicy.getDevelopmentVersion( newVersionPolicyRequest( "1.0.0" ) ) - .getVersion(); + public void testConvertToSnapshot() throws Exception { + String suggestedVersion = versionPolicy + .getDevelopmentVersion(newVersionPolicyRequest("1.0.0")) + .getVersion(); - assertEquals( "1.0.1-SNAPSHOT", suggestedVersion ); + assertEquals("1.0.1-SNAPSHOT", suggestedVersion); } @Test - public void testConvertToRelease() - throws Exception - { - String suggestedVersion = versionPolicy.getReleaseVersion( newVersionPolicyRequest( "1.0.0-SNAPSHOT" ) ) - .getVersion(); + public void testConvertToRelease() throws Exception { + String suggestedVersion = versionPolicy + .getReleaseVersion(newVersionPolicyRequest("1.0.0-SNAPSHOT")) + .getVersion(); - assertEquals( "1.0.0", suggestedVersion ); + assertEquals("1.0.0", suggestedVersion); } @Test - public void testConvertOddToRelease() - throws Exception - { - String suggestedVersion = versionPolicy.getReleaseVersion( newVersionPolicyRequest( "1.0.1-SNAPSHOT" ) ) - .getVersion(); + public void testConvertOddToRelease() throws Exception { + String suggestedVersion = versionPolicy + .getReleaseVersion(newVersionPolicyRequest("1.0.1-SNAPSHOT")) + .getVersion(); - assertEquals( "1.0.2", suggestedVersion ); + assertEquals("1.0.2", suggestedVersion); } - private static VersionPolicyRequest newVersionPolicyRequest( String version ) - { - return new VersionPolicyRequest().setVersion( version ); + private static VersionPolicyRequest newVersionPolicyRequest(String version) { + return new VersionPolicyRequest().setVersion(version); } - } diff --git a/maven-release-policies/maven-release-semver-policy/pom.xml b/maven-release-policies/maven-release-semver-policy/pom.xml index 38a062a92..17b18a229 100644 --- a/maven-release-policies/maven-release-semver-policy/pom.xml +++ b/maven-release-policies/maven-release-semver-policy/pom.xml @@ -17,7 +17,6 @@ ~ specific language governing permissions and limitations ~ under the License. --> - 4.0.0 @@ -31,9 +30,7 @@ maven-release-semver-policy Maven Release SemVer Policy - - A version policy that enforce SemVer format and upgrades minor element for next development version. - + A version policy that enforce SemVer format and upgrades minor element for next development version. @@ -66,4 +63,4 @@ - \ No newline at end of file + diff --git a/maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicy.java b/maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicy.java index 88d70fd1c..37f19765b 100644 --- a/maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicy.java +++ b/maven-release-policies/maven-release-semver-policy/src/main/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicy.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.semver; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.shared.release.policy.semver; import javax.inject.Named; import javax.inject.Singleton; @@ -35,47 +34,36 @@ * Uses SemVer implementation to increase minor element when resolving the development version */ @Singleton -@Named( "SemVerVersionPolicy" ) -@Description( "A VersionPolicy following the SemVer rules" ) -public class SemVerVersionPolicy implements VersionPolicy -{ +@Named("SemVerVersionPolicy") +@Description("A VersionPolicy following the SemVer rules") +public class SemVerVersionPolicy implements VersionPolicy { @Override - public VersionPolicyResult getReleaseVersion( VersionPolicyRequest request ) - throws VersionParseException - { + public VersionPolicyResult getReleaseVersion(VersionPolicyRequest request) throws VersionParseException { Version version; - try - { - version = Version.parse( request.getVersion() ); - } - catch ( IllegalArgumentException e ) - { - throw new VersionParseException( e.getMessage() ); + try { + version = Version.parse(request.getVersion()); + } catch (IllegalArgumentException e) { + throw new VersionParseException(e.getMessage()); } - + VersionPolicyResult result = new VersionPolicyResult(); - result.setVersion( version.toReleaseVersion().toString() ); + result.setVersion(version.toReleaseVersion().toString()); return result; } @Override - public VersionPolicyResult getDevelopmentVersion( VersionPolicyRequest request ) - throws VersionParseException - { + public VersionPolicyResult getDevelopmentVersion(VersionPolicyRequest request) throws VersionParseException { Version version; - try - { - version = Version.parse( request.getVersion() ); - } - catch ( IllegalArgumentException e ) - { - throw new VersionParseException( e.getMessage() ); + try { + version = Version.parse(request.getVersion()); + } catch (IllegalArgumentException e) { + throw new VersionParseException(e.getMessage()); } - - version = version.next( Element.MINOR ); + + version = version.next(Element.MINOR); VersionPolicyResult result = new VersionPolicyResult(); - result.setVersion( version + "-SNAPSHOT" ); + result.setVersion(version + "-SNAPSHOT"); return result; } } diff --git a/maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicyTest.java b/maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicyTest.java index fb15556c2..55c89fea1 100644 --- a/maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicyTest.java +++ b/maven-release-policies/maven-release-semver-policy/src/test/java/org/apache/maven/shared/release/policy/semver/SemVerVersionPolicyTest.java @@ -1,5 +1,3 @@ -package org.apache.maven.shared.release.policy.semver; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,40 +16,37 @@ * specific language governing permissions and limitations * under the License. */ - -import static org.junit.Assert.*; +package org.apache.maven.shared.release.policy.semver; import org.apache.maven.shared.release.policy.version.VersionPolicy; import org.apache.maven.shared.release.policy.version.VersionPolicyRequest; import org.junit.Test; -public final class SemVerVersionPolicyTest -{ +import static org.junit.Assert.*; + +public final class SemVerVersionPolicyTest { private final VersionPolicy versionPolicy = new SemVerVersionPolicy(); @Test - public void testConvertToSnapshot() - throws Exception - { - String suggestedVersion = versionPolicy.getDevelopmentVersion( newVersionPolicyRequest( "1.0.0" ) ) - .getVersion(); + public void testConvertToSnapshot() throws Exception { + String suggestedVersion = versionPolicy + .getDevelopmentVersion(newVersionPolicyRequest("1.0.0")) + .getVersion(); - assertEquals( "1.1.0-SNAPSHOT", suggestedVersion ); + assertEquals("1.1.0-SNAPSHOT", suggestedVersion); } @Test - public void testConvertToRelease() - throws Exception - { - String suggestedVersion = versionPolicy.getReleaseVersion( newVersionPolicyRequest( "1.0.0-SNAPSHOT" ) ) - .getVersion(); + public void testConvertToRelease() throws Exception { + String suggestedVersion = versionPolicy + .getReleaseVersion(newVersionPolicyRequest("1.0.0-SNAPSHOT")) + .getVersion(); - assertEquals( "1.0.0", suggestedVersion ); + assertEquals("1.0.0", suggestedVersion); } - private static VersionPolicyRequest newVersionPolicyRequest( String version ) - { - return new VersionPolicyRequest().setVersion( version ); + private static VersionPolicyRequest newVersionPolicyRequest(String version) { + return new VersionPolicyRequest().setVersion(version); } } diff --git a/pom.xml b/pom.xml index 1429ac0a7..15908a0e3 100644 --- a/pom.xml +++ b/pom.xml @@ -17,14 +17,13 @@ ~ specific language governing permissions and limitations ~ under the License. --> - 4.0.0 org.apache.maven maven-parent - 36 + 39 @@ -36,6 +35,30 @@ Maven Release Tooling to release a project with Maven, saving a lot of repetitive, manual work. + + + John R Fallows + + + Gertjan Gaillet + + + Russ Kociuba + + + Georges-Etienne Legendre + + + Henning Schmiedehausen + + + Thorsten Heit + + + Niels Basjes + + + maven-release-api maven-release-manager @@ -47,8 +70,8 @@ scm:git:https://gitbox.apache.org/repos/asf/maven-release.git scm:git:https://gitbox.apache.org/repos/asf/maven-release.git - https://github.com/apache/maven-release/tree/${project.scm.tag} maven-release-3.0.0-M7 + https://github.com/apache/maven-release/tree/${project.scm.tag} jira @@ -65,30 +88,6 @@ - - - John R Fallows - - - Gertjan Gaillet - - - Russ Kociuba - - - Georges-Etienne Legendre - - - Henning Schmiedehausen - - - Thorsten Heit - - - Niels Basjes - - - 2.0.0-M3 8 @@ -105,30 +104,6 @@ 3.2.2 - - - - - org.apache.rat - apache-rat-plugin - - - .repository - **/*.iml - **/target/** - - - - - - - - org.eclipse.sisu - sisu-maven-plugin - - - - @@ -327,4 +302,29 @@ + + + + + + org.apache.rat + apache-rat-plugin + + + .repository + **/*.iml + **/target/** + **/.gitattributes + + + + + + + + org.eclipse.sisu + sisu-maven-plugin + + +