From 016c8e31b59fd75d05b623b08b092322a2b46848 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Gonzalez Date: Sat, 28 Jan 2006 02:39:17 +0000 Subject: [PATCH] Don't print null values in DefaultArtifact.toString git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@373073 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/artifact/DefaultArtifact.java | 14 ++++++++++---- .../apache/maven/artifact/DefaultArtifactTest.java | 9 +++------ 2 files changed, 13 insertions(+), 10 deletions(-) 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() ); } }