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