1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency.fromDependencies;
20
21 import java.io.File;
22 import java.util.Set;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
26 import org.apache.maven.project.MavenProject;
27
28 public class TestIncludeExcludeUnpackDependenciesMojo extends AbstractDependencyMojoTestCase {
29 private final String PACKED_FILE = "test.zip";
30
31 private final String UNPACKED_FILE_PREFIX = "test";
32
33 private final String UNPACKED_FILE_SUFFIX = ".txt";
34
35 private final String PACKED_FILE_PATH = "target/test-classes/unit/unpack-dependencies-test/" + PACKED_FILE;
36
37 private UnpackDependenciesMojo mojo;
38
39 protected void setUp() throws Exception {
40
41 super.setUp("unpack-dependencies", true);
42
43 File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-dependencies-test/plugin-config.xml");
44 mojo = (UnpackDependenciesMojo) lookupMojo("unpack-dependencies", testPom);
45 mojo.outputDirectory = new File(this.testDir, "outputDirectory");
46
47
48
49
50
51
52 stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
53
54 assertNotNull(mojo);
55 assertNotNull(mojo.getProject());
56 MavenProject project = mojo.getProject();
57
58 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
59 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
60 artifacts.addAll(directArtifacts);
61
62 project.setArtifacts(artifacts);
63 project.setDependencyArtifacts(directArtifacts);
64 mojo.markersDirectory = new File(this.testDir, "markers");
65 }
66
67 protected void tearDown() {
68 super.tearDown();
69
70 mojo = null;
71 System.gc();
72 }
73
74 private void assertUnpacked(boolean unpacked, String fileName) {
75 File destFile = new File(mojo.getOutputDirectory().getAbsolutePath(), fileName);
76 assertEquals(unpacked, destFile.exists());
77 }
78
79
80
81
82
83
84 public void testUnpackIncludesManyFiles() throws Exception {
85 mojo.setIncludes("**/*1" + UNPACKED_FILE_SUFFIX);
86 mojo.execute();
87 assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
88 assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
89 assertUnpacked(false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
90 assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
91 }
92
93
94
95
96
97
98 public void testUnpackIncludesSingleFile() throws Exception {
99 mojo.setIncludes("**/test2" + UNPACKED_FILE_SUFFIX);
100 mojo.execute();
101 assertUnpacked(false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
102 assertUnpacked(false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
103 assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
104 assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
105 }
106
107
108
109
110
111
112 public void testUnpackIncludesAllFiles() throws Exception {
113 mojo.setIncludes("**/*");
114 mojo.execute();
115 assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
116 assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
117 assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
118 assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
119 }
120
121
122
123
124
125
126 public void testUnpackExcludesManyFiles() throws Exception {
127 mojo.setExcludes("**/*1" + UNPACKED_FILE_SUFFIX);
128 mojo.execute();
129 assertUnpacked(false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
130 assertUnpacked(false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
131 assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
132 assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
133 }
134
135
136
137
138
139
140 public void testUnpackExcludesSingleFile() throws Exception {
141 mojo.setExcludes("**/test2" + UNPACKED_FILE_SUFFIX);
142 mojo.execute();
143 assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
144 assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
145 assertUnpacked(false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
146 assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
147 }
148
149
150
151
152
153
154 public void testUnpackExcludesAllFiles() throws Exception {
155 mojo.setExcludes("**/*");
156 mojo.execute();
157 assertUnpacked(false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
158 assertUnpacked(false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
159 assertUnpacked(false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
160 assertUnpacked(false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
161 }
162
163 public void testNoIncludeExcludes() throws Exception {
164 mojo.execute();
165 assertUnpacked(true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX);
166 assertUnpacked(true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX);
167 assertUnpacked(true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX);
168 assertUnpacked(true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX);
169 }
170 }