コード例 #1
0
  public void shaderWithPattern(String shadedPattern, File jar) throws Exception {
    Shader s = (Shader) lookup(Shader.ROLE);

    Set<File> set = new LinkedHashSet<File>();

    set.add(new File(getBasedir(), "src/test/jars/test-project-1.0-SNAPSHOT.jar"));

    set.add(new File(getBasedir(), "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(
                "org/codehaus/plexus/util/xml/Xpp3Dom", "org/codehaus/plexus/util/xml/pull.*")));

    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);
  }
コード例 #2
0
  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]));
  }