Search in sources :

Example 6 with SimpleRelocator

use of org.apache.maven.plugins.shade.relocation.SimpleRelocator in project maven-plugins by apache.

the class DefaultShaderTest method shaderWithPattern.

private void shaderWithPattern(String shadedPattern, File jar, String[] excludes) throws Exception {
    DefaultShader s = newShader();
    Set<File> set = new LinkedHashSet<File>();
    set.add(new File("src/test/jars/test-project-1.0-SNAPSHOT.jar"));
    set.add(new File("src/test/jars/plexus-utils-1.4.1.jar"));
    List<Relocator> relocators = new ArrayList<Relocator>();
    relocators.add(new SimpleRelocator("org/codehaus/plexus/util", shadedPattern, null, Arrays.asList(excludes)));
    List<ResourceTransformer> resourceTransformers = new ArrayList<ResourceTransformer>();
    resourceTransformers.add(new ComponentsXmlResourceTransformer());
    List<Filter> filters = new ArrayList<Filter>();
    ShadeRequest shadeRequest = new ShadeRequest();
    shadeRequest.setJars(set);
    shadeRequest.setUberJar(jar);
    shadeRequest.setFilters(filters);
    shadeRequest.setRelocators(relocators);
    shadeRequest.setResourceTransformers(resourceTransformers);
    s.shade(shadeRequest);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Relocator(org.apache.maven.plugins.shade.relocation.Relocator) SimpleRelocator(org.apache.maven.plugins.shade.relocation.SimpleRelocator) SimpleRelocator(org.apache.maven.plugins.shade.relocation.SimpleRelocator) Filter(org.apache.maven.plugins.shade.filter.Filter) ComponentsXmlResourceTransformer(org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer) ResourceTransformer(org.apache.maven.plugins.shade.resource.ResourceTransformer) ComponentsXmlResourceTransformer(org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer) File(java.io.File)

Example 7 with SimpleRelocator

use of org.apache.maven.plugins.shade.relocation.SimpleRelocator in project maven-plugins by apache.

the class ShadeMojoTest method testShaderWithExclusions.

public void testShaderWithExclusions() throws Exception {
    File jarFile = new File(getBasedir(), "target/unit/foo-bar.jar");
    Shader s = (Shader) lookup(Shader.ROLE, "default");
    Set<File> set = new LinkedHashSet<File>();
    set.add(new File(getBasedir(), "src/test/jars/test-artifact-1.0-SNAPSHOT.jar"));
    List<Relocator> relocators = new ArrayList<Relocator>();
    relocators.add(new SimpleRelocator("org.codehaus.plexus.util", "hidden", null, Arrays.asList("org.codehaus.plexus.util.xml.Xpp3Dom", "org.codehaus.plexus.util.xml.pull.*")));
    List<ResourceTransformer> resourceTransformers = new ArrayList<ResourceTransformer>();
    List<Filter> filters = new ArrayList<Filter>();
    ShadeRequest shadeRequest = new ShadeRequest();
    shadeRequest.setJars(set);
    shadeRequest.setUberJar(jarFile);
    shadeRequest.setFilters(filters);
    shadeRequest.setRelocators(relocators);
    shadeRequest.setResourceTransformers(resourceTransformers);
    s.shade(shadeRequest);
    ClassLoader cl = new URLClassLoader(new URL[] { jarFile.toURI().toURL() });
    Class<?> c = cl.loadClass("org.apache.maven.plugins.shade.Lib");
    Field field = c.getDeclaredField("CLASS_REALM_PACKAGE_IMPORT");
    assertEquals("org.codehaus.plexus.util.xml.pull", field.get(null));
    Method method = c.getDeclaredMethod("getClassRealmPackageImport", new Class[0]);
    assertEquals("org.codehaus.plexus.util.xml.pull", method.invoke(null, new Object[0]));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Shader(org.apache.maven.plugins.shade.Shader) ShadeRequest(org.apache.maven.plugins.shade.ShadeRequest) SimpleRelocator(org.apache.maven.plugins.shade.relocation.SimpleRelocator) Relocator(org.apache.maven.plugins.shade.relocation.Relocator) SimpleRelocator(org.apache.maven.plugins.shade.relocation.SimpleRelocator) Field(java.lang.reflect.Field) Filter(org.apache.maven.plugins.shade.filter.Filter) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ResourceTransformer(org.apache.maven.plugins.shade.resource.ResourceTransformer) ComponentsXmlResourceTransformer(org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer) File(java.io.File)

Aggregations

File (java.io.File)7 Relocator (org.apache.maven.plugins.shade.relocation.Relocator)7 SimpleRelocator (org.apache.maven.plugins.shade.relocation.SimpleRelocator)7 ArrayList (java.util.ArrayList)5 LinkedHashSet (java.util.LinkedHashSet)5 Filter (org.apache.maven.plugins.shade.filter.Filter)5 ComponentsXmlResourceTransformer (org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer)5 ResourceTransformer (org.apache.maven.plugins.shade.resource.ResourceTransformer)5 URLClassLoader (java.net.URLClassLoader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 JarEntry (java.util.jar.JarEntry)2 JarFile (java.util.jar.JarFile)2 JarOutputStream (java.util.jar.JarOutputStream)2 ShadeRequest (org.apache.maven.plugins.shade.ShadeRequest)2 Shader (org.apache.maven.plugins.shade.Shader)2 Test (org.junit.Test)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1