Skip to content

Commit

Permalink
Get rid usage of MavenSession#lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Dec 28, 2023
1 parent ec65730 commit 1a8446b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo {
* @since 1.0
*/
@Component
private ThirdPartyTool thirdPartyTool;
ThirdPartyTool thirdPartyTool;

/**
* Dependencies tool. (pluggable component to find dependencies that match up with
Expand All @@ -610,7 +610,7 @@ public abstract class AbstractAddThirdPartyMojo extends AbstractLicenseMojo {
* @since 1.1
*/
@Component
protected DependenciesTool dependenciesTool;
DependenciesTool dependenciesTool;

// ----------------------------------------------------------------------
// Private fields
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/codehaus/mojo/license/AbstractLicenseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -71,14 +70,6 @@ public abstract class AbstractLicenseMojo extends AbstractMojo {
@Parameter(property = "license.encoding", defaultValue = "${project.build.sourceEncoding}")
String encoding;

/**
* Current maven session. (used to launch certain mojo once by build).
*
* @since 1.0
*/
@Parameter(defaultValue = "${session}", readonly = true)
MavenSession session;

/**
* The reacted project.
*
Expand Down Expand Up @@ -234,13 +225,6 @@ public final void setVerbose(boolean verbose) {
this.verbose = verbose;
}

/**
* @return the {@link MavenSession}.
*/
public final MavenSession getSession() {
return session;
}

// ----------------------------------------------------------------------
// Protected Methods
// ----------------------------------------------------------------------
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/org/codehaus/mojo/license/AddThirdPartyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ public class AddThirdPartyMojo extends AbstractAddThirdPartyMojo implements Mave
*/
private boolean doGenerateMissing;

/**
* The reactor projects. When resolving dependencies, the aggregator goal needs to do custom handling
* of sibling dependencies for projects in the reactor,
* to avoid trying to load artifacts for projects that haven't been built/published yet.
*/
private List<MavenProject> reactorProjectDependencies;

/**
* Copies of the project's dependency sets. AddThirdParty needs to load dependencies only for the single project it
* is run for, while AggregateAddThirdParty needs to load dependencies for the parent project, as well as all child
Expand Down Expand Up @@ -378,8 +371,7 @@ private void writeMissingFile() throws IOException {
}

// magic method - to refactor
void initFromMojo(AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject, List<MavenProject> reactorProjects)
throws Exception {
void initFromMojo(AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject) throws Exception {
project = mavenProject;
deployMissingFile = mojo.deployMissingFile;
useRepositoryMissingFiles = mojo.useRepositoryMissingFiles;
Expand Down Expand Up @@ -413,14 +405,13 @@ void initFromMojo(AggregatorAddThirdPartyMojo mojo, MavenProject mavenProject, L
failOnBlacklist = mojo.failOnBlacklist;
sortArtifactByName = mojo.sortArtifactByName;
fileTemplate = mojo.fileTemplate;
session = mojo.session;
verbose = mojo.verbose;
encoding = mojo.encoding;
thirdPartyTool = mojo.thirdPartyTool;
dependenciesTool = mojo.dependenciesTool;

setLog(mojo.getLog());

reactorProjectDependencies = reactorProjects;

// magic used by AggregatorAddThirdPartyMojo - only by build dependencies map for child projects
// so actions in init should be always executed
force = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
Expand Down Expand Up @@ -215,10 +214,8 @@ protected void doAction() throws Exception {
continue;
}

AddThirdPartyMojo mojo =
(AddThirdPartyMojo) getSession().lookup(AddThirdPartyMojo.ROLE, addThirdPartyRoleHint);

mojo.initFromMojo(this, reactorProject, new ArrayList<>(this.reactorProjects));
AddThirdPartyMojo mojo = new AddThirdPartyMojo();
mojo.initFromMojo(this, reactorProject);

LicenseMap childLicenseMap = mojo.licenseMap;
if (isVerbose()) {
Expand Down

0 comments on commit 1a8446b

Please sign in to comment.