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