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