2929import org .apache .maven .artifact .repository .ArtifactRepository ;
3030import org .apache .maven .plugin .MojoExecutionException ;
3131import org .apache .maven .plugin .MojoFailureException ;
32- import org .apache .maven .plugin .logging .Log ;
3332import org .apache .maven .plugins .annotations .Component ;
3433import org .apache .maven .plugins .annotations .Parameter ;
3534import org .apache .maven .project .MavenProject ;
5958import org .codehaus .mojo .license .api .DependenciesToolException ;
6059import org .eclipse .aether .resolution .ArtifactResolutionException ;
6160import 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.
6970public 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,18 +757,18 @@ 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 ]+" ) );
@@ -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