Author: gboue
Date: Fri Sep 30 20:23:50 2016
New Revision: 1762963
URL: http://svn.apache.org/viewvc?rev=1762963&view=rev
Log:
[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.
Added:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
(with props)
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-one/0.1/
maven/plugins/trunk/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
(with props)
maven/plugins/trunk/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
(with props)
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/repo/org/apache/maven/its/shade/srt/mshade-237-two/0.1/
maven/plugins/trunk/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
(with props)
maven/plugins/trunk/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
(with props)
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
(with props)
Modified:
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
Added:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml?rev=1762963&view=auto
==============================================================================
---
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
(added)
+++
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
Fri Sep 30 20:23:50 2016
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.srt</groupId>
+ <artifactId>mshade-237</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+ <name>MSHADE-237</name>
+ <description>
+ Test the merging of META-INF/services/** entries, when relocation
includes/excludes patterns are specified
+ </description>
+
+ <repositories>
+ <repository>
+ <id>shade-it</id>
+ <url>file:///${basedir}/repo</url>
+ <releases>
+ <checksumPolicy>ignore</checksumPolicy>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.shade.srt</groupId>
+ <artifactId>mshade-237-one</artifactId>
+ <version>0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.its.shade.srt</groupId>
+ <artifactId>mshade-237-two</artifactId>
+ <version>0.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>attach-shade</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <shadedArtifactAttached>false</shadedArtifactAttached>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.maven.its.shade</pattern>
+
<shadedPattern>shaded.org.apache.maven.its.shade</shadedPattern>
+ <excludes>
+ <exclude>org.apache.maven.its.shade.One</exclude>
+ </excludes>
+ </relocation>
+ </relocations>
+ <transformers>
+ <transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"
/>
+ </transformers>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
maven/plugins/trunk/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
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/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?rev=1762963&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
maven/plugins/trunk/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
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
maven/plugins/trunk/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
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/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?rev=1762963&view=auto
==============================================================================
---
maven/plugins/trunk/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
(added)
+++
maven/plugins/trunk/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
Fri Sep 30 20:23:50 2016
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.srt</groupId>
+ <artifactId>mshade-237-one</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+
+ <distributionManagement>
+ <repository>
+ <id>maven-core-it</id>
+ <url>file:///${basedir}/repo</url>
+ </repository>
+ </distributionManagement>
+</project>
Propchange:
maven/plugins/trunk/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
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/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
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
maven/plugins/trunk/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
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/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?rev=1762963&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
maven/plugins/trunk/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
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added:
maven/plugins/trunk/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
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/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?rev=1762963&view=auto
==============================================================================
---
maven/plugins/trunk/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
(added)
+++
maven/plugins/trunk/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
Fri Sep 30 20:23:50 2016
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.srt</groupId>
+ <artifactId>mshade-237-two</artifactId>
+ <version>0.1</version>
+ <packaging>jar</packaging>
+
+ <distributionManagement>
+ <repository>
+ <id>maven-core-it</id>
+ <url>file:///${basedir}/repo</url>
+ </repository>
+ </distributionManagement>
+</project>
Propchange:
maven/plugins/trunk/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
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/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
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh?rev=1762963&view=auto
==============================================================================
---
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
(added)
+++
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
Fri Sep 30 20:23:50 2016
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+import java.util.Arrays;
+import java.util.jar.*;
+import org.codehaus.plexus.util.*;
+
+JarFile jarFile = new JarFile( new File( basedir, "target/mshade-237-1.0.jar"
) );
+JarEntry jarEntry = jarFile.getEntry(
"META-INF/services/org.apache.maven.shade" );
+String service = IOUtil.toString( jarFile.getInputStream( jarEntry ), "UTF-8"
);
+jarFile.close();
+
+String[] services = service.split( "(\r\n)|(\r)|(\n)" );
+String[] expected = { "org.apache.maven.its.shade.One",
"shaded.org.apache.maven.its.shade.Two" };
+
+Arrays.sort(services);
+Arrays.sort(expected);
+if ( !Arrays.equals( services, expected ) )
+{
+ throw new IllegalStateException( "Different services than expected: " +
service );
+}
Propchange:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/plugins/trunk/maven-shade-plugin/src/it/services-resource-transformer-with-reloc-includes-excludes/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java?rev=1762963&r1=1762962&r2=1762963&view=diff
==============================================================================
---
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
(original)
+++
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java
Fri Sep 30 20:23:50 2016
@@ -86,7 +86,10 @@ public class ServicesResourceTransformer
String relContent = line;
for ( Relocator relocator : relocators )
{
- relContent = relocator.applyToSourceContent( relContent );
+ if ( relocator.canRelocateClass( relContent ) )
+ {
+ relContent = relocator.applyToSourceContent( relContent );
+ }
}
fout.append( relContent + "\n" );
}
Modified:
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java?rev=1762963&r1=1762962&r2=1762963&view=diff
==============================================================================
---
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
(original)
+++
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ServiceResourceTransformerTest.java
Fri Sep 30 20:23:50 2016
@@ -27,6 +27,7 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
+import java.util.Arrays;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -46,10 +47,11 @@ public class ServiceResourceTransformerT
@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, Arrays.asList(
"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";
@@ -72,8 +74,9 @@ public class ServiceResourceTransformerT
assertNotNull( jarEntry );
InputStream entryStream = jarFile.getInputStream( jarEntry );
try {
- String xformedContent = IOUtils.toString(entryStream, "utf-8");
- assertEquals("borg.foo.Service" + System.getProperty(
"line.separator" ), xformedContent);
+ String xformedContent = IOUtils.toString( entryStream, "utf-8"
);
+ assertEquals( "borg.foo.Service" + System.getProperty(
"line.separator" )
+ + "org.foo.exclude.OtherService" + System.getProperty(
"line.separator" ), xformedContent );
} finally {
IOUtils.closeQuietly( entryStream );
jarFile.close();