Skip to content

Commit

Permalink
Fix mojohaus#308 Dependencies with broken POMs ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Mar 7, 2019
1 parent 92a75a9 commit c23185b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,15 @@ public void execute()
getLog().debug( "Checking licenses for project " + artifact );
final ProjectLicenseInfo depProject = createDependencyProject( artifact );
matchers.replaceMatches( depProject );

/* Copy the messages and handle them via handleError() that may eventually add them back */
final List<String> msgs = new ArrayList<>( depProject.getDownloaderMessages() );
depProject.getDownloaderMessages().clear();
for ( String msg : msgs )
{
handleError( depProject, msg );
}

depProjectLicenses.add( depProject );
}
if ( !offline )
Expand Down Expand Up @@ -1074,19 +1083,26 @@ private Proxy findActiveProxy()
*
* @param depMavenProject the dependency maven project
* @return DependencyProject with artifact and license info
* @throws MojoFailureException
*/
private ProjectLicenseInfo createDependencyProject( LicensedArtifact depMavenProject )
private ProjectLicenseInfo createDependencyProject( LicensedArtifact depMavenProject ) throws MojoFailureException
{
ProjectLicenseInfo dependencyProject =
final ProjectLicenseInfo dependencyProject =
new ProjectLicenseInfo( depMavenProject.getGroupId(), depMavenProject.getArtifactId(),
depMavenProject.getVersion() );
List<org.codehaus.mojo.license.download.License> licenses = depMavenProject.getLicenses();
final List<org.codehaus.mojo.license.download.License> licenses = depMavenProject.getLicenses();
for ( org.codehaus.mojo.license.download.License license : licenses )
{
dependencyProject.addLicense( new ProjectLicense( license.getName(), license.getUrl(),
license.getDistribution(), license.getComments(),
null ) );
}
List<String> msgs = depMavenProject.getErrorMessages();
for ( String msg : msgs )
{
dependencyProject.addDownloaderMessage( msg );
}

return dependencyProject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void replaceMatches( ProjectLicenseInfo dependency )
dependency.setLicenses( matcher.cloneLicenses() );
}
dependency.setApproved( true );
dependency.getDownloaderMessages().clear();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,25 @@ public static Builder builder( String groupId, String artifactId, String version
return new Builder( groupId, artifactId, version );
}

LicensedArtifact( String groupId, String artifactId, String version, List<License> licenses )
private final String groupId;

private final String artifactId;

private final String version;

private final List<License> licenses;

private final List<String> errorMessages;

LicensedArtifact( String groupId, String artifactId, String version, List<License> licenses,
List<String> errorMessages )
{
super();
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.licenses = licenses;
this.errorMessages = errorMessages;
}

@Override
Expand Down Expand Up @@ -102,14 +114,6 @@ else if ( !version.equals( other.version ) )
// CHECKSTYLE_ON: NeedBraces
}

private final String groupId;

private final String artifactId;

private final String version;

private final List<License> licenses;

public String getGroupId()
{
return groupId;
Expand All @@ -130,6 +134,11 @@ public List<License> getLicenses()
return licenses;
}

public List<String> getErrorMessages()
{
return errorMessages;
}

/**
* A {@link LicensedArtifact} builder.
*/
Expand All @@ -152,6 +161,14 @@ public Builder( String groupId, String artifactId, String version )

private List<License> licenses = new ArrayList<>();

private List<String> errorMessages = new ArrayList<>();

public Builder errorMessage( String errorMessage )
{
this.errorMessages.add( errorMessage );
return this;
}

public Builder license( License license )
{
this.licenses.add( license );
Expand All @@ -162,7 +179,9 @@ public LicensedArtifact build()
{
final List<License> lics = Collections.unmodifiableList( licenses );
licenses = null;
return new LicensedArtifact( groupId, artifactId, version, lics );
final List<String> msgs = Collections.unmodifiableList( errorMessages );
errorMessages = null;
return new LicensedArtifact( groupId, artifactId, version, lics, msgs );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public void loadProjectDependencies( ResolvedProjectDependencies artifacts,
}
catch ( ProjectBuildingException e )
{
log.warn( "Unable to obtain POM for artifact : " + artifact, e );
continue;
laBuilder.errorMessage( e.getClass().getSimpleName() + ": " + e.getMessage() );
}

depMavenProject = laBuilder.build();
Expand Down

0 comments on commit c23185b

Please sign in to comment.