Skip to content

Commit

Permalink
mojohaus#99: First stage of maven 3 migration
Browse files Browse the repository at this point in the history
Resolves mojohaus#143: migration to JSR330
  • Loading branch information
andrzejj0 committed Jan 14, 2023
1 parent 4d4037e commit 1e6389a
Show file tree
Hide file tree
Showing 19 changed files with 460 additions and 415 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
71 changes: 71 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,71 @@
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 groupId groupId of the artifact to create, may not be {@code null}
* @param artifactId artifactId of the artifact to create, may not be {@code null}
* @param classifier classifier of the artifact to create, may be {@code null}
* @param type type of the artifact to create, may be {@code null}
* @param version version of the artifact to create, may not be {@code null}
* @return new {@link org.eclipse.aether.artifact.Artifact} instance
*/
public static org.eclipse.aether.artifact.Artifact createArtifact(
MavenSession mavenSession,
String groupId,
String artifactId,
String classifier,
String type,
String version) {
assert mavenSession != null;
assert groupId != null;
assert artifactId != null;
assert version != null;

Optional<ArtifactType> artifactType =
ofNullable(type).map(mavenSession.getRepositorySession().getArtifactTypeRegistry()::get);
return new org.eclipse.aether.artifact.DefaultArtifact(
groupId,
artifactId,
ofNullable(classifier)
.orElse(artifactType.map(ArtifactType::getClassifier).orElse(null)),
artifactType.map(ArtifactType::getExtension).orElse(null),
version,
artifactType.orElse(null));
}

/**
* <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) {
return createArtifact(
mavenSession,
artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getClassifier(),
artifact.getType(),
artifact.getTimestampVersion());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

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;

/**
Expand All @@ -29,8 +31,18 @@ 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,14 +16,10 @@

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.
Expand All @@ -33,65 +29,24 @@
*/
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.

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 1e6389a

Please sign in to comment.