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