Skip to content

Commit

Permalink
Output proper JSON (perform proper string quoting of group and artifa…
Browse files Browse the repository at this point in the history
…ct id), set new Disy patch version 3.4.0-disy-2

* also reuse StringBuilder when composing the deps. string
  • Loading branch information
adrian.nistor committed Dec 7, 2023
1 parent 6ba529d commit 1f605f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ under the License.
</parent>

<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0-disy-1</version>
<version>3.4.0-disy-2</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven Dependency Plugin</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,19 +620,23 @@ private void writeDependencyXML( Set<Artifact> artifacts )
getLog().info( System.lineSeparator() + out.getBuffer() );
}
}
private String joinArtifacts( List<Artifact> artifacts )

private void joinArtifacts( StringBuilder sb, Set<Artifact> 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<Artifact> usedUndeclared, Set<Artifact> unusedDeclared )
Expand All @@ -642,21 +646,18 @@ private void writeDependencyJSON( Set<Artifact> usedUndeclared, Set<Artifact> 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( "}" );
Expand Down

0 comments on commit 1f605f6

Please sign in to comment.