You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/03/13 13:37:31 UTC

svn commit: r1300099 - in /maven/plugins/trunk/maven-shade-plugin/src: it/empty-relocation-pattern/ it/empty-relocation-shaded-pattern/ main/java/org/apache/maven/plugins/shade/relocation/ test/java/org/apache/maven/plugins/shade/relocation/

Author: olamy
Date: Tue Mar 13 12:37:31 2012
New Revision: 1300099

URL: http://svn.apache.org/viewvc?rev=1300099&view=rev
Log:
[MSHADE-94] NullPointerException on empty relocation pattern (default package)
Submitted by Robert Burrell Donkin.

Added:
    maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/
    maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/pom.xml   (with props)
    maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/
    maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml   (with props)
    maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java   (with props)
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/empty-relocation-pattern/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/pom.xml?rev=1300099&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/pom.xml Tue Mar 13 12:37:31 2012
@@ -0,0 +1,66 @@
+<?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/xsd/maven-4.0.0.xsd"
+>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.shade.eant</groupId>
+  <artifactId>empty-relocation-pattern</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+  
+  <name>MSHADE-94</name>
+  <description>
+    Test that NullPointerException is not thrown when pattern parameter is unset.
+  </description>
+  
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+  
+            <configuration>
+              <relocations>
+                <relocation>
+                  <pattern />
+                  <shadedPattern>org.example</shadedPattern>
+                </relocation>
+              </relocations>              
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-pattern/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml?rev=1300099&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml Tue Mar 13 12:37:31 2012
@@ -0,0 +1,65 @@
+<?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/xsd/maven-4.0.0.xsd"
+>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.shade.eant</groupId>
+  <artifactId>empty-relocation-shaded-pattern</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+  
+  <name>MSHADE-94</name>
+  <description>
+    Test that NullPointerException is not thrown when shadedPattern parameter is unset.
+  </description>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+  
+            <configuration>
+              <relocations>
+                <relocation>
+                  <pattern>org.example</pattern>
+                  <shadedPattern/>
+                </relocation>
+              </relocations>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-shade-plugin/src/it/empty-relocation-shaded-pattern/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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=1300099&r1=1300098&r2=1300099&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 Tue Mar 13 12:37:31 2012
@@ -19,6 +19,8 @@ package org.apache.maven.plugins.shade.r
  * under the License.
  */
 
+import org.codehaus.plexus.util.SelectorUtils;
+
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
@@ -26,8 +28,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.regex.Pattern;
 
-import org.codehaus.plexus.util.SelectorUtils;
-
 /**
  * @author Jason van Zyl
  * @author Mauro Talevi
@@ -47,18 +47,18 @@ public class SimpleRelocator
     private final Set includes;
 
     private final Set excludes;
-    
+
     private final boolean rawString;
 
     public SimpleRelocator( String patt, String shadedPattern, List includes, List excludes )
     {
         this( patt, shadedPattern, includes, excludes, false );
     }
-    
+
     public SimpleRelocator( String patt, String shadedPattern, List includes, List excludes, boolean rawString )
     {
         this.rawString = rawString;
-        
+
         if ( rawString )
         {
             this.pathPattern = patt;
@@ -69,8 +69,16 @@ public class SimpleRelocator
         }
         else
         {
-            this.pattern = patt.replace( '/', '.' );
-            this.pathPattern = patt.replace( '.', '/' );
+            if ( patt == null )
+            {
+                this.pattern = "";
+                this.pathPattern = "";
+            }
+            else
+            {
+                this.pattern = patt.replace( '/', '.' );
+                this.pathPattern = patt.replace( '.', '/' );
+            }
 
             if ( shadedPattern != null )
             {
@@ -156,7 +164,7 @@ public class SimpleRelocator
         {
             return Pattern.compile( pathPattern ).matcher( path ).find();
         }
-        
+
         if ( path.endsWith( ".class" ) )
         {
             path = path.substring( 0, path.length() - 6 );

Added: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java?rev=1300099&view=auto
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java (added)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java Tue Mar 13 12:37:31 2012
@@ -0,0 +1,49 @@
+package org.apache.maven.plugins.shade.relocation;
+
+/*
+ * 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.util.Collections;
+
+import junit.framework.TestCase;
+
+public class SimpleRelocatorParameterTest extends TestCase {
+
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	public void testThatNullPatternInConstructorShouldNotThrowNullPointerException() {
+		constructThenFailOnNullPointerException(null, "");
+	}
+
+	public void testThatNullShadedPatternInConstructorShouldNotThrowNullPointerException() {
+		constructThenFailOnNullPointerException("", null);
+	}
+	
+	private void constructThenFailOnNullPointerException(
+			String pattern, String shadedPattern) {
+		try {
+			new SimpleRelocator(pattern, shadedPattern, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+		} catch (NullPointerException e) {
+			fail("Constructor should not throw null pointer exceptions");
+		}
+	}
+}

Propchange: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/relocation/SimpleRelocatorParameterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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=1300099&r1=1300098&r2=1300099&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 Tue Mar 13 12:37:31 2012
@@ -1,12 +1,12 @@
 package org.apache.maven.plugins.shade.relocation;
 
-import java.util.Arrays;
-
 import junit.framework.TestCase;
 
+import java.util.Arrays;
+
 /**
  * Test for {@link SimpleRelocator}.
- * 
+ *
  * @author Benjamin Bentmann
  * @version $Id$
  */
@@ -28,9 +28,8 @@ public class SimpleRelocatorTest
         assertEquals( false, relocator.canRelocatePath( "org/Foo/Class" ) );
         assertEquals( false, relocator.canRelocatePath( "org/Foo/Class.class" ) );
 
-        relocator =
-            new SimpleRelocator( "org.foo", null, null, Arrays.asList( new String[] { "org.foo.Excluded", "org.foo.public.*",
-                "org.foo.Public*Stuff" } ) );
+        relocator = new SimpleRelocator( "org.foo", null, null, Arrays.asList(
+            new String[]{ "org.foo.Excluded", "org.foo.public.*", "org.foo.Public*Stuff" } ) );
         assertEquals( true, relocator.canRelocatePath( "org/foo/Class" ) );
         assertEquals( true, relocator.canRelocatePath( "org/foo/Class.class" ) );
         assertEquals( true, relocator.canRelocatePath( "org/foo/excluded" ) );
@@ -58,9 +57,8 @@ public class SimpleRelocatorTest
         assertEquals( false, relocator.canRelocateClass( "com.foo.bar.Class" ) );
         assertEquals( false, relocator.canRelocateClass( "org.Foo.Class" ) );
 
-        relocator =
-            new SimpleRelocator( "org.foo", null, null, Arrays.asList( new String[] { "org.foo.Excluded", "org.foo.public.*",
-                "org.foo.Public*Stuff" } ) );
+        relocator = new SimpleRelocator( "org.foo", null, null, Arrays.asList(
+            new String[]{ "org.foo.Excluded", "org.foo.public.*", "org.foo.Public*Stuff" } ) );
         assertEquals( true, relocator.canRelocateClass( "org.foo.Class" ) );
         assertEquals( true, relocator.canRelocateClass( "org.foo.excluded" ) );
         assertEquals( false, relocator.canRelocateClass( "org.foo.Excluded" ) );
@@ -71,7 +69,7 @@ public class SimpleRelocatorTest
         assertEquals( false, relocator.canRelocateClass( "org.foo.PublicStuff" ) );
         assertEquals( false, relocator.canRelocateClass( "org.foo.PublicUtilStuff" ) );
     }
-    
+
     public void testCanRelocateRawString()
     {
         SimpleRelocator relocator;