From b5728486af13288096f42f29b59905005ca01294 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Thu, 28 Nov 2024 21:44:35 +0100 Subject: [PATCH] Replace deprecated Component annotation --- .../license/AbstractAddThirdPartyMojo.java | 36 +++++++++---------- .../license/AbstractDownloadLicensesMojo.java | 5 +++ .../mojo/license/AbstractFileHeaderMojo.java | 8 +++-- .../mojo/license/AbstractLicenseMojo.java | 15 ++++---- .../mojo/license/AbstractLicensesXmlMojo.java | 8 +++-- .../license/AbstractThirdPartyReport.java | 26 +++++++------- .../mojo/license/AddThirdPartyMojo.java | 18 ++++++---- .../AggregateDownloadLicensesMojo.java | 8 +++++ .../license/AggregatorAddThirdPartyMojo.java | 16 ++++++--- .../license/AggregatorThirdPartyReport.java | 12 +++++++ .../mojo/license/CheckFileHeaderMojo.java | 10 ++++++ .../mojo/license/CommentStyleListMojo.java | 11 ++++-- .../mojo/license/DownloadLicensesMojo.java | 8 +++++ .../LicensesXmlInsertVersionsMojo.java | 8 +++++ .../mojo/license/RemoveFileHeaderMojo.java | 11 ++++-- .../mojo/license/ThirdPartyReport.java | 11 ++++++ .../mojo/license/UpdateFileHeaderMojo.java | 10 ++++++ .../license/api/DefaultThirdPartyTool.java | 23 +++++++----- .../mojo/license/api/ThirdPartyTool.java | 5 --- 19 files changed, 174 insertions(+), 75 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java index aed15b59e..dcabf9389 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java @@ -39,7 +39,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; @@ -600,8 +599,7 @@ public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo { * * @since 1.0 */ - @Component - ThirdPartyTool thirdPartyTool; + final ThirdPartyTool thirdPartyTool; /** * Dependencies tool. (pluggable component to find dependencies that match up with @@ -609,8 +607,7 @@ public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo { * * @since 1.1 */ - @Component - DependenciesTool dependenciesTool; + final DependenciesTool dependenciesTool; // ---------------------------------------------------------------------- // Private fields @@ -669,6 +666,11 @@ public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo { @Parameter(property = "license.artifactFiltersUrl") protected String artifactFiltersUrl; + protected AbstractAddThirdPartyMojo(ThirdPartyTool thirdPartyTool, DependenciesTool dependenciesTool) { + this.thirdPartyTool = thirdPartyTool; + this.dependenciesTool = dependenciesTool; + } + // ---------------------------------------------------------------------- // Abstract Methods // ---------------------------------------------------------------------- @@ -860,7 +862,7 @@ void resolveUnsafeDependenciesFromArtifact(String groupId, String artifactId, St resolveUnsafeDependenciesFromFile(missingLicensesFromArtifact); } - void resolveUnsafeDependenciesFromFile(File missingLicenses) throws IOException, MojoExecutionException { + void resolveUnsafeDependenciesFromFile(File missingLicenses) throws IOException { if (missingLicenses == null) { return; } @@ -897,18 +899,16 @@ void resolveUnsafeDependenciesFromFile(File missingLicenses) throws IOException, } void checkUnsafeDependencies() { - if (CollectionUtils.isNotEmpty(unsafeDependencies)) { - 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); - for (MavenProject dep : unsafeDependencies) { - - // no license found for the dependency - LOG.warn(" - {}", MojoHelper.getArtifactId(dep.getArtifact())); - } + if (CollectionUtils.isNotEmpty(unsafeDependencies) && 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); + for (MavenProject dep : unsafeDependencies) { + + // no license found for the dependency + LOG.warn(" - {}", MojoHelper.getArtifactId(dep.getArtifact())); } } } diff --git a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java index 15a6b096e..1ac52cb40 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractDownloadLicensesMojo.java @@ -63,6 +63,7 @@ import org.codehaus.mojo.license.download.LicenseMatchers; import org.codehaus.mojo.license.download.LicenseSummaryReader; import org.codehaus.mojo.license.download.LicensedArtifact; +import org.codehaus.mojo.license.download.LicensedArtifactResolver; import org.codehaus.mojo.license.download.PreferredFileNames; import org.codehaus.mojo.license.download.ProjectLicense; import org.codehaus.mojo.license.download.ProjectLicenseInfo; @@ -778,6 +779,10 @@ public abstract class AbstractDownloadLicensesMojo extends AbstractLicensesXmlMo private UrlReplacements urlReplacements; + protected AbstractDownloadLicensesMojo(LicensedArtifactResolver licensedArtifactResolver) { + super(licensedArtifactResolver); + } + protected abstract boolean isSkip(); protected MavenProject getProject() { diff --git a/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java index 78ba9d0be..44d9f786a 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractFileHeaderMojo.java @@ -40,7 +40,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.mojo.license.api.FreeMarkerHelper; import org.codehaus.mojo.license.header.FileHeader; @@ -328,8 +327,7 @@ public abstract class AbstractFileHeaderMojo extends AbstractLicenseNameMojo { * * @since 1.0 */ - @Component(role = FileHeaderTransformer.class) - private Map transformers; + private final Map transformers; // ---------------------------------------------------------------------- // Private fields @@ -376,6 +374,10 @@ public abstract class AbstractFileHeaderMojo extends AbstractLicenseNameMojo { */ private FreeMarkerHelper freeMarkerHelper = FreeMarkerHelper.newDefaultHelper(); + protected AbstractFileHeaderMojo(Map transformers) { + this.transformers = transformers; + } + // ---------------------------------------------------------------------- // Abstract Methods // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java index 683318d3f..65316ad25 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java @@ -23,6 +23,7 @@ */ import java.io.File; +import java.nio.charset.Charset; import org.apache.commons.lang3.StringUtils; import org.apache.maven.plugin.AbstractMojo; @@ -31,7 +32,6 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.license.utils.MojoHelper; -import org.codehaus.plexus.util.ReaderFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -150,9 +150,7 @@ public final void execute() throws MojoExecutionException, MojoFailureException init(); - } catch (MojoFailureException e) { - throw e; - } catch (MojoExecutionException e) { + } catch (MojoFailureException | MojoExecutionException e) { throw e; } catch (Exception e) { throw new MojoExecutionException( @@ -169,9 +167,7 @@ public final void execute() throws MojoExecutionException, MojoFailureException try { doAction(); - } catch (MojoFailureException e) { - throw e; - } catch (MojoExecutionException e) { + } catch (MojoFailureException | MojoExecutionException e) { throw e; } catch (Exception e) { throw new MojoExecutionException( @@ -320,10 +316,11 @@ protected void checkEncoding() { LOG.info("Will check encoding: {}", getEncoding()); } if (StringUtils.isEmpty(getEncoding())) { + String sysEncoding = Charset.defaultCharset().displayName(); LOG.warn( "File encoding has not been set, using platform encoding {}, i.e. build is platform dependent!", - ReaderFactory.FILE_ENCODING); - setEncoding(ReaderFactory.FILE_ENCODING); + sysEncoding); + setEncoding(sysEncoding); } } diff --git a/src/main/java/org/codehaus/mojo/license/AbstractLicensesXmlMojo.java b/src/main/java/org/codehaus/mojo/license/AbstractLicensesXmlMojo.java index b77b007d4..233e12d24 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractLicensesXmlMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractLicensesXmlMojo.java @@ -34,7 +34,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.license.download.LicenseSummaryWriter; @@ -106,11 +105,14 @@ public abstract class AbstractLicensesXmlMojo extends AbstractMojo { * * @since 1.0 */ - @Component - protected LicensedArtifactResolver licensedArtifactResolver; + protected final LicensedArtifactResolver licensedArtifactResolver; private Charset charset; + protected AbstractLicensesXmlMojo(LicensedArtifactResolver licensedArtifactResolver) { + this.licensedArtifactResolver = licensedArtifactResolver; + } + /** {@inheritDoc} */ public String getEncoding() { initEncoding(); diff --git a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReport.java b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReport.java index adb6e93a7..326209438 100644 --- a/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReport.java +++ b/src/main/java/org/codehaus/mojo/license/AbstractThirdPartyReport.java @@ -40,7 +40,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; @@ -227,9 +226,9 @@ public abstract class AbstractThirdPartyReport extends AbstractMavenReport private String overrideUrl; /** - * A {@link URL} prepared either our of {@link #overrideFile} or {@link #overrideUrl} or the default value. + * A URL 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; @@ -300,24 +299,21 @@ public abstract class AbstractThirdPartyReport extends AbstractMavenReport * * @since 1.1 */ - @Component - private I18N i18n; + private final I18N i18n; /** * dependencies tool. * * @since 1.1 */ - @Component - private DependenciesTool dependenciesTool; + private final DependenciesTool dependenciesTool; /** * third party tool. * * @since 1.1 */ - @Component - private ThirdPartyTool thirdPartyTool; + private final ThirdPartyTool thirdPartyTool; /** * A URL returning a plain text file that contains include/exclude artifact filters in the following format: @@ -341,6 +337,12 @@ public abstract class AbstractThirdPartyReport extends AbstractMavenReport private ArtifactFilters artifactFilters; + protected AbstractThirdPartyReport(I18N i18n, DependenciesTool dependenciesTool, ThirdPartyTool thirdPartyTool) { + this.i18n = i18n; + this.dependenciesTool = dependenciesTool; + this.thirdPartyTool = thirdPartyTool; + } + // ---------------------------------------------------------------------- // Protected Abstract Methods // ---------------------------------------------------------------------- @@ -396,7 +398,7 @@ protected void executeReport(Locale locale) throws MavenReportException { } ThirdPartyReportRenderer renderer = - new ThirdPartyReportRenderer(getSink(), i18n, getOutputName(), locale, details); + new ThirdPartyReportRenderer(getSink(), i18n, getOutputPath(), locale, details); renderer.render(); } @@ -405,7 +407,7 @@ protected void executeReport(Locale locale) throws MavenReportException { */ @Override public String getDescription(Locale locale) { - return i18n.getString(getOutputName(), locale, "report.description"); + return i18n.getString(getOutputPath(), locale, "report.description"); } /** @@ -413,7 +415,7 @@ public String getDescription(Locale locale) { */ @Override public String getName(Locale locale) { - return i18n.getString(getOutputName(), locale, "report.title"); + return i18n.getString(getOutputPath(), locale, "report.title"); } // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java index 6482b6cad..526fbde0d 100644 --- a/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -43,9 +45,11 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; import org.codehaus.mojo.license.api.ArtifactFilters; +import org.codehaus.mojo.license.api.DependenciesTool; import org.codehaus.mojo.license.api.DependenciesToolException; import org.codehaus.mojo.license.api.MavenProjectDependenciesConfigurator; import org.codehaus.mojo.license.api.ResolvedProjectDependencies; +import org.codehaus.mojo.license.api.ThirdPartyTool; import org.codehaus.mojo.license.api.ThirdPartyToolException; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.MojoHelper; @@ -121,6 +125,11 @@ public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo implements Mave private ArtifactFilters artifactFilters; + @Inject + public AddThirdPartyMojo(ThirdPartyTool thirdPartyTool, DependenciesTool dependenciesTool) { + super(thirdPartyTool, dependenciesTool); + } + // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementaton // ---------------------------------------------------------------------- @@ -354,7 +363,7 @@ private boolean computeDoGenerateMissingFile( } /** - * Write the missing file ({@link #getMissingFile()}. + * Write the missing file. * * @throws IOException if error while writing missing file */ @@ -363,8 +372,7 @@ private void writeMissingFile() throws IOException { Files.createDirectories(missingFile.getParentFile().toPath()); LOG.info("Regenerate missing license file {}", missingFile); - FileOutputStream writer = new FileOutputStream(missingFile); - try { + try (FileOutputStream writer = new FileOutputStream(missingFile)) { StringBuilder sb = new StringBuilder(" Generated by " + getClass().getName()); List licenses = new ArrayList<>(licenseMap.keySet()); licenses.remove(LicenseMap.UNKNOWN_LICENSE_MESSAGE); @@ -378,8 +386,6 @@ private void writeMissingFile() throws IOException { sb.append("\n-------------------------------------------------------------------------------"); sb.append("\n Please fill the missing licenses for dependencies :\n\n"); unsafeMappings.store(writer, sb.toString()); - } finally { - writer.close(); } } @@ -420,8 +426,6 @@ void initFromMojo(AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject) t fileTemplate = mojo.fileTemplate; verbose = mojo.verbose; encoding = mojo.encoding; - thirdPartyTool = mojo.thirdPartyTool; - dependenciesTool = mojo.dependenciesTool; setLog(mojo.getLog()); diff --git a/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java index 6c2aecc47..59704f201 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregateDownloadLicensesMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -33,6 +35,7 @@ import org.apache.maven.project.MavenProject; import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.download.LicensedArtifact; +import org.codehaus.mojo.license.download.LicensedArtifactResolver; import org.codehaus.mojo.license.utils.MojoHelper; /** @@ -108,6 +111,11 @@ public class AggregateDownloadLicensesMojo extends AbstractDownloadLicensesMojo @Parameter(property = "license.extendedInfo", defaultValue = "false") private boolean extendedInfo; + @Inject + public AggregateDownloadLicensesMojo(LicensedArtifactResolver licensedArtifactResolver) { + super(licensedArtifactResolver); + } + // ---------------------------------------------------------------------- // AbstractDownloadLicensesMojo Implementation // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java index f36f6ebe7..8c0e619b6 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorAddThirdPartyMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.util.List; @@ -40,6 +42,8 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.mojo.license.api.DependenciesTool; +import org.codehaus.mojo.license.api.ThirdPartyTool; import org.codehaus.mojo.license.model.LicenseMap; import org.codehaus.mojo.license.utils.SortedProperties; import org.slf4j.Logger; @@ -107,6 +111,11 @@ public class AggregatorAddThirdPartyMojo extends AbstractAddThirdPartyMojo { @Parameter(property = "license.aggregateMissingLicensesFile") private File aggregateMissingLicensesFile; + @Inject + public AggregatorAddThirdPartyMojo(ThirdPartyTool thirdPartyTool, DependenciesTool dependenciesTool) { + super(thirdPartyTool, dependenciesTool); + } + // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementaton // ---------------------------------------------------------------------- @@ -168,14 +177,13 @@ protected void doAction() throws Exception { licenseMap = new LicenseMap(); - Artifact pluginArtifact = - (Artifact) project.getPluginArtifactMap().get("org.codehaus.mojo:license-maven-plugin"); + Artifact pluginArtifact = project.getPluginArtifactMap().get("org.codehaus.mojo:license-maven-plugin"); String groupId = null; String artifactId = null; String version = null; if (pluginArtifact == null) { - Plugin plugin = (Plugin) + Plugin plugin = project.getPluginManagement().getPluginsAsMap().get("org.codehaus.mojo:license-maven-plugin"); if (plugin != null) { groupId = plugin.getGroupId(); @@ -214,7 +222,7 @@ protected void doAction() throws Exception { continue; } - AddThirdPartyMojo mojo = new AddThirdPartyMojo(); + AddThirdPartyMojo mojo = new AddThirdPartyMojo(thirdPartyTool, dependenciesTool); mojo.initFromMojo(this, reactorProject); LicenseMap childLicenseMap = mojo.licenseMap; diff --git a/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReport.java b/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReport.java index 4f2e61936..a0d37370f 100644 --- a/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReport.java +++ b/src/main/java/org/codehaus/mojo/license/AggregatorThirdPartyReport.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.io.IOException; import java.util.Collection; import java.util.LinkedHashSet; @@ -33,9 +35,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.mojo.license.api.DependenciesTool; import org.codehaus.mojo.license.api.DependenciesToolException; import org.codehaus.mojo.license.api.ThirdPartyDetails; +import org.codehaus.mojo.license.api.ThirdPartyTool; import org.codehaus.mojo.license.api.ThirdPartyToolException; +import org.codehaus.plexus.i18n.I18N; /** * Generates a report of all third-parties detected in the module. @@ -73,6 +78,11 @@ public class AggregatorThirdPartyReport extends AbstractThirdPartyReport { defaultValue = "true") private boolean executeOnlyOnRootModule; + @Inject + public AggregatorThirdPartyReport(I18N i18n, DependenciesTool dependenciesTool, ThirdPartyTool thirdPartyTool) { + super(i18n, dependenciesTool, thirdPartyTool); + } + // ---------------------------------------------------------------------- // MavenReport Implementaton // ---------------------------------------------------------------------- @@ -80,6 +90,8 @@ public class AggregatorThirdPartyReport extends AbstractThirdPartyReport { /** * {@inheritDoc} */ + @Override + @Deprecated public String getOutputName() { return "aggregate-third-party-report"; } diff --git a/src/main/java/org/codehaus/mojo/license/CheckFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/CheckFileHeaderMojo.java index de6e05fc2..a1bcd840d 100644 --- a/src/main/java/org/codehaus/mojo/license/CheckFileHeaderMojo.java +++ b/src/main/java/org/codehaus/mojo/license/CheckFileHeaderMojo.java @@ -22,8 +22,13 @@ * #L% */ +import javax.inject.Inject; + +import java.util.Map; + import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer; /** * The goal to check if the state of header on project source files. @@ -62,6 +67,11 @@ public class CheckFileHeaderMojo extends AbstractFileHeaderMojo { @Parameter(property = "license.skipCheckLicense", defaultValue = "false") private boolean skipCheckLicense; + @Inject + public CheckFileHeaderMojo(Map transformers) { + super(transformers); + } + // ---------------------------------------------------------------------- // AbstractLicenseFileNameMojo Implementation // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java b/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java index dc10229c8..60d2afbbe 100644 --- a/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java +++ b/src/main/java/org/codehaus/mojo/license/CommentStyleListMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -30,7 +32,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer; @@ -68,8 +69,12 @@ public class CommentStyleListMojo extends AbstractLicenseMojo { * * @since 1.0 */ - @Component(role = FileHeaderTransformer.class) - private Map transformers; + private final Map transformers; + + @Inject + public CommentStyleListMojo(Map transformers) { + this.transformers = transformers; + } // ---------------------------------------------------------------------- // AbstractLicenseMojo Implementation diff --git a/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java b/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java index 34a059510..da3b3c231 100644 --- a/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java +++ b/src/main/java/org/codehaus/mojo/license/DownloadLicensesMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.util.Map; import java.util.TreeMap; @@ -31,6 +33,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.download.LicensedArtifact; +import org.codehaus.mojo.license.download.LicensedArtifactResolver; import org.codehaus.mojo.license.utils.MojoHelper; /** @@ -71,6 +74,11 @@ public class DownloadLicensesMojo extends AbstractDownloadLicensesMojo { @Parameter(property = "license.skipDownloadLicenses", defaultValue = "false") protected boolean skipDownloadLicenses; + @Inject + public DownloadLicensesMojo(LicensedArtifactResolver licensedArtifactResolver) { + super(licensedArtifactResolver); + } + // ---------------------------------------------------------------------- // AbstractDownloadLicensesMojo Implementation // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java b/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java index fe1fae60d..1071a4c5e 100644 --- a/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java +++ b/src/main/java/org/codehaus/mojo/license/LicensesXmlInsertVersionsMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -41,6 +43,7 @@ import org.codehaus.mojo.license.api.ResolvedProjectDependencies; import org.codehaus.mojo.license.download.LicenseSummaryReader; import org.codehaus.mojo.license.download.LicensedArtifact; +import org.codehaus.mojo.license.download.LicensedArtifactResolver; import org.codehaus.mojo.license.download.ProjectLicenseInfo; import org.codehaus.mojo.license.utils.MojoHelper; import org.slf4j.Logger; @@ -76,6 +79,11 @@ public class LicensesXmlInsertVersionsMojo extends AbstractLicensesXmlMojo { @Parameter(property = "license.skipDownloadLicenses", defaultValue = "false") private boolean skipDownloadLicenses; + @Inject + public LicensesXmlInsertVersionsMojo(LicensedArtifactResolver licensedArtifactResolver) { + super(licensedArtifactResolver); + } + public void execute() throws MojoExecutionException, MojoFailureException { if (skipDownloadLicenses) { diff --git a/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java index c0eb09b9b..7ad337f39 100644 --- a/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java +++ b/src/main/java/org/codehaus/mojo/license/RemoveFileHeaderMojo.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -36,7 +38,6 @@ import freemarker.template.Template; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer; @@ -186,8 +187,7 @@ public class RemoveFileHeaderMojo extends AbstractLicenseNameMojo { * * @since 1.0 */ - @Component(role = FileHeaderTransformer.class) - private Map transformers; + private final Map transformers; // ---------------------------------------------------------------------- // Private fields @@ -220,6 +220,11 @@ public class RemoveFileHeaderMojo extends AbstractLicenseNameMojo { */ private Map> filesToTreatByCommentStyle; + @Inject + public RemoveFileHeaderMojo(Map transformers) { + this.transformers = transformers; + } + // ---------------------------------------------------------------------- // AbstractLicenceMojo Implementation // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/ThirdPartyReport.java b/src/main/java/org/codehaus/mojo/license/ThirdPartyReport.java index 52e7f1497..0125922bd 100644 --- a/src/main/java/org/codehaus/mojo/license/ThirdPartyReport.java +++ b/src/main/java/org/codehaus/mojo/license/ThirdPartyReport.java @@ -22,6 +22,8 @@ * #L% */ +import javax.inject.Inject; + import java.io.IOException; import java.util.Collection; @@ -31,9 +33,12 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.ProjectBuildingException; +import org.codehaus.mojo.license.api.DependenciesTool; import org.codehaus.mojo.license.api.DependenciesToolException; import org.codehaus.mojo.license.api.ThirdPartyDetails; +import org.codehaus.mojo.license.api.ThirdPartyTool; import org.codehaus.mojo.license.api.ThirdPartyToolException; +import org.codehaus.plexus.i18n.I18N; /** * Generates a report of all third-parties detected in the module. @@ -56,6 +61,11 @@ public class ThirdPartyReport extends AbstractThirdPartyReport { @Parameter(property = "license.skipThirdPartyReport", defaultValue = "false") private boolean skipThirdPartyReport; + @Inject + public ThirdPartyReport(I18N i18n, DependenciesTool dependenciesTool, ThirdPartyTool thirdPartyTool) { + super(i18n, dependenciesTool, thirdPartyTool); + } + // ---------------------------------------------------------------------- // MavenReport Implementaton // ---------------------------------------------------------------------- @@ -63,6 +73,7 @@ public class ThirdPartyReport extends AbstractThirdPartyReport { /** * {@inheritDoc} */ + @Deprecated public String getOutputName() { return "third-party-report"; } diff --git a/src/main/java/org/codehaus/mojo/license/UpdateFileHeaderMojo.java b/src/main/java/org/codehaus/mojo/license/UpdateFileHeaderMojo.java index 0dacd5a6a..9cdbf4556 100644 --- a/src/main/java/org/codehaus/mojo/license/UpdateFileHeaderMojo.java +++ b/src/main/java/org/codehaus/mojo/license/UpdateFileHeaderMojo.java @@ -22,8 +22,13 @@ * #L% */ +import javax.inject.Inject; + +import java.util.Map; + import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.mojo.license.header.transformer.FileHeaderTransformer; /** * The goal to update (or add) the header on project source files. @@ -82,6 +87,11 @@ public class UpdateFileHeaderMojo extends AbstractFileHeaderMojo { @Parameter(property = "dryRun", defaultValue = "false") private boolean dryRun; + @Inject + public UpdateFileHeaderMojo(Map transformers) { + super(transformers); + } + // ---------------------------------------------------------------------- // AbstractLicenceMojo Implementation // ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java index 42c17d337..140e76f19 100644 --- a/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/DefaultThirdPartyTool.java @@ -114,17 +114,14 @@ public class DefaultThirdPartyTool implements ThirdPartyTool { /** * Maven Artifact Resolver repoSystem */ - @Inject - private RepositorySystem aetherRepoSystem; + private final RepositorySystem aetherRepoSystem; - @Inject - private Provider mavenSessionProvider; + private final Provider mavenSessionProvider; /** * Maven ProjectHelper. */ - @Inject - private MavenProjectHelper projectHelper; + private final MavenProjectHelper projectHelper; /** * freeMarker helper. @@ -138,6 +135,16 @@ public class DefaultThirdPartyTool implements ThirdPartyTool { private boolean verbose; + @Inject + DefaultThirdPartyTool( + RepositorySystem aetherRepoSystem, + Provider mavenSessionProvider, + MavenProjectHelper projectHelper) { + this.aetherRepoSystem = aetherRepoSystem; + this.mavenSessionProvider = mavenSessionProvider; + this.projectHelper = projectHelper; + } + /** * {@inheritDoc} */ @@ -657,8 +664,8 @@ private void loadOneGlobalSet( // ---------------------------------------------------------------------- /** - * @param project not null - * @param remoteRepositories not null + * @param project not null + * @param remoteRepositories not null * @return the resolved third party descriptor * @throws ArtifactResolutionException if any */ diff --git a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java index 98e7eba61..0f98eb8af 100644 --- a/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java +++ b/src/main/java/org/codehaus/mojo/license/api/ThirdPartyTool.java @@ -50,11 +50,6 @@ */ public interface ThirdPartyTool { - /** - * Plexus Role. - */ - String ROLE = ThirdPartyTool.class.getName(); - /** * Is log should be verbose? *