diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
index 40107327f5..23032931d8 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
@@ -69,29 +69,6 @@ public class DefaultArtifact
String type,
String classifier )
{
- // These should help us catch coding errors until this code gets a whole lot clearer
- if( groupId == null )
- {
- throw new NullPointerException( "Artifact groupId cannot be null." );
- }
-
- if( artifactId == null )
- {
- throw new NullPointerException( "Artifact artifactId cannot be null." );
- }
-
- // From here at least we can report the g:a
-
- if ( type == null )
- {
- throw new NullPointerException( "Artifact type cannot be null for " + groupId + ":" + artifactId );
- }
-
- if( version == null )
- {
- throw new NullPointerException( "Artifact version cannot be null for " + groupId + ":" + artifactId );
- }
-
this.groupId = groupId;
this.artifactId = artifactId;
@@ -103,6 +80,36 @@ public class DefaultArtifact
this.scope = scope;
this.classifier = classifier;
+
+ validateIdentity();
+ }
+
+ private void validateIdentity()
+ {
+ if( empty( groupId ) )
+ {
+ throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The groupId cannot be empty." );
+ }
+
+ if( artifactId == null )
+ {
+ throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The artifactId cannot be empty." );
+ }
+
+ if ( type == null )
+ {
+ throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The type cannot be empty." );
+ }
+
+ if( version == null )
+ {
+ throw new InvalidArtifactRTException( groupId, artifactId, version, type, "The version cannot be empty." );
+ }
+ }
+
+ private boolean empty( String value )
+ {
+ return value == null || value.trim().length() < 1;
}
public DefaultArtifact( String groupId, String artifactId, String version, String scope, String type )
diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/InvalidArtifactRTException.java b/maven-artifact/src/main/java/org/apache/maven/artifact/InvalidArtifactRTException.java
new file mode 100644
index 0000000000..86525bc6bc
--- /dev/null
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/InvalidArtifactRTException.java
@@ -0,0 +1,85 @@
+package org.apache.maven.artifact;
+
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 InvalidArtifactRTException
+ extends RuntimeException
+{
+
+ private final String groupId;
+ private final String artifactId;
+ private final String version;
+ private final String type;
+ private final String baseMessage;
+
+ public InvalidArtifactRTException( String groupId, String artifactId, String version, String type, String message )
+ {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ this.type = type;
+ this.baseMessage = message;
+ }
+
+ public InvalidArtifactRTException( String groupId, String artifactId, String version, String type, String message, Throwable cause )
+ {
+ super( cause );
+
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ this.type = type;
+ this.baseMessage = message;
+ }
+
+ public String getMessage()
+ {
+ return "For artifact {" + getArtifactKey() + "}: " + getBaseMessage();
+ }
+
+ public String getBaseMessage()
+ {
+ return baseMessage;
+ }
+
+ public String getArtifactId()
+ {
+ return artifactId;
+ }
+
+ public String getGroupId()
+ {
+ return groupId;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public String getArtifactKey()
+ {
+ return groupId + ":" + artifactId + ":" + version + ":" + type;
+ }
+
+}
diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
index dbf0c1261b..40159217bf 100644
--- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
+++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
@@ -380,7 +380,32 @@ public class DefaultMaven
getLogger().error( "BUILD ERROR" );
line();
+
+ Throwable error = r.getException();
+ String message = null;
+ if ( errorDiagnosers != null )
+ {
+ for ( Iterator it = errorDiagnosers.values().iterator(); it.hasNext(); )
+ {
+ ErrorDiagnoser diagnoser = (ErrorDiagnoser) it.next();
+
+ if ( diagnoser.canDiagnose( error ) )
+ {
+ message = diagnoser.diagnose( error );
+ }
+ }
+ }
+
+ if ( message == null )
+ {
+ message = error.getMessage();
+ }
+
+ getLogger().info( "Diagnosis: " + message );
+
+ line();
+
getLogger().error( "Cause: ", r.getException() );
line();
@@ -390,7 +415,7 @@ public class DefaultMaven
line();
}
- protected void logFailure( MavenExecutionResponse r, Throwable e, String longMessage )
+ protected void logFailure( MavenExecutionResponse r, Throwable error, String longMessage )
{
line();
@@ -405,16 +430,16 @@ public class DefaultMaven
{
ErrorDiagnoser diagnoser = (ErrorDiagnoser) it.next();
- if ( diagnoser.canDiagnose( e ) )
+ if ( diagnoser.canDiagnose( error ) )
{
- message = diagnoser.diagnose( e );
+ message = diagnoser.diagnose( error );
}
}
}
if ( message == null )
{
- message = "Reason: " + e.getMessage();
+ message = "Reason: " + error.getMessage();
}
getLogger().info( message );
@@ -431,7 +456,7 @@ public class DefaultMaven
// TODO: needs to honour -e
if ( getLogger().isDebugEnabled() )
{
- getLogger().debug( "Trace", e );
+ getLogger().debug( "Trace", error );
line();
}
diff --git a/maven-core/src/main/java/org/apache/maven/usability/InvalidArtifactDiagnoser.java b/maven-core/src/main/java/org/apache/maven/usability/InvalidArtifactDiagnoser.java
new file mode 100644
index 0000000000..bb1fcb8d07
--- /dev/null
+++ b/maven-core/src/main/java/org/apache/maven/usability/InvalidArtifactDiagnoser.java
@@ -0,0 +1,61 @@
+package org.apache.maven.usability;
+
+import org.apache.maven.artifact.InvalidArtifactRTException;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 InvalidArtifactDiagnoser
+ implements ErrorDiagnoser
+{
+
+ public boolean canDiagnose( Throwable error )
+ {
+ return error instanceof InvalidArtifactRTException;
+ }
+
+ public String diagnose( Throwable error )
+ {
+ StringBuffer diagnosis = new StringBuffer();
+
+ InvalidArtifactRTException e = (InvalidArtifactRTException) error;
+
+ diagnosis.append( "An invalid artifact was detected.\n\n" )
+ .append( "This artifact might be in your project's POM, ")
+ .append( "or it might have been included transitively during the resolution process. ")
+ .append( "Here is the information we do have for this artifact:\n")
+ .append( "\n o GroupID: ").append( maybeFlag( e.getGroupId() ) )
+ .append( "\n o ArtifactID: ").append( maybeFlag( e.getArtifactId() ) )
+ .append( "\n o Version: ").append( maybeFlag( e.getVersion() ) )
+ .append( "\n o Type: ").append( maybeFlag( e.getType() ) )
+ .append( "\n" );
+
+ return diagnosis.toString();
+ }
+
+ private String maybeFlag( String value )
+ {
+ if( value == null || value.trim().length() < 1 )
+ {
+ return "<<< MISSING >>>";
+ }
+ else
+ {
+ return value;
+ }
+ }
+
+}
diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml
index d4fb18a3d8..c3491c5b8b 100644
--- a/maven-core/src/main/resources/META-INF/plexus/components.xml
+++ b/maven-core/src/main/resources/META-INF/plexus/components.xml
@@ -26,24 +26,34 @@
org.apache.maven.usability.ErrorDiagnoser
- plugin-configuration
+ PluginConfigurationDiagnoser
org.apache.maven.usability.PluginConfigurationDiagnoser
org.apache.maven.usability.ErrorDiagnoser
- artifact-resolution
+ ArtifactResolverDiagnoser
org.apache.maven.usability.ArtifactResolverDiagnoser
+
+
+ org.apache.maven.usability.ErrorDiagnoser
+ InvalidArtifactDiagnoser
+ org.apache.maven.usability.InvalidArtifactDiagnoser
+