You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/11/01 17:13:38 UTC
svn commit: r831693 - in /maven/plugins/trunk/maven-shade-plugin/src:
it/reloc-class-from-string-pool/ it/reloc-class-from-string-pool/src/
it/reloc-class-from-string-pool/src/main/
it/reloc-class-from-string-pool/src/main/java/ it/reloc-class-from-str...
Author: bentmann
Date: Sun Nov 1 16:13:38 2009
New Revision: 831693
URL: http://svn.apache.org/viewvc?rev=831693&view=rev
Log:
[MSHADE-47] Shade misses class references stored as strings during relocation
o Fixed handling of non-array class references
o Added IT
Added:
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java (with props)
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/
maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java (with props)
Modified:
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml?rev=831693&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml Sun Nov 1 16:13:38 2009
@@ -0,0 +1,104 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.shade.rcfsp</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <name>MSHADE-47</name>
+ <description>
+ Test that classes in strings like "[Lnet/sf/cglib/proxy/Callback" get properly relocated.
+ </description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.1</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>shade</id>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <relocations>
+ <relocation>
+ <pattern>relocated</pattern>
+ <shadedPattern>hidden</shadedPattern>
+ </relocation>
+ </relocations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1.1</version>
+ <executions>
+ <execution>
+ <id>run</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <executable>java</executable>
+ <arguments>
+ <argument>-classpath</argument>
+ <argument>${project.build.directory}/test-1.0.jar</argument>
+ <argument>Main</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3.1</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java?rev=831693&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java Sun Nov 1 16:13:38 2009
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+public class Main
+{
+
+ public static void main( String[] args )
+ throws Exception
+ {
+ testClassWithSlashes();
+ testClassWithDots();
+ testArrayClassWithDots();
+ testArrayClassWithDots();
+ }
+
+ private static void testClassWithSlashes()
+ throws Exception
+ {
+ String typeName = "Lrelocated/RelocatedClass;";
+ typeName = typeName.substring( 1, typeName.length() - 1 );
+ typeName = typeName.replace( '/', '.' );
+ Class type = Class.forName( typeName );
+ System.out.println( type.getName() );
+ }
+
+ private static void testClassWithDots()
+ throws Exception
+ {
+ String typeName = "Lrelocated.RelocatedClass;";
+ typeName = typeName.substring( 1, typeName.length() - 1 );
+ typeName = typeName.replace( '/', '.' );
+ Class type = Class.forName( typeName );
+ System.out.println( type.getName() );
+ }
+
+ private static void testArrayClassWithSlashes()
+ throws Exception
+ {
+ String typeName = "[[[Lrelocated/RelocatedClass;";
+ typeName = typeName.substring( 4, typeName.length() - 1 );
+ typeName = typeName.replace( '/', '.' );
+ Class type = Class.forName( typeName );
+ System.out.println( type.getName() );
+ }
+
+ private static void testArrayClassWithDots()
+ throws Exception
+ {
+ String typeName = "[[[[Lrelocated.RelocatedClass;";
+ typeName = typeName.substring( 5, typeName.length() - 1 );
+ typeName = typeName.replace( '/', '.' );
+ Class type = Class.forName( typeName );
+ System.out.println( type.getName() );
+ }
+
+}
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/Main.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java?rev=831693&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java Sun Nov 1 16:13:38 2009
@@ -0,0 +1,24 @@
+package relocated;
+
+/*
+ * 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.
+ */
+
+public class RelocatedClass
+{
+}
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/reloc-class-from-string-pool/src/main/java/relocated/RelocatedClass.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java?rev=831693&r1=831692&r2=831693&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java (original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java Sun Nov 1 16:13:38 2009
@@ -32,6 +32,8 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.zip.ZipException;
import org.apache.maven.plugins.shade.relocation.Relocator;
@@ -280,6 +282,9 @@
class RelocatorRemapper
extends Remapper
{
+
+ private final Pattern classPattern = Pattern.compile( "(\\[*)?L(.+);" );
+
List relocators;
public RelocatorRemapper( List relocators )
@@ -302,59 +307,30 @@
{
Relocator r = (Relocator) i.next();
+ String prefix = "";
+ String suffix = "";
+
+ Matcher m = classPattern.matcher( name );
+ if ( m.matches() )
+ {
+ prefix = m.group( 1 ) + "L";
+ suffix = ";";
+ name = m.group( 2 );
+ }
+
if ( r.canRelocateClass( name ) )
{
- value = r.relocateClass( name );
+ value = prefix + r.relocateClass( name ) + suffix;
break;
- }
+ }
else if ( r.canRelocatePath( name ) )
{
- value = r.relocatePath( name );
+ value = prefix + r.relocatePath( name ) + suffix;
break;
}
-
- if ( name.length() > 0 && name.charAt( 0 ) == '[' )
- {
- int count = 0;
- while ( name.length() > 0 && name.charAt(0) == '[' )
- {
- name = name.substring( 1 );
- ++count;
- }
-
- if ( name.length() > 0
- && name.charAt( 0 ) == 'L'
- && name.charAt( name.length() - 1 ) == ';' )
- {
- name = name.substring( 1, name.length() - 1 );
-
- if ( r.canRelocatePath( name ) )
- {
- value = 'L' + r.relocatePath( name ) + ';';
- while ( count > 0 )
- {
- value = '[' + value;
- --count;
- }
- break;
- }
-
- if ( r.canRelocateClass( name ) )
- {
- value = 'L' + r.relocateClass( name ) + ';';
- while (count > 0)
- {
- value = '[' + value;
- --count;
- }
- break;
- }
-
- }
- }
}
return value;
- }
+ }
return super.mapValue( object );
}