Uploaded image for project: 'Maven Shade Plugin'
  1. Maven Shade Plugin
  2. MSHADE-237

ServicesResourceTransformer relocates excluded classes

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.3
    • Fix Version/s: 3.0.0
    • Labels:
      None
    • Flags:
      Patch, Important

      Description

      If an exclude pattern is specified on a relocator, the ServicesResourceTransformer ignores them.

      This is demonstrated by the test, and fixed in the following:

      Index: src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
      ===================================================================
      --- src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java	(revision 1762668)
      +++ src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java	(working copy)
      @@ -86,7 +86,10 @@
                   String relContent = line;
                   for ( Relocator relocator : relocators )
                   {
      -                relContent = relocator.applyToSourceContent( relContent );
      +                if ( relocator.canRelocateClass(relContent) )
      +                {
      +                    relContent = relocator.relocateClass(relContent);
      +                }
                   }
                   fout.append( relContent + "\n" );
               }
      Index: src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
      ===================================================================
      --- src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java	(revision 1762668)
      +++ src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java	(working copy)
      @@ -27,6 +27,7 @@
       import java.io.File;
       import java.io.FileOutputStream;
       import java.io.InputStream;
      +import java.util.Collections;
       import java.util.List;
       import java.util.jar.JarEntry;
       import java.util.jar.JarFile;
      @@ -46,10 +47,11 @@
       
           @Test
           public void relocatedClasses() throws Exception {
      -        SimpleRelocator relocator = new SimpleRelocator("org.foo", "borg.foo", null, null);
      +        SimpleRelocator relocator = new SimpleRelocator("org.foo", "borg.foo", null,
      +                Collections.singletonList("org.foo.exclude.**"));
               List<Relocator> relocators = Lists.<Relocator>newArrayList( relocator );
       
      -        String content = "org.foo.Service\n";
      +        String content = "org.foo.Service\norg.foo.exclude.OtherService\n";
               byte[] contentBytes = content.getBytes( "UTF-8" );
               InputStream contentStream = new ByteArrayInputStream( contentBytes );
               String contentResource = "META-INF/services/org.foo.something.another";
      @@ -73,7 +75,8 @@
                   InputStream entryStream = jarFile.getInputStream( jarEntry );
                   try {
                       String xformedContent = IOUtils.toString(entryStream, "utf-8");
      -                assertEquals("borg.foo.Service" + System.getProperty( "line.separator" ), xformedContent);
      +                assertEquals("borg.foo.Service" + System.getProperty( "line.separator" )
      +                        + "org.foo.exclude.OtherService" + System.getProperty( "line.separator" ), xformedContent);
                   } finally {
                       IOUtils.closeQuietly( entryStream );
                       jarFile.close();
      

        Activity

        Hide
        gboue Guillaume Boué added a comment -

        Fixed in r1762963. Thanks for the diff!

        Show
        gboue Guillaume Boué added a comment - Fixed in r1762963 . Thanks for the diff!
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Jenkins build maven-plugins #7322 (See https://builds.apache.org/job/maven-plugins/7322/)
        MSHADE-237 ServicesResourceTransformer relocates excluded classes

        Exclude pattern specified for relocations were ignored by the ServicesResourceTransformer. This could result in fully qualified name of implementation classes, present in a file for a given interface, being relocated, when the actual class was not. (gboue: http://svn.apache.org/viewvc/?view=rev&rev=1762963)

        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1/mshade-237-one-0.1.jar
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1/mshade-237-one-0.1.pom
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1/mshade-237-two-0.1.jar
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1/mshade-237-two-0.1.pom
        • (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
        • (edit) maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
        • (edit) maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Jenkins build maven-plugins #7322 (See https://builds.apache.org/job/maven-plugins/7322/ ) MSHADE-237 ServicesResourceTransformer relocates excluded classes Exclude pattern specified for relocations were ignored by the ServicesResourceTransformer. This could result in fully qualified name of implementation classes, present in a file for a given interface, being relocated, when the actual class was not. (gboue: http://svn.apache.org/viewvc/?view=rev&rev=1762963 ) (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1 (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1/mshade-237-one-0.1.jar (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1/mshade-237-one-0.1.pom (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1 (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1/mshade-237-two-0.1.jar (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1/mshade-237-two-0.1.pom (add) maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh (edit) maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java (edit) maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java

          People

          • Assignee:
            gboue Guillaume Boué
            Reporter:
            mrpotes James Phillpotts
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development