Author: evenisse Date: Tue Apr 10 08:14:31 2007 New Revision: 527154 URL: http://svn.apache.org/viewvc?view=rev&rev=527154 Log: Add branch mojo
Added: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java (with props) maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java (with props) maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/ maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml (with props) maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml (with props) Modified: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/TagMojo.java Added: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java?view=auto&rev=527154 ============================================================================== --- maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java (added) +++ maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java Tue Apr 10 08:14:31 2007 @@ -0,0 +1,79 @@ +package org.apache.maven.scm.plugin; + +/* + * 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.plugin.MojoExecutionException; +import org.apache.maven.scm.ScmException; +import org.apache.maven.scm.command.branch.BranchScmResult; +import org.apache.maven.scm.provider.ScmProvider; +import org.apache.maven.scm.repository.ScmRepository; + +import java.io.IOException; + +/** + * Branch the project. + * + * @author <a href="[EMAIL PROTECTED]">Emmanuel Venisse</a> + * @version $Id$ + * @goal branch + * @description Branch the project + */ +public class BranchMojo + extends AbstractScmMojo +{ + /** + * Tag name. + * + * @parameter expression="${branch}" + */ + private String branch; + + /** + * The message applied to the tag creation. + * + * @parameter expression="${message}" + */ + private String message; + + public void execute() + throws MojoExecutionException + { + try + { + ScmRepository repository = getScmRepository(); + ScmProvider provider = getScmManager().getProviderByRepository( repository ); + + String finalBranch = provider.sanitizeTagName( branch ); + getLog().info( "Final Branch Name: '" + finalBranch + "'" ); + + BranchScmResult result = provider.branch( repository, getFileSet(), finalBranch, message ); + + checkResult( result ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Cannot run branch command : ", e ); + } + catch ( ScmException e ) + { + throw new MojoExecutionException( "Cannot run branch command : ", e ); + } + } +} Propchange: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/BranchMojo.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/TagMojo.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/TagMojo.java?view=diff&rev=527154&r1=527153&r2=527154 ============================================================================== --- maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/TagMojo.java (original) +++ maven/scm/trunk/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/TagMojo.java Tue Apr 10 08:14:31 2007 @@ -108,7 +108,7 @@ ScmProvider provider = getScmManager().getProviderByRepository( repository ); finalTag = provider.sanitizeTagName( finalTag ); - getLog().info( "Final Tag Name'" + finalTag + "'" ); + getLog().info( "Final Tag Name: '" + finalTag + "'" ); TagScmResult result = provider.tag( repository, getFileSet(), finalTag, message ); Added: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java?view=auto&rev=527154 ============================================================================== --- maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java (added) +++ maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java Tue Apr 10 08:14:31 2007 @@ -0,0 +1,103 @@ +package org.apache.maven.scm.plugin; + +/* + * 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.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.scm.provider.svn.SvnScmTestUtils; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; + +/** + * @author <a href="mailto:[EMAIL PROTECTED]">Emmanuel Venisse</a> + * @version $Id$ + */ +public class BranchMojoTest + extends AbstractMojoTestCase +{ + File checkoutDir; + + File repository; + + protected void setUp() + throws Exception + { + super.setUp(); + + checkoutDir = getTestFile( "target/checkout" ); + + FileUtils.forceDelete( checkoutDir ); + + repository = getTestFile( "target/repository" ); + + FileUtils.forceDelete( repository ); + + SvnScmTestUtils.initializeRepository( repository ); + + CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile( + "src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) ); + checkoutMojo.setWorkingDirectory( new File( getBasedir() ) ); + + String connectionUrl = checkoutMojo.getConnectionUrl(); + connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); + connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); + checkoutMojo.setConnectionUrl( connectionUrl ); + + checkoutMojo.setCheckoutDirectory( checkoutDir ); + + checkoutMojo.execute(); + } + + public void testBranch() + throws Exception + { + BranchMojo mojo = + (BranchMojo) lookupMojo( "branch", getTestFile( "src/test/resources/mojos/branch/branch.xml" ) ); + mojo.setWorkingDirectory( checkoutDir ); + + String connectionUrl = mojo.getConnectionUrl(); + connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); + connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); + mojo.setConnectionUrl( connectionUrl ); + + mojo.execute(); + + CheckoutMojo checkoutMojo = + (CheckoutMojo) lookupMojo( "checkout", getTestFile( "src/test/resources/mojos/branch/checkout.xml" ) ); + checkoutMojo.setWorkingDirectory( new File( getBasedir() ) ); + + connectionUrl = checkoutMojo.getConnectionUrl(); + connectionUrl = StringUtils.replace( connectionUrl, "${basedir}", getBasedir() ); + connectionUrl = StringUtils.replace( connectionUrl, "\\", "/" ); + checkoutMojo.setConnectionUrl( connectionUrl ); + + File branchCheckoutDir = getTestFile( "target/branches/mybranch" ); + if ( branchCheckoutDir.exists() ) + { + FileUtils.deleteDirectory( branchCheckoutDir ); + } + checkoutMojo.setCheckoutDirectory( branchCheckoutDir ); + + assertFalse( new File( branchCheckoutDir, "pom.xml" ).exists() ); + checkoutMojo.execute(); + assertTrue( new File( branchCheckoutDir, "pom.xml" ).exists() ); + } +} Propchange: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/BranchMojoTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml?view=auto&rev=527154 ============================================================================== --- maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml (added) +++ maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml Tue Apr 10 08:14:31 2007 @@ -0,0 +1,34 @@ +<!-- + ~ 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. + --> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-scm-plugin</artifactId> + <configuration> + <settings implementation="org.apache.maven.settings.Settings"/> + <connectionUrl>scm:svn:file:///${basedir}/target/repository/trunk</connectionUrl> + <connectionType>connection</connectionType> + <branch>mybranch</branch> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/branch.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Added: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml?view=auto&rev=527154 ============================================================================== --- maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml (added) +++ maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml Tue Apr 10 08:14:31 2007 @@ -0,0 +1,36 @@ +<!-- + ~ 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. + --> + +<project> + <build> + <plugins> + <plugin> + <artifactId>maven-scm-plugin</artifactId> + <configuration> + <settings implementation="org.apache.maven.settings.Settings"/> + <checkoutDirectory>target/branches/mybranch</checkoutDirectory> + <connectionType>connection</connectionType> + <connectionUrl>scm:svn:file:///${basedir}/target/repository/trunk</connectionUrl> + <scmVersionType>branch</scmVersionType> + <scmVersion>mybranch</scmVersion> + </configuration> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/scm/trunk/maven-scm-plugin/src/test/resources/mojos/branch/checkout.xml ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision"