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   *
34   */
35  @RunWith(JUnit4.class)
36  public class ExportMojoTest extends AbstractJUnit4MojoTestCase {
37      File exportDir;
38  
39      File repository;
40  
41      @Before
42      public void setUp() throws Exception {
43          super.setUp();
44  
45          exportDir = getTestFile("target/export");
46  
47          repository = getTestFile("target/repository");
48  
49          FileUtils.forceDelete(exportDir);
50      }
51  
52      @Test
53      public void testExport() throws Exception {
54          checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
55  
56          SvnScmTestUtils.initializeRepository(repository);
57  
58          checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
59  
60          ExportMojo mojo = (ExportMojo) lookupMojo("export", getTestFile("src/test/resources/mojos/export/export.xml"));
61  
62          mojo.setExportDirectory(exportDir.getAbsoluteFile());
63  
64          mojo.execute();
65  
66          assertTrue(exportDir.listFiles().length > 0);
67          assertFalse(new File(exportDir, ".svn").exists());
68      }
69  
70      @Test
71      public void testSkipExportIfExists() throws Exception {
72          exportDir.mkdirs();
73  
74          ExportMojo mojo = (ExportMojo) lookupMojo(
75                  "export", getTestFile("src/test/resources/mojos/export/exportWhenExportDirectoryExistsAndSkip.xml"));
76  
77          mojo.setExportDirectory(exportDir);
78  
79          mojo.execute();
80  
81          assertEquals(0, exportDir.listFiles().length);
82      }
83  
84      @Test
85      public void testExcludeInclude() throws Exception {
86          checkScmPresence(SvnScmTestUtils.SVNADMIN_COMMAND_LINE);
87  
88          SvnScmTestUtils.initializeRepository(repository);
89  
90          exportDir.mkdirs();
91  
92          checkScmPresence(SvnScmTestUtils.SVN_COMMAND_LINE);
93  
94          ExportMojo mojo = (ExportMojo)
95                  lookupMojo("export", getTestFile("src/test/resources/mojos/export/exportWithExcludesIncludes.xml"));
96  
97          mojo.setExportDirectory(exportDir);
98  
99          mojo.execute();
100 
101         assertTrue(exportDir.listFiles().length > 0);
102         assertTrue(new File(exportDir, "pom.xml").exists());
103         assertFalse(new File(exportDir, "readme.txt").exists());
104         assertFalse(new File(exportDir, "src/test").exists());
105     }
106 }