1 package org.apache.maven.plugins.shade;
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.ArrayList;
24 import java.util.Arrays;
25 import java.util.LinkedHashSet;
26 import java.util.List;
27 import java.util.Set;
28 import java.net.URLClassLoader;
29 import java.net.URL;
30
31 import junit.framework.TestCase;
32
33 import org.apache.maven.plugins.shade.relocation.SimpleRelocator;
34 import org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer;
35
36
37
38
39
40 public class DefaultShaderTest
41 extends TestCase
42 {
43 private static final String[] EXCLUDES = new String[] {
44 "org/codehaus/plexus/util/xml/Xpp3Dom",
45 "org/codehaus/plexus/util/xml/pull.*" };
46
47 public void testShaderWithDefaultShadedPattern()
48 throws Exception
49 {
50 shaderWithPattern( null, new File( "target/foo-default.jar" ), EXCLUDES );
51 }
52
53 public void testShaderWithStaticInitializedClass()
54 throws Exception
55 {
56 Shader s = new DefaultShader();
57
58 Set set = new LinkedHashSet();
59
60 set.add( new File( "src/test/jars/test-artifact-1.0-SNAPSHOT.jar" ) );
61
62 List relocators = new ArrayList();
63
64 relocators.add( new SimpleRelocator( "org.apache.maven.plugins.shade", null, null ) );
65
66 List resourceTransformers = new ArrayList();
67
68 List filters = new ArrayList();
69
70 File file = new File( "target/testShaderWithStaticInitializedClass.jar" );
71 s.shade( set, file, filters, relocators, resourceTransformers );
72
73 URLClassLoader cl = new URLClassLoader( new URL[]{file.toURL()} );
74 Class c = cl.loadClass( "hidden.org.apache.maven.plugins.shade.Lib" );
75 Object o = c.newInstance();
76 assertEquals( "foo.bar/baz", c.getDeclaredField( "CONSTANT" ).get( o ) );
77 }
78
79 public void testShaderWithCustomShadedPattern()
80 throws Exception
81 {
82 shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom.jar" ), EXCLUDES );
83 }
84
85 public void testShaderWithoutExcludesShouldRemoveReferencesOfOriginalPattern()
86 throws Exception
87 {
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116