From 91894251505fe917b911885d565e6bc1c8bebadd Mon Sep 17 00:00:00 2001 From: Dennis Lundberg Date: Wed, 22 Jul 2020 11:01:35 +0200 Subject: [PATCH] [MNG-6967] Improve the command line output from maven-artifact. --- .../versioning/ComparableVersion.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java index 23eb846b86..41a9ad1537 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java @@ -590,6 +590,32 @@ public class ComparableVersion } return buffer.toString(); } + + /** + * Return the contents in the same format that is used when you call toString() on a List. + */ + private String toListString() + { + StringBuilder buffer = new StringBuilder(); + buffer.append( "[" ); + for ( Item item : this ) + { + if ( buffer.length() > 1 ) + { + buffer.append( ", " ); + } + if ( item instanceof ListItem ) + { + buffer.append( ( (ListItem ) item ).toListString() ); + } + else + { + buffer.append( item ); + } + } + buffer.append( "]" ); + return buffer.toString(); + } } public ComparableVersion( String version ) @@ -773,10 +799,10 @@ public class ComparableVersion * @param args the version strings to parse and compare. You can pass arbitrary number of version strings and always * two adjacent will be compared */ - // CHECKSTYLE_ON: LineLength public static void main( String... args ) { - System.out.println( "Display parameters as parsed by Maven (in canonical form) and comparison result:" ); + System.out.println( "Display parameters as parsed by Maven (in canonical form and as a list of tokens) and" + + " comparison result:" ); if ( args.length == 0 ) { return; @@ -795,9 +821,10 @@ public class ComparableVersion + ( ( compare == 0 ) ? "==" : ( ( compare < 0 ) ? "<" : ">" ) ) + ' ' + version ); } - System.out.println( String.valueOf( i++ ) + ". " + version + " == " + c.getCanonical() ); + System.out.println( ( i++ ) + ". " + version + " -> " + c.getCanonical() + "; tokens: " + c.items.toListString() ); prev = c; } } + // CHECKSTYLE_ON: LineLength }