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.plugin.testing.AbstractMojoTestCase;
24  import org.apache.maven.scm.ScmTestCase;
25  import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
26  import org.codehaus.plexus.util.FileUtils;
27  
28  /**
29   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
30   *
31   */
32  public class TagMojoTest extends AbstractMojoTestCase {
33      File checkoutDir;
34  
35      File repository;
36  
37      protected void setUp() throws Exception {
38          super.setUp();
39  
40          checkoutDir = getTestFile("target/checkout");
41  
42          FileUtils.forceDelete(checkoutDir);
43  
44          repository = getTestFile("target/repository");
45  
46          FileUtils.forceDelete(repository);
47  
48          if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVNADMIN_COMMAND_LINE)) {
49              ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVNADMIN_COMMAND_LINE, "setUp");
50              return;
51          }
52  
53          SvnScmTestUtils.initializeRepository(repository);
54  
55          if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
56              ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, "setUp");
57              return;
58          }
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      public void testTag() throws Exception {
79          if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
80              ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
81              return;
82          }
83  
84          TagMojo mojo = (TagMojo) lookupMojo("tag", getTestFile("src/test/resources/mojos/tag/tag.xml"));
85          mojo.setWorkingDirectory(checkoutDir);
86  
87          setupConnectionUrl(mojo);
88  
89          mojo.execute();
90  
91          CheckoutMojo checkoutMojo =
92                  (CheckoutMojo) lookupMojo("checkout", getTestFile("src/test/resources/mojos/tag/checkout.xml"));
93          checkoutMojo.setWorkingDirectory(new File(getBasedir()));
94  
95          setupConnectionUrl(checkoutMojo);
96  
97          File tagCheckoutDir = getTestFile("target/tags/mytag");
98          if (tagCheckoutDir.exists()) {
99              FileUtils.deleteDirectory(tagCheckoutDir);
100         }
101         checkoutMojo.setCheckoutDirectory(tagCheckoutDir);
102 
103         assertFalse(new File(tagCheckoutDir, "pom.xml").exists());
104         checkoutMojo.execute();
105         assertTrue(new File(tagCheckoutDir, "pom.xml").exists());
106     }
107 
108     public void testTagWithTimestamp() throws Exception {
109         if (!ScmTestCase.isSystemCmd(SvnScmTestUtils.SVN_COMMAND_LINE)) {
110             ScmTestCase.printSystemCmdUnavail(SvnScmTestUtils.SVN_COMMAND_LINE, getName());
111             return;
112         }
113 
114         TagMojo mojo = (TagMojo) lookupMojo("tag", getTestFile("src/test/resources/mojos/tag/tagWithTimestamp.xml"));
115         mojo.setWorkingDirectory(checkoutDir);
116 
117         setupConnectionUrl(mojo);
118 
119         mojo.execute();
120     }
121 }