You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by fg...@apache.org on 2006/06/27 12:10:53 UTC

svn commit: r417396 - /maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java

Author: fgiust
Date: Tue Jun 27 03:10:51 2006
New Revision: 417396

URL: http://svn.apache.org/viewvc?rev=417396&view=rev
Log:
avoid NPEs for non-existing build/plugins elements in POM

Modified:
    maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java

Modified: maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java?rev=417396&r1=417395&r2=417396&view=diff
==============================================================================
--- maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java (original)
+++ maven/shared/trunk/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/AbstractMojoTestCase.java Tue Jun 27 03:10:51 2006
@@ -194,27 +194,37 @@
     protected PlexusConfiguration extractPluginConfiguration( String artifactId, Xpp3Dom pomDom )
         throws Exception
     {
-        Xpp3Dom[] pluginElements = pomDom.getChild( "build" ).getChild( "plugins" ).getChildren();
-
         Xpp3Dom pluginConfigurationElement = null;
 
-        for ( int i = 0; i < pluginElements.length; i++ )
+        Xpp3Dom buildElement = pomDom.getChild( "build" );
+        if ( buildElement != null )
         {
-            Xpp3Dom pluginElement = pluginElements[i];
-
-            String pluginElementArtifactId = pluginElement.getChild( "artifactId" ).getValue();
+            Xpp3Dom pluginsRootElement = buildElement.getChild( "plugins" );
 
-            if ( pluginElementArtifactId.equals( artifactId ) )
+            if ( pluginsRootElement != null )
             {
-                pluginConfigurationElement = pluginElement.getChild( "configuration" );
+                Xpp3Dom[] pluginElements = pluginsRootElement.getChildren();
+
+                for ( int i = 0; i < pluginElements.length; i++ )
+                {
+                    Xpp3Dom pluginElement = pluginElements[i];
+
+                    String pluginElementArtifactId = pluginElement.getChild( "artifactId" ).getValue();
+
+                    if ( pluginElementArtifactId.equals( artifactId ) )
+                    {
+                        pluginConfigurationElement = pluginElement.getChild( "configuration" );
 
-                break;
+                        break;
+                    }
+                }
             }
         }
 
         if ( pluginConfigurationElement == null )
         {
-            throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of " + artifactId + "." );
+            throw new ConfigurationException( "Cannot find a configuration element for a plugin with an artifactId of "
+                + artifactId + "." );
         }
 
         return new XmlPlexusConfiguration( pluginConfigurationElement );