Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#201 - Reduce log level for unknown dependencies to debug to reduce l… #300

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

Expand Up @@ -600,6 +600,20 @@ public abstract class AbstractAddThirdPartyMojo
@Parameter( property = "project.artifacts", required = true, readonly = true )
protected Set<Artifact> dependencies;


/**
* What to do on defined files not found in project. The possible values are:
* <li>
* <ul>{@link UnkownFileRemedy#debug}: unkown files are logged debug</ul>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo throughout the change Unkown -> Unknown

* <ul>{@link UnkownFileRemedy#warn}: unkown files are output to the log as warnings</ul>
* <ul>{@link UnkownFileRemedy#failFast}: a {@link MojoExecutionException} is thrown on the
* file not found in project</ul>
* </li>
* @since 2.0.1
*/
@Parameter( property = "license.unkownFileRemedy", defaultValue = "warn" )
protected UnkownFileRemedy unkownFileRemedy;

// ----------------------------------------------------------------------
// Plexus components
// ----------------------------------------------------------------------
Expand Down
Expand Up @@ -229,9 +229,9 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
private String overrideUrl;

/**
* A {@link URL} prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value.
* A {@link String} prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value.
*
* @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(URL, File, String, File)
* @see LicenseMojoUtils#prepareThirdPartyOverrideUrl(String, File, String, File)
*/
String resolvedOverrideUrl;

Expand Down Expand Up @@ -311,6 +311,19 @@ public abstract class AbstractThirdPartyReportMojo extends AbstractMavenReport
@Parameter( defaultValue = "${project}", readonly = true )
private MavenProject project;

/**
* What to do on defined files not found in project. The possible values are:
* <li>
* <ul>{@link UnkownFileRemedy#debug}: unkown files are logged debug</ul>
* <ul>{@link UnkownFileRemedy#warn}: unkown files are output to the log as warnings</ul>
* <ul>{@link UnkownFileRemedy#failFast}: a {@link MojoExecutionException} is thrown on the
* file not found in project</ul>
* </li>
* @since 2.0.1
*/
@Parameter( property = "license.unkownFileRemedy", defaultValue = "warn" )
protected UnkownFileRemedy unkownFileRemedy;

// ----------------------------------------------------------------------
// Plexus Components
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -385,7 +398,7 @@ protected abstract Collection<ThirdPartyDetails> createThirdPartyDetails()
/**
* Method to initialize the mojo before doing any concrete actions.
*
* <b>Note:</b> The method is invoked before the {@link #executeReport()} method.
* <b>Note:</b> The method is invoked before the {@link #executeReport(Locale)} method.
* @throws IOException
*/
protected void init()
Expand Down Expand Up @@ -593,7 +606,7 @@ Collection<ThirdPartyDetails> createThirdPartyDetails( MavenProject project, boo
// Resolve unsafe dependencies using missing files, this will update licenseMap and unsafeDependencies
thirdPartyHelper.createUnsafeMapping( licenseMap, missingFile, missingFileUrl,
useRepositoryMissingFiles, dependenciesWithNoLicense,
projectDependencies, loadedDependencies.getAllDependencies() );
projectDependencies, loadedDependencies.getAllDependencies(), unkownFileRemedy);
}
}

Expand Down Expand Up @@ -639,5 +652,4 @@ public String getEncoding()
{
return encoding;
}

}
Expand Up @@ -264,7 +264,7 @@ protected SortedProperties createUnsafeMapping()
getHelper().createUnsafeMapping( licenseMap, missingFile, missingFileUrl,
useRepositoryMissingFiles, unsafeDependencies,
projectDependencies,
resolveDependencyArtifacts().getAllDependencies() );
resolveDependencyArtifacts().getAllDependencies(), unkownFileRemedy);
if ( isVerbose() )
{
LOG.info( "found {} unsafe mappings", unsafeMappings.size() );
Expand Down
Expand Up @@ -314,7 +314,7 @@ protected SortedProperties createUnsafeMapping()
if ( file.exists() )
{

SortedProperties tmp = getHelper().loadUnsafeMapping( licenseMap, file, null, projectDependencies );
SortedProperties tmp = getHelper().loadUnsafeMapping( licenseMap, file, null, projectDependencies, unkownFileRemedy );
unsafeMappings.putAll( tmp );
}

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/codehaus/mojo/license/UnkownFileRemedy.java
@@ -0,0 +1,30 @@
/******************************************************************************
* COMINTO GmbH
* Klosterstr. 49
* 40211 Düsseldorf
* Germany
*
* (c) Copyright 2020 by COMINTO GmbH
* ALL RIGHTS RESERVED
*
******************************************************************************/
package org.codehaus.mojo.license;

import org.apache.maven.plugin.MojoExecutionException;

/**
* What to do in case of a file not found in project.
*
* @since 2.0.1
*/
public enum UnkownFileRemedy
{
/** Unkown files will be logged debug */
debug,
/** Unkown files are output to the log as warnings */
warn,
/**
* The first encountered unkown file is logged and a {@link MojoExecutionException} is thrown
*/
failFast,
}
Expand Up @@ -29,6 +29,7 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.mojo.license.UnkownFileRemedy;
import org.codehaus.mojo.license.model.LicenseMap;
import org.codehaus.mojo.license.utils.SortedProperties;

Expand Down Expand Up @@ -169,12 +170,13 @@ public SortedProperties loadThirdPartyDescriptorForUnsafeMapping( Set<Artifact>
/**
* {@inheritDoc}
*/
public SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl,
SortedMap<String, MavenProject> projectDependencies )
public SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl,
SortedMap<String, MavenProject> projectDependencies,
UnkownFileRemedy unkownFileRemedy)
throws IOException, MojoExecutionException
{
return thirdPartyTool.loadUnsafeMapping( licenseMap, projectDependencies, encoding, missingFile,
missingFileUrl );
missingFileUrl, unkownFileRemedy );
}

/**
Expand Down Expand Up @@ -213,16 +215,17 @@ public SortedSet<MavenProject> getProjectsWithNoLicense( LicenseMap licenseMap )
/**
* {@inheritDoc}
*/
public SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl,
boolean useRepositoryMissingFiles,
SortedSet<MavenProject> unsafeDependencies,
SortedMap<String, MavenProject> projectDependencies,
Set<Artifact> dependencyArtifacts )
public SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl,
boolean useRepositoryMissingFiles,
SortedSet<MavenProject> unsafeDependencies,
SortedMap<String, MavenProject> projectDependencies,
Set<Artifact> dependencyArtifacts,
UnkownFileRemedy unkownFileRemedy)
throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException
{

SortedProperties unsafeMappings = loadUnsafeMapping( licenseMap, missingFile, missingFileUrl,
projectDependencies );
projectDependencies, unkownFileRemedy);

if ( CollectionUtils.isNotEmpty( unsafeDependencies ) )
{
Expand Down
Expand Up @@ -52,6 +52,7 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.mojo.license.LicenseMojoUtils;
import org.codehaus.mojo.license.UnkownFileRemedy;
import org.codehaus.mojo.license.model.LicenseMap;
import org.codehaus.mojo.license.utils.FileUtil;
import org.codehaus.mojo.license.utils.MojoHelper;
Expand Down Expand Up @@ -450,11 +451,13 @@ public void mergeLicenses( LicenseMap licenseMap, String mainLicense, Set<String
/**
* {@inheritDoc}
*/
public SortedProperties loadUnsafeMapping( LicenseMap licenseMap,
SortedMap<String, MavenProject> artifactCache,
String encoding,
File missingFile,
String missingFileUrl ) throws IOException, MojoExecutionException
public SortedProperties loadUnsafeMapping(LicenseMap licenseMap,
SortedMap<String, MavenProject> artifactCache,
String encoding,
File missingFile,
String missingFileUrl,
UnkownFileRemedy unkownFileRemedy)
throws IOException, MojoExecutionException
{
Map<String, MavenProject> snapshots = new HashMap<>();

Expand Down Expand Up @@ -536,8 +539,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap,
// there is some unknown dependencies in the missing file, remove them
for ( String id : unknownDependenciesId )
{
getLogger().debug(
"dependency [" + id + "] does not exist in project, remove it from the missing file." );
handleUnkownDependency(unkownFileRemedy,"dependency [" + id + "] does not exist in project, remove it from the missing file.");
unsafeMappings.remove( id );
}

Expand All @@ -552,7 +554,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap,
MavenProject project = artifactCache.get( id );
if ( project == null )
{
LOG.warn( "dependency [{}] does not exist in project.", id );
handleUnkownDependency(unkownFileRemedy, "dependency [" + id + "] does not exist in project." );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably cleaner to hand id down to handleUnkownDependency instead of passing the log message around.

continue;
}

Expand Down Expand Up @@ -594,6 +596,26 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap,
return unsafeMappings;
}

private void handleUnkownDependency(final UnkownFileRemedy unkownFileRemedy, final String message)
throws MojoExecutionException {

switch ( unkownFileRemedy )
{
case debug:
LOG.debug( message );
break;
case failFast:
throw new MojoExecutionException(message);
case warn:
LOG.warn( message );
break;
default:
throw new IllegalStateException( "Unexpected value of " + UnkownFileRemedy.class.getName() + ": "
+ unkownFileRemedy );
}

}

/**
* {@inheritDoc}
*/
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/codehaus/mojo/license/api/ThirdPartyHelper.java
Expand Up @@ -27,6 +27,7 @@
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.mojo.license.UnkownFileRemedy;
import org.codehaus.mojo.license.model.LicenseMap;
import org.codehaus.mojo.license.utils.SortedProperties;

Expand Down Expand Up @@ -86,11 +87,12 @@ SortedProperties loadThirdPartyDescriptorForUnsafeMapping( Set<Artifact> topLeve
* resource hoster and that will be merged with the content of the missing file.
* @param projectDependencies project dependencies used to detect which dependencies in the missing file
* are unknown to the project.
* @param unkownFileRemedy
* @return the map of all unsafe mapping
* @throws IOException if could not load missing file
*/
SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl,
SortedMap<String, MavenProject> projectDependencies )
SortedProperties loadUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl,
SortedMap<String, MavenProject> projectDependencies, final UnkownFileRemedy unkownFileRemedy)
throws IOException, MojoExecutionException;

/**
Expand Down Expand Up @@ -147,16 +149,17 @@ SortedProperties loadUnsafeMapping( LicenseMap licenseMap, File missingFile, Str
* @param unsafeDependencies all unsafe dependencies
* @param projectDependencies all project dependencies
* @param dependencyArtifacts all project dependency artifacts
* @param unkownFileRemedy
* @return the loaded unsafe mapping
* @throws ProjectBuildingException if could not build some dependencies maven project
* @throws IOException if could not load missing file
* @throws ThirdPartyToolException if pb with third-party tool
*/
SortedProperties createUnsafeMapping( LicenseMap licenseMap, File missingFile, String missingFileUrl,
boolean useRepositoryMissingFiles,
SortedSet<MavenProject> unsafeDependencies,
SortedMap<String, MavenProject> projectDependencies,
Set<Artifact> dependencyArtifacts )
SortedProperties createUnsafeMapping(LicenseMap licenseMap, File missingFile, String missingFileUrl,
boolean useRepositoryMissingFiles,
SortedSet<MavenProject> unsafeDependencies,
SortedMap<String, MavenProject> projectDependencies,
Set<Artifact> dependencyArtifacts, final UnkownFileRemedy unkownFileRemedy)
throws ProjectBuildingException, IOException, ThirdPartyToolException, MojoExecutionException;

/**
Expand Down
Expand Up @@ -26,6 +26,7 @@
import org.apache.maven.model.License;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.license.UnkownFileRemedy;
import org.codehaus.mojo.license.model.LicenseMap;
import org.codehaus.mojo.license.utils.SortedProperties;

Expand Down Expand Up @@ -138,11 +139,12 @@ File resolveMissingLicensesDescriptor( String groupId, String artifactId, String
* @param missingFile location of the optional missing file
* @param missingFileUrl location of an optional missing file extension that can be downloaded from some
* resource hoster and that will be merged with the content of the missing file.
* @param unkownFileRemedy
* @return the unsafe mapping
* @throws IOException if pb while reading missing file
*/
SortedProperties loadUnsafeMapping( LicenseMap licenseMap, SortedMap<String, MavenProject> artifactCache,
String encoding, File missingFile, String missingFileUrl )
SortedProperties loadUnsafeMapping(LicenseMap licenseMap, SortedMap<String, MavenProject> artifactCache,
String encoding, File missingFile, String missingFileUrl, final UnkownFileRemedy unkownFileRemedy)
throws IOException, MojoExecutionException;

/**
Expand Down