Author: rfscholte Date: Thu Feb 2 13:06:22 2017 New Revision: 1781389 URL: http://svn.apache.org/viewvc?rev=1781389&view=rev Log: [MRELEASE-979] Support NamingPolicies to manage Branch and Tag names Patch provided by Henning Schmiedehausen, reviewed and adjusted by Robert Scholte
Added: maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/ maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java Modified: maven/release/trunk/maven-release-manager/pom.xml maven/release/trunk/maven-release-manager/src/main/components-fragment.xml maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java maven/release/trunk/maven-release-manager/src/main/mdo/release-descriptor.mdo maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java maven/release/trunk/pom.xml Added: maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java?rev=1781389&view=auto ============================================================================== --- maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java (added) +++ maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicy.java Thu Feb 2 13:06:22 2017 @@ -0,0 +1,37 @@ +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 + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "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 + * + * 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. + */ + +import org.apache.maven.shared.release.policy.PolicyException; + +/** + * API for branch and tag naming. Used by maven-release-plugin to suggest names for tags and branches. + * + * @since 3.0.0 (MRELEASE-979) + */ +public interface NamingPolicy +{ + /** + * Calculation of the name used for branching or tagging. + */ + NamingPolicyResult getName( NamingPolicyRequest request ) + throws PolicyException; + +} Added: maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java?rev=1781389&view=auto ============================================================================== --- maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java (added) +++ maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyRequest.java Thu Feb 2 13:06:22 2017 @@ -0,0 +1,67 @@ +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 + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "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 + * + * 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. + */ + +/** + * + * @author Robert Scholte + * @since 3.0.0 + */ +public class NamingPolicyRequest +{ + private String groupId; + + private String artifactId; + + private String version; + + public String getGroupId() + { + return groupId; + } + + public NamingPolicyRequest setGroupId( String groupId ) + { + this.groupId = groupId; + return this; + } + + public String getArtifactId() + { + return artifactId; + } + + public NamingPolicyRequest setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + return this; + } + + public String getVersion() + { + return version; + } + + public NamingPolicyRequest setVersion( String version ) + { + this.version = version; + return this; + } +} Added: maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java?rev=1781389&view=auto ============================================================================== --- maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java (added) +++ maven/release/trunk/maven-release-api/src/main/java/org/apache/maven/shared/release/policy/naming/NamingPolicyResult.java Thu Feb 2 13:06:22 2017 @@ -0,0 +1,44 @@ +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 + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "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 + * + * 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. + */ + +/** + * + * @since 3.0.0 (MRELEASE-979) + */ +public class NamingPolicyResult +{ + /** + * The tag or branch name to use. + */ + private String name; + + public String getName() + { + return name; + } + + public NamingPolicyResult setName( String name ) + { + this.name = name; + return this; + } + +} Modified: maven/release/trunk/maven-release-manager/pom.xml URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/pom.xml?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/pom.xml (original) +++ maven/release/trunk/maven-release-manager/pom.xml Thu Feb 2 13:06:22 2017 @@ -211,7 +211,7 @@ </execution> </executions> <configuration> - <version>2.5.1</version> + <version>3.0.0</version> <packageWithVersion>false</packageWithVersion> <useJava5>true</useJava5> <models> Modified: maven/release/trunk/maven-release-manager/src/main/components-fragment.xml URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/components-fragment.xml?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/main/components-fragment.xml (original) +++ maven/release/trunk/maven-release-manager/src/main/components-fragment.xml Thu Feb 2 13:06:22 2017 @@ -238,6 +238,10 @@ <requirement> <role>org.apache.maven.shared.release.scm.ScmRepositoryConfigurator</role> </requirement> + <requirement> + <role>org.apache.maven.shared.release.policy.naming.NamingPolicy</role> + <field-name>namingPolicies</field-name> + </requirement> </requirements> </component> <component> @@ -255,6 +259,10 @@ <requirement> <role>org.apache.maven.shared.release.scm.ScmRepositoryConfigurator</role> </requirement> + <requirement> + <role>org.apache.maven.shared.release.policy.naming.NamingPolicy</role> + <field-name>namingPolicies</field-name> + </requirement> </requirements> </component> </components> Modified: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java (original) +++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/InputVariablesPhase.java Thu Feb 2 13:06:22 2017 @@ -19,6 +19,10 @@ package org.apache.maven.shared.release. * under the License. */ +import java.util.List; +import java.util.Map; +import java.util.Properties; + import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.project.MavenProject; import org.apache.maven.scm.manager.NoSuchScmProviderException; @@ -29,6 +33,9 @@ import org.apache.maven.shared.release.R import org.apache.maven.shared.release.ReleaseResult; import org.apache.maven.shared.release.config.ReleaseDescriptor; import org.apache.maven.shared.release.env.ReleaseEnvironment; +import org.apache.maven.shared.release.policy.PolicyException; +import org.apache.maven.shared.release.policy.naming.NamingPolicy; +import org.apache.maven.shared.release.policy.naming.NamingPolicyRequest; import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException; import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator; import org.apache.maven.shared.release.util.ReleaseUtil; @@ -43,9 +50,6 @@ import org.codehaus.plexus.interpolation import org.codehaus.plexus.interpolation.StringSearchInterpolator; import org.codehaus.plexus.util.StringUtils; -import java.util.List; -import java.util.Properties; - /** * Input any variables that were not yet configured. * @@ -70,6 +74,12 @@ public class InputVariablesPhase */ @Requirement private ScmRepositoryConfigurator scmRepositoryConfigurator; + + /** + * Component used for custom or default naming policy + */ + @Requirement + private Map<String, NamingPolicy> namingPolicies; void setPrompter( Prompter prompter ) { @@ -148,7 +158,15 @@ public class InputVariablesPhase } else { - defaultTag = project.getArtifactId() + "-" + releaseVersion; + try + { + defaultTag = + resolveSuggestedName( releaseDescriptor.getProjectNamingPolicyId(), releaseVersion, project ); + } + catch ( PolicyException e ) + { + throw new ReleaseExecutionException( e.getMessage(), e ); + } } ScmProvider provider = null; @@ -218,5 +236,20 @@ public class InputVariablesPhase return result; } + + private String resolveSuggestedName( String policyId, String version, MavenProject project ) + throws PolicyException + { + 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(); + } } Added: maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java?rev=1781389&view=auto ============================================================================== --- maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java (added) +++ maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/policies/DefaultNamingPolicy.java Thu Feb 2 13:06:22 2017 @@ -0,0 +1,42 @@ +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 + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "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 + * + * 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. + */ + +import org.apache.maven.shared.release.policy.PolicyException; +import org.apache.maven.shared.release.policy.naming.NamingPolicy; +import org.apache.maven.shared.release.policy.naming.NamingPolicyRequest; +import org.apache.maven.shared.release.policy.naming.NamingPolicyResult; +import org.codehaus.plexus.component.annotations.Component; + +/** + * + * @author Robert Scholte + * @since 3.0.0 + */ +@Component( role = NamingPolicy.class, hint = "default" ) +public class DefaultNamingPolicy implements NamingPolicy +{ + @Override + public NamingPolicyResult getName( NamingPolicyRequest request ) + throws PolicyException + { + return new NamingPolicyResult().setName( request.getArtifactId() + "-" + request.getVersion() ); + } +} Modified: maven/release/trunk/maven-release-manager/src/main/mdo/release-descriptor.mdo URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/mdo/release-descriptor.mdo?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/maven-release-manager/src/main/mdo/release-descriptor.mdo (original) +++ maven/release/trunk/maven-release-manager/src/main/mdo/release-descriptor.mdo Thu Feb 2 13:06:22 2017 @@ -443,6 +443,15 @@ The role-hint for the VersionPolicy implementation used to calculate the project versions. </description> </field> + <field> + <name>projectNamingPolicyId</name> + <version>3.0.0+</version> + <type>String</type> + <defaultValue>default</defaultValue> + <description> + The role-hint for the NamingPolicy implementation used to calculate the project branch and tag names. + </description> + </field> <field> <name>remoteTagging</name> @@ -869,7 +878,7 @@ { return true; } - + if ( thisScm.getConnection() != null ? !thisScm.getConnection().equals( thatScm.getConnection() ) : thatScm.getConnection() != null ) { @@ -888,15 +897,15 @@ { return false; } - + if ( thisScm instanceof org.apache.maven.shared.release.scm.IdentifiedScm && thatScm instanceof org.apache.maven.shared.release.scm.IdentifiedScm ) { - org.apache.maven.shared.release.scm.IdentifiedScm thisIdentifiedScm = (org.apache.maven.shared.release.scm.IdentifiedScm) thisScm; - org.apache.maven.shared.release.scm.IdentifiedScm thatIdentifiedScm = (org.apache.maven.shared.release.scm.IdentifiedScm) thatScm; - if ( thisIdentifiedScm.getId() != null ? !thisIdentifiedScm.getId().equals( thatIdentifiedScm.getId() ) : thatIdentifiedScm.getId() != null ) - { - return false; - } + org.apache.maven.shared.release.scm.IdentifiedScm thisIdentifiedScm = (org.apache.maven.shared.release.scm.IdentifiedScm) thisScm; + org.apache.maven.shared.release.scm.IdentifiedScm thatIdentifiedScm = (org.apache.maven.shared.release.scm.IdentifiedScm) thatScm; + if ( thisIdentifiedScm.getId() != null ? !thisIdentifiedScm.getId().equals( thatIdentifiedScm.getId() ) : thatIdentifiedScm.getId() != null ) + { + return false; + } } } Added: maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java?rev=1781389&view=auto ============================================================================== --- maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java (added) +++ maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/policies/DefaultNamingPolicyTest.java Thu Feb 2 13:06:22 2017 @@ -0,0 +1,44 @@ +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 + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "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 + * + * 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. + */ + +import static org.junit.Assert.assertEquals; + +import org.apache.maven.shared.release.policy.naming.NamingPolicyRequest; +import org.junit.Test; + +public class DefaultNamingPolicyTest +{ + private 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() ); + } + + private NamingPolicyRequest newNamingPolicyRequest( String artifactId, String version ) + { + return new NamingPolicyRequest().setArtifactId( artifactId ).setVersion( version ); + } +} Modified: maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java (original) +++ maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/BranchReleaseMojo.java Thu Feb 2 13:06:22 2017 @@ -199,6 +199,14 @@ public class BranchReleaseMojo private String projectVersionPolicyId; /** + * The role-hint for the NamingPolicy implementation used to calculate the project branch and tag names. + * + * @since 3.0.0 + */ + @Parameter( defaultValue = "default", property = "projectNamingPolicyId" ) + private String projectNamingPolicyId; + + /** * {@inheritDoc} */ public void execute() @@ -222,6 +230,7 @@ public class BranchReleaseMojo config.setDefaultDevelopmentVersion( developmentVersion ); config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeBranch ); config.setProjectVersionPolicyId( projectVersionPolicyId ); + config.setProjectNamingPolicyId( projectNamingPolicyId ); // Create a config containing values from the session properties (ie command line properties with cli). ReleaseDescriptor sysPropertiesConfig Modified: maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java URL: http://svn.apache.org/viewvc/maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java (original) +++ maven/release/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/PrepareReleaseMojo.java Thu Feb 2 13:06:22 2017 @@ -226,6 +226,14 @@ public class PrepareReleaseMojo private String projectVersionPolicyId; /** + * The role-hint for the NamingPolicy implementation used to calculate the project branch and tag names. + * + * @since 3.0.0 + */ + @Parameter( defaultValue = "default", property = "projectNamingPolicyId" ) + private String projectNamingPolicyId; + + /** * {@inheritDoc} */ public void execute() @@ -265,6 +273,7 @@ public class PrepareReleaseMojo config.setSuppressCommitBeforeTagOrBranch( suppressCommitBeforeTag ); config.setWaitBeforeTagging( waitBeforeTagging ); config.setProjectVersionPolicyId( projectVersionPolicyId ); + config.setProjectNamingPolicyId( projectNamingPolicyId ); if ( checkModificationExcludeList != null ) { Modified: maven/release/trunk/pom.xml URL: http://svn.apache.org/viewvc/maven/release/trunk/pom.xml?rev=1781389&r1=1781388&r2=1781389&view=diff ============================================================================== --- maven/release/trunk/pom.xml (original) +++ maven/release/trunk/pom.xml Thu Feb 2 13:06:22 2017 @@ -79,6 +79,9 @@ <contributor> <name>Georges-Etienne Legendre</name> </contributor> + <contributor> + <name>Henning Schmiedehausen</name> + </contributor> </contributors> <properties>