Skip to content

Commit

Permalink
#99: First stage of maven 3 migration
Browse files Browse the repository at this point in the history
Resolves #143: migration to JSR330
  • Loading branch information
jarmoniuk authored and slawekjaranowski committed Feb 13, 2023
1 parent fa8c6a4 commit 4ce45f7
Show file tree
Hide file tree
Showing 20 changed files with 415 additions and 452 deletions.
2 changes: 1 addition & 1 deletion mrm-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
41 changes: 41 additions & 0 deletions mrm-api/src/main/java/org/codehaus/mojo/mrm/api/ResolverUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.codehaus.mojo.mrm.api;

import java.util.Optional;

import org.apache.maven.execution.MavenSession;
import org.codehaus.mojo.mrm.api.maven.Artifact;
import org.eclipse.aether.artifact.ArtifactType;

import static java.util.Optional.ofNullable;

/**
* Miscellaneous utilities for manipulating Resolver entities
*/
public class ResolverUtils {

/**
* <p>Creates a new {@link org.eclipse.aether.artifact.Artifact} based on an {@link Artifact} object.</p>
* <p>Future deprecation: This method will be replaced with the new Maven 4
* {@code org.apache.maven.api.services.ArtifactFactory} once it becomes available.</p>
*
* @param mavenSession {@link MavenSession} instance, may not be {@code null}
* @param artifact object to read the data from, may not be {@code null}
* @return new {@link org.eclipse.aether.artifact.Artifact} instance
*/
public static org.eclipse.aether.artifact.Artifact createArtifact(MavenSession mavenSession, Artifact artifact) {
String groupId = artifact.getGroupId();
String artifactId = artifact.getArtifactId();
String version = artifact.getTimestampVersion();

Optional<ArtifactType> artifactType = ofNullable(artifact.getType())
.map(mavenSession.getRepositorySession().getArtifactTypeRegistry()::get);
return new org.eclipse.aether.artifact.DefaultArtifact(
groupId,
artifactId,
ofNullable(artifact.getClassifier())
.orElse(artifactType.map(ArtifactType::getClassifier).orElse(null)),
artifactType.map(ArtifactType::getExtension).orElse(null),
version,
artifactType.orElse(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,32 @@

package org.codehaus.mojo.mrm.plugin;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.mojo.mrm.api.maven.ArtifactStore;

/**
* Something that produces {@link ArtifactStore} instances.
*
* @see FactoryHelperRequired
* @since 1.0
*/
public interface ArtifactStoreFactory {
/**
* Creates a new {@link ArtifactStore} instance, note that implementations are free to create a singleton and always
* return that instance.
*
* @param session {@link MavenSession} instance
* @param log {@link Log} instance
*
* @return the {@link ArtifactStore} instance.
* @since 1.0
*/
ArtifactStore newInstance();
ArtifactStore newInstance(MavenSession session, Log log);

/**
* Sets the {@link FactoryHelper} instance where the object is not injected by dependency injection
*
* @param factoryHelper {@link FactoryHelper} instance
*/
void setFactoryHelper(FactoryHelper factoryHelper);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,82 +16,36 @@

package org.codehaus.mojo.mrm.plugin;

import java.util.List;

import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.logging.Log;
import org.eclipse.aether.RepositorySystem;

/**
* Helper interface that exposes the Maven components that may be required.
*
* @see FactoryHelperRequired
* @since 1.0
*/
public interface FactoryHelper {
/**
* Returns the {@link RepositoryMetadataManager} provided by Maven.
*
* @return The {@link RepositoryMetadataManager} provided by Maven.
* @since 1.0
*/
RepositoryMetadataManager getRepositoryMetadataManager();

/**
* Returns the remote plugin repositories provided by Maven.
*
* @return The remote plugin repositories provided by Maven.
* @since 1.0
* @return returns the {@link RepositorySystem} instance
*/
List<ArtifactRepository> getRemotePluginRepositories();
RepositorySystem getRepositorySystem();

/**
* Returns the {@link ArtifactRepository} provided by Maven.
*
* @return The {@link ArtifactRepository} provided by Maven.
* @return returns the {@link RepositoryMetadataManager} instance
* @since 1.0
*/
ArtifactRepository getLocalRepository();
RepositoryMetadataManager getRepositoryMetadataManager();

/**
* Returns the {@link ArtifactFactory} provided by Maven.
*
* @return The {@link ArtifactFactory} provided by Maven.
* @return returns the {@link ArtifactFactory} instance
* @since 1.0
*/
ArtifactFactory getArtifactFactory();

/**
* Returns the remote repositories that we will query.
*
* @return The remote repositories that we will query.
* @since 1.0
*/
List<ArtifactRepository> getRemoteArtifactRepositories();

/**
* Returns the {@link ArtifactResolver} provided by Maven.
*
* @return The {@link ArtifactResolver} provided by Maven.
* @since 1.0
*/
ArtifactResolver getArtifactResolver();

/**
* Returns the {@link Log} to log to.
*
* @return The {@link Log} to log to.
* @since 1.0
*/
Log getLog();

/**
* Returns the {@link ArchetypeManager}
*
* @return The {@link ArchetypeManager}
* @return returns the {@link ArchetypeManager} instance
* @since 1.0
*/
ArchetypeManager getArchetypeManager();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
/**
* Something that produces new {@link FileSystem} instances.
*
* @see FactoryHelperRequired
* @since 1.0
*/
public interface FileSystemFactory {
Expand Down
8 changes: 4 additions & 4 deletions mrm-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<scope>provided</scope>
</dependency>

Expand Down
Loading

0 comments on commit 4ce45f7

Please sign in to comment.