29
29
import org .apache .maven .artifact .repository .ArtifactRepository ;
30
30
import org .apache .maven .plugin .MojoExecutionException ;
31
31
import org .apache .maven .plugin .MojoFailureException ;
32
- import org .apache .maven .plugin .logging .Log ;
33
32
import org .apache .maven .plugins .annotations .Component ;
34
33
import org .apache .maven .plugins .annotations .Parameter ;
35
34
import org .apache .maven .project .MavenProject ;
59
58
import org .codehaus .mojo .license .api .DependenciesToolException ;
60
59
import org .eclipse .aether .resolution .ArtifactResolutionException ;
61
60
import org .eclipse .aether .transfer .ArtifactNotFoundException ;
61
+ import org .slf4j .Logger ;
62
+ import org .slf4j .LoggerFactory ;
62
63
63
64
/**
64
65
* Abstract mojo for all third-party mojos.
69
70
public abstract class AbstractAddThirdPartyMojo
70
71
extends AbstractLicenseMojo
71
72
{
73
+ private static final Logger LOG = LoggerFactory .getLogger ( AbstractAddThirdPartyMojo .class );
72
74
73
75
// ----------------------------------------------------------------------
74
76
// Mojo Parameters
@@ -715,11 +717,8 @@ protected void init()
715
717
throws Exception
716
718
{
717
719
718
- Log log = getLog ();
719
-
720
- if ( log .isDebugEnabled () )
720
+ if ( getLog ().isDebugEnabled () )
721
721
{
722
-
723
722
// always be verbose in debug mode
724
723
setVerbose ( true );
725
724
}
@@ -728,11 +727,8 @@ protected void init()
728
727
729
728
long buildTimestamp = getBuildTimestamp ();
730
729
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 () );
736
732
737
733
doGenerate = force || !thirdPartyFile .exists () || buildTimestamp > thirdPartyFile .lastModified ();
738
734
@@ -741,10 +737,7 @@ protected void init()
741
737
742
738
File bundleFile = FileUtil .getFile ( outputDirectory , bundleThirdPartyPath );
743
739
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 () );
748
741
doGenerateBundle = force || !bundleFile .exists () || buildTimestamp > bundleFile .lastModified ();
749
742
}
750
743
else
@@ -764,26 +757,26 @@ protected void init()
764
757
{
765
758
throw new MojoExecutionException ( "You can't use both licenseMergesFile and licenseMergesUrl" );
766
759
}
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 ( "" );
772
765
licenseMerges = FileUtils .readLines ( new File ( licenseMergesFile ), "utf-8" );
773
766
}
774
767
else if ( licenseMergesUrl != null )
775
768
{
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 ( "" );
779
772
if ( UrlRequester .isStringUrl ( licenseMergesUrl ) )
780
773
{
781
774
licenseMerges = Arrays .asList ( UrlRequester .getFromUrl ( licenseMergesUrl ).split ( "[\n \r ]+" ) );
782
775
}
783
776
}
784
777
785
778
resolvedOverrideUrl = LicenseMojoUtils .prepareThirdPartyOverrideUrl ( resolvedOverrideUrl , overrideFile ,
786
- overrideUrl , project .getBasedir (), getLog () );
779
+ overrideUrl , project .getBasedir () );
787
780
}
788
781
789
782
void consolidate () throws IOException , ArtifactNotFoundException , ArtifactResolutionException , MojoFailureException ,
@@ -874,7 +867,7 @@ protected ThirdPartyHelper getHelper()
874
867
{
875
868
helper = new DefaultThirdPartyHelper ( getProject (), getEncoding (), isVerbose (), dependenciesTool ,
876
869
thirdPartyTool , getProject ().getRemoteArtifactRepositories (),
877
- getProject ().getRemoteProjectRepositories (), getLog () );
870
+ getProject ().getRemoteProjectRepositories () );
878
871
}
879
872
return helper ;
880
873
}
@@ -934,20 +927,19 @@ void checkUnsafeDependencies()
934
927
{
935
928
if ( CollectionUtils .isNotEmpty ( unsafeDependencies ) )
936
929
{
937
- Log log = getLog ();
938
- if ( log .isWarnEnabled () )
930
+ if ( LOG .isWarnEnabled () )
939
931
{
940
932
boolean plural = unsafeDependencies .size () > 1 ;
941
933
String message = String .format ( "There %s %d %s with no license :" ,
942
934
plural ? "are" : "is" ,
943
935
unsafeDependencies .size (),
944
936
plural ? "dependencies" : "dependency" );
945
- log .warn ( message );
937
+ LOG .warn ( message );
946
938
for ( MavenProject dep : unsafeDependencies )
947
939
{
948
940
949
941
// no license found for the dependency
950
- log .warn ( " - " + MojoHelper .getArtifactId ( dep .getArtifact () ) );
942
+ LOG .warn ( " - {}" , MojoHelper .getArtifactId ( dep .getArtifact () ) );
951
943
}
952
944
}
953
945
}
@@ -961,7 +953,7 @@ boolean checkForbiddenLicenses()
961
953
if ( CollectionUtils .isNotEmpty ( blackLicenses ) )
962
954
{
963
955
Set <String > licenses = licenseMap .keySet ();
964
- getLog () .info ( "Excluded licenses (blacklist): " + blackLicenses );
956
+ LOG .info ( "Excluded licenses (blacklist): {}" , blackLicenses );
965
957
966
958
for ( String excludeLicense : blackLicenses )
967
959
{
@@ -977,20 +969,19 @@ boolean checkForbiddenLicenses()
977
969
if ( CollectionUtils .isNotEmpty ( whiteLicenses ) )
978
970
{
979
971
Set <String > dependencyLicenses = licenseMap .keySet ();
980
- getLog () .info ( "Included licenses (whitelist): " + whiteLicenses );
972
+ LOG .info ( "Included licenses (whitelist): {}" , whiteLicenses );
981
973
982
974
for ( String dependencyLicense : dependencyLicenses )
983
975
{
984
- getLog () .debug ( "Testing license '" + dependencyLicense + "'" );
976
+ LOG .debug ( "Testing license '{}'" , dependencyLicense );
985
977
if ( !whiteLicenses .contains ( dependencyLicense )
986
978
&& CollectionUtils .isNotEmpty ( licenseMap .get ( dependencyLicense ) ) )
987
979
{
988
- getLog ().debug ( "Testing dependency license '" + dependencyLicense
989
- + "' against all other licenses" );
980
+ LOG .debug ( "Testing dependency license '{}' against all other licenses" , dependencyLicense );
990
981
991
982
for ( MavenProject dependency : licenseMap .get ( dependencyLicense ) )
992
983
{
993
- getLog () .debug ( " testing dependency " + dependency );
984
+ LOG .debug ( "- testing dependency {} " + dependency );
994
985
995
986
boolean forbiddenLicenseUsed = true ;
996
987
@@ -1012,8 +1003,10 @@ boolean checkForbiddenLicenses()
1012
1003
1013
1004
if ( licenseMap .get ( otherLicense ).contains ( dependency ) )
1014
1005
{
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 );
1017
1010
// this dependency is licensed under another license from white list
1018
1011
forbiddenLicenseUsed = false ;
1019
1012
break ;
@@ -1035,8 +1028,7 @@ boolean checkForbiddenLicenses()
1035
1028
1036
1029
if ( !safe )
1037
1030
{
1038
- Log log = getLog ();
1039
- log .warn ( "There are " + unsafeLicenses .size () + " forbidden licenses used:" );
1031
+ LOG .warn ( "There are {} forbidden licenses used:" , unsafeLicenses .size () );
1040
1032
for ( String unsafeLicense : unsafeLicenses )
1041
1033
{
1042
1034
@@ -1050,7 +1042,7 @@ boolean checkForbiddenLicenses()
1050
1042
{
1051
1043
sb .append ( "\n -" ).append ( MojoHelper .getArtifactName ( dep ) );
1052
1044
}
1053
- log .warn ( sb . toString () );
1045
+ LOG .warn ( "{}" , sb );
1054
1046
}
1055
1047
}
1056
1048
}
0 commit comments