Author: rfscholte Date: Fri Jan 20 16:36:04 2017 New Revision: 1779644 URL: http://svn.apache.org/viewvc?rev=1779644&view=rev Log: [MSHADE-240] support relocation pom.properties and pom.xml descriptors in shaded jars
Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/pom.xml maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/verify.groovy Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/pom.xml?rev=1779644&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/pom.xml (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/pom.xml Fri Jan 20 16:36:04 2017 @@ -0,0 +1,67 @@ +<?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.plugins.shade.its</groupId> + <artifactId>mshade240</artifactId> + <version>1.0-SNAPSHOT</version> + + <url>https://issues.apache.org/jira/browse/MSHADE-240</url> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>3.0</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <shadedArtifactAttached>false</shadedArtifactAttached> + <relocations> + <relocation> + <pattern>META-INF/maven</pattern> + <shadedPattern>META-INF/shade/maven</shadedPattern> + <excludes> + <exclude>META-INF/maven/${project.groupId}/${project.artifactId}/pom.*</exclude> + </excludes> + </relocation> + </relocations> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/verify.groovy URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/verify.groovy?rev=1779644&view=auto ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/verify.groovy (added) +++ maven/plugins/trunk/maven-shade-plugin/src/it/MSHADE-240_reloc-mavenfiles/verify.groovy Fri Jan 20 16:36:04 2017 @@ -0,0 +1,36 @@ +/* + * 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. + */ + +def jarFile = new java.util.jar.JarFile( new File( basedir, "target/mshade240-1.0-SNAPSHOT.jar" ) ) +try +{ + assert null != jarFile.getJarEntry( "META-INF/maven/org.apache.maven.plugins.shade.its/mshade240/pom.properties" ) + assert null != jarFile.getJarEntry( "META-INF/maven/org.apache.maven.plugins.shade.its/mshade240/pom.xml" ) + assert null != jarFile.getJarEntry( "META-INF/shade/maven/org.apache.maven/maven-core/pom.properties" ) + assert null != jarFile.getJarEntry( "META-INF/shade/maven/org.apache.maven/maven-core/pom.xml" ) + + assert null == jarFile.getJarEntry( "META-INF/shade/maven/org.apache.maven.plugins.shade.its/mshade240/pom.properties" ) + assert null == jarFile.getJarEntry( "META-INF/shade/maven/org.apache.maven.plugins.shade.its/mshade240/pom.xml" ) + assert null == jarFile.getJarEntry( "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) + assert null == jarFile.getJarEntry( "META-INF/maven/org.apache.maven/maven-core/pom.xml" ) +} +finally +{ + jarFile.close() +} Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java?rev=1779644&r1=1779643&r2=1779644&view=diff ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java (original) +++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java Fri Jan 20 16:36:04 2017 @@ -94,6 +94,17 @@ public class SimpleRelocator this.includes = normalizePatterns( includes ); this.excludes = normalizePatterns( excludes ); + + // Don't replace all dots to slashes, otherwise /META-INF/maven/${groupId} can't be matched. + if ( includes != null && !includes.isEmpty() ) + { + this.includes.addAll( includes ); + } + + if ( excludes != null && !excludes.isEmpty() ) + { + this.excludes.addAll( excludes ); + } } private static Set<String> normalizePatterns( Collection<String> patterns ) Modified: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java?rev=1779644&r1=1779643&r2=1779644&view=diff ============================================================================== --- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java (original) +++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorTest.java Fri Jan 20 16:36:04 2017 @@ -23,6 +23,7 @@ package org.apache.maven.plugins.shade.r import junit.framework.TestCase; import java.util.Arrays; +import java.util.Collections; /** * Test for {@link SimpleRelocator}. @@ -141,4 +142,18 @@ public class SimpleRelocatorTest relocator = new SimpleRelocator( "^META-INF/org.foo.xml$", "META-INF/hidden.org.foo.xml", null, null, true ); assertEquals( "META-INF/hidden.org.foo.xml", relocator.relocatePath( "META-INF/org.foo.xml" ) ); } + + public void testRelocateMavenFiles() + { + SimpleRelocator relocator = + new SimpleRelocator( "META-INF/maven", "META-INF/shade/maven", null, + Collections.singletonList( "META-INF/maven/com.foo.bar/artifactId/pom.*" ) ); + assertEquals( false, relocator.canRelocatePath( "META-INF/maven/com.foo.bar/artifactId/pom.properties" ) ); + assertEquals( false, relocator.canRelocatePath( "META-INF/maven/com.foo.bar/artifactId/pom.xml" ) ); + assertEquals( true, relocator.canRelocatePath( "META-INF/maven/com/foo/bar/artifactId/pom.properties" ) ); + assertEquals( true, relocator.canRelocatePath( "META-INF/maven/com/foo/bar/artifactId/pom.xml" ) ); + assertEquals( true, relocator.canRelocatePath( "META-INF/maven/com-foo-bar/artifactId/pom.properties" ) ); + assertEquals( true, relocator.canRelocatePath( "META-INF/maven/com-foo-bar/artifactId/pom.xml" ) ); + + } }