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