Skip to content

Commit

Permalink
Migrate to JSR330
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 authored and slachiewicz committed Sep 18, 2022
1 parent 484a581 commit a54e87f
Show file tree
Hide file tree
Showing 39 changed files with 575 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,26 @@
* under the License.
*/

import javax.inject.Inject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Parent;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter;
import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
Expand Down Expand Up @@ -137,6 +144,16 @@ public abstract class AbstractVersionsDependencyUpdaterMojo
@Parameter( property = "excludeReactor", defaultValue = "true" )
private boolean excludeReactor;

@Inject
protected AbstractVersionsDependencyUpdaterMojo( RepositorySystem repositorySystem,
MavenProjectBuilder projectBuilder,
ArtifactMetadataSource artifactMetadataSource,
WagonManager wagonManager,
ArtifactResolver artifactResolver )
{
super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver );
}

/**
* Should the project/dependencies section of the pom be processed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import javax.inject.Inject;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -27,7 +29,12 @@
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.repository.RepositorySystem;

/**
* Abstract base class for the Display___ mojos.
Expand Down Expand Up @@ -76,6 +83,16 @@ public abstract class AbstractVersionsDisplayMojo

private boolean outputFileError = false;

@Inject
protected AbstractVersionsDisplayMojo( RepositorySystem repositorySystem,
MavenProjectBuilder projectBuilder,
ArtifactMetadataSource artifactMetadataSource,
WagonManager wagonManager,
ArtifactResolver artifactResolver )
{
super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver );
}

protected void logInit()
{
if ( outputFile != null && !outputFileError )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import javax.inject.Inject;

import java.io.File;
import java.util.List;
import java.util.Locale;
Expand All @@ -37,7 +39,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
Expand All @@ -64,18 +65,10 @@ public abstract class AbstractVersionsReport
*
* @since 1.0-alpha-3
*/
@Component
protected I18N i18n;

@Component
protected RepositorySystem repositorySystem;

/**
* @since 1.0-alpha-3
*/
@Component
private ArtifactResolver resolver;

/**
* Skip entire check.
*
Expand All @@ -89,7 +82,6 @@ public abstract class AbstractVersionsReport
*
* @since 1.0-alpha-1
*/
@Component
protected ArtifactMetadataSource artifactMetadataSource;

/**
Expand All @@ -107,7 +99,6 @@ public abstract class AbstractVersionsReport
/**
* @since 1.0-alpha-3
*/
@Component
private WagonManager wagonManager;

/**
Expand Down Expand Up @@ -168,7 +159,6 @@ public abstract class AbstractVersionsReport
@Parameter( defaultValue = "${mojoExecution}", required = true, readonly = true )
private MojoExecution mojoExecution;

@Component
protected ArtifactResolver artifactResolver;

/**
Expand Down Expand Up @@ -200,6 +190,17 @@ public abstract class AbstractVersionsReport

// --------------------- GETTER / SETTER METHODS ---------------------

@Inject
protected AbstractVersionsReport( I18N i18n, RepositorySystem repositorySystem, ArtifactResolver artifactResolver,
ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager )
{
this.i18n = i18n;
this.repositorySystem = repositorySystem;
this.artifactResolver = artifactResolver;
this.artifactMetadataSource = artifactMetadataSource;
this.wagonManager = wagonManager;
}

public VersionsHelper getHelper()
throws MavenReportException
{
Expand Down Expand Up @@ -359,11 +360,6 @@ public String getComparisonMethod()
return comparisonMethod;
}

public ArtifactResolver getResolver()
{
return resolver;
}

public I18N getI18n()
{
return i18n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import javax.inject.Inject;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;

Expand All @@ -45,7 +46,6 @@
import org.apache.maven.plugin.MojoExecution;
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.MavenProjectBuilder;
Expand Down Expand Up @@ -86,19 +86,11 @@ public abstract class AbstractVersionsUpdaterMojo
@Parameter( defaultValue = "${project}", required = true, readonly = true )
protected MavenProject project;

@Component
protected RepositorySystem repositorySystem;

/**
* @since 1.0-alpha-1
*/
@Component
protected org.apache.maven.artifact.resolver.ArtifactResolver resolver;

/**
* @since 1.0-alpha-1
*/
@Component
protected MavenProjectBuilder projectBuilder;

/**
Expand All @@ -112,7 +104,6 @@ public abstract class AbstractVersionsUpdaterMojo
*
* @since 1.0-alpha-1
*/
@Component
protected ArtifactMetadataSource artifactMetadataSource;

/**
Expand All @@ -136,7 +127,6 @@ public abstract class AbstractVersionsUpdaterMojo
/**
* @since 1.0-alpha-3
*/
@Component
private WagonManager wagonManager;

/**
Expand Down Expand Up @@ -195,7 +185,6 @@ public abstract class AbstractVersionsUpdaterMojo
@Parameter( defaultValue = "${mojoExecution}", required = true, readonly = true )
private MojoExecution mojoExecution;

@Component
protected ArtifactResolver artifactResolver;
/**
* The format used to record changes. If "none" is specified, no changes are recorded.
Expand Down Expand Up @@ -247,6 +236,20 @@ public abstract class AbstractVersionsUpdaterMojo

// --------------------- GETTER / SETTER METHODS ---------------------

@Inject
protected AbstractVersionsUpdaterMojo( RepositorySystem repositorySystem,
MavenProjectBuilder projectBuilder,
ArtifactMetadataSource artifactMetadataSource,
WagonManager wagonManager,
ArtifactResolver artifactResolver )
{
this.repositorySystem = repositorySystem;
this.projectBuilder = projectBuilder;
this.artifactMetadataSource = artifactMetadataSource;
this.wagonManager = wagonManager;
this.artifactResolver = artifactResolver;
}

public VersionsHelper getHelper() throws MojoExecutionException
{
if ( helper == null )
Expand Down Expand Up @@ -526,7 +529,7 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A
artifact.setVersion( updateVersion.toString() );
try
{
resolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository );
artifactResolver.resolveAlways( artifact, remoteArtifactRepositories, localRepository );
}
catch ( ArtifactResolutionException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;

import java.io.File;
Expand All @@ -31,15 +32,18 @@
import java.util.Map;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Dependency;
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.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.mojo.versions.api.ArtifactAssociation;
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.PropertyVersions;
Expand Down Expand Up @@ -112,11 +116,22 @@ public class CompareDependenciesMojo
/**
* The project builder used to initialize the remote project.
*/
@Component
protected MavenProjectBuilder mavenProjectBuilder;

// ------------------------------ METHODS --------------------------

@Inject
public CompareDependenciesMojo( RepositorySystem repositorySystem,
MavenProjectBuilder projectBuilder,
ArtifactMetadataSource artifactMetadataSource,
WagonManager wagonManager,
ArtifactResolver artifactResolver,
MavenProjectBuilder mavenProjectBuilder )
{
super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver );
this.mavenProjectBuilder = mavenProjectBuilder;
}

/**
* @param pom the pom to update.
* @throws org.apache.maven.plugin.MojoExecutionException Something wrong with the plugin itself
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@
* under the License.
*/

import javax.inject.Inject;

import java.io.File;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.reporting.MavenReportException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.mojo.versions.api.ArtifactVersions;
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.codehaus.plexus.i18n.I18N;

import static java.util.Collections.EMPTY_MAP;
import static org.codehaus.mojo.versions.utils.MiscUtils.filter;
Expand Down Expand Up @@ -93,6 +100,13 @@ public class DependencyUpdatesReport extends AbstractVersionsReport
@Parameter( property = "onlyUpgradable", defaultValue = "false" )
protected boolean onlyUpgradable;

@Inject
protected DependencyUpdatesReport( I18N i18n, RepositorySystem repositorySystem, ArtifactResolver artifactResolver,
ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager )
{
super( i18n, repositorySystem, artifactResolver, artifactMetadataSource, wagonManager );
}

/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit a54e87f

Please sign in to comment.