Author: bimargulies
Date: Sat Jul  2 11:29:03 2011
New Revision: 1142204

URL: http://svn.apache.org/viewvc?rev=1142204&view=rev
Log:
[MSHADE-101] ApacheNoticeResourceTransformer NullPointerException for some 
licenses when no parameters set.
Submitted by Robert Robert Burrell Donkin

Added:
    maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/
    
maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/pom.xml
   (with props)
    
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
   (with props)
Modified:
    
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java

Added: 
maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/pom.xml?rev=1142204&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/pom.xml
 Sat Jul  2 11:29:03 2011
@@ -0,0 +1,79 @@
+<?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-apache-notice-transform</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+  
+  <name>MSHADE-101</name>
+  <description>
+    Test that NullPointerException is not thrown when projectName parameter is 
unset.
+  </description>
+  
+
+  <dependencies>
+    <dependency>
+        <groupId>org.apache.velocity</groupId>
+        <artifactId>velocity</artifactId>
+        <version>1.7</version>
+    </dependency>
+  
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <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>
+               <transformers>
+                <transformer 
implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
+                </transformer>
+              </transformers>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

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

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/it/empty-apache-notice-transform/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java?rev=1142204&r1=1142203&r2=1142204&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java
 (original)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java
 Sat Jul  2 11:29:03 2011
@@ -49,7 +49,7 @@ public class ApacheNoticeResourceTransfo
     Set entries = new LinkedHashSet();
     Map organizationEntries = new LinkedHashMap();
 
-    String projectName;
+    String projectName = ""; // MSHADE-101 :: NullPointerException when 
projectName is missing
     boolean addHeader = true;
 
     String preamble1 =

Added: 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java?rev=1142204&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
 (added)
+++ 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
 Sat Jul  2 11:29:03 2011
@@ -0,0 +1,82 @@
+package org.apache.maven.plugins.shade.resource;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+
+/*
+ * 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.
+ */
+
+/**
+ * Tests {@link ApacheLicenseResourceTransformer} parameters.
+ */
+public class ApacheNoticeResourceTransformerParameterTests extends TestCase {
+       
+       private static final String NOTICE_RESOURCE = "META-INF/NOTICE";
+       private ApacheNoticeResourceTransformer subject;
+
+       protected void setUp() throws Exception {
+               super.setUp();
+               subject = new ApacheNoticeResourceTransformer();
+       }
+
+       
+       public void testNoParametersShouldNotThrowNullPointerWhenNoInput() 
throws IOException {
+               processAndFailOnNullPointer("");
+       }
+       
+       public void 
testNoParametersShouldNotThrowNullPointerWhenNoLinesOfInput() throws 
IOException {
+               processAndFailOnNullPointer("Some notice text");
+       }
+
+       public void 
testNoParametersShouldNotThrowNullPointerWhenOneLineOfInput() throws 
IOException {
+               processAndFailOnNullPointer("Some notice text\n");
+       }
+
+       public void 
testNoParametersShouldNotThrowNullPointerWhenTwoLinesOfInput() throws 
IOException {
+               processAndFailOnNullPointer("Some notice text\nSome notice 
text\n");
+       }
+
+       public void 
testNoParametersShouldNotThrowNullPointerWhenLineStartsWithSlashSlash() throws 
IOException {
+               processAndFailOnNullPointer("Some notice text\n//Some notice 
text\n");
+       }
+
+       public void 
testNoParametersShouldNotThrowNullPointerWhenLineIsSlashSlash() throws 
IOException {
+               processAndFailOnNullPointer("//\n");
+       }
+
+       public void testNoParametersShouldNotThrowNullPointerWhenLineIsEmpty() 
throws IOException {
+               processAndFailOnNullPointer("\n");
+       }
+       
+       private void processAndFailOnNullPointer(final String noticeText)
+                       throws IOException {
+               try {
+                       final ByteArrayInputStream noticeInputStream = new 
ByteArrayInputStream(noticeText.getBytes());
+                       final List emptyList = Collections.EMPTY_LIST;
+                       subject.processResource(NOTICE_RESOURCE, 
noticeInputStream, emptyList);
+               } catch (NullPointerException e) {
+                       fail("Null pointer should not be thrown when no 
parameters are set.");
+               }
+       }
+}

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

Propchange: 
maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformerParameterTests.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to