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
This commit is contained in:
Carlos Sanchez Gonzalez 2006-01-28 02:39:17 +00:00
parent e46a983a42
commit 016c8e31b5
2 changed files with 13 additions and 10 deletions

View File

@ -273,8 +273,11 @@ public class DefaultArtifact
public String toString() public String toString()
{ {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
if ( getGroupId() != null )
{
sb.append( getGroupId() ); sb.append( getGroupId() );
sb.append( ":" ); sb.append( ":" );
}
appendArtifactTypeClassifierString( sb ); appendArtifactTypeClassifierString( sb );
sb.append( ":" ); sb.append( ":" );
if ( version != null || baseVersion != null ) if ( version != null || baseVersion != null )
@ -285,8 +288,11 @@ public class DefaultArtifact
{ {
sb.append( versionRange.toString() ); sb.append( versionRange.toString() );
} }
if ( scope != null )
{
sb.append( ":" ); sb.append( ":" );
sb.append( scope ); sb.append( scope );
}
return sb.toString(); return sb.toString();
} }

View File

@ -75,22 +75,19 @@ public class DefaultArtifactTest
public void testToStringNullGroupId() public void testToStringNullGroupId()
{ {
artifact.setGroupId( null ); artifact.setGroupId( null );
assertEquals( null + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact assertEquals( artifactId + ":" + type + ":" + classifier + ":" + version + ":" + scope, artifact.toString() );
.toString() );
} }
public void testToStringNullClassifier() public void testToStringNullClassifier()
{ {
artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler ); artifact = new DefaultArtifact( groupId, artifactId, versionRange, scope, type, null, artifactHandler );
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact assertEquals( groupId + ":" + artifactId + ":" + type + ":" + version + ":" + scope, artifact.toString() );
.toString() );
} }
public void testToStringNullScope() public void testToStringNullScope()
{ {
artifact.setScope( null ); artifact.setScope( null );
assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version + ":" + null, artifact assertEquals( groupId + ":" + artifactId + ":" + type + ":" + classifier + ":" + version, artifact.toString() );
.toString() );
} }
} }