Skip to content

Commit

Permalink
apply json patch, set version
Browse files Browse the repository at this point in the history
  • Loading branch information
cgo-disy committed Nov 29, 2022
1 parent 8fecf8a commit 6ba529d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
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</version>
<version>3.4.0-disy-1</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 @@ -112,6 +112,12 @@ public abstract class AbstractAnalyzeMojo
@Parameter( property = "ignoreUnusedRuntime", defaultValue = "false" )
private boolean ignoreUnusedRuntime;

/**
* Output the xml for the missing dependencies (used but not declared).
*/
@Parameter( property = "outputJSON", defaultValue = "false" )
private boolean outputJSON;

/**
* Ignore all dependencies that are used only in test but not test-scoped. Setting
* this flag has the same effect as adding all dependencies that have been flagged with
Expand Down Expand Up @@ -219,6 +225,13 @@ public abstract class AbstractAnalyzeMojo
@Parameter
private String[] ignoredUsedUndeclaredDependencies = new String[0];

/**
* Ignore dependencies with scope:compile, which are only used in tests.
*/
@Parameter
private String[] ignoredCompileScopedUsedOnlyInTestsDependencies = new String[0];


/**
* List of dependencies that will be ignored if they are declared but unused. The filter syntax is:
*
Expand Down Expand Up @@ -469,6 +482,11 @@ private boolean checkDependencies()
writeDependencyXML( usedUndeclaredWithClasses.keySet() );
}

if ( outputJSON )
{
writeDependencyJSON( usedUndeclaredWithClasses.keySet(), unusedDeclared );
}

if ( scriptableOutput )
{
writeScriptableOutput( usedUndeclaredWithClasses.keySet() );
Expand Down Expand Up @@ -602,6 +620,49 @@ private void writeDependencyXML( Set<Artifact> artifacts )
getLog().info( System.lineSeparator() + out.getBuffer() );
}
}
private String joinArtifacts( List<Artifact> artifacts )
{
StringBuffer sb = new StringBuffer();
for ( int i = 0; i < artifacts.size(); i++ )
{
if ( i != 0 )
{
sb.append( ", " );
}
Artifact artifact = artifacts.get( i );
sb.append( artifact.getGroupId() + ":" + artifact.getArtifactId() );
}
return sb.toString();
}

private void writeDependencyJSON( Set<Artifact> usedUndeclared, Set<Artifact> unusedDeclared )
{
if ( !usedUndeclared.isEmpty() || !unusedDeclared.isEmpty() )
{
StringBuilder buf = new StringBuilder();

buf.append( "{dependencyIssues:\"true\", " );
buf.append( "originModule: \"" + project.getGroupId() + ":" + project.getArtifactId() + "\", " );
if ( !usedUndeclared.isEmpty() )
{
buf.append( "usedUndeclared: [" );
buf.append( joinArtifacts( new ArrayList<>( usedUndeclared ) ) );
buf.append( "]" );
}
if ( !unusedDeclared.isEmpty() )
{
if ( !usedUndeclared.isEmpty() )
{
buf.append( ", " );
}
buf.append( "unusedDeclared: [" );
buf.append( joinArtifacts( new ArrayList<>( unusedDeclared ) ) );
buf.append( "]" );
}
buf.append( "}" );
getLog().warn( buf.toString() );
}
}

private void writeScriptableOutput( Set<Artifact> artifacts )
{
Expand Down

0 comments on commit 6ba529d

Please sign in to comment.