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
andrzejj0 committed Jan 14, 2023
1 parent 4d4037e commit d36206b
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 445 deletions.
8 changes: 8 additions & 0 deletions mrm-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact-manager</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-repository-metadata</artifactId>
Expand All @@ -58,6 +62,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
</dependency>

</dependencies>

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
16 changes: 14 additions & 2 deletions mrm-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
<version>${project.version}</version>
</dependency>

<!-- maven compat - to be removed -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<scope>provided</scope>
</dependency>

<!-- maven core dependencies -->
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -77,15 +84,20 @@
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand Down
Loading

0 comments on commit d36206b

Please sign in to comment.