Author: bentmann
Date: Tue Apr 27 11:09:54 2010
New Revision: 938410

URL: http://svn.apache.org/viewvc?rev=938410&view=rev
Log:
[MNG-4648] NullPointerException thrown from 
DefaultPluginRealmCache#pluginHashCode method if project-level plugin 
dependency misses version

Added:
    
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml
   (with props)
    
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml
   (with props)
    
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml
   (with props)
    
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml
   (with props)
Modified:
    
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
    
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java

Modified: 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java?rev=938410&r1=938409&r2=938410&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
 Tue Apr 27 11:09:54 2010
@@ -253,12 +253,7 @@ public class DefaultModelValidator
                     validateBoolean( "build.plugins.plugin.extensions", 
problems, errOn30, p.getExtensions(),
                                      p.getKey() );
 
-                    for ( Dependency d : p.getDependencies() )
-                    {
-                        validateEnum( "build.plugins.plugin[" + p.getKey() + 
"].dependencies.dependency.scope",
-                                      problems, errOn30, d.getScope(), 
d.getManagementKey(),
-                                      "compile", "runtime", "system" );
-                    }
+                    validateEffectivePluginDependencies( problems, p, request 
);
                 }
 
                 validateResources( problems, build.getResources(), 
"build.resources.resource", request );
@@ -365,67 +360,21 @@ public class DefaultModelValidator
     }
 
     private void validateEffectiveDependencies( ModelProblemCollector 
problems, List<Dependency> dependencies,
-                                                boolean managed, 
ModelBuildingRequest request )
+                                                boolean management, 
ModelBuildingRequest request )
     {
         Severity errOn30 = getSeverity( request, 
ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
 
-        String prefix = managed ? 
"dependencyManagement.dependencies.dependency." : "dependencies.dependency.";
+        String prefix = management ? 
"dependencyManagement.dependencies.dependency." : "dependencies.dependency.";
 
         for ( Dependency d : dependencies )
         {
-            validateId( prefix + "artifactId", problems, d.getArtifactId(), 
d.getManagementKey() );
-
-            validateId( prefix + "groupId", problems, d.getGroupId(), 
d.getManagementKey() );
-
-            if ( !managed )
-            {
-                validateStringNotEmpty( prefix + "type", problems, 
Severity.ERROR, d.getType(), d.getManagementKey() );
-
-                validateStringNotEmpty( prefix + "version", problems, 
Severity.ERROR, d.getVersion(),
-                                        d.getManagementKey() );
-            }
-
-            if ( "system".equals( d.getScope() ) )
-            {
-                String systemPath = d.getSystemPath();
-
-                if ( StringUtils.isEmpty( systemPath ) )
-                {
-                    addViolation( problems, Severity.ERROR, prefix + 
"systemPath", d.getManagementKey(), "is missing." );
-                }
-                else
-                {
-                    File sysFile = new File( systemPath );
-                    if ( !sysFile.isAbsolute() )
-                    {
-                        addViolation( problems, Severity.ERROR, prefix + 
"systemPath", d.getManagementKey(),
-                                      "must specify an absolute path but is " 
+ systemPath );
-                    }
-                    else if ( !sysFile.isFile() )
-                    {
-                        String msg = "refers to a non-existing file " + 
sysFile.getAbsolutePath();
-                        systemPath = systemPath.replace( '/', 
File.separatorChar ).replace( '\\', File.separatorChar );
-                        String jdkHome =
-                            request.getSystemProperties().getProperty( 
"java.home", "" ) + File.separator + "..";
-                        if ( systemPath.startsWith( jdkHome ) )
-                        {
-                            msg += ". Please verify that you run Maven using a 
JDK and not just a JRE.";
-                        }
-                        addViolation( problems, Severity.WARNING, prefix + 
"systemPath", d.getManagementKey(), msg );
-                    }
-                }
-            }
-            else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
-            {
-                addViolation( problems, Severity.ERROR, prefix + "systemPath", 
d.getManagementKey(), "must be omitted."
-                    + " This field may only be specified for a dependency with 
system scope." );
-            }
+            validateEffectiveDependency( problems, d, management, prefix, 
request );
 
             if ( request.getValidationLevel() >= 
ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
             {
                 validateBoolean( prefix + "optional", problems, errOn30, 
d.getOptional(), d.getManagementKey() );
 
-                if ( !managed )
+                if ( !management )
                 {
                     validateVersion( prefix + "version", problems, errOn30, 
d.getVersion(), d.getManagementKey() );
 
@@ -440,6 +389,80 @@ public class DefaultModelValidator
         }
     }
 
+    private void validateEffectivePluginDependencies( ModelProblemCollector 
problems, Plugin plugin,
+                                                      ModelBuildingRequest 
request )
+    {
+        List<Dependency> dependencies = plugin.getDependencies();
+
+        if ( !dependencies.isEmpty() )
+        {
+            String prefix = "build.plugins.plugin[" + plugin.getKey() + 
"].dependencies.dependency.";
+
+            Severity errOn30 = getSeverity( request, 
ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0 );
+
+            for ( Dependency d : dependencies )
+            {
+                validateEffectiveDependency( problems, d, false, prefix, 
request );
+
+                validateVersion( prefix + "version", problems, errOn30, 
d.getVersion(), d.getManagementKey() );
+
+                validateEnum( prefix + "scope", problems, errOn30, 
d.getScope(), d.getManagementKey(), "compile",
+                              "runtime", "system" );
+            }
+        }
+    }
+
+    private void validateEffectiveDependency( ModelProblemCollector problems, 
Dependency d, boolean management,
+                                              String prefix, 
ModelBuildingRequest request )
+    {
+        validateId( prefix + "artifactId", problems, d.getArtifactId(), 
d.getManagementKey() );
+
+        validateId( prefix + "groupId", problems, d.getGroupId(), 
d.getManagementKey() );
+
+        if ( !management )
+        {
+            validateStringNotEmpty( prefix + "type", problems, Severity.ERROR, 
d.getType(), d.getManagementKey() );
+
+            validateStringNotEmpty( prefix + "version", problems, 
Severity.ERROR, d.getVersion(), d.getManagementKey() );
+        }
+
+        if ( "system".equals( d.getScope() ) )
+        {
+            String systemPath = d.getSystemPath();
+
+            if ( StringUtils.isEmpty( systemPath ) )
+            {
+                addViolation( problems, Severity.ERROR, prefix + "systemPath", 
d.getManagementKey(), "is missing." );
+            }
+            else
+            {
+                File sysFile = new File( systemPath );
+                if ( !sysFile.isAbsolute() )
+                {
+                    addViolation( problems, Severity.ERROR, prefix + 
"systemPath", d.getManagementKey(),
+                                  "must specify an absolute path but is " + 
systemPath );
+                }
+                else if ( !sysFile.isFile() )
+                {
+                    String msg = "refers to a non-existing file " + 
sysFile.getAbsolutePath();
+                    systemPath = systemPath.replace( '/', File.separatorChar 
).replace( '\\', File.separatorChar );
+                    String jdkHome =
+                        request.getSystemProperties().getProperty( 
"java.home", "" ) + File.separator + "..";
+                    if ( systemPath.startsWith( jdkHome ) )
+                    {
+                        msg += ". Please verify that you run Maven using a JDK 
and not just a JRE.";
+                    }
+                    addViolation( problems, Severity.WARNING, prefix + 
"systemPath", d.getManagementKey(), msg );
+                }
+            }
+        }
+        else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
+        {
+            addViolation( problems, Severity.ERROR, prefix + "systemPath", 
d.getManagementKey(), "must be omitted."
+                + " This field may only be specified for a dependency with 
system scope." );
+        }
+    }
+
     private void validateRepositories( ModelProblemCollector problems, 
List<Repository> repositories, String prefix,
                                        ModelBuildingRequest request )
     {

Modified: 
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java?rev=938410&r1=938409&r2=938410&view=diff
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
 (original)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
 Tue Apr 27 11:09:54 2010
@@ -449,4 +449,44 @@ public class DefaultModelValidatorTest
                                                           
"'distributionManagement.snapshotRepository.id' must not be 'local'" ) );
     }
 
+    public void testMissingPluginDependencyGroupId()
+        throws Exception
+    {
+        SimpleProblemCollector result = validate( 
"missing-plugin-dependency-groupId.xml" );
+
+        assertViolations( result, 0, 1, 0 );
+
+        assertTrue( result.getErrors().get( 0 ).contains( ":a:" ) );
+    }
+
+    public void testMissingPluginDependencyArtifactId()
+        throws Exception
+    {
+        SimpleProblemCollector result = validate( 
"missing-plugin-dependency-artifactId.xml" );
+
+        assertViolations( result, 0, 1, 0 );
+
+        assertTrue( result.getErrors().get( 0 ).contains( "test:" ) );
+    }
+
+    public void testMissingPluginDependencyVersion()
+        throws Exception
+    {
+        SimpleProblemCollector result = validate( 
"missing-plugin-dependency-version.xml" );
+
+        assertViolations( result, 0, 1, 0 );
+
+        assertTrue( result.getErrors().get( 0 ).contains( "test:a" ) );
+    }
+
+    public void testBadPluginDependencyVersion()
+        throws Exception
+    {
+        SimpleProblemCollector result = validate( 
"bad-plugin-dependency-version.xml" );
+
+        assertViolations( result, 0, 1, 0 );
+
+        assertTrue( result.getErrors().get( 0 ).contains( "test:b" ) );
+    }
+
 }

Added: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml?rev=938410&view=auto
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml
 (added)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml
 Tue Apr 27 11:09:54 2010
@@ -0,0 +1,46 @@
+<!--
+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>
+  <artifactId>aid</artifactId>
+  <groupId>gid</groupId>
+  <version>0.1</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-it-plugin</artifactId>
+        <version>1.0</version>
+        <dependencies>
+          <dependency>
+            <groupId>test</groupId>
+            <artifactId>a</artifactId>
+            <version>0.1</version>
+          </dependency>
+          <dependency>
+            <groupId>test</groupId>
+            <artifactId>b</artifactId>
+            <version>${missing.property}</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/bad-plugin-dependency-version.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml?rev=938410&view=auto
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml
 (added)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml
 Tue Apr 27 11:09:54 2010
@@ -0,0 +1,41 @@
+<!--
+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>
+  <artifactId>aid</artifactId>
+  <groupId>gid</groupId>
+  <version>1.0</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-it-plugin</artifactId>
+        <version>1.0</version>
+        <dependencies>
+          <dependency>
+            <groupId>test</groupId>
+            <!-- artifact id missing -->
+            <version>2.0</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-artifactId.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml?rev=938410&view=auto
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml
 (added)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml
 Tue Apr 27 11:09:54 2010
@@ -0,0 +1,41 @@
+<!--
+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>
+  <artifactId>aid</artifactId>
+  <groupId>gid</groupId>
+  <version>1.0</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-it-plugin</artifactId>
+        <version>1.0</version>
+        <dependencies>
+          <dependency>
+            <!-- groupd id missing -->
+            <artifactId>a</artifactId>
+            <version>2.0</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-groupId.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml
URL: 
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml?rev=938410&view=auto
==============================================================================
--- 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml
 (added)
+++ 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml
 Tue Apr 27 11:09:54 2010
@@ -0,0 +1,41 @@
+<!--
+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>
+  <artifactId>aid</artifactId>
+  <groupId>gid</groupId>
+  <version>1.0</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-it-plugin</artifactId>
+        <version>1.0</version>
+        <dependencies>
+          <dependency>
+            <groupId>test</groupId>
+            <artifactId>a</artifactId>
+            <!-- version missing -->
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/maven-3/trunk/maven-model-builder/src/test/resources/poms/validation/missing-plugin-dependency-version.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision


Reply via email to