Skip to content

Commit

Permalink
Get rid usage of deprecated ArtifactFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Sep 17, 2023
1 parent 7dc5432 commit 3e9dab9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.codehaus.mojo.mrm.plugin;

import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.eclipse.aether.RepositorySystem;

Expand All @@ -38,12 +37,6 @@ public interface FactoryHelper {
*/
RepositoryMetadataManager getRepositoryMetadataManager();

/**
* @return returns the {@link ArtifactFactory} instance
* @since 1.0
*/
ArtifactFactory getArtifactFactory();

/**
* @return returns the {@link ArchetypeManager} instance
* @since 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.commons.lang.StringUtils;
import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.archetype.catalog.ArchetypeCatalog;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.*;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
Expand Down Expand Up @@ -86,8 +85,6 @@ public class ProxyArtifactStore extends BaseArtifactStore {

private final RepositoryMetadataManager repositoryMetadataManager;

private final ArtifactFactory artifactFactory;

private final ArchetypeManager archetypeManager;

/**
Expand All @@ -100,7 +97,6 @@ public class ProxyArtifactStore extends BaseArtifactStore {
public ProxyArtifactStore(FactoryHelper factoryHelper, MavenSession session, Log log) {
this.repositorySystem = Objects.requireNonNull(factoryHelper.getRepositorySystem());
this.repositoryMetadataManager = Objects.requireNonNull(factoryHelper.getRepositoryMetadataManager());
this.artifactFactory = Objects.requireNonNull(factoryHelper.getArtifactFactory());
this.archetypeManager = Objects.requireNonNull(factoryHelper.getArchetypeManager());
this.log = log;
this.session = Objects.requireNonNull(session);
Expand Down Expand Up @@ -255,8 +251,7 @@ public Metadata getMetadata(String path) throws MetadataNotFoundException {
String artifactId = slashIndex == -1 ? null : path.substring(slashIndex + 1);
String groupId = slashIndex == -1 ? null : path.substring(0, slashIndex).replace('/', '.');
if (!StringUtils.isEmpty(artifactId) && !StringUtils.isEmpty(groupId)) {
org.apache.maven.artifact.Artifact artifact =
artifactFactory.createDependencyArtifact(groupId, artifactId, ANY_VERSION, "pom", null, "compile");
org.apache.maven.artifact.Artifact artifact = createDependencyArtifact(groupId, artifactId);
ArtifactRepositoryMetadata artifactRepositoryMetadata = new ArtifactRepositoryMetadata(artifact);
try {
repositoryMetadataManager.resolve(
Expand Down Expand Up @@ -286,6 +281,12 @@ public Metadata getMetadata(String path) throws MetadataNotFoundException {
return metadata;
}

private org.apache.maven.artifact.Artifact createDependencyArtifact(String groupId, String artifactId) {

return new org.apache.maven.artifact.DefaultArtifact(
groupId, artifactId, ANY_VERSION, "compile", "pom", "", null);
}

@Override
public long getMetadataLastModified(String path) throws MetadataNotFoundException {
Metadata metadata = getMetadata(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import javax.inject.Singleton;

import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.eclipse.aether.RepositorySystem;

Expand All @@ -21,19 +20,15 @@ public class DefaultFactoryHelper implements FactoryHelper {

private RepositoryMetadataManager repositoryMetadataManager;

private ArtifactFactory artifactFactory;

private ArchetypeManager archetypeManager;

@Inject
public DefaultFactoryHelper(
RepositorySystem repositorySystem,
RepositoryMetadataManager repositoryMetadataManager,
ArtifactFactory artifactFactory,
ArchetypeManager archetypeManager) {
this.repositorySystem = repositorySystem;
this.repositoryMetadataManager = repositoryMetadataManager;
this.artifactFactory = artifactFactory;
this.archetypeManager = archetypeManager;
}

Expand All @@ -47,11 +42,6 @@ public RepositoryMetadataManager getRepositoryMetadataManager() {
return repositoryMetadataManager;
}

@Override
public ArtifactFactory getArtifactFactory() {
return artifactFactory;
}

@Override
public ArchetypeManager getArchetypeManager() {
return archetypeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Collections;

import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -65,7 +64,6 @@ void verifyArtifactNotFoundExceptionOnGet() throws Exception {
FactoryHelper factoryHelper = mock(FactoryHelper.class);
when(factoryHelper.getRepositorySystem()).thenReturn(repositorySystem);
when(factoryHelper.getRepositoryMetadataManager()).then(i -> mock(RepositoryMetadataManager.class));
when(factoryHelper.getArtifactFactory()).then(i -> mock(ArtifactFactory.class));
when(factoryHelper.getArchetypeManager()).then(i -> mock(ArchetypeManager.class));

ProxyArtifactStore store = new ProxyArtifactStore(factoryHelper, mavenSession, null);
Expand All @@ -82,7 +80,6 @@ void verifyArtifactResolutionExceptionOnGet() throws Exception {
FactoryHelper factoryHelper = mock(FactoryHelper.class);
when(factoryHelper.getRepositorySystem()).thenReturn(repositorySystem);
when(factoryHelper.getRepositoryMetadataManager()).then(i -> mock(RepositoryMetadataManager.class));
when(factoryHelper.getArtifactFactory()).then(i -> mock(ArtifactFactory.class));
when(factoryHelper.getArchetypeManager()).then(i -> mock(ArchetypeManager.class));

ProxyArtifactStore store = new ProxyArtifactStore(factoryHelper, mavenSession, null);
Expand All @@ -99,7 +96,6 @@ void verifyArchetypeCatalogNotFoundException() throws Exception {
FactoryHelper factoryHelper = mock(FactoryHelper.class);
when(factoryHelper.getRepositorySystem()).then(i -> mock(RepositorySystem.class));
when(factoryHelper.getRepositoryMetadataManager()).then(i -> mock(RepositoryMetadataManager.class));
when(factoryHelper.getArtifactFactory()).then(i -> mock(ArtifactFactory.class));
when(factoryHelper.getArchetypeManager()).thenReturn(archetypeManager);
ProxyArtifactStore store = new ProxyArtifactStore(factoryHelper, mavenSession, null);

Expand Down

0 comments on commit 3e9dab9

Please sign in to comment.