diff --git a/archetype-common/pom.xml b/archetype-common/pom.xml
index c3636264..9d950fb1 100644
--- a/archetype-common/pom.xml
+++ b/archetype-common/pom.xml
@@ -92,10 +92,6 @@
org.apache.maven.shared
maven-invoker
-
- org.apache.maven.shared
- maven-artifact-transfer
-
org.codehaus.plexus
plexus-utils
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeGenerationRequest.java b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeGenerationRequest.java
index 891bb697..9c46a560 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeGenerationRequest.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeGenerationRequest.java
@@ -18,41 +18,25 @@
*/
package org.apache.maven.archetype;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.apache.maven.archetype.catalog.Archetype;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.settings.Mirror;
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-import org.apache.maven.wagon.events.TransferListener;
+import org.eclipse.aether.repository.RemoteRepository;
/** @author Jason van Zyl */
public class ArchetypeGenerationRequest {
private ProjectBuildingRequest projectBuildingRequest;
- private boolean offline;
-
private boolean interactiveMode;
private boolean askForDefaultPropertyValues;
- private TransferListener transferListener;
-
private String outputDirectory;
- private ArtifactRepository localRepository;
-
- private List remoteArtifactRepositories;
-
- private Proxy activeProxy;
-
- private List servers = new ArrayList<>();
-
- private List mirrors = new ArrayList<>();
+ private List remoteArtifactRepositories = Collections.emptyList();
// Archetype definition
private String archetypeName;
@@ -235,16 +219,6 @@ public ArchetypeGenerationRequest setProperties(Properties additionalProperties)
return this;
}
- public ArtifactRepository getLocalRepository() {
- return localRepository;
- }
-
- public ArchetypeGenerationRequest setLocalRepository(ArtifactRepository localRepository) {
- this.localRepository = localRepository;
-
- return this;
- }
-
public String getOutputDirectory() {
return outputDirectory;
}
@@ -275,71 +249,11 @@ public ArchetypeGenerationRequest setAskForDefaultPropertyValues(boolean askForD
return this;
}
- public boolean isOffline() {
- return offline;
- }
-
- public ArchetypeGenerationRequest setOffline(boolean offline) {
- this.offline = offline;
-
- return this;
- }
-
- public TransferListener getTransferListener() {
- return transferListener;
- }
-
- public ArchetypeGenerationRequest setTransferListener(TransferListener transferListener) {
- this.transferListener = transferListener;
-
- return this;
- }
-
- public Proxy getActiveProxy() {
- return activeProxy;
- }
-
- public ArchetypeGenerationRequest setActiveProxy(Proxy activeProxy) {
- this.activeProxy = activeProxy;
-
- return this;
- }
-
- public ArchetypeGenerationRequest addMirror(Mirror mirror) {
- mirrors.add(mirror);
-
- return this;
- }
-
- public List getMirrors() {
- return mirrors;
- }
-
- /**
- * @deprecated Use {@link #addServer(Server)} instead
- */
- @Deprecated
- public ArchetypeGenerationRequest addMirror(Server server) {
- return addServer(server);
- }
-
- public ArchetypeGenerationRequest addServer(Server server) {
- servers.add(server);
-
- return this;
- }
-
- public List getServers() {
- return servers;
- }
-
- public List getRemoteArtifactRepositories() {
+ public List getRemoteArtifactRepositories() {
return remoteArtifactRepositories;
}
- @SuppressWarnings("checkstyle:linelength")
- public ArchetypeGenerationRequest setRemoteArtifactRepositories(
- List remoteArtifactRepositories) {
+ public ArchetypeGenerationRequest setRemoteArtifactRepositories(List remoteArtifactRepositories) {
this.remoteArtifactRepositories = remoteArtifactRepositories;
return this;
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java
index bbfa6751..25669732 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java
@@ -25,27 +25,22 @@
import org.apache.maven.archetype.exception.UnknownArchetype;
import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
-import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
public interface ArchetypeArtifactManager {
String ROLE = ArchetypeArtifactManager.class.getName();
Model getArchetypePom(File jar) throws XmlPullParserException, UnknownArchetype, IOException;
- /**
- * @param buildingRequest TODO
- */
File getArchetypeFile(
String groupId,
String artifactId,
String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest)
+ List repositories,
+ RepositorySystemSession repositorySystemSession)
throws UnknownArchetype;
/**
@@ -60,45 +55,16 @@ File getArchetypeFile(
*/
boolean isFileSetArchetype(File archetypeFile);
- /**
- * @param buildingRequest TODO
- */
- boolean isFileSetArchetype(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest);
-
/**
*/
boolean isOldArchetype(File archetypeFile);
- /**
- * @param buildingRequest TODO
- */
- boolean isOldArchetype(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest);
-
- /**
- * @param buildingRequest TODO
- */
boolean exists(
String archetypeGroupId,
String archetypeArtifactId,
String archetypeVersion,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repos,
- ProjectBuildingRequest buildingRequest);
+ List repos,
+ RepositorySystemSession repositorySystemSession);
/**
* Get the archetype file's post-generation script content, read as UTF-8 content.
@@ -114,19 +80,6 @@ boolean exists(
*/
ArchetypeDescriptor getFileSetArchetypeDescriptor(File archetypeFile) throws UnknownArchetype;
- /**
- * @param buildingRequest TODO
- */
- ArchetypeDescriptor getFileSetArchetypeDescriptor(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest)
- throws UnknownArchetype;
-
/**
*/
List getFilesetArchetypeResources(File archetypeFile) throws UnknownArchetype;
@@ -135,17 +88,4 @@ ArchetypeDescriptor getFileSetArchetypeDescriptor(
*/
org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor(File archetypeFile)
throws UnknownArchetype;
-
- /**
- * @param buildingRequest TODO
- */
- org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest)
- throws UnknownArchetype;
}
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
index d38b4f3d..e2dfe823 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java
@@ -45,12 +45,12 @@
import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
import org.apache.maven.archetype.metadata.io.xpp3.ArchetypeDescriptorXpp3Reader;
import org.apache.maven.archetype.old.descriptor.ArchetypeDescriptorBuilder;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Model;
-import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
@Named
@Singleton
@@ -68,30 +68,19 @@ public File getArchetypeFile(
final String groupId,
final String artifactId,
final String version,
- ArtifactRepository archetypeRepository,
- final ArtifactRepository localRepository,
- final List repositories,
- ProjectBuildingRequest buildingRequest)
+ final List repositories,
+ RepositorySystemSession repositorySystemSession)
throws UnknownArchetype {
try {
File archetype = getArchetype(groupId, artifactId, version);
if (archetype == null) {
- archetype = downloader.download(
- groupId,
- artifactId,
- version,
- archetypeRepository,
- localRepository,
- repositories,
- buildingRequest);
+ archetype = downloader.download(groupId, artifactId, version, repositories, repositorySystemSession);
setArchetype(groupId, artifactId, version, archetype);
}
return archetype;
- } catch (DownloadNotFoundException ex) {
- throw new UnknownArchetype(ex);
- } catch (DownloadException ex) {
+ } catch (DownloadNotFoundException | DownloadException ex) {
throw new UnknownArchetype(ex);
}
}
@@ -159,26 +148,6 @@ public boolean isFileSetArchetype(File archetypeFile) {
}
}
- @Override
- public boolean isFileSetArchetype(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest) {
- try {
- File archetypeFile = getArchetypeFile(
- groupId, artifactId, version, archetypeRepository, localRepository, repositories, buildingRequest);
-
- return isFileSetArchetype(archetypeFile);
- } catch (UnknownArchetype e) {
- getLogger().debug(e.toString());
- return false;
- }
- }
-
@Override
public boolean isOldArchetype(File archetypeFile) {
getLogger().debug("checking old archetype status on " + archetypeFile);
@@ -191,35 +160,13 @@ public boolean isOldArchetype(File archetypeFile) {
}
}
- @Override
- public boolean isOldArchetype(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest) {
- try {
- File archetypeFile = getArchetypeFile(
- groupId, artifactId, version, archetypeRepository, localRepository, repositories, buildingRequest);
-
- return isOldArchetype(archetypeFile);
- } catch (UnknownArchetype e) {
- getLogger().debug(e.toString());
- return false;
- }
- }
-
@Override
public boolean exists(
String archetypeGroupId,
String archetypeArtifactId,
String archetypeVersion,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List remoteRepositories,
- ProjectBuildingRequest buildingRequest) {
+ List remoteRepositories,
+ RepositorySystemSession repositorySystemSession) {
try {
File archetype = getArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion);
if (archetype == null) {
@@ -227,22 +174,13 @@ public boolean exists(
archetypeGroupId,
archetypeArtifactId,
archetypeVersion,
- archetypeRepository,
- localRepository,
remoteRepositories,
- buildingRequest);
+ repositorySystemSession);
setArchetype(archetypeGroupId, archetypeArtifactId, archetypeVersion, archetype);
}
return archetype.exists();
- } catch (DownloadException e) {
- getLogger()
- .debug(
- "Archetype " + archetypeGroupId + ":" + archetypeArtifactId + ":" + archetypeVersion
- + " doesn't exist",
- e);
- return false;
- } catch (DownloadNotFoundException e) {
+ } catch (DownloadException | DownloadNotFoundException e) {
getLogger()
.debug(
"Archetype " + archetypeGroupId + ":" + archetypeArtifactId + ":" + archetypeVersion
@@ -271,22 +209,6 @@ public ArchetypeDescriptor getFileSetArchetypeDescriptor(File archetypeFile) thr
}
}
- @Override
- public org.apache.maven.archetype.metadata.ArchetypeDescriptor getFileSetArchetypeDescriptor(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest)
- throws UnknownArchetype {
- File archetypeFile = getArchetypeFile(
- groupId, artifactId, version, archetypeRepository, localRepository, repositories, buildingRequest);
-
- return getFileSetArchetypeDescriptor(archetypeFile);
- }
-
@Override
public List getFilesetArchetypeResources(File archetypeFile) throws UnknownArchetype {
getLogger().debug("getFilesetArchetypeResources( \"" + archetypeFile.getAbsolutePath() + "\" )");
@@ -323,22 +245,6 @@ public org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArche
}
}
- @Override
- public org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor getOldArchetypeDescriptor(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List repositories,
- ProjectBuildingRequest buildingRequest)
- throws UnknownArchetype {
- File archetypeFile = getArchetypeFile(
- groupId, artifactId, version, archetypeRepository, localRepository, repositories, buildingRequest);
-
- return getOldArchetypeDescriptor(archetypeFile);
- }
-
private File getArchetype(String archetypeGroupId, String archetypeArtifactId, String archetypeVersion) {
String key = archetypeGroupId + ":" + archetypeArtifactId + ":" + archetypeVersion;
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
index b45f3589..4df53e2e 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DefaultDownloader.java
@@ -23,15 +23,15 @@
import javax.inject.Singleton;
import java.io.File;
-import java.util.ArrayList;
import java.util.List;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResolutionException;
+import org.eclipse.aether.resolution.ArtifactResult;
/**
* @author Jason van Zyl
@@ -39,83 +39,27 @@
@Named
@Singleton
public class DefaultDownloader implements Downloader {
+
@Inject
- private ArtifactResolver artifactResolver;
+ private RepositorySystem repositorySystem;
@Override
public File download(
String groupId,
String artifactId,
String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List remoteRepositories,
- ProjectBuildingRequest buildingRequest)
+ List remoteRepositories,
+ RepositorySystemSession repositorySystemSession)
throws DownloadException, DownloadNotFoundException {
- DefaultArtifactCoordinate jarCoordinate = new DefaultArtifactCoordinate();
- jarCoordinate.setGroupId(groupId);
- jarCoordinate.setArtifactId(artifactId);
- jarCoordinate.setVersion(version);
-
- DefaultArtifactCoordinate pomCoordinate = new DefaultArtifactCoordinate();
- pomCoordinate.setGroupId(groupId);
- pomCoordinate.setArtifactId(artifactId);
- pomCoordinate.setVersion(version);
- pomCoordinate.setExtension("pom");
-
- List repositories = new ArrayList<>(remoteRepositories);
- if (repositories.isEmpty() && archetypeRepository != null) {
- repositories.add(archetypeRepository);
- } else if (repositories.isEmpty() && localRepository != null) {
- repositories.add(localRepository);
- }
-
- ArtifactRepository localRepo = localRepository;
- buildingRequest.setLocalRepository(localRepo);
- buildingRequest.setRemoteRepositories(repositories);
-
- Artifact artifact;
- try {
- artifact = artifactResolver
- .resolveArtifact(buildingRequest, jarCoordinate)
- .getArtifact();
- } catch (ArtifactResolverException e) {
- throw new DownloadException("Error downloading " + jarCoordinate + ".", e);
- }
-
- // still required???
- try {
- artifactResolver.resolveArtifact(buildingRequest, pomCoordinate);
- } catch (ArtifactResolverException e) {
- throw new DownloadException("Error downloading POM for " + artifact.getId() + ".", e);
- }
-
- return artifact.getFile();
- }
-
- @Override
- public File downloadOld(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List remoteRepositories,
- ProjectBuildingRequest buildingRequest)
- throws DownloadException, DownloadNotFoundException {
- DefaultArtifactCoordinate jarCoordinate = new DefaultArtifactCoordinate();
- jarCoordinate.setGroupId(groupId);
- jarCoordinate.setArtifactId(artifactId);
- jarCoordinate.setVersion(version);
+ DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, "", "jar", version);
+ ArtifactRequest request = new ArtifactRequest(artifact, remoteRepositories, "archetype");
try {
- return artifactResolver
- .resolveArtifact(buildingRequest, jarCoordinate)
- .getArtifact()
- .getFile();
- } catch (ArtifactResolverException e) {
- throw new DownloadException("Error downloading " + jarCoordinate + ".", e);
+ ArtifactResult result = repositorySystem.resolveArtifact(repositorySystemSession, request);
+ return result.getArtifact().getFile();
+ } catch (ArtifactResolutionException e) {
+ throw new DownloadException("Could not resolve artifact " + artifactId, e);
}
}
}
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/Downloader.java b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/Downloader.java
index e0561e23..9d15066d 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/Downloader.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/Downloader.java
@@ -21,8 +21,8 @@
import java.io.File;
import java.util.List;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.ProjectBuildingRequest;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
/**
* @author Jason van Zyl
@@ -32,19 +32,7 @@ File download(
String groupId,
String artifactId,
String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List remoteRepositories,
- ProjectBuildingRequest buildingRequest)
- throws DownloadException, DownloadNotFoundException;
-
- File downloadOld(
- String groupId,
- String artifactId,
- String version,
- ArtifactRepository archetypeRepository,
- ArtifactRepository localRepository,
- List remoteRepositories,
- ProjectBuildingRequest buildingRequest)
+ List remoteRepositories,
+ RepositorySystemSession repositorySystemSession)
throws DownloadException, DownloadNotFoundException;
}
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultArchetypeGenerator.java b/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultArchetypeGenerator.java
index 33d573d7..e8550faf 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultArchetypeGenerator.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultArchetypeGenerator.java
@@ -24,6 +24,7 @@
import java.io.File;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.maven.archetype.ArchetypeGenerationRequest;
@@ -35,12 +36,13 @@
import org.apache.maven.archetype.exception.InvalidPackaging;
import org.apache.maven.archetype.exception.UnknownArchetype;
import org.apache.maven.archetype.old.OldArchetype;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.repository.RepositoryPolicy;
@Named
@Singleton
@@ -60,17 +62,22 @@ public class DefaultArchetypeGenerator extends AbstractLogEnabled implements Arc
@Inject
private OldArchetype oldArchetype;
- private File getArchetypeFile(ArchetypeGenerationRequest request, ArtifactRepository localRepository)
- throws ArchetypeException {
+ @Inject
+ private RepositorySystem repositorySystem;
+
+ private File getArchetypeFile(ArchetypeGenerationRequest request) throws ArchetypeException {
if (!isArchetypeDefined(request)) {
throw new ArchetypeNotDefined("The archetype is not defined");
}
- List repos = new ArrayList<>();
+ List repos = new ArrayList<>(request.getRemoteArtifactRepositories());
- ArtifactRepository remoteRepo = null;
+ RemoteRepository remoteRepo = null;
if (request != null && request.getArchetypeRepository() != null) {
- remoteRepo = createRepository(request.getArchetypeRepository(), request.getArchetypeArtifactId() + "-repo");
+ RepositorySystemSession repositorySession =
+ request.getProjectBuildingRequest().getRepositorySession();
+ remoteRepo = createRepository(
+ repositorySession, request.getArchetypeRepository(), request.getArchetypeArtifactId() + "-repo");
repos.add(remoteRepo);
}
@@ -79,10 +86,8 @@ private File getArchetypeFile(ArchetypeGenerationRequest request, ArtifactReposi
request.getArchetypeGroupId(),
request.getArchetypeArtifactId(),
request.getArchetypeVersion(),
- remoteRepo,
- localRepository,
repos,
- request.getProjectBuildingRequest())) {
+ request.getProjectBuildingRequest().getRepositorySession())) {
throw new UnknownArchetype("The desired archetype does not exist (" + request.getArchetypeGroupId() + ":"
+ request.getArchetypeArtifactId() + ":" + request.getArchetypeVersion() + ")");
}
@@ -91,10 +96,8 @@ private File getArchetypeFile(ArchetypeGenerationRequest request, ArtifactReposi
request.getArchetypeGroupId(),
request.getArchetypeArtifactId(),
request.getArchetypeVersion(),
- remoteRepo,
- localRepository,
repos,
- request.getProjectBuildingRequest());
+ request.getProjectBuildingRequest().getRepositorySession());
return archetypeFile;
}
@@ -143,7 +146,7 @@ public void generateArchetype(
@Override
public void generateArchetype(ArchetypeGenerationRequest request, ArchetypeGenerationResult result) {
try {
- File archetypeFile = getArchetypeFile(request, request.getLocalRepository());
+ File archetypeFile = getArchetypeFile(request);
generateArchetype(request, archetypeFile, result);
} catch (ArchetypeException ex) {
@@ -151,24 +154,24 @@ public void generateArchetype(ArchetypeGenerationRequest request, ArchetypeGener
}
}
- private ArtifactRepository createRepository(String url, String repositoryId) {
+ private RemoteRepository createRepository(
+ RepositorySystemSession repositorySession, String url, String repositoryId) {
// snapshots vs releases
// offline = to turning the update policy off
// TODO: we'll need to allow finer grained creation of repositories but this will do for now
- String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
-
- String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
-
- ArtifactRepositoryPolicy snapshotsPolicy =
- new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag);
+ RepositoryPolicy repositoryPolicy = new RepositoryPolicy(
+ true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN);
- ArtifactRepositoryPolicy releasesPolicy =
- new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag);
+ RemoteRepository remoteRepository = new RemoteRepository.Builder(repositoryId, "default", url)
+ .setSnapshotPolicy(repositoryPolicy)
+ .setReleasePolicy(repositoryPolicy)
+ .build();
- return new MavenArtifactRepository(
- repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy);
+ return repositorySystem
+ .newResolutionRepositories(repositorySession, Collections.singletonList(remoteRepository))
+ .get(0);
}
}
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java b/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java
index f6a12447..e08a5c51 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/old/DefaultOldArchetype.java
@@ -50,7 +50,6 @@
import org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor;
import org.apache.maven.archetype.old.descriptor.ArchetypeDescriptorBuilder;
import org.apache.maven.archetype.old.descriptor.TemplateDescriptor;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@@ -103,7 +102,7 @@ public class DefaultOldArchetype extends AbstractLogEnabled implements OldArchet
// version = latest
@Override
- public void createArchetype(ArchetypeGenerationRequest request, ArtifactRepository archetypeRepository)
+ public void createArchetype(ArchetypeGenerationRequest request)
throws UnknownArchetype, ArchetypeDescriptorException, ArchetypeTemplateProcessingException,
InvalidPackaging {
// ----------------------------------------------------------------------
@@ -114,10 +113,8 @@ public void createArchetype(ArchetypeGenerationRequest request, ArtifactReposito
request.getArchetypeGroupId(),
request.getArchetypeArtifactId(),
request.getArchetypeVersion(),
- archetypeRepository,
- request.getLocalRepository(),
request.getRemoteArtifactRepositories(),
- request.getProjectBuildingRequest());
+ request.getProjectBuildingRequest().getRepositorySession());
createArchetype(request, archetypeFile);
}
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/old/OldArchetype.java b/archetype-common/src/main/java/org/apache/maven/archetype/old/OldArchetype.java
index 9813a135..4b8c25cb 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/old/OldArchetype.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/old/OldArchetype.java
@@ -23,7 +23,6 @@
import org.apache.maven.archetype.ArchetypeGenerationRequest;
import org.apache.maven.archetype.exception.InvalidPackaging;
import org.apache.maven.archetype.exception.UnknownArchetype;
-import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Create a Maven project from an old archetype.
@@ -46,7 +45,7 @@ public interface OldArchetype {
/**
* Download an archetype then create a project from it.
*/
- void createArchetype(ArchetypeGenerationRequest request, ArtifactRepository archetypeRepository)
+ void createArchetype(ArchetypeGenerationRequest request)
throws UnknownArchetype, ArchetypeNotFoundException, ArchetypeDescriptorException,
ArchetypeTemplateProcessingException, InvalidPackaging;
diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSource.java b/archetype-common/src/main/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSource.java
index f8a039c4..cefcb04a 100644
--- a/archetype-common/src/main/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSource.java
+++ b/archetype-common/src/main/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSource.java
@@ -18,7 +18,6 @@
*/
package org.apache.maven.archetype.source;
-import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -30,19 +29,17 @@
import org.apache.maven.archetype.catalog.Archetype;
import org.apache.maven.archetype.catalog.ArchetypeCatalog;
import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.repository.RepositoryManager;
import org.codehaus.plexus.util.ReaderFactory;
@Named("catalog")
@Singleton
public class LocalCatalogArchetypeDataSource extends CatalogArchetypeDataSource {
- @Inject
- private RepositoryManager repositoryManager;
@Override
public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype)
throws ArchetypeDataSourceException {
- File localRepo = repositoryManager.getLocalRepositoryBasedir(buildingRequest);
+ File localRepo =
+ buildingRequest.getRepositorySession().getLocalRepository().getBasedir();
File catalogFile = new File(localRepo, ARCHETYPE_CATALOG_FILENAME);
@@ -92,7 +89,8 @@ public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype arch
@Override
public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest)
throws ArchetypeDataSourceException {
- File localRepo = repositoryManager.getLocalRepositoryBasedir(buildingRequest);
+ File localRepo =
+ buildingRequest.getRepositorySession().getLocalRepository().getBasedir();
File catalogFile = new File(localRepo, ARCHETYPE_CATALOG_FILENAME);
diff --git a/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java b/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
index c17f991f..1a0b9447 100644
--- a/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
+++ b/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java
@@ -95,8 +95,7 @@ private void generateProjectFromArchetype(ArchetypeGenerationRequest request) th
}
}
- private ArchetypeGenerationResult generateProjectFromArchetypeWithFailure(ArchetypeGenerationRequest request)
- throws Exception {
+ private ArchetypeGenerationResult generateProjectFromArchetypeWithFailure(ArchetypeGenerationRequest request) {
ArchetypeGenerationResult result = new ArchetypeGenerationResult();
generator.generateArchetype(request, result);
@@ -512,7 +511,7 @@ protected void setUp() throws Exception {
localRepository =
new DefaultArtifactRepository("local", repositories + "/local", new DefaultRepositoryLayout());
- remoteRepository = repositories + "/central";
+ remoteRepository = repositories + "central";
generator = (ArchetypeGenerator) lookup(ArchetypeGenerator.ROLE);
assertNotNull(generator);
@@ -528,7 +527,6 @@ private ArchetypeGenerationRequest createArchetypeGenerationRequest(String proje
projectDirectory = new File(outputDirectory, "file-value");
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
- request.setLocalRepository(localRepository);
request.setArchetypeRepository(remoteRepository);
request.setOutputDirectory(outputDirectory);
diff --git a/archetype-common/src/test/java/org/apache/maven/archetype/old/ArchetypeTest.java b/archetype-common/src/test/java/org/apache/maven/archetype/old/ArchetypeTest.java
index 2ad2d7cc..b3cc3c50 100644
--- a/archetype-common/src/test/java/org/apache/maven/archetype/old/ArchetypeTest.java
+++ b/archetype-common/src/test/java/org/apache/maven/archetype/old/ArchetypeTest.java
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.maven.RepositoryUtils;
import org.apache.maven.archetype.ArchetypeGenerationRequest;
import org.apache.maven.archetype.exception.InvalidPackaging;
import org.apache.maven.artifact.Artifact;
@@ -113,12 +114,11 @@ public void testArchetype() throws Exception {
.setArchetypeGroupId("org.apache.maven.archetypes")
.setArchetypeArtifactId("maven-archetype-quickstart")
.setArchetypeVersion("1.0-alpha-1-SNAPSHOT")
- .setLocalRepository(localRepository)
- .setRemoteArtifactRepositories(remoteRepositories)
+ .setRemoteArtifactRepositories(RepositoryUtils.toRepos(remoteRepositories))
.setOutputDirectory(getTestFile("target").getAbsolutePath());
// parameters.put( "name", "jason" );
- archetype.createArchetype(request, remoteRepository);
+ archetype.createArchetype(request);
// ----------------------------------------------------------------------
// Set up the Velocity context
diff --git a/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetypeGenerationTest.java b/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetypeGenerationTest.java
index 2434ba78..5cf4c091 100644
--- a/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetypeGenerationTest.java
+++ b/archetype-common/src/test/java/org/apache/maven/archetype/test/ArchetypeGenerationTest.java
@@ -96,7 +96,7 @@ public void testProjectGenerationFromAnArchetype() throws Exception {
ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest(selection)
.setOutputDirectory(outputDirectory.getAbsolutePath())
- .setLocalRepository(localRepository)
+ // .setLocalRepository(localRepository)
.setGroupId(groupId)
.setArtifactId(artifactId)
.setVersion(version)
diff --git a/archetype-common/src/test/java/org/apache/maven/archetype/test/InternalCatalogArchetypesVerificationTest.java b/archetype-common/src/test/java/org/apache/maven/archetype/test/InternalCatalogArchetypesVerificationTest.java
index ae6f4225..ad32db85 100644
--- a/archetype-common/src/test/java/org/apache/maven/archetype/test/InternalCatalogArchetypesVerificationTest.java
+++ b/archetype-common/src/test/java/org/apache/maven/archetype/test/InternalCatalogArchetypesVerificationTest.java
@@ -86,8 +86,8 @@ public void testInternalCatalog() throws Exception {
.setArtifactId("archetype" + count)
.setVersion("1.0-SNAPSHOT")
.setPackage("com.acme")
- .setOutputDirectory(outputDirectory.getPath())
- .setLocalRepository(localRepository);
+ .setOutputDirectory(outputDirectory.getPath());
+ // .setLocalRepository(localRepository);
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
diff --git a/maven-archetype-plugin/pom.xml b/maven-archetype-plugin/pom.xml
index 31ef0cc4..3fbd8937 100644
--- a/maven-archetype-plugin/pom.xml
+++ b/maven-archetype-plugin/pom.xml
@@ -123,10 +123,6 @@
org.apache.maven.shared
maven-invoker
-
- org.apache.maven.shared
- maven-artifact-transfer
-
org.apache.commons
commons-lang3
diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
index 8c9603f5..a46123f0 100644
--- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
+++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateProjectFromArchetypeMojo.java
@@ -20,7 +20,6 @@
import java.io.File;
import java.util.Arrays;
-import java.util.List;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
@@ -29,7 +28,6 @@
import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.archetype.ui.generation.ArchetypeGenerationConfigurator;
import org.apache.maven.archetype.ui.generation.ArchetypeSelector;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.ContextEnabled;
@@ -40,6 +38,7 @@
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.InvocationResult;
@@ -130,18 +129,6 @@ public class CreateProjectFromArchetypeMojo extends AbstractMojo implements Cont
@Parameter(property = "askForDefaultPropertyValues", defaultValue = "false", required = true)
private Boolean askForDefaultPropertyValues;
- /**
- * Local Maven repository.
- */
- @Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
- private ArtifactRepository localRepository;
-
- /**
- * List of remote repositories used by the resolver.
- */
- @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true)
- private List remoteArtifactRepositories;
-
/**
* User settings used to check the interactiveMode.
*/
@@ -151,9 +138,12 @@ public class CreateProjectFromArchetypeMojo extends AbstractMojo implements Cont
@Parameter(defaultValue = "${basedir}", property = "outputDirectory")
private File outputDirectory;
- @Parameter(defaultValue = "${session}", readonly = true)
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
private MavenSession session;
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
+ private MavenProject project;
+
/**
* Goals to immediately run on the project created from the archetype.
*/
@@ -182,8 +172,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.setArchetypeArtifactId(archetypeArtifactId)
.setArchetypeVersion(archetypeVersion)
.setOutputDirectory(outputDirectory.getAbsolutePath())
- .setLocalRepository(localRepository)
- .setRemoteArtifactRepositories(remoteArtifactRepositories)
+ .setRemoteArtifactRepositories(project.getRemoteProjectRepositories())
.setFilter(filter)
.setAskForDefaultPropertyValues(askForDefaultPropertyValues)
.setProjectBuildingRequest(session.getProjectBuildingRequest());
diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
index 04123741..7561f301 100644
--- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
+++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/IntegrationTestMojo.java
@@ -42,9 +42,11 @@
import org.apache.maven.archetype.ArchetypeGenerationRequest;
import org.apache.maven.archetype.ArchetypeGenerationResult;
import org.apache.maven.archetype.common.Constants;
+import org.apache.maven.archetype.downloader.DownloadException;
+import org.apache.maven.archetype.downloader.DownloadNotFoundException;
+import org.apache.maven.archetype.downloader.Downloader;
import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
import org.apache.maven.archetype.generator.ArchetypeGenerator;
-import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -52,9 +54,7 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
@@ -64,9 +64,6 @@
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.apache.maven.shared.scriptinterpreter.ScriptException;
import org.apache.maven.shared.scriptinterpreter.ScriptRunner;
-import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver;
-import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.InterpolationFilterReader;
@@ -140,16 +137,10 @@ public class IntegrationTestMojo extends AbstractMojo {
private ArchetypeGenerator archetypeGenerator;
@Component
- private Invoker invoker;
+ private Downloader downloader;
@Component
- private ArtifactResolver artifactResolver;
-
- @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true)
- protected List remoteRepositories;
-
- @Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
- protected ArtifactRepository localRepository;
+ private Invoker invoker;
/**
* The archetype project to execute the integration tests on.
@@ -547,7 +538,7 @@ private File setupParentProjects(File configFolder, File buildFolder)
File archetypeFile;
try {
archetypeFile = getArchetypeFile(groupId, artifactId, version);
- } catch (ArtifactResolverException e) {
+ } catch (DownloadNotFoundException | DownloadException e) {
throw new MojoExecutionException("Could not resolve archetype artifact ", e);
}
Properties archetypeProperties = getProperties(archetypePomPropertiesFile);
@@ -557,24 +548,10 @@ private File setupParentProjects(File configFolder, File buildFolder)
return new File(buildFolder, request.getArtifactId());
}
- private File getArchetypeFile(String groupId, String artifactId, String version) throws ArtifactResolverException {
- ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
- if (localRepository != null) {
- buildingRequest = buildingRequest.setLocalRepository(localRepository);
- }
- if (remoteRepositories != null && !remoteRepositories.isEmpty()) {
- buildingRequest = buildingRequest.setRemoteRepositories(remoteRepositories);
- }
-
- DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
- coordinate.setGroupId(groupId);
- coordinate.setArtifactId(artifactId);
- coordinate.setVersion(version);
-
- return artifactResolver
- .resolveArtifact(buildingRequest, coordinate)
- .getArtifact()
- .getFile();
+ private File getArchetypeFile(String groupId, String artifactId, String version)
+ throws DownloadNotFoundException, DownloadException {
+ return downloader.download(
+ groupId, artifactId, version, project.getRemoteProjectRepositories(), session.getRepositorySession());
}
private Properties getProperties(File goalFile) throws IOException {
diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
index 621aafd2..5eb7844c 100644
--- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
+++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator.java
@@ -47,9 +47,6 @@
import org.apache.maven.archetype.ui.ArchetypeConfiguration;
import org.apache.maven.archetype.ui.ArchetypeDefinition;
import org.apache.maven.archetype.ui.ArchetypeFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
@@ -65,6 +62,10 @@
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.velocity.VelocityComponent;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.repository.RepositoryPolicy;
// TODO: this seems to have more responsibilities than just a configurator
@Named("default")
@@ -92,6 +93,9 @@ public class DefaultArchetypeGenerationConfigurator extends AbstractLogEnabled
@Inject
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
+ @Inject
+ private RepositorySystem repositorySystem;
+
public void setArchetypeArtifactManager(ArchetypeArtifactManager archetypeArtifactManager) {
this.archetypeArtifactManager = archetypeArtifactManager;
}
@@ -100,27 +104,27 @@ public void setArchetypeArtifactManager(ArchetypeArtifactManager archetypeArtifa
@SuppressWarnings("checkstyle:MethodLength")
public void configureArchetype(
ArchetypeGenerationRequest request, Boolean interactiveMode, Properties executionProperties)
- throws ArchetypeNotDefined, UnknownArchetype, ArchetypeNotConfigured, IOException, PrompterException,
+ throws ArchetypeNotDefined, UnknownArchetype, ArchetypeNotConfigured, PrompterException,
ArchetypeGenerationConfigurationFailure {
- ArtifactRepository localRepository = request.getLocalRepository();
-
- ArtifactRepository archetypeRepository = null;
- List repositories = new ArrayList<>();
+ List repositories = new ArrayList<>();
Properties properties = new Properties(executionProperties);
ArchetypeDefinition ad = new ArchetypeDefinition(request);
if (!ad.isDefined()) {
- if (!interactiveMode.booleanValue()) {
+ if (!interactiveMode) {
throw new ArchetypeNotDefined("No archetype was chosen");
} else {
throw new ArchetypeNotDefined("The archetype is not defined");
}
}
if (request.getArchetypeRepository() != null) {
- archetypeRepository = createRepository(request.getArchetypeRepository(), ad.getArtifactId() + "-repo");
+ RepositorySystemSession repositorySession =
+ request.getProjectBuildingRequest().getRepositorySession();
+ RemoteRepository archetypeRepository =
+ createRepository(repositorySession, request.getArchetypeRepository(), ad.getArtifactId() + "-repo");
repositories.add(archetypeRepository);
}
if (request.getRemoteArtifactRepositories() != null) {
@@ -131,10 +135,8 @@ public void configureArchetype(
ad.getGroupId(),
ad.getArtifactId(),
ad.getVersion(),
- archetypeRepository,
- localRepository,
repositories,
- request.getProjectBuildingRequest())) {
+ request.getProjectBuildingRequest().getRepositorySession())) {
throw new UnknownArchetype("The desired archetype does not exist (" + ad.getGroupId() + ":"
+ ad.getArtifactId() + ":" + ad.getVersion() + ")");
}
@@ -147,10 +149,8 @@ public void configureArchetype(
ad.getGroupId(),
ad.getArtifactId(),
ad.getVersion(),
- archetypeRepository,
- localRepository,
repositories,
- request.getProjectBuildingRequest());
+ request.getProjectBuildingRequest().getRepositorySession());
if (archetypeArtifactManager.isFileSetArchetype(archetypeFile)) {
org.apache.maven.archetype.metadata.ArchetypeDescriptor archetypeDescriptor =
archetypeArtifactManager.getFileSetArchetypeDescriptor(archetypeFile);
@@ -416,24 +416,24 @@ private boolean references(String targetProperty, String sourceProperty) {
}
}
- private ArtifactRepository createRepository(String url, String repositoryId) {
+ private RemoteRepository createRepository(
+ RepositorySystemSession repositorySession, String url, String repositoryId) {
// snapshots vs releases
// offline = to turning the update policy off
// TODO: we'll need to allow finer grained creation of repositories but this will do for now
- String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
-
- String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
-
- ArtifactRepositoryPolicy snapshotsPolicy =
- new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag);
+ RepositoryPolicy repositoryPolicy = new RepositoryPolicy(
+ true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN);
- ArtifactRepositoryPolicy releasesPolicy =
- new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag);
+ RemoteRepository remoteRepository = new RemoteRepository.Builder(repositoryId, "default", url)
+ .setSnapshotPolicy(repositoryPolicy)
+ .setReleasePolicy(repositoryPolicy)
+ .build();
- return new MavenArtifactRepository(
- repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy);
+ return repositorySystem
+ .newResolutionRepositories(repositorySession, Collections.singletonList(remoteRepository))
+ .get(0);
}
}
diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeSelector.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeSelector.java
index a389d7a7..dab4f3ea 100644
--- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeSelector.java
+++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeSelector.java
@@ -172,7 +172,7 @@ private Map> getArchetypesByCatalog(
List archetypesFromRemote =
archetypeManager.getRemoteCatalog(buildingRequest).getArchetypes();
- if (archetypesFromRemote.size() > 0) {
+ if (!archetypesFromRemote.isEmpty()) {
archetypes.put("remote", archetypesFromRemote);
} else {
getLogger().warn("No archetype found in remote catalog. Defaulting to internal catalog");
@@ -185,7 +185,7 @@ private Map> getArchetypesByCatalog(
}
}
- if (archetypes.size() == 0) {
+ if (archetypes.isEmpty()) {
getLogger().info("No catalog defined. Using internal catalog");
archetypes.put("internal", archetypeManager.getInternalCatalog().getArchetypes());
diff --git a/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
index 8b9ce6f5..5bece149 100644
--- a/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
+++ b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfigurator2Test.java
@@ -19,23 +19,23 @@
package org.apache.maven.archetype.ui.generation;
import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Properties;
-import java.util.regex.Pattern;
import org.apache.maven.archetype.ArchetypeGenerationRequest;
import org.apache.maven.archetype.common.ArchetypeArtifactManager;
import org.apache.maven.archetype.metadata.ArchetypeDescriptor;
import org.apache.maven.archetype.metadata.RequiredProperty;
-import org.apache.maven.archetype.ui.ArchetypeConfiguration;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusTestCase;
import org.easymock.EasyMock;
import org.easymock.IAnswer;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.isNull;
+
/**
* Tests the ability to use variables in default fields in batch mode.
*/
@@ -55,8 +55,6 @@ public void setUp() throws Exception {
configurator = (DefaultArchetypeGenerationConfigurator) lookup(ArchetypeGenerationConfigurator.ROLE);
- ProjectBuildingRequest buildingRequest = null;
-
descriptor = new ArchetypeDescriptor();
RequiredProperty groupId = new RequiredProperty();
groupId.setKey("groupId");
@@ -82,12 +80,20 @@ public void setUp() throws Exception {
ArchetypeArtifactManager manager = EasyMock.createMock(ArchetypeArtifactManager.class);
File archetype = new File("archetype.jar");
- List x = new ArrayList<>();
+
EasyMock.expect(manager.exists(
- "archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
+ eq("archetypeGroupId"),
+ eq("archetypeArtifactId"),
+ eq("archetypeVersion"),
+ anyObject(),
+ anyObject()))
.andReturn(true);
EasyMock.expect(manager.getArchetypeFile(
- "archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
+ eq("archetypeGroupId"),
+ eq("archetypeArtifactId"),
+ eq("archetypeVersion"),
+ anyObject(),
+ anyObject()))
.andReturn(archetype);
EasyMock.expect(manager.isFileSetArchetype(archetype)).andReturn(true);
EasyMock.expect(manager.isOldArchetype(archetype)).andReturn(false);
@@ -105,6 +111,7 @@ public void testJIRA_509_FileSetArchetypeDefaultsWithVariables() throws Exceptio
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
properties.setProperty("groupName", "myGroupName");
properties.setProperty("serviceName", "myServiceName");
@@ -122,18 +129,16 @@ public void testInteractive() throws Exception {
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.eq("groupName"), EasyMock.anyString(), EasyMock.isNull()))
+ EasyMock.expect(queryer.getPropertyValue(eq("groupName"), anyString(), isNull()))
.andReturn("myGroupName");
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.eq("serviceName"), EasyMock.anyString(), EasyMock.isNull()))
+ EasyMock.expect(queryer.getPropertyValue(eq("serviceName"), anyString(), isNull()))
.andReturn("myServiceName");
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject()))
+ EasyMock.expect(queryer.getPropertyValue(anyString(), anyString(), anyObject()))
.andAnswer(new IAnswer() {
@Override
@@ -143,8 +148,7 @@ public String answer() throws Throwable {
})
.anyTimes();
- EasyMock.expect(queryer.confirmConfiguration(EasyMock.anyObject()))
- .andReturn(Boolean.TRUE);
+ EasyMock.expect(queryer.confirmConfiguration(anyObject())).andReturn(Boolean.TRUE);
EasyMock.replay(queryer);
configurator.configureArchetype(request, Boolean.TRUE, properties);
@@ -165,18 +169,16 @@ public void testArchetype406ComplexCustomPropertyValue() throws Exception {
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.eq("groupName"), EasyMock.anyString(), EasyMock.isNull()))
+ EasyMock.expect(queryer.getPropertyValue(eq("groupName"), anyString(), isNull()))
.andReturn("myGroupName");
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.eq("serviceName"), EasyMock.anyString(), EasyMock.isNull()))
+ EasyMock.expect(queryer.getPropertyValue(eq("serviceName"), anyString(), isNull()))
.andReturn("myServiceName");
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject()))
+ EasyMock.expect(queryer.getPropertyValue(anyString(), anyString(), anyObject()))
.andAnswer(new IAnswer() {
@Override
@@ -186,8 +188,7 @@ public String answer() throws Throwable {
})
.anyTimes();
- EasyMock.expect(queryer.confirmConfiguration(EasyMock.anyObject()))
- .andReturn(Boolean.TRUE);
+ EasyMock.expect(queryer.confirmConfiguration(anyObject())).andReturn(Boolean.TRUE);
EasyMock.replay(queryer);
configurator.configureArchetype(request, Boolean.TRUE, properties);
@@ -208,18 +209,16 @@ public void testArchetype618() throws Exception {
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.eq("groupName"), EasyMock.anyString(), EasyMock.isNull()))
+ EasyMock.expect(queryer.getPropertyValue(eq("groupName"), anyString(), isNull()))
.andReturn("myGroupName");
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.eq("artifactId"), EasyMock.anyString(), EasyMock.isNull()))
+ EasyMock.expect(queryer.getPropertyValue(eq("artifactId"), anyString(), isNull()))
.andReturn("my-service-name");
- EasyMock.expect(queryer.getPropertyValue(
- EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject()))
+ EasyMock.expect(queryer.getPropertyValue(anyString(), anyString(), anyObject()))
.andAnswer(new IAnswer() {
@Override
@@ -229,8 +228,7 @@ public String answer() throws Throwable {
})
.anyTimes();
- EasyMock.expect(queryer.confirmConfiguration(EasyMock.anyObject()))
- .andReturn(Boolean.TRUE);
+ EasyMock.expect(queryer.confirmConfiguration(anyObject())).andReturn(Boolean.TRUE);
EasyMock.replay(queryer);
configurator.configureArchetype(request, Boolean.TRUE, properties);
diff --git a/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfiguratorTest.java b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfiguratorTest.java
index 38e0adc1..f452b2f9 100644
--- a/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfiguratorTest.java
+++ b/maven-archetype-plugin/src/test/java/org/apache/maven/archetype/ui/generation/DefaultArchetypeGenerationConfiguratorTest.java
@@ -19,9 +19,6 @@
package org.apache.maven.archetype.ui.generation;
import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Properties;
import org.apache.maven.archetype.ArchetypeGenerationRequest;
@@ -29,17 +26,17 @@
import org.apache.maven.archetype.exception.ArchetypeGenerationConfigurationFailure;
import org.apache.maven.archetype.exception.ArchetypeNotConfigured;
import org.apache.maven.archetype.exception.ArchetypeNotDefined;
-import org.apache.maven.archetype.exception.ArchetypeSelectionFailure;
import org.apache.maven.archetype.exception.UnknownArchetype;
-import org.apache.maven.archetype.exception.UnknownGroup;
import org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.codehaus.plexus.ContainerConfiguration;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.components.interactivity.PrompterException;
import org.easymock.EasyMock;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.eq;
+
/**
* TODO probably testing a little deep, could just test ArchetypeConfiguration
*/
@@ -57,17 +54,22 @@ public void setUp() throws Exception {
configurator = (DefaultArchetypeGenerationConfigurator) lookup(ArchetypeGenerationConfigurator.ROLE);
- ProjectBuildingRequest buildingRequest = null;
-
ArchetypeArtifactManager manager = EasyMock.createMock(ArchetypeArtifactManager.class);
File archetype = new File("archetype.jar");
- List x = new ArrayList<>();
EasyMock.expect(manager.exists(
- "archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
+ eq("archetypeGroupId"),
+ eq("archetypeArtifactId"),
+ eq("archetypeVersion"),
+ anyObject(),
+ anyObject()))
.andReturn(true);
EasyMock.expect(manager.getArchetypeFile(
- "archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, x, buildingRequest))
+ eq("archetypeGroupId"),
+ eq("archetypeArtifactId"),
+ eq("archetypeVersion"),
+ anyObject(),
+ anyObject()))
.andReturn(archetype);
EasyMock.expect(manager.isFileSetArchetype(archetype)).andReturn(false);
EasyMock.expect(manager.isOldArchetype(archetype)).andReturn(true);
@@ -79,12 +81,13 @@ public void setUp() throws Exception {
}
public void testOldArchetypeGeneratedFieldsInRequestBatchMode()
- throws PrompterException, ArchetypeGenerationConfigurationFailure, IOException, ArchetypeNotConfigured,
- UnknownArchetype, ArchetypeNotDefined {
+ throws PrompterException, ArchetypeGenerationConfigurationFailure, ArchetypeNotConfigured, UnknownArchetype,
+ ArchetypeNotDefined {
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
properties.setProperty("groupId", "preset-groupId");
properties.setProperty("artifactId", "preset-artifactId");
@@ -100,12 +103,13 @@ public void testOldArchetypeGeneratedFieldsInRequestBatchMode()
}
public void testOldArchetypeGeneratedFieldsDefaultsBatchMode()
- throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype,
- ArchetypeNotDefined, ArchetypeGenerationConfigurationFailure, ArchetypeNotConfigured {
+ throws PrompterException, UnknownArchetype, ArchetypeNotDefined, ArchetypeGenerationConfigurationFailure,
+ ArchetypeNotConfigured {
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
properties.setProperty("groupId", "preset-groupId");
properties.setProperty("artifactId", "preset-artifactId");
@@ -120,12 +124,12 @@ public void testOldArchetypeGeneratedFieldsDefaultsBatchMode()
// TODO: should test this in interactive mode to check for prompting
public void testOldArchetypeGeneratedFieldsDefaultsMissingGroupId()
- throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype,
- ArchetypeNotDefined, ArchetypeGenerationConfigurationFailure, ArchetypeNotConfigured {
+ throws PrompterException, UnknownArchetype, ArchetypeNotDefined, ArchetypeGenerationConfigurationFailure {
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setArchetypeGroupId("archetypeGroupId");
request.setArchetypeArtifactId("archetypeArtifactId");
request.setArchetypeVersion("archetypeVersion");
+ request.setProjectBuildingRequest(new DefaultProjectBuildingRequest());
Properties properties = new Properties();
properties.setProperty("artifactId", "preset-artifactId");
diff --git a/pom.xml b/pom.xml
index 1f88430e..6d8b20bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,11 +150,6 @@
maven-invoker
3.3.0
-
- org.apache.maven.shared
- maven-artifact-transfer
- 0.13.1
-
commons-io
commons-io