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();
      

        Attachments

          Activity

            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: