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.plugins.source;
20  
21  import java.io.File;
22  
23  /**
24   * @author <a href="mailto:oching@exist.com">Maria Odea Ching</a>
25   */
26  public class SourceJarMojoTest extends AbstractSourcePluginTestCase {
27      protected String getGoal() {
28          return "jar";
29      }
30  
31      private String[] addMavenDescriptor(String project, String[] listOfElements) {
32          final String METAINF = "META-INF/";
33          final String MAVENSOURCE = "maven/source/maven-source-plugin-test-";
34          String[] result = new String[listOfElements.length + 5];
35          System.arraycopy(listOfElements, 0, result, 0, listOfElements.length);
36          result[listOfElements.length] = METAINF + "maven/";
37          result[listOfElements.length + 1] = METAINF + "maven/source/";
38          result[listOfElements.length + 2] = METAINF + MAVENSOURCE + project + "/";
39          result[listOfElements.length + 3] = METAINF + MAVENSOURCE + project + "/pom.properties";
40          result[listOfElements.length + 4] = METAINF + MAVENSOURCE + project + "/pom.xml";
41          return result;
42      }
43  
44      public void testDefaultConfiguration() throws Exception {
45          doTestProjectWithSourceArchive(
46                  "project-001",
47                  addMavenDescriptor("project-001", new String[] {
48                      "default-configuration.properties",
49                      "foo/project001/App.java",
50                      "foo/project001/",
51                      "foo/",
52                      "META-INF/MANIFEST.MF",
53                      "META-INF/"
54                  }),
55                  "sources");
56      }
57  
58      public void testExcludes() throws Exception {
59          doTestProjectWithSourceArchive(
60                  "project-003",
61                  addMavenDescriptor("project-003", new String[] {
62                      "default-configuration.properties",
63                      "foo/project003/App.java",
64                      "foo/project003/",
65                      "foo/",
66                      "META-INF/MANIFEST.MF",
67                      "META-INF/"
68                  }),
69                  "sources");
70      }
71  
72      public void testNoSources() throws Exception {
73          executeMojo("project-005", "sources");
74          // Now make sure that no archive got created
75          final File expectedFile = getTestTargetDir("project-005");
76          assertFalse(
77                  "Source archive should not have been created[" + expectedFile.getAbsolutePath() + "]",
78                  expectedFile.exists());
79      }
80  
81      public void testIncludes() throws Exception {
82          doTestProjectWithSourceArchive(
83                  "project-007",
84                  addMavenDescriptor("project-007", new String[] {
85                      "templates/configuration-template.properties",
86                      "foo/project007/App.java",
87                      "templates/",
88                      "foo/project007/",
89                      "foo/",
90                      "META-INF/MANIFEST.MF",
91                      "META-INF/"
92                  }),
93                  "sources");
94      }
95  
96      public void testIncludePom() throws Exception {
97          doTestProjectWithSourceArchive(
98                  "project-009",
99                  addMavenDescriptor("project-009", new String[] {
100                     "default-configuration.properties",
101                     "pom.xml",
102                     "foo/project009/App.java",
103                     "foo/project009/",
104                     "foo/",
105                     "META-INF/MANIFEST.MF",
106                     "META-INF/"
107                 }),
108                 "sources");
109     }
110 
111     public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exception {
112         doTestProjectWithSourceArchive(
113                 "project-010",
114                 addMavenDescriptor("project-010", new String[] {
115                     "default-configuration.properties",
116                     "foo/project010/App.java",
117                     "foo/project010/",
118                     "foo/",
119                     "META-INF/MANIFEST.MF",
120                     "META-INF/"
121                 }),
122                 "sources");
123     }
124 }