Skip to content

Commit

Permalink
Switch components to JSR-330, Require JDK 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Jul 1, 2023
1 parent 1c8fab2 commit 6c9d391
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 99 deletions.
28 changes: 5 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
</roles>
</developer>
</developers>

<contributors>
<contributor>
<name>Curtis Rueden</name>
Expand Down Expand Up @@ -106,8 +107,7 @@

<properties>
<mavenVersion>3.5.4</mavenVersion>
<mojo.java.target>7</mojo.java.target>
<minimalJavaBuildVersion>1.7</minimalJavaBuildVersion>
<mojo.java.target>8</mojo.java.target>

<processorVersion>1.3</processorVersion>

Expand Down Expand Up @@ -245,12 +245,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
<version>${plexusComponentVersion}</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down Expand Up @@ -322,11 +316,6 @@
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>${plexusComponentVersion}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand All @@ -341,8 +330,8 @@
</plugin>
</plugins>
</pluginManagement>
<plugins>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down Expand Up @@ -381,15 +370,8 @@
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
</executions>
<groupId>org.eclipse.sisu</groupId>
<artifactId>sisu-maven-plugin</artifactId>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* #L%
*/

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -48,7 +53,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.License;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.mojo.license.LicenseMojoUtils;
Expand All @@ -57,8 +61,7 @@
import org.codehaus.mojo.license.utils.MojoHelper;
import org.codehaus.mojo.license.utils.SortedProperties;
import org.codehaus.mojo.license.utils.UrlRequester;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.artifact.DefaultArtifactType;
Expand All @@ -76,7 +79,8 @@
* @author <a href="mailto:tchemit@codelutin.com">Tony Chemit</a>
* @version $Id$
*/
@Component( role = ThirdPartyTool.class, hint = "default" )
@Named
@Singleton
public class DefaultThirdPartyTool
implements ThirdPartyTool
{
Expand Down Expand Up @@ -112,22 +116,22 @@ public class DefaultThirdPartyTool
/**
* Maven Artifact Resolver repoSystem
*/
@Requirement
private org.eclipse.aether.RepositorySystem aetherRepoSystem;
@Inject
private RepositorySystem aetherRepoSystem;

@Requirement
private MavenSession mavenSession;
@Inject
private Provider<MavenSession> mavenSessionProvider;

/**
* Maven ProjectHelper.
*/
@Requirement
@Inject
private MavenProjectHelper projectHelper;

/**
* freeMarker helper.
*/
private FreeMarkerHelper freeMarkerHelper = FreeMarkerHelper.newDefaultHelper();
private final FreeMarkerHelper freeMarkerHelper = FreeMarkerHelper.newDefaultHelper();

/**
* Maven project comparator.
Expand Down Expand Up @@ -247,16 +251,13 @@ public SortedProperties loadThirdPartyDescriptorsForUnsafeMapping( Set<Artifact>
}

}

try
{
loadGlobalLicenses( topLevelDependencies, remoteRepositories, unsafeDependencies,
licenseMap, unsafeProjects, result );
}
catch ( ArtifactNotFoundException e )
{
throw new ThirdPartyToolException( "Failed to load global licenses", e );
}
catch ( ArtifactResolutionException e )
catch ( ArtifactNotFoundException | ArtifactResolutionException e )
{
throw new ThirdPartyToolException( "Failed to load global licenses", e );
}
Expand Down Expand Up @@ -312,21 +313,11 @@ public File resolvThirdPartyDescriptor( MavenProject project, List<RemoteReposit
{
return resolveThirdPartyDescriptor( project, remoteRepositories );
}
catch ( ArtifactNotFoundException e )
{
LOG.debug( "ArtifactNotFoundException: Unable to locate third party descriptor", e );
return null;
}
catch ( ArtifactResolutionException e )
{
throw new ThirdPartyToolException(
"ArtifactResolutionException: Unable to locate third party descriptor: " + e.getMessage(), e );
}
catch ( IOException e )
{
throw new ThirdPartyToolException(
"IOException: Unable to locate third party descriptor: " + e.getMessage(), e );
}
}

/**
Expand Down Expand Up @@ -454,8 +445,7 @@ public SortedProperties loadUnsafeMapping( LicenseMap licenseMap,
SortedMap<String, MavenProject> artifactCache,
String encoding,
File missingFile,
String missingFileUrl ) throws IOException, MojoExecutionException
{
String missingFileUrl ) throws IOException {
Map<String, MavenProject> snapshots = new HashMap<>();

synchronized ( artifactCache )
Expand Down Expand Up @@ -712,7 +702,7 @@ private void loadOneGlobalSet( SortedSet<MavenProject> unsafeDependencies, Licen
Map<String, MavenProject> unsafeProjects, Artifact dep,
List<RemoteRepository> remoteRepositories,
SortedProperties result )
throws IOException, ArtifactNotFoundException, ArtifactResolutionException
throws IOException, ArtifactResolutionException
{
File propFile = resolveArtifact( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getType(),
dep.getClassifier(), remoteRepositories );
Expand Down Expand Up @@ -745,15 +735,12 @@ private void loadOneGlobalSet( SortedSet<MavenProject> unsafeDependencies, Licen

/**
* @param project not null
* @param localRepository not null
* @param repositories not null
* @return the resolved site descriptor
* @throws IOException if any
* @param remoteRepositories not null
* @return the resolved third party descriptor
* @throws ArtifactResolutionException if any
* @throws ArtifactNotFoundException if any
*/
private File resolveThirdPartyDescriptor( MavenProject project, List<RemoteRepository> remoteRepositories )
throws IOException, ArtifactResolutionException, ArtifactNotFoundException
throws ArtifactResolutionException
{
File result;
try
Expand Down Expand Up @@ -792,7 +779,7 @@ private File resolveThirdPartyDescriptor( MavenProject project, List<RemoteRepos
* repository, because the parent was already released
* (and snapshots are updated automatically if changed)
*/
RepositorySystemSession aetherSession = mavenSession.getRepositorySession();
RepositorySystemSession aetherSession = mavenSessionProvider.get().getRepositorySession();
result = new File( aetherSession.getLocalRepository().getBasedir(),
aetherSession.getLocalRepositoryManager().getPathForLocalArtifact( artifact ) );
}
Expand Down Expand Up @@ -823,7 +810,7 @@ private File resolveArtifact( String groupId, String artifactId, String version,
ArtifactRequest artifactRequest = new ArtifactRequest()
.setArtifact( artifact2 )
.setRepositories( remoteRepositories );
ArtifactResult result = aetherRepoSystem.resolveArtifact( mavenSession.getRepositorySession(),
ArtifactResult result = aetherRepoSystem.resolveArtifact( mavenSessionProvider.get().getRepositorySession(),
artifactRequest );

return result.getArtifact().getFile();
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/org/codehaus/mojo/license/api/DependenciesTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
* #L%
*/

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.mojo.license.utils.MojoHelper;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,7 +53,8 @@
* @author tchemit dev@tchemit.fr
* @since 1.0
*/
@Component( role = DependenciesTool.class, hint = "default" )
@Named
@Singleton
public class DependenciesTool
{
private static final Logger LOG = LoggerFactory.getLogger( DependenciesTool.class );
Expand All @@ -64,11 +68,11 @@ public class DependenciesTool
/**
* Project builder.
*/
@Requirement
@Inject
private ProjectBuilder mavenProjectBuilder;

@Requirement
private MavenSession mavenSession;
@Inject
private Provider<MavenSession> mavenSessionProvider;

// CHECKSTYLE_OFF: MethodLength
/**
Expand Down Expand Up @@ -123,7 +127,7 @@ public SortedMap<String, MavenProject> loadProjectDependencies( ResolvedProjectD
}
}
ProjectBuildingRequest projectBuildingRequest
= new DefaultProjectBuildingRequest( mavenSession.getProjectBuildingRequest() )
= new DefaultProjectBuildingRequest( mavenSessionProvider.get().getProjectBuildingRequest() )
.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL )
//We already have the relevant part of the dependency tree
//Re-resolving risks including e.g. excluded artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* #L%
*/

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -41,8 +46,6 @@
import org.codehaus.mojo.license.api.MavenProjectDependenciesConfigurator;
import org.codehaus.mojo.license.api.ResolvedProjectDependencies;
import org.codehaus.mojo.license.download.LicensedArtifact.Builder;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -52,7 +55,8 @@
* @author tchemit dev@tchemit.fr
* @since 1.0
*/
@Component( role = LicensedArtifactResolver.class, hint = "default" )
@Named
@Singleton
public class LicensedArtifactResolver
{
private static final Logger LOG = LoggerFactory.getLogger( LicensedArtifactResolver.class );
Expand All @@ -66,23 +70,19 @@ public class LicensedArtifactResolver
/**
* Project builder.
*/
@Requirement
@Inject
private ProjectBuilder mavenProjectBuilder;

@Requirement
private MavenSession mavenSession;
@Inject
private Provider<MavenSession> mavenSessionProvider;

// CHECKSTYLE_OFF: MethodLength
/**
* For a given {@code project}, obtain the universe of its dependencies after applying transitivity and filtering
* rules given in the {@code configuration} object. Result is given in a map where keys are unique artifact id
*
* @param dependencies the project dependencies
* @param configuration the configuration
* @param localRepository local repository used to resolv dependencies
* @param remoteRepositories remote repositories used to resolv dependencies
* @param cache a optional cache where to keep resolved dependencies
* @return the map of resolved dependencies indexed by their unique id.
* @see MavenProjectDependenciesConfigurator
*/
public void loadProjectDependencies( ResolvedProjectDependencies artifacts,
Expand Down Expand Up @@ -114,7 +114,7 @@ public void loadProjectDependencies( ResolvedProjectDependencies artifacts,
final Map<String, Artifact> includeArtifacts = new HashMap<>();

ProjectBuildingRequest projectBuildingRequest
= new DefaultProjectBuildingRequest( mavenSession.getProjectBuildingRequest() )
= new DefaultProjectBuildingRequest( mavenSessionProvider.get().getProjectBuildingRequest() )
.setRemoteRepositories( remoteRepositories )
.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL )
.setResolveDependencies( false )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
* #L%
*/

import org.codehaus.plexus.component.annotations.Component;
import javax.inject.Named;
import javax.inject.Singleton;

/**
* Implementation of {@link FileHeaderTransformer} for apt format.
*
* @author tchemit dev@tchemit.fr
* @since 1.0
*/
@Component( role = FileHeaderTransformer.class, hint = "apt" )
@Named("apt")
@Singleton
public class AptFileHeaderTransformer
extends AbstractFileHeaderTransformer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
* #L%
*/

import org.codehaus.plexus.component.annotations.Component;
import javax.inject.Named;
import javax.inject.Singleton;

/**
* Implementation of {@link FileHeaderTransformer} for freemarker format.
*
* @author tchemit dev@tchemit.fr
* @since 1.0
*/
@Component( role = FileHeaderTransformer.class, hint = "ftl" )
@Named("ftl")
@Singleton
public class FreeMarkerFileHeaderTransformer
extends AbstractFileHeaderTransformer
{
Expand Down
Loading

0 comments on commit 6c9d391

Please sign in to comment.