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 import org.codehaus.plexus.logging.Logger;
36 import org.codehaus.plexus.logging.console.ConsoleLogger;
37
38
39
40
41
42 public class DefaultShaderTest
43 extends TestCase
44 {
45 private static final String[] EXCLUDES = new String[] {
46 "org/codehaus/plexus/util/xml/Xpp3Dom",
47 "org/codehaus/plexus/util/xml/pull.*" };
48
49 public void testShaderWithDefaultShadedPattern()
50 throws Exception
51 {
52 shaderWithPattern( null, new File( "target/foo-default.jar" ), EXCLUDES );
53 }
54
55 public void testShaderWithStaticInitializedClass()
56 throws Exception
57 {
58 Shader s = newShader();
59
60 Set set = new LinkedHashSet();
61
62 set.add( new File( "src/test/jars/test-artifact-1.0-SNAPSHOT.jar" ) );
63
64 List relocators = new ArrayList();
65
66 relocators.add( new SimpleRelocator( "org.apache.maven.plugins.shade", null, null, null ) );
67
68 List resourceTransformers = new ArrayList();
69
70 List filters = new ArrayList();
71
72 File file = new File( "target/testShaderWithStaticInitializedClass.jar" );
73 s.shade( set, file, filters, relocators, resourceTransformers );
74
75 URLClassLoader cl = new URLClassLoader( new URL[]{file.toURI().toURL()} );
76 Class c = cl.loadClass( "hidden.org.apache.maven.plugins.shade.Lib" );
77 Object o = c.newInstance();
78 assertEquals( "foo.bar/baz", c.getDeclaredField( "CONSTANT" ).get( o ) );
79 }
80
81 public void testShaderWithCustomShadedPattern()
82 throws Exception
83 {
84 shaderWithPattern( "org/shaded/plexus/util", new File( "target/foo-custom.jar" ), EXCLUDES );
85 }
86
87 public void testShaderWithoutExcludesShouldRemoveReferencesOfOriginalPattern()
88 throws Exception
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
117
118
119
120
121
122
123
124
125
126
127