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

Fix #337 Use slf4j over old logging APIs in Maven #342

Merged
merged 2 commits into from Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions pom.xml
Expand Up @@ -137,6 +137,11 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${pluginPluginVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand All @@ -147,6 +152,11 @@
<artifactId>httpcore</artifactId>
<version>${version.httpcomponents.httpcore}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -237,7 +247,6 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${pluginPluginVersion}</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -301,10 +310,8 @@
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/license/THIRD-PARTY.properties
Expand Up @@ -20,7 +20,7 @@
#Sat Feb 23 19:57:14 CET 2019
classworlds--classworlds--1.1=http\://classworlds.codehaus.org/license.html
commons-beanutils--commons-beanutils--1.7.0=The Apache Software License, Version 2.0
dom4j--dom4j--1.1=BSD 4-Cluse JDOM
dom4j--dom4j--1.1=BSD 4-Clause DOM4J
nekohtml--xercesMinimal--1.9.6.2=The Apache Software License, Version 2.0
org.codehaus.plexus--plexus-container-default--1.0-alpha-9-stable-1=The Apache Software License, Version 2.0
org.codehaus.plexus--plexus-i18n--1.0-beta-7=The Apache Software License, Version 2.0
Expand Down
Expand Up @@ -29,7 +29,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -59,6 +58,8 @@
import org.codehaus.mojo.license.api.DependenciesToolException;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.transfer.ArtifactNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Abstract mojo for all third-party mojos.
Expand All @@ -69,6 +70,7 @@
public abstract class AbstractAddThirdPartyMojo
extends AbstractLicenseMojo
{
private static final Logger LOG = LoggerFactory.getLogger( AbstractAddThirdPartyMojo.class );

// ----------------------------------------------------------------------
// Mojo Parameters
Expand Down Expand Up @@ -715,11 +717,8 @@ protected void init()
throws Exception
{

Log log = getLog();

if ( log.isDebugEnabled() )
if ( getLog().isDebugEnabled() )
{

// always be verbose in debug mode
setVerbose( true );
}
Expand All @@ -728,11 +727,8 @@ protected void init()

long buildTimestamp = getBuildTimestamp();

if ( isVerbose() || getLog().isDebugEnabled() )
{
log.debug( "Build start at : " + buildTimestamp );
log.debug( "third-party file : " + thirdPartyFile.lastModified() );
}
LOG.debug( "Build start at: {}", buildTimestamp );
LOG.debug( "third-party file: {}", thirdPartyFile.lastModified() );

doGenerate = force || !thirdPartyFile.exists() || buildTimestamp > thirdPartyFile.lastModified();

Expand All @@ -741,10 +737,7 @@ protected void init()

File bundleFile = FileUtil.getFile( outputDirectory, bundleThirdPartyPath );

if ( isVerbose() || getLog().isDebugEnabled() )
{
log.debug( "bundle third-party file : " + bundleFile.lastModified() );
}
LOG.debug( "bundle third-party file: {}", bundleFile.lastModified() );
doGenerateBundle = force || !bundleFile.exists() || buildTimestamp > bundleFile.lastModified();
}
else
Expand All @@ -764,26 +757,26 @@ protected void init()
{
throw new MojoExecutionException( "You can't use both licenseMergesFile and licenseMergesUrl" );
}
getLog().warn( "" );
getLog().warn( "!!! licenseMergesFile is deprecated, use now licenseMergesUrl !!!" );
getLog().warn( "" );
getLog().warn( "licenseMerges will be overridden by licenseMergesFile." );
getLog().warn( "" );
LOG.warn( "" );
LOG.warn( "!!! licenseMergesFile is deprecated, use now licenseMergesUrl !!!" );
LOG.warn( "" );
LOG.warn( "licenseMerges will be overridden by licenseMergesFile." );
LOG.warn( "" );
licenseMerges = FileUtils.readLines( new File( licenseMergesFile ), "utf-8" );
}
else if ( licenseMergesUrl != null )
{
getLog().warn( "" );
getLog().warn( "licenseMerges will be overridden by licenseMergesUrl." );
getLog().warn( "" );
LOG.warn( "" );
LOG.warn( "licenseMerges will be overridden by licenseMergesUrl." );
LOG.warn( "" );
if ( UrlRequester.isStringUrl( licenseMergesUrl ) )
{
licenseMerges = Arrays.asList( UrlRequester.getFromUrl( licenseMergesUrl ).split( "[\n\r]+" ) );
}
}

resolvedOverrideUrl = LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedOverrideUrl, overrideFile,
overrideUrl, project.getBasedir(), getLog() );
overrideUrl, project.getBasedir() );
}

void consolidate() throws IOException, ArtifactNotFoundException, ArtifactResolutionException, MojoFailureException,
Expand Down Expand Up @@ -874,7 +867,7 @@ protected ThirdPartyHelper getHelper()
{
helper = new DefaultThirdPartyHelper( getProject(), getEncoding(), isVerbose(), dependenciesTool,
thirdPartyTool, getProject().getRemoteArtifactRepositories(),
getProject().getRemoteProjectRepositories(), getLog() );
getProject().getRemoteProjectRepositories() );
}
return helper;
}
Expand Down Expand Up @@ -934,20 +927,19 @@ void checkUnsafeDependencies()
{
if ( CollectionUtils.isNotEmpty( unsafeDependencies ) )
{
Log log = getLog();
if ( log.isWarnEnabled() )
if ( LOG.isWarnEnabled() )
{
boolean plural = unsafeDependencies.size() > 1;
String message = String.format( "There %s %d %s with no license :",
plural ? "are" : "is",
unsafeDependencies.size(),
plural ? "dependencies" : "dependency" );
log.warn( message );
LOG.warn( message );
for ( MavenProject dep : unsafeDependencies )
{

// no license found for the dependency
log.warn( " - " + MojoHelper.getArtifactId( dep.getArtifact() ) );
LOG.warn( " - {}", MojoHelper.getArtifactId( dep.getArtifact() ) );
}
}
}
Expand All @@ -961,7 +953,7 @@ boolean checkForbiddenLicenses()
if ( CollectionUtils.isNotEmpty( blackLicenses ) )
{
Set<String> licenses = licenseMap.keySet();
getLog().info( "Excluded licenses (blacklist): " + blackLicenses );
LOG.info( "Excluded licenses (blacklist): {}", blackLicenses );

for ( String excludeLicense : blackLicenses )
{
Expand All @@ -977,20 +969,19 @@ boolean checkForbiddenLicenses()
if ( CollectionUtils.isNotEmpty( whiteLicenses ) )
{
Set<String> dependencyLicenses = licenseMap.keySet();
getLog().info( "Included licenses (whitelist): " + whiteLicenses );
LOG.info( "Included licenses (whitelist): {}", whiteLicenses );

for ( String dependencyLicense : dependencyLicenses )
{
getLog().debug( "Testing license '" + dependencyLicense + "'" );
LOG.debug( "Testing license '{}'", dependencyLicense );
if ( !whiteLicenses.contains( dependencyLicense )
&& CollectionUtils.isNotEmpty( licenseMap.get( dependencyLicense ) ) )
{
getLog().debug( "Testing dependency license '" + dependencyLicense
+ "' against all other licenses" );
LOG.debug( "Testing dependency license '{}' against all other licenses", dependencyLicense );

for ( MavenProject dependency : licenseMap.get( dependencyLicense ) )
{
getLog().debug( " testing dependency " + dependency );
LOG.debug( "- testing dependency {}" + dependency );

boolean forbiddenLicenseUsed = true;

Expand All @@ -1012,8 +1003,10 @@ boolean checkForbiddenLicenses()

if ( licenseMap.get( otherLicense ).contains( dependency ) )
{
getLog().info( "License: '" + dependencyLicense + "' for '" + dependency + "'is OK "
+ "since it is also licensed under '" + otherLicense + "'" );
LOG.info( "License: '{}' for '{}' is OK since it is also licensed under '{}'",
dependencyLicense,
dependency,
otherLicense );
// this dependency is licensed under another license from white list
forbiddenLicenseUsed = false;
break;
Expand All @@ -1035,8 +1028,7 @@ boolean checkForbiddenLicenses()

if ( !safe )
{
Log log = getLog();
log.warn( "There are " + unsafeLicenses.size() + " forbidden licenses used:" );
LOG.warn( "There are {} forbidden licenses used:", unsafeLicenses.size() );
for ( String unsafeLicense : unsafeLicenses )
{

Expand All @@ -1050,7 +1042,7 @@ boolean checkForbiddenLicenses()
{
sb.append( "\n -" ).append( MojoHelper.getArtifactName( dep ) );
}
log.warn( sb.toString() );
LOG.warn( "{}", sb );
}
}
}
Expand Down