1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.source;
20
21 import java.io.File;
22
23
24
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 int length = listOfElements.length;
35 String[] result = new String[length + 5];
36 System.arraycopy(listOfElements, 0, result, 0, length);
37 result[length] = metainf + "maven/";
38 result[length + 1] = metainf + "maven/source/";
39 result[length + 2] = metainf + mavensource + project + "/";
40 result[length + 3] = metainf + mavensource + project + "/pom.properties";
41 result[length + 4] = metainf + mavensource + project + "/pom.xml";
42 return result;
43 }
44
45 public void testDefaultConfiguration() throws Exception {
46 doTestProjectWithSourceArchive(
47 "project-001",
48 addMavenDescriptor("project-001", new String[] {
49 "default-configuration.properties",
50 "foo/project001/App.java",
51 "foo/project001/",
52 "foo/",
53 "META-INF/MANIFEST.MF",
54 "META-INF/"
55 }),
56 "sources");
57 }
58
59 public void testExcludes() throws Exception {
60 doTestProjectWithSourceArchive(
61 "project-003",
62 addMavenDescriptor("project-003", new String[] {
63 "default-configuration.properties",
64 "foo/project003/App.java",
65 "foo/project003/",
66 "foo/",
67 "META-INF/MANIFEST.MF",
68 "META-INF/"
69 }),
70 "sources");
71 }
72
73 public void testNoSources() throws Exception {
74 executeMojo("project-005", "sources");
75
76 final File expectedFile = getTestTargetDir("project-005");
77 assertFalse(
78 "Source archive should not have been created[" + expectedFile.getAbsolutePath() + "]",
79 expectedFile.exists());
80 }
81
82 public void testIncludes() throws Exception {
83 doTestProjectWithSourceArchive(
84 "project-007",
85 addMavenDescriptor("project-007", new String[] {
86 "templates/configuration-template.properties",
87 "foo/project007/App.java",
88 "templates/",
89 "foo/project007/",
90 "foo/",
91 "META-INF/MANIFEST.MF",
92 "META-INF/"
93 }),
94 "sources");
95 }
96
97 public void testIncludePom() throws Exception {
98 doTestProjectWithSourceArchive(
99 "project-009",
100 addMavenDescriptor("project-009", new String[] {
101 "default-configuration.properties",
102 "pom.xml",
103 "foo/project009/App.java",
104 "foo/project009/",
105 "foo/",
106 "META-INF/MANIFEST.MF",
107 "META-INF/"
108 }),
109 "sources");
110 }
111
112 public void testIncludeMavenDescriptorWhenExplicitlyConfigured() throws Exception {
113 doTestProjectWithSourceArchive(
114 "project-010",
115 addMavenDescriptor("project-010", new String[] {
116 "default-configuration.properties",
117 "foo/project010/App.java",
118 "foo/project010/",
119 "foo/",
120 "META-INF/MANIFEST.MF",
121 "META-INF/"
122 }),
123 "sources");
124 }
125 }