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 64a912a65e..59c1513118 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 @@ -273,8 +273,11 @@ public class DefaultArtifact public String toString() { StringBuffer sb = new StringBuffer(); - sb.append( getGroupId() ); - sb.append( ":" ); + if ( getGroupId() != null ) + { + sb.append( getGroupId() ); + sb.append( ":" ); + } appendArtifactTypeClassifierString( sb ); sb.append( ":" ); if ( version != null || baseVersion != null ) @@ -285,8 +288,11 @@ public class DefaultArtifact { sb.append( versionRange.toString() ); } - sb.append( ":" ); - sb.append( scope ); + if ( scope != null ) + { + sb.append( ":" ); + sb.append( scope ); + } return sb.toString(); } diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java index 7328e7d9fc..5894d90edf 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/DefaultArtifactTest.java @@ -75,22 +75,19 @@ public class DefaultArtifactTest public void testToStringNullGroupId() { artifact.setGroupId( null ); - assertEquals( null + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact - .toString() ); + assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() ); } public void testToStringNullClassifier() { artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler ); - assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact - .toString() ); + assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString() ); } public void testToStringNullScope() { artifact.setScope( null ); - assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + null, artifact - .toString() ); + assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString() ); } }