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