1 package org.apache.maven.plugin.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.plugin.dependency.AbstractDependencyMojoTestCase;
27 import org.apache.maven.plugin.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 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 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 public void testUnpackIncludesManyFiles()
92 throws Exception
93 {
94 mojo.setIncludes( "**/*1" + UNPACKED_FILE_SUFFIX );
95 mojo.execute();
96 assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
97 assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
98 assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
99 assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
100 }
101
102
103
104
105
106 public void testUnpackIncludesSingleFile()
107 throws Exception
108 {
109 mojo.setIncludes( "**/test2" + UNPACKED_FILE_SUFFIX );
110 mojo.execute();
111 assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
112 assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
113 assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
114 assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
115 }
116
117
118
119
120
121 public void testUnpackIncludesAllFiles()
122 throws Exception
123 {
124 mojo.setIncludes( "**/*" );
125 mojo.execute();
126 assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
127 assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
128 assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
129 assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
130 }
131
132
133
134
135
136 public void testUnpackExcludesManyFiles()
137 throws Exception
138 {
139 mojo.setExcludes( "**/*1" + UNPACKED_FILE_SUFFIX );
140 mojo.execute();
141 assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
142 assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
143 assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
144 assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
145 }
146
147
148
149
150
151 public void testUnpackExcludesSingleFile()
152 throws Exception
153 {
154 mojo.setExcludes( "**/test2" + UNPACKED_FILE_SUFFIX );
155 mojo.execute();
156 assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
157 assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
158 assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
159 assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
160 }
161
162
163
164
165
166 public void testUnpackExcludesAllFiles()
167 throws Exception
168 {
169 mojo.setExcludes( "**/*" );
170 mojo.execute();
171 assertUnpacked( false, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
172 assertUnpacked( false, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
173 assertUnpacked( false, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
174 assertUnpacked( false, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
175 }
176
177 public void testNoIncludeExcludes()
178 throws Exception
179 {
180 mojo.execute();
181 assertUnpacked( true, UNPACKED_FILE_PREFIX + 1 + UNPACKED_FILE_SUFFIX );
182 assertUnpacked( true, UNPACKED_FILE_PREFIX + 11 + UNPACKED_FILE_SUFFIX );
183 assertUnpacked( true, UNPACKED_FILE_PREFIX + 2 + UNPACKED_FILE_SUFFIX );
184 assertUnpacked( true, UNPACKED_FILE_PREFIX + 3 + UNPACKED_FILE_SUFFIX );
185 }
186 }