View Javadoc
1   package org.apache.maven.scm.plugin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
23  import org.apache.maven.scm.ScmTestCase;
24  import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
25  import org.codehaus.plexus.util.FileUtils;
26  import org.junit.Assume;
27  
28  import java.io.File;
29  
30  /**
31   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
32   *
33   */
34  public class TagMojoTest
35      extends AbstractMojoTestCase
36  {
37      File checkoutDir;
38  
39      File repository;
40  
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45  
46          checkoutDir = getTestFile( "target/checkout" );
47  
48          FileUtils.forceDelete( checkoutDir );
49  
50          repository = getTestFile( "target/repository" );
51  
52          FileUtils.forceDelete( repository );
53  
54          Assume.assumeTrue( ScmTestCase.isSystemCmd( SvnScmTestUtils.SVNADMIN_COMMAND_LINE ) );
55  
56          SvnScmTestUtils.initializeRepository( repository );
57  
58          CheckoutMojo checkoutMojo = (CheckoutMojo) lookupMojo( "checkout", getTestFile(
59              "src/test/resources/mojos/checkout/checkoutWithConnectionUrl.xml" ) );
60          checkoutMojo.setWorkingDirectory( new File( getBasedir() ) );
61  
62          setupConnectionUrl( checkoutMojo );
63  
64          checkoutMojo.setCheckoutDirectory( checkoutDir );
65  
66          checkoutMojo.execute();
67      }
68  
69      private static void setupConnectionUrl( AbstractScmMojo mojo )
70      {
71          String connectionUrl = mojo.getConnectionUrl();
72          connectionUrl = connectionUrl.replace( "${basedir}", getBasedir() );
73          connectionUrl = connectionUrl.replace( '\\', '/' );
74          mojo.setConnectionUrl( connectionUrl );
75      }
76  
77      public void testTag()
78          throws Exception
79      {
80  
81          TagMojo mojo = (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tag.xml" ) );
82          mojo.setWorkingDirectory( checkoutDir );
83  
84          setupConnectionUrl( mojo );
85  
86          mojo.execute();
87  
88          CheckoutMojo checkoutMojo =
89              (CheckoutMojo) lookupMojo( "checkout", getTestFile( "src/test/resources/mojos/tag/checkout.xml" ) );
90          checkoutMojo.setWorkingDirectory( new File( getBasedir() ) );
91  
92          setupConnectionUrl( checkoutMojo );
93  
94          File tagCheckoutDir = getTestFile( "target/tags/mytag" );
95          if ( tagCheckoutDir.exists() )
96          {
97              FileUtils.deleteDirectory( tagCheckoutDir );
98          }
99          checkoutMojo.setCheckoutDirectory( tagCheckoutDir );
100 
101         assertFalse( new File( tagCheckoutDir, "pom.xml" ).exists() );
102         checkoutMojo.execute();
103         assertTrue( new File( tagCheckoutDir, "pom.xml" ).exists() );
104     }
105 
106     public void testTagWithTimestamp()
107         throws Exception
108     {
109 
110         TagMojo mojo =
111             (TagMojo) lookupMojo( "tag", getTestFile( "src/test/resources/mojos/tag/tagWithTimestamp.xml" ) );
112         mojo.setWorkingDirectory( checkoutDir );
113 
114         setupConnectionUrl( mojo );
115 
116         mojo.execute();
117     }
118 }