Skip to content

Commit ebb3a99

Browse files
authored
Merge pull request #342 from ppalaga/i337
Fix #337 Use slf4j over old logging APIs in Maven
2 parents c4015c1 + 9c53509 commit ebb3a99

35 files changed

+494
-626
lines changed

pom.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@
137137

138138
<dependencyManagement>
139139
<dependencies>
140+
<dependency>
141+
<groupId>org.apache.maven.plugin-tools</groupId>
142+
<artifactId>maven-plugin-annotations</artifactId>
143+
<version>${pluginPluginVersion}</version>
144+
</dependency>
140145
<dependency>
141146
<groupId>org.apache.httpcomponents</groupId>
142147
<artifactId>httpclient</artifactId>
@@ -147,6 +152,11 @@
147152
<artifactId>httpcore</artifactId>
148153
<version>${version.httpcomponents.httpcore}</version>
149154
</dependency>
155+
<dependency>
156+
<groupId>org.slf4j</groupId>
157+
<artifactId>slf4j-api</artifactId>
158+
<version>1.7.26</version>
159+
</dependency>
150160
</dependencies>
151161
</dependencyManagement>
152162

@@ -237,7 +247,6 @@
237247
<dependency>
238248
<groupId>org.apache.maven.plugin-tools</groupId>
239249
<artifactId>maven-plugin-annotations</artifactId>
240-
<version>${pluginPluginVersion}</version>
241250
<scope>provided</scope>
242251
</dependency>
243252

@@ -301,10 +310,8 @@
301310
</dependency>
302311

303312
<dependency>
304-
<groupId>log4j</groupId>
305-
<artifactId>log4j</artifactId>
306-
<version>1.2.17</version>
307-
<scope>runtime</scope>
313+
<groupId>org.slf4j</groupId>
314+
<artifactId>slf4j-api</artifactId>
308315
</dependency>
309316

310317
<dependency>

src/license/THIRD-PARTY.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#Sat Feb 23 19:57:14 CET 2019
2121
classworlds--classworlds--1.1=http\://classworlds.codehaus.org/license.html
2222
commons-beanutils--commons-beanutils--1.7.0=The Apache Software License, Version 2.0
23-
dom4j--dom4j--1.1=BSD 4-Cluse JDOM
23+
dom4j--dom4j--1.1=BSD 4-Clause DOM4J
2424
nekohtml--xercesMinimal--1.9.6.2=The Apache Software License, Version 2.0
2525
org.codehaus.plexus--plexus-container-default--1.0-alpha-9-stable-1=The Apache Software License, Version 2.0
2626
org.codehaus.plexus--plexus-i18n--1.0-beta-7=The Apache Software License, Version 2.0

src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.maven.artifact.repository.ArtifactRepository;
3030
import org.apache.maven.plugin.MojoExecutionException;
3131
import org.apache.maven.plugin.MojoFailureException;
32-
import org.apache.maven.plugin.logging.Log;
3332
import org.apache.maven.plugins.annotations.Component;
3433
import org.apache.maven.plugins.annotations.Parameter;
3534
import org.apache.maven.project.MavenProject;
@@ -59,6 +58,8 @@
5958
import org.codehaus.mojo.license.api.DependenciesToolException;
6059
import org.eclipse.aether.resolution.ArtifactResolutionException;
6160
import org.eclipse.aether.transfer.ArtifactNotFoundException;
61+
import org.slf4j.Logger;
62+
import org.slf4j.LoggerFactory;
6263

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

7375
// ----------------------------------------------------------------------
7476
// Mojo Parameters
@@ -715,11 +717,8 @@ protected void init()
715717
throws Exception
716718
{
717719

718-
Log log = getLog();
719-
720-
if ( log.isDebugEnabled() )
720+
if ( getLog().isDebugEnabled() )
721721
{
722-
723722
// always be verbose in debug mode
724723
setVerbose( true );
725724
}
@@ -728,11 +727,8 @@ protected void init()
728727

729728
long buildTimestamp = getBuildTimestamp();
730729

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

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

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

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

744-
if ( isVerbose() || getLog().isDebugEnabled() )
745-
{
746-
log.debug( "bundle third-party file : " + bundleFile.lastModified() );
747-
}
740+
LOG.debug( "bundle third-party file: {}", bundleFile.lastModified() );
748741
doGenerateBundle = force || !bundleFile.exists() || buildTimestamp > bundleFile.lastModified();
749742
}
750743
else
@@ -764,26 +757,26 @@ protected void init()
764757
{
765758
throw new MojoExecutionException( "You can't use both licenseMergesFile and licenseMergesUrl" );
766759
}
767-
getLog().warn( "" );
768-
getLog().warn( "!!! licenseMergesFile is deprecated, use now licenseMergesUrl !!!" );
769-
getLog().warn( "" );
770-
getLog().warn( "licenseMerges will be overridden by licenseMergesFile." );
771-
getLog().warn( "" );
760+
LOG.warn( "" );
761+
LOG.warn( "!!! licenseMergesFile is deprecated, use now licenseMergesUrl !!!" );
762+
LOG.warn( "" );
763+
LOG.warn( "licenseMerges will be overridden by licenseMergesFile." );
764+
LOG.warn( "" );
772765
licenseMerges = FileUtils.readLines( new File( licenseMergesFile ), "utf-8" );
773766
}
774767
else if ( licenseMergesUrl != null )
775768
{
776-
getLog().warn( "" );
777-
getLog().warn( "licenseMerges will be overridden by licenseMergesUrl." );
778-
getLog().warn( "" );
769+
LOG.warn( "" );
770+
LOG.warn( "licenseMerges will be overridden by licenseMergesUrl." );
771+
LOG.warn( "" );
779772
if ( UrlRequester.isStringUrl( licenseMergesUrl ) )
780773
{
781774
licenseMerges = Arrays.asList( UrlRequester.getFromUrl( licenseMergesUrl ).split( "[\n\r]+" ) );
782775
}
783776
}
784777

785778
resolvedOverrideUrl = LicenseMojoUtils.prepareThirdPartyOverrideUrl( resolvedOverrideUrl, overrideFile,
786-
overrideUrl, project.getBasedir(), getLog() );
779+
overrideUrl, project.getBasedir() );
787780
}
788781

789782
void consolidate() throws IOException, ArtifactNotFoundException, ArtifactResolutionException, MojoFailureException,
@@ -874,7 +867,7 @@ protected ThirdPartyHelper getHelper()
874867
{
875868
helper = new DefaultThirdPartyHelper( getProject(), getEncoding(), isVerbose(), dependenciesTool,
876869
thirdPartyTool, getProject().getRemoteArtifactRepositories(),
877-
getProject().getRemoteProjectRepositories(), getLog() );
870+
getProject().getRemoteProjectRepositories() );
878871
}
879872
return helper;
880873
}
@@ -934,20 +927,19 @@ void checkUnsafeDependencies()
934927
{
935928
if ( CollectionUtils.isNotEmpty( unsafeDependencies ) )
936929
{
937-
Log log = getLog();
938-
if ( log.isWarnEnabled() )
930+
if ( LOG.isWarnEnabled() )
939931
{
940932
boolean plural = unsafeDependencies.size() > 1;
941933
String message = String.format( "There %s %d %s with no license :",
942934
plural ? "are" : "is",
943935
unsafeDependencies.size(),
944936
plural ? "dependencies" : "dependency" );
945-
log.warn( message );
937+
LOG.warn( message );
946938
for ( MavenProject dep : unsafeDependencies )
947939
{
948940

949941
// no license found for the dependency
950-
log.warn( " - " + MojoHelper.getArtifactId( dep.getArtifact() ) );
942+
LOG.warn( " - {}", MojoHelper.getArtifactId( dep.getArtifact() ) );
951943
}
952944
}
953945
}
@@ -961,7 +953,7 @@ boolean checkForbiddenLicenses()
961953
if ( CollectionUtils.isNotEmpty( blackLicenses ) )
962954
{
963955
Set<String> licenses = licenseMap.keySet();
964-
getLog().info( "Excluded licenses (blacklist): " + blackLicenses );
956+
LOG.info( "Excluded licenses (blacklist): {}", blackLicenses );
965957

966958
for ( String excludeLicense : blackLicenses )
967959
{
@@ -977,20 +969,19 @@ boolean checkForbiddenLicenses()
977969
if ( CollectionUtils.isNotEmpty( whiteLicenses ) )
978970
{
979971
Set<String> dependencyLicenses = licenseMap.keySet();
980-
getLog().info( "Included licenses (whitelist): " + whiteLicenses );
972+
LOG.info( "Included licenses (whitelist): {}", whiteLicenses );
981973

982974
for ( String dependencyLicense : dependencyLicenses )
983975
{
984-
getLog().debug( "Testing license '" + dependencyLicense + "'" );
976+
LOG.debug( "Testing license '{}'", dependencyLicense );
985977
if ( !whiteLicenses.contains( dependencyLicense )
986978
&& CollectionUtils.isNotEmpty( licenseMap.get( dependencyLicense ) ) )
987979
{
988-
getLog().debug( "Testing dependency license '" + dependencyLicense
989-
+ "' against all other licenses" );
980+
LOG.debug( "Testing dependency license '{}' against all other licenses", dependencyLicense );
990981

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

995986
boolean forbiddenLicenseUsed = true;
996987

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

10131004
if ( licenseMap.get( otherLicense ).contains( dependency ) )
10141005
{
1015-
getLog().info( "License: '" + dependencyLicense + "' for '" + dependency + "'is OK "
1016-
+ "since it is also licensed under '" + otherLicense + "'" );
1006+
LOG.info( "License: '{}' for '{}' is OK since it is also licensed under '{}'",
1007+
dependencyLicense,
1008+
dependency,
1009+
otherLicense );
10171010
// this dependency is licensed under another license from white list
10181011
forbiddenLicenseUsed = false;
10191012
break;
@@ -1035,8 +1028,7 @@ boolean checkForbiddenLicenses()
10351028

10361029
if ( !safe )
10371030
{
1038-
Log log = getLog();
1039-
log.warn( "There are " + unsafeLicenses.size() + " forbidden licenses used:" );
1031+
LOG.warn( "There are {} forbidden licenses used:", unsafeLicenses.size() );
10401032
for ( String unsafeLicense : unsafeLicenses )
10411033
{
10421034

@@ -1050,7 +1042,7 @@ boolean checkForbiddenLicenses()
10501042
{
10511043
sb.append( "\n -" ).append( MojoHelper.getArtifactName( dep ) );
10521044
}
1053-
log.warn( sb.toString() );
1045+
LOG.warn( "{}", sb );
10541046
}
10551047
}
10561048
}

0 commit comments

Comments
 (0)