diff --git a/pom.xml b/pom.xml index 26c849949..e774e1cb7 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ under the License. maven-dependency-plugin - 3.4.0-disy-1 + 3.4.0-disy-2 maven-plugin Apache Maven Dependency Plugin diff --git a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java index 004333ca5..07a7c00ab 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java @@ -620,19 +620,23 @@ private void writeDependencyXML( Set artifacts ) getLog().info( System.lineSeparator() + out.getBuffer() ); } } - private String joinArtifacts( List artifacts ) + + private void joinArtifacts( StringBuilder sb, Set artifacts ) { - StringBuffer sb = new StringBuffer(); - for ( int i = 0; i < artifacts.size(); i++ ) + boolean isFirst = true; + for ( Artifact artifact : artifacts ) { - if ( i != 0 ) + if ( isFirst ) + { + isFirst = false; + } + else { sb.append( ", " ); } - Artifact artifact = artifacts.get( i ); - sb.append( artifact.getGroupId() + ":" + artifact.getArtifactId() ); + sb.append( "\"" ).append( artifact.getGroupId() ) + .append( ":" ).append( artifact.getArtifactId() ).append( "\"" ); } - return sb.toString(); } private void writeDependencyJSON( Set usedUndeclared, Set unusedDeclared ) @@ -642,21 +646,18 @@ private void writeDependencyJSON( Set usedUndeclared, Set un StringBuilder buf = new StringBuilder(); buf.append( "{dependencyIssues:\"true\", " ); - buf.append( "originModule: \"" + project.getGroupId() + ":" + project.getArtifactId() + "\", " ); + buf.append( "originModule: \"" ).append( project.getGroupId() ) + .append( ":" ).append( project.getArtifactId() ).append( "\"" ); if ( !usedUndeclared.isEmpty() ) { - buf.append( "usedUndeclared: [" ); - buf.append( joinArtifacts( new ArrayList<>( usedUndeclared ) ) ); + buf.append( ", usedUndeclared: [" ); + joinArtifacts( buf, usedUndeclared ); buf.append( "]" ); } if ( !unusedDeclared.isEmpty() ) { - if ( !usedUndeclared.isEmpty() ) - { - buf.append( ", " ); - } - buf.append( "unusedDeclared: [" ); - buf.append( joinArtifacts( new ArrayList<>( unusedDeclared ) ) ); + buf.append( ", unusedDeclared: [" ); + joinArtifacts( buf, unusedDeclared ); buf.append( "]" ); } buf.append( "}" );