diff --git a/archetype-common/pom.xml b/archetype-common/pom.xml index ce3944c9..e41c836c 100644 --- a/archetype-common/pom.xml +++ b/archetype-common/pom.xml @@ -112,10 +112,6 @@ org.apache.velocity velocity-engine-core - - org.apache.maven.wagon - wagon-provider-api - junit junit diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeCreationRequest.java b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeCreationRequest.java index 9bba301b..3e3f4a28 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeCreationRequest.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeCreationRequest.java @@ -23,20 +23,15 @@ import java.util.List; import java.util.Properties; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuildingRequest; /** @author Jason van Zyl */ public class ArchetypeCreationRequest { - private ProjectBuildingRequest projectBuildingRequest; - private ArtifactRepository localRepository; + private File localRepositoryBasedir; private MavenProject project; - // private File propertyFile; - private List languages = new ArrayList<>(); private List filtereds = new ArrayList<>(); @@ -65,27 +60,15 @@ public String getPostPhase() { public ArchetypeCreationRequest setPostPhase(String postPhase) { this.postPhase = postPhase; - return this; } - public ArtifactRepository getLocalRepository() { - return localRepository; + public File getLocalRepositoryBasedir() { + return localRepositoryBasedir; } - public ArchetypeCreationRequest setLocalRepository(ArtifactRepository localRepository) { - this.localRepository = localRepository; - - return this; - } - - public ProjectBuildingRequest getProjectBuildingRequest() { - return projectBuildingRequest; - } - - public ArchetypeCreationRequest setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) { - this.projectBuildingRequest = projectBuildingRequest; - + public ArchetypeCreationRequest setLocalRepositoryBasedir(File localRepository) { + this.localRepositoryBasedir = localRepository; return this; } @@ -95,29 +78,15 @@ public MavenProject getProject() { public ArchetypeCreationRequest setProject(MavenProject project) { this.project = project; - return this; } - // public File getPropertyFile() - // { - // return propertyFile; - // } - // - // public ArchetypeCreationRequest setPropertyFile( File propertyFile ) - // { - // this.propertyFile = propertyFile; - // - // return this; - // } - public List getLanguages() { return languages; } public ArchetypeCreationRequest setLanguages(List languages) { this.languages = languages; - return this; } @@ -127,7 +96,6 @@ public List getFiltereds() { public ArchetypeCreationRequest setFiltereds(List filtereds) { this.filtereds = filtereds; - return this; } @@ -137,7 +105,6 @@ public String getDefaultEncoding() { public ArchetypeCreationRequest setDefaultEncoding(String defaultEncoding) { this.defaultEncoding = defaultEncoding; - return this; } @@ -147,7 +114,6 @@ public boolean isPreserveCData() { public ArchetypeCreationRequest setPreserveCData(boolean preserveCData) { this.preserveCData = preserveCData; - return this; } @@ -157,7 +123,6 @@ public boolean isKeepParent() { public ArchetypeCreationRequest setKeepParent(boolean keepParent) { this.keepParent = keepParent; - return this; } @@ -167,7 +132,6 @@ public boolean isPartialArchetype() { public ArchetypeCreationRequest setPartialArchetype(boolean partialArchetype) { this.partialArchetype = partialArchetype; - return this; } @@ -177,7 +141,6 @@ public Properties getProperties() { public ArchetypeCreationRequest setProperties(Properties properties) { this.properties = properties; - return this; } @@ -187,7 +150,6 @@ public String getPackageName() { public ArchetypeCreationRequest setPackageName(String packageName) { this.packageName = packageName; - return this; } @@ -197,7 +159,6 @@ public File getOutputDirectory() { public ArchetypeCreationRequest setOutputDirectory(File outputDirectory) { this.outputDirectory = outputDirectory; - return this; } @@ -207,7 +168,6 @@ public File getSettingsFile() { public ArchetypeCreationRequest setSettingsFile(File settingsFile) { this.settingsFile = settingsFile; - return this; } } 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 9c46a560..3a229831 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 @@ -23,12 +23,13 @@ import java.util.Properties; import org.apache.maven.archetype.catalog.Archetype; -import org.apache.maven.project.ProjectBuildingRequest; +import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; /** @author Jason van Zyl */ public class ArchetypeGenerationRequest { - private ProjectBuildingRequest projectBuildingRequest; + + private RepositorySystemSession repositorySession; private boolean interactiveMode; @@ -87,12 +88,12 @@ public ArchetypeGenerationRequest(Archetype archetype) { this.archetypeRepository = archetype.getRepository(); } - public ProjectBuildingRequest getProjectBuildingRequest() { - return projectBuildingRequest; + public RepositorySystemSession getRepositorySession() { + return repositorySession; } - public ArchetypeGenerationRequest setProjectBuildingRequest(ProjectBuildingRequest projectBuildingRequest) { - this.projectBuildingRequest = projectBuildingRequest; + public ArchetypeGenerationRequest setRepositorySession(RepositorySystemSession repoSession) { + this.repositorySession = repoSession; return this; } @@ -102,7 +103,6 @@ public String getArchetypeGroupId() { public ArchetypeGenerationRequest setArchetypeGroupId(String archetypeGroupId) { this.archetypeGroupId = archetypeGroupId; - return this; } @@ -112,7 +112,6 @@ public String getArchetypeArtifactId() { public ArchetypeGenerationRequest setArchetypeArtifactId(String archetypeArtifactId) { this.archetypeArtifactId = archetypeArtifactId; - return this; } @@ -122,7 +121,6 @@ public String getArchetypeVersion() { public ArchetypeGenerationRequest setArchetypeVersion(String archetypeVersion) { this.archetypeVersion = archetypeVersion; - return this; } @@ -132,7 +130,6 @@ public String getArchetypeGoals() { public ArchetypeGenerationRequest setArchetypeGoals(String archetypeGoals) { this.archetypeGoals = archetypeGoals; - return this; } @@ -142,7 +139,6 @@ public String getArchetypeName() { public ArchetypeGenerationRequest setArchetypeName(String archetypeName) { this.archetypeName = archetypeName; - return this; } @@ -175,7 +171,6 @@ public String getArtifactId() { public ArchetypeGenerationRequest setArtifactId(String artifactId) { this.artifactId = artifactId; - return this; } @@ -185,7 +180,6 @@ public String getGroupId() { public ArchetypeGenerationRequest setGroupId(String groupId) { this.groupId = groupId; - return this; } @@ -195,7 +189,6 @@ public String getVersion() { public ArchetypeGenerationRequest setVersion(String version) { this.version = version; - return this; } @@ -205,7 +198,6 @@ public String getPackage() { public ArchetypeGenerationRequest setPackage(String packageName) { this.packageName = packageName; - return this; } @@ -225,7 +217,6 @@ public String getOutputDirectory() { public ArchetypeGenerationRequest setOutputDirectory(String outputDirectory) { this.outputDirectory = outputDirectory; - return this; } @@ -235,7 +226,6 @@ public boolean isInteractiveMode() { public ArchetypeGenerationRequest setInteractiveMode(boolean interactiveMode) { this.interactiveMode = interactiveMode; - return this; } @@ -245,7 +235,6 @@ public boolean isAskForDefaultPropertyValues() { public ArchetypeGenerationRequest setAskForDefaultPropertyValues(boolean askForDefaultPropertyValues) { this.askForDefaultPropertyValues = askForDefaultPropertyValues; - return this; } @@ -255,7 +244,6 @@ public List getRemoteArtifactRepositories() { public ArchetypeGenerationRequest setRemoteArtifactRepositories(List remoteArtifactRepositories) { this.remoteArtifactRepositories = remoteArtifactRepositories; - return this; } @@ -265,7 +253,6 @@ public String getFilter() { public ArchetypeGenerationRequest setFilter(String filter) { this.filter = filter; - return this; } } diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java index 866e4d8b..62c881de 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java @@ -20,11 +20,13 @@ import java.io.File; import java.io.IOException; +import java.util.List; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.project.ProjectBuildingRequest; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; /** @author Jason van Zyl */ public interface ArchetypeManager { @@ -60,19 +62,21 @@ public interface ArchetypeManager { * if path is a file, it used as is. * if path is a directory, archetype-catalog.xml is appended to it. * - * @param buildingRequest the catalog file path or directory containing the catalog file. + * @param repositorySession * @return the catalog. */ - ArchetypeCatalog getLocalCatalog(ProjectBuildingRequest buildingRequest); + ArchetypeCatalog getLocalCatalog(RepositorySystemSession repositorySession); /** * Gives the catalog of archetypes located at * https://repo.maven.apache.org/maven2/archetype-catalog.xml. - * @param buildingRequest TODO * + * @param repositorySession + * @param remoteRepositories * @return the catalog. */ - ArchetypeCatalog getRemoteCatalog(ProjectBuildingRequest buildingRequest); + ArchetypeCatalog getRemoteCatalog( + RepositorySystemSession repositorySession, List remoteRepositories); /** * Creates a jar file for an archetype. @@ -89,5 +93,5 @@ public interface ArchetypeManager { File archiveArchetype(File archetypeDirectory, File outputDirectory, String finalName) throws DependencyResolutionRequiredException, IOException; - File updateLocalCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype); + File updateLocalCatalog(RepositorySystemSession repositorySystemSession, Archetype archetype); } diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/DefaultArchetypeManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/DefaultArchetypeManager.java index 3d0a2590..44e429dc 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/DefaultArchetypeManager.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/DefaultArchetypeManager.java @@ -26,6 +26,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.List; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -36,10 +37,10 @@ import org.apache.maven.archetype.generator.ArchetypeGenerator; import org.apache.maven.archetype.source.ArchetypeDataSource; import org.apache.maven.archetype.source.ArchetypeDataSourceException; -import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.IOUtil; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; /** * @author Jason van Zyl @@ -77,8 +78,7 @@ public ArchetypeGenerationResult generateProjectFromArchetype(ArchetypeGeneratio } @Override - public File archiveArchetype(File archetypeDirectory, File outputDirectory, String finalName) - throws DependencyResolutionRequiredException, IOException { + public File archiveArchetype(File archetypeDirectory, File outputDirectory, String finalName) throws IOException { File jarFile = new File(outputDirectory, finalName + ".jar"); zip(archetypeDirectory, jarFile); @@ -144,29 +144,30 @@ public ArchetypeCatalog getInternalCatalog() { try { ArchetypeDataSource source = archetypeSources.get("internal-catalog"); - return source.getArchetypeCatalog(null); + return source.getArchetypeCatalog(null, null); } catch (ArchetypeDataSourceException e) { return new ArchetypeCatalog(); } } @Override - public ArchetypeCatalog getLocalCatalog(ProjectBuildingRequest buildingRequest) { + public ArchetypeCatalog getLocalCatalog(RepositorySystemSession repositorySession) { try { ArchetypeDataSource source = archetypeSources.get("catalog"); - return source.getArchetypeCatalog(buildingRequest); + return source.getArchetypeCatalog(repositorySession, null); } catch (ArchetypeDataSourceException e) { return new ArchetypeCatalog(); } } @Override - public ArchetypeCatalog getRemoteCatalog(ProjectBuildingRequest buildingRequest) { + public ArchetypeCatalog getRemoteCatalog( + RepositorySystemSession repositorySession, List remoteRepositories) { try { ArchetypeDataSource source = archetypeSources.get("remote-catalog"); - return source.getArchetypeCatalog(buildingRequest); + return source.getArchetypeCatalog(repositorySession, remoteRepositories); } catch (ArchetypeDataSourceException e) { getLogger().warn("failed to download from remote", e); return new ArchetypeCatalog(); @@ -174,11 +175,11 @@ public ArchetypeCatalog getRemoteCatalog(ProjectBuildingRequest buildingRequest) } @Override - public File updateLocalCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype) { + public File updateLocalCatalog(RepositorySystemSession repositorySystemSession, Archetype archetype) { try { ArchetypeDataSource source = archetypeSources.get("catalog"); - return source.updateCatalog(buildingRequest, archetype); + return source.updateCatalog(repositorySystemSession, archetype); } catch (ArchetypeDataSourceException e) { getLogger().warn("failed to update catalog", e); } 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 e2dfe823..3325640f 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 @@ -39,7 +39,6 @@ import org.apache.commons.io.IOUtils; 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.UnknownArchetype; import org.apache.maven.archetype.metadata.ArchetypeDescriptor; @@ -80,7 +79,7 @@ public File getArchetypeFile( setArchetype(groupId, artifactId, version, archetype); } return archetype; - } catch (DownloadNotFoundException | DownloadException ex) { + } catch (DownloadException ex) { throw new UnknownArchetype(ex); } } @@ -180,7 +179,7 @@ public boolean exists( } return archetype.exists(); - } catch (DownloadException | DownloadNotFoundException e) { + } catch (DownloadException e) { getLogger() .debug( "Archetype " + archetypeGroupId + ":" + archetypeArtifactId + ":" + archetypeVersion @@ -301,8 +300,6 @@ private org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor loadOldArc ArchetypeDescriptorBuilder builder = new ArchetypeDescriptorBuilder(); return builder.build(reader); - } catch (IOException | XmlPullParserException ex) { - throw ex; } } diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java index 0cdf60dc..021b6cc6 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java @@ -51,7 +51,6 @@ import org.apache.maven.archetype.common.util.FileCharsetDetector; import org.apache.maven.archetype.common.util.ListScanner; import org.apache.maven.archetype.common.util.PathUtils; -import org.apache.maven.archetype.exception.TemplateCreationException; import org.apache.maven.archetype.metadata.ArchetypeDescriptor; import org.apache.maven.archetype.metadata.FileSet; import org.apache.maven.archetype.metadata.ModuleDescriptor; @@ -66,7 +65,6 @@ import org.apache.maven.model.Profile; import org.apache.maven.model.Resource; import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.invoker.DefaultInvocationRequest; import org.apache.maven.shared.invoker.InvocationRequest; import org.apache.maven.shared.invoker.InvocationResult; @@ -133,8 +131,7 @@ public void createArchetype(ArchetypeCreationRequest request, ArchetypeCreationR getLogger().debug("Creating archetype in " + outputDirectory); try { - File archetypePomFile = createArchetypeProjectPom( - project, request.getProjectBuildingRequest(), configurationProperties, outputDirectory); + File archetypePomFile = createArchetypeProjectPom(project, configurationProperties, outputDirectory); File archetypeResourcesDirectory = new File(outputDirectory, getTemplateOutputDirectory()); @@ -285,11 +282,8 @@ public void createArchetype(ArchetypeCreationRequest request, ArchetypeCreationR InvocationRequest internalRequest = new DefaultInvocationRequest(); internalRequest.setPomFile(archetypePomFile); internalRequest.setUserSettingsFile(request.getSettingsFile()); - internalRequest.setGoals(Collections.singletonList(request.getPostPhase())); - if (request.getLocalRepository() != null) { - internalRequest.setLocalRepositoryDirectory( - new File(request.getLocalRepository().getBasedir())); - } + internalRequest.addArg(request.getPostPhase()); + internalRequest.setLocalRepositoryDirectory(request.getLocalRepositoryBasedir()); String httpsProtocols = System.getProperty("https.protocols"); if (httpsProtocols != null) { @@ -379,12 +373,8 @@ private void extractPropertiesFromProject( /** * Create the archetype project pom.xml file, that will be used to build the archetype. */ - private File createArchetypeProjectPom( - MavenProject project, - ProjectBuildingRequest buildingRequest, - Properties configurationProperties, - File projectDir) - throws TemplateCreationException, IOException { + private File createArchetypeProjectPom(MavenProject project, Properties configurationProperties, File projectDir) + throws IOException { Model model = new Model(); model.setModelVersion("4.0.0"); // these values should be retrieved from the request with sensible defaults 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 4df53e2e..6f89df03 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 @@ -50,7 +50,7 @@ public File download( String version, List remoteRepositories, RepositorySystemSession repositorySystemSession) - throws DownloadException, DownloadNotFoundException { + throws DownloadException { DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, "", "jar", version); diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadException.java b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadException.java index 8cd10092..0596f119 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadException.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadException.java @@ -22,15 +22,8 @@ * @author Jason van Zyl */ public class DownloadException extends Exception { - public DownloadException(String string) { - super(string); - } public DownloadException(String string, Throwable throwable) { super(string, throwable); } - - public DownloadException(Throwable throwable) { - super(throwable); - } } diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadNotFoundException.java b/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadNotFoundException.java deleted file mode 100644 index e5ebeac0..00000000 --- a/archetype-common/src/main/java/org/apache/maven/archetype/downloader/DownloadNotFoundException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.archetype.downloader; - -/** - * @author Jason van Zyl - */ -public class DownloadNotFoundException extends Exception { - public DownloadNotFoundException(String string) { - super(string); - } - - public DownloadNotFoundException(String string, Throwable throwable) { - super(string, throwable); - } - - public DownloadNotFoundException(Throwable throwable) { - super(throwable); - } -} 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 9d15066d..b7440c7a 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 @@ -34,5 +34,5 @@ File download( String version, List remoteRepositories, RepositorySystemSession repositorySystemSession) - throws DownloadException, DownloadNotFoundException; + throws DownloadException; } 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 e8550faf..3c0b272d 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 @@ -36,7 +36,6 @@ 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.layout.ArtifactRepositoryLayout; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; import org.eclipse.aether.RepositorySystem; @@ -47,11 +46,6 @@ @Named @Singleton public class DefaultArchetypeGenerator extends AbstractLogEnabled implements ArchetypeGenerator { - /** - * Determines whether the layout is legacy or not. - */ - @Inject - private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; @Inject private ArchetypeArtifactManager archetypeArtifactManager; @@ -74,8 +68,7 @@ private File getArchetypeFile(ArchetypeGenerationRequest request) throws Archety RemoteRepository remoteRepo = null; if (request != null && request.getArchetypeRepository() != null) { - RepositorySystemSession repositorySession = - request.getProjectBuildingRequest().getRepositorySession(); + RepositorySystemSession repositorySession = request.getRepositorySession(); remoteRepo = createRepository( repositorySession, request.getArchetypeRepository(), request.getArchetypeArtifactId() + "-repo"); @@ -87,18 +80,17 @@ private File getArchetypeFile(ArchetypeGenerationRequest request) throws Archety request.getArchetypeArtifactId(), request.getArchetypeVersion(), repos, - request.getProjectBuildingRequest().getRepositorySession())) { + request.getRepositorySession())) { throw new UnknownArchetype("The desired archetype does not exist (" + request.getArchetypeGroupId() + ":" + request.getArchetypeArtifactId() + ":" + request.getArchetypeVersion() + ")"); } - File archetypeFile = archetypeArtifactManager.getArchetypeFile( + return archetypeArtifactManager.getArchetypeFile( request.getArchetypeGroupId(), request.getArchetypeArtifactId(), request.getArchetypeVersion(), repos, - request.getProjectBuildingRequest().getRepositorySession()); - return archetypeFile; + request.getRepositorySession()); } private void generateArchetype(ArchetypeGenerationRequest request, File archetypeFile) throws ArchetypeException { 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 e08a5c51..470ca4af 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 @@ -114,7 +114,7 @@ public void createArchetype(ArchetypeGenerationRequest request) request.getArchetypeArtifactId(), request.getArchetypeVersion(), request.getRemoteArtifactRepositories(), - request.getProjectBuildingRequest().getRepositorySession()); + request.getRepositorySession()); createArchetype(request, archetypeFile); } diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java b/archetype-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java index 86b62590..aa837fd0 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/source/ArchetypeDataSource.java @@ -19,10 +19,12 @@ package org.apache.maven.archetype.source; import java.io.File; +import java.util.List; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; -import org.apache.maven.project.ProjectBuildingRequest; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; /** * Sources we can get Archetypes from. This may be the local registry, a Wiki, or, @@ -36,7 +38,10 @@ public interface ArchetypeDataSource { String ARCHETYPE_CATALOG_FILENAME = "archetype-catalog.xml"; - ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest) throws ArchetypeDataSourceException; + ArchetypeCatalog getArchetypeCatalog( + RepositorySystemSession repositorySession, List remoteRepositories) + throws ArchetypeDataSourceException; - File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype) throws ArchetypeDataSourceException; + File updateCatalog(RepositorySystemSession repositorySession, Archetype archetype) + throws ArchetypeDataSourceException; } diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/source/InternalCatalogArchetypeDataSource.java b/archetype-common/src/main/java/org/apache/maven/archetype/source/InternalCatalogArchetypeDataSource.java index 19d10dbf..9b5c4515 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/source/InternalCatalogArchetypeDataSource.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/source/InternalCatalogArchetypeDataSource.java @@ -25,11 +25,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; +import java.util.List; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; -import org.apache.maven.project.ProjectBuildingRequest; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlStreamReader; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; /** * @author Jason van Zyl @@ -39,12 +41,11 @@ public class InternalCatalogArchetypeDataSource extends CatalogArchetypeDataSource { @Override - public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest) + public ArchetypeCatalog getArchetypeCatalog( + RepositorySystemSession repositorySession, List remoteRepositories) throws ArchetypeDataSourceException { - try { - InputStream in = getClass().getClassLoader().getResourceAsStream(ARCHETYPE_CATALOG_FILENAME); - Reader reader = ReaderFactory.newXmlReader(in); - + try (InputStream in = getClass().getClassLoader().getResourceAsStream(ARCHETYPE_CATALOG_FILENAME); + Reader reader = new XmlStreamReader(in)) { return readCatalog(reader); } catch (IOException e) { throw new ArchetypeDataSourceException("Error reading archetype catalog.", e); @@ -52,7 +53,7 @@ public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingReque } @Override - public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype) + public File updateCatalog(RepositorySystemSession repositorySession, Archetype archetype) throws ArchetypeDataSourceException { throw new ArchetypeDataSourceException("Not supported yet."); } 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 cefcb04a..55d8069f 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 @@ -24,22 +24,24 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.Reader; import java.util.Iterator; +import java.util.List; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; -import org.apache.maven.project.ProjectBuildingRequest; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlStreamReader; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; @Named("catalog") @Singleton public class LocalCatalogArchetypeDataSource extends CatalogArchetypeDataSource { @Override - public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype) + public File updateCatalog(RepositorySystemSession repositorySession, Archetype archetype) throws ArchetypeDataSourceException { - File localRepo = - buildingRequest.getRepositorySession().getLocalRepository().getBasedir(); + File localRepo = repositorySession.getLocalRepository().getBasedir(); File catalogFile = new File(localRepo, ARCHETYPE_CATALOG_FILENAME); @@ -47,9 +49,9 @@ public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype arch ArchetypeCatalog catalog; if (catalogFile.exists()) { - try { + try (Reader reader = new XmlStreamReader(catalogFile)) { getLogger().debug("Reading catalog to be updated: " + catalogFile); - catalog = readCatalog(ReaderFactory.newXmlReader(catalogFile)); + catalog = readCatalog(reader); } catch (FileNotFoundException ex) { getLogger().debug("Catalog file don't exist"); catalog = new ArchetypeCatalog(); @@ -87,10 +89,11 @@ public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype arch } @Override - public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest) + public ArchetypeCatalog getArchetypeCatalog( + RepositorySystemSession repositorySession, List remoteRepositories) throws ArchetypeDataSourceException { - File localRepo = - buildingRequest.getRepositorySession().getLocalRepository().getBasedir(); + + File localRepo = repositorySession.getLocalRepository().getBasedir(); File catalogFile = new File(localRepo, ARCHETYPE_CATALOG_FILENAME); @@ -101,7 +104,7 @@ public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingReque if (catalogFile.exists()) { try { - return readCatalog(ReaderFactory.newXmlReader(catalogFile)); + return readCatalog(new XmlStreamReader(catalogFile)); } catch (FileNotFoundException e) { throw new ArchetypeDataSourceException("The specific archetype catalog does not exist.", e); } catch (IOException e) { diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java b/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java index f77afb87..d85c1517 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/source/RemoteCatalogArchetypeDataSource.java @@ -24,29 +24,19 @@ import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.List; -import java.util.Map; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.LegacySupport; -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.settings.crypto.DefaultSettingsDecryptionRequest; -import org.apache.maven.settings.crypto.SettingsDecrypter; -import org.apache.maven.settings.crypto.SettingsDecryptionResult; -import org.apache.maven.wagon.UnsupportedProtocolException; -import org.apache.maven.wagon.Wagon; -import org.apache.maven.wagon.WagonException; -import org.apache.maven.wagon.authentication.AuthenticationInfo; -import org.apache.maven.wagon.proxy.ProxyInfo; -import org.apache.maven.wagon.repository.Repository; -import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.xml.XmlStreamReader; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.metadata.DefaultMetadata; +import org.eclipse.aether.metadata.Metadata; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.MetadataRequest; +import org.eclipse.aether.resolution.MetadataResult; /** * @author Jason van Zyl @@ -54,19 +44,9 @@ @Named("remote-catalog") @Singleton public class RemoteCatalogArchetypeDataSource extends CatalogArchetypeDataSource implements ArchetypeDataSource { - @Inject - private Map wagons; - - @Inject - private LegacySupport legacySupport; @Inject - private SettingsDecrypter settingsDecrypter; - - // Should be used for mirror/proxy/authentication - // available since M3.2.3 - // @Requirement - // private MavenRepositorySystem; + private RepositorySystem repositorySystem; /** * Id of the repository used to download catalog file. Proxy or authentication info can @@ -77,303 +57,56 @@ public class RemoteCatalogArchetypeDataSource extends CatalogArchetypeDataSource public static final String CENTRAL_REPOSITORY_ID = "central"; @Override - public ArchetypeCatalog getArchetypeCatalog(ProjectBuildingRequest buildingRequest) - throws ArchetypeDataSourceException { - // With M3 artifactRepositories are already injected with their mirror, including the new id - // First look for mirrorId of both 'central' and 'archetype' - final String archetypeRepoId; - Mirror archetypeMirror = getMirror(ARCHETYPE_REPOSITORY_ID); - if (archetypeMirror != null) { - archetypeRepoId = archetypeMirror.getId(); - } else { - archetypeRepoId = ARCHETYPE_REPOSITORY_ID; - } - - final String centralRepoId; - Mirror centralMirror = getMirror(CENTRAL_REPOSITORY_ID); - if (centralMirror != null) { - centralRepoId = centralMirror.getId(); - } else { - centralRepoId = CENTRAL_REPOSITORY_ID; - } - - ArtifactRepository centralRepository = null; - ArtifactRepository archetypeRepository = null; - for (ArtifactRepository remoteRepository : buildingRequest.getRemoteRepositories()) { - if (archetypeRepoId.equals(remoteRepository.getId())) { - archetypeRepository = remoteRepository; - break; - } else if (centralRepoId.equals(remoteRepository.getId())) { - centralRepository = remoteRepository; - } - } - - if (archetypeRepository == null) { - archetypeRepository = centralRepository; - } - - try { - return downloadCatalog(archetypeRepository); - } catch (IOException e) { - throw new ArchetypeDataSourceException(e); - } catch (WagonException e) { - throw new ArchetypeDataSourceException(e); - } - } - - @Override - public File updateCatalog(ProjectBuildingRequest buildingRequest, Archetype archetype) + public ArchetypeCatalog getArchetypeCatalog( + RepositorySystemSession repositorySession, List remoteRepositories) throws ArchetypeDataSourceException { - throw new ArchetypeDataSourceException("Not supported yet."); - } - - private ArchetypeCatalog downloadCatalog(ArtifactRepository repository) - throws WagonException, IOException, ArchetypeDataSourceException { - getLogger().debug("Searching for remote catalog: " + repository.getUrl() + "/" + ARCHETYPE_CATALOG_FILENAME); - - // We use wagon to take advantage of a Proxy that has already been setup in a Maven environment. - Repository wagonRepository = new Repository(repository.getId(), repository.getUrl()); - - AuthenticationInfo authInfo = getAuthenticationInfo(wagonRepository.getId()); - ProxyInfo proxyInfo = getProxy(wagonRepository.getProtocol()); - - Wagon wagon = getWagon(wagonRepository); - - File catalog = File.createTempFile("archetype-catalog", ".xml"); - try { - wagon.connect(wagonRepository, authInfo, proxyInfo); - wagon.get(ARCHETYPE_CATALOG_FILENAME, catalog); - - return readCatalog(ReaderFactory.newXmlReader(catalog)); - } finally { - disconnectWagon(wagon); - catalog.delete(); - } - } - - private void disconnectWagon(Wagon wagon) { - try { - wagon.disconnect(); - } catch (Exception e) { - getLogger().warn("Problem disconnecting from wagon - ignoring: " + e.getMessage()); - } - } - - // - - private Wagon getWagon(Repository repository) throws UnsupportedProtocolException { - return getWagon(repository.getProtocol()); - } - - private Wagon getWagon(String protocol) throws UnsupportedProtocolException { - if (protocol == null) { - throw new UnsupportedProtocolException("Unspecified protocol"); - } - - String hint = protocol.toLowerCase(java.util.Locale.ENGLISH); - - Wagon wagon = wagons.get(hint); - if (wagon == null) { - throw new UnsupportedProtocolException( - "Cannot find wagon which supports the requested protocol: " + protocol); - } - - return wagon; - } - - private AuthenticationInfo getAuthenticationInfo(String id) { - MavenSession session = legacySupport.getSession(); - if (session != null && id != null) { - MavenExecutionRequest request = session.getRequest(); + MetadataRequest request = new MetadataRequest(); + request.setRepository(getRemoteRepo(remoteRepositories)); + request.setMetadata(new DefaultMetadata(ARCHETYPE_CATALOG_FILENAME, Metadata.Nature.RELEASE)); - if (request != null) { - List servers = request.getServers(); + MetadataResult metadataResult = repositorySystem + .resolveMetadata(repositorySession, Collections.singletonList(request)) + .get(0); - if (servers != null) { - for (Server server : servers) { - if (id.equalsIgnoreCase(server.getId())) { - SettingsDecryptionResult result = - settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(server)); - server = result.getServer(); - - AuthenticationInfo authInfo = new AuthenticationInfo(); - authInfo.setUserName(server.getUsername()); - authInfo.setPassword(server.getPassword()); - authInfo.setPrivateKey(server.getPrivateKey()); - authInfo.setPassphrase(server.getPassphrase()); - - return authInfo; - } - } - } - } - } - - // empty one to prevent NPE - return new AuthenticationInfo(); - } - - private ProxyInfo getProxy(String protocol) { - MavenSession session = legacySupport.getSession(); - - if (session != null && protocol != null) { - MavenExecutionRequest request = session.getRequest(); - - if (request != null) { - List proxies = request.getProxies(); - - if (proxies != null) { - for (Proxy proxy : proxies) { - if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol())) { - SettingsDecryptionResult result = - settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy)); - proxy = result.getProxy(); - - ProxyInfo proxyInfo = new ProxyInfo(); - proxyInfo.setHost(proxy.getHost()); - proxyInfo.setType(proxy.getProtocol()); - proxyInfo.setPort(proxy.getPort()); - proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts()); - proxyInfo.setUserName(proxy.getUsername()); - proxyInfo.setPassword(proxy.getPassword()); - - return proxyInfo; - } - } - } + if (metadataResult.isResolved()) { + try { + return readCatalog( + new XmlStreamReader(metadataResult.getMetadata().getFile())); + } catch (IOException e) { + throw new ArchetypeDataSourceException(e); } + } else { + throw new ArchetypeDataSourceException(metadataResult.getException()); } - - return null; } - private Mirror getMirror(String repoId) { - MavenSession session = legacySupport.getSession(); - - MavenExecutionRequest request = null; + private RemoteRepository getRemoteRepo(List remoteRepositories) { - if (session != null) { - request = session.getRequest(); + if (remoteRepositories == null || remoteRepositories.isEmpty()) { + return null; } - if (request != null) { - return getMirror(repoId, request.getMirrors()); - } - - return null; - } - - private static final String WILDCARD = "*"; - - private static final String EXTERNAL_WILDCARD = "external:*"; - - private Mirror getMirror(String repoId, List mirrors) { - if (repoId != null && mirrors != null) { - for (Mirror mirror : mirrors) { - if (repoId.equals(mirror.getMirrorOf())) { - return mirror; - } + for (RemoteRepository remoteRepository : remoteRepositories) { + if (ARCHETYPE_REPOSITORY_ID.equals(remoteRepository.getId())) { + return remoteRepository; } - for (Mirror mirror : mirrors) { - if (matchPattern(repoId, mirror.getMirrorOf())) { - return mirror; - } + if (CENTRAL_REPOSITORY_ID.equals(remoteRepository.getId())) { + return remoteRepository; } - } - - return null; - } - /** - * This method checks if the pattern matches the originalRepository. Valid patterns: * = - * everything external:* = everything not on the localhost and not file based. repo,repo1 = repo - * or repo1 *,!repo1 = everything except repo1 - * - * @param originalId to compare for a match. - * @param pattern used for match. Currently only '*' is supported. - * @return true if the repository is a match to this pattern. - */ - static boolean matchPattern(String originalId, String pattern) { - boolean result = false; - - // simple checks first to short circuit processing below. - if (WILDCARD.equals(pattern) || pattern.equals(originalId)) { - result = true; - } else { - // process the list - String[] repos = pattern.split(","); - for (String repo : repos) { - // see if this is a negative match - if (repo.length() > 1 && repo.startsWith("!")) { - if (repo.substring(1).equals(originalId)) { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if (repo.equals(originalId)) { - result = true; - break; - } - // check for external:* - else if (EXTERNAL_WILDCARD.equals(repo)) { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } else if (WILDCARD.equals(repo)) { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } + if (getRemoteRepo(remoteRepository.getMirroredRepositories()) != null) { + return remoteRepository; } } - return result; - } - static boolean matchesLayout(ArtifactRepository repository, Mirror mirror) { - return matchesLayout(repository.getLayout().getId(), mirror.getMirrorOfLayouts()); + return null; } - /** - * Checks whether the layouts configured for a mirror match with the layout of the repository. - * - * @param repoLayout The layout of the repository, may be {@code null}. - * @param mirrorLayout The layouts supported by the mirror, may be {@code null}. - * @return {@code true} if the layouts associated with the mirror match the layout of the original repository, - * {@code false} otherwise. - */ - static boolean matchesLayout(String repoLayout, String mirrorLayout) { - boolean result = false; - - // simple checks first to short circuit processing below. - if ((mirrorLayout == null || mirrorLayout.isEmpty()) || WILDCARD.equals(mirrorLayout)) { - result = true; - } else if (mirrorLayout.equals(repoLayout)) { - result = true; - } else { - // process the list - String[] layouts = mirrorLayout.split(","); - for (String layout : layouts) { - // see if this is a negative match - if (layout.length() > 1 && layout.startsWith("!")) { - if (layout.substring(1).equals(repoLayout)) { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if (layout.equals(repoLayout)) { - result = true; - break; - } else if (WILDCARD.equals(layout)) { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - - return result; + @Override + public File updateCatalog(RepositorySystemSession repositorySession, Archetype archetype) + throws ArchetypeDataSourceException { + throw new ArchetypeDataSourceException("Not supported yet."); } } 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 1a0b9447..5bc61059 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 @@ -28,14 +28,9 @@ import org.apache.maven.archetype.ArchetypeGenerationRequest; import org.apache.maven.archetype.ArchetypeGenerationResult; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.ReaderFactory; @@ -75,7 +70,7 @@ public class DefaultArchetypeGeneratorTest extends AbstractMojoTestCase { ADDITIONAL_PROPERTIES.setProperty("property_underscored-2", "prop2"); } - ArtifactRepository localRepository; + String localRepository; String remoteRepository; @@ -504,14 +499,11 @@ protected void tearDown() throws Exception { protected void setUp() throws Exception { super.setUp(); - String repositories = new File(getBasedir(), "target/test-classes/repositories") - .toURI() - .toString(); + File repositories = new File(getBasedir(), "target/test-classes/repositories"); - localRepository = - new DefaultArtifactRepository("local", repositories + "/local", new DefaultRepositoryLayout()); + localRepository = new File(repositories, "local").toString(); - remoteRepository = repositories + "central"; + remoteRepository = new File(repositories, "central").toURI().toString(); generator = (ArchetypeGenerator) lookup(ArchetypeGenerator.ROLE); assertNotNull(generator); @@ -541,15 +533,13 @@ private ArchetypeGenerationRequest createArchetypeGenerationRequest(String proje request.setProperties(ADDITIONAL_PROPERTIES); - ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); RepositorySystem repositorySystem = lookup(RepositorySystem.class); - LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( - repositorySession, new LocalRepository(localRepository.getBasedir())); + LocalRepositoryManager localRepositoryManager = + repositorySystem.newLocalRepositoryManager(repositorySession, new LocalRepository(localRepository)); repositorySession.setLocalRepositoryManager(localRepositoryManager); - buildingRequest.setRepositorySession(repositorySession); - request.setProjectBuildingRequest(buildingRequest); + request.setRepositorySession(repositorySession); return request; } 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 b3cc3c50..82a1f48e 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,21 +30,10 @@ 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; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; import org.apache.velocity.VelocityContext; import org.apache.velocity.context.Context; import org.codehaus.plexus.ContainerConfiguration; @@ -54,8 +43,15 @@ import org.codehaus.plexus.velocity.VelocityComponent; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.repository.RepositoryPolicy; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResult; import static org.hamcrest.MatcherAssert.assertThat; import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo; @@ -79,34 +75,27 @@ public void testArchetype() throws Exception { // This needs to be encapsulated in a maven test case. // ---------------------------------------------------------------------- - ArtifactRepositoryLayout layout = - (ArtifactRepositoryLayout) getContainer().lookup(ArtifactRepositoryLayout.ROLE); - String mavenRepoLocal = - getTestFile("target/local-repository").toURI().toURL().toString(); - - ArtifactRepository localRepository = new DefaultArtifactRepository("local", mavenRepoLocal, layout); - - List remoteRepositories = new ArrayList<>(); + getTestFile("target/local-repository").toURI().toURL().getFile(); String mavenRepoRemote = getTestFile("src/test/repository").toURI().toURL().toString(); - ArtifactRepository remoteRepository = new DefaultArtifactRepository("remote", mavenRepoRemote, layout); + RemoteRepository remoteRepository = new RemoteRepository.Builder("remote", "default", mavenRepoRemote) + .setReleasePolicy(new RepositoryPolicy()) + .setSnapshotPolicy(new RepositoryPolicy()) + .build(); + List remoteRepositories = new ArrayList<>(); remoteRepositories.add(remoteRepository); - ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); - buildingRequest.setRemoteRepositories(remoteRepositories); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); RepositorySystem repositorySystem = lookup(RepositorySystem.class); - LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( - repositorySession, new LocalRepository(localRepository.getBasedir())); + LocalRepositoryManager localRepositoryManager = + repositorySystem.newLocalRepositoryManager(repositorySession, new LocalRepository(mavenRepoLocal)); repositorySession.setLocalRepositoryManager(localRepositoryManager); - buildingRequest.setRepositorySession(repositorySession); ArchetypeGenerationRequest request = new ArchetypeGenerationRequest() - .setProjectBuildingRequest(buildingRequest) .setPackage("org.apache.maven.quickstart") .setGroupId("maven") .setArtifactId("quickstart") @@ -114,9 +103,9 @@ public void testArchetype() throws Exception { .setArchetypeGroupId("org.apache.maven.archetypes") .setArchetypeArtifactId("maven-archetype-quickstart") .setArchetypeVersion("1.0-alpha-1-SNAPSHOT") - .setRemoteArtifactRepositories(RepositoryUtils.toRepos(remoteRepositories)) + .setRemoteArtifactRepositories(remoteRepositories) + .setRepositorySession(repositorySession) .setOutputDirectory(getTestFile("target").getAbsolutePath()); - // parameters.put( "name", "jason" ); archetype.createArchetype(request); @@ -142,20 +131,15 @@ public void testArchetype() throws Exception { // Validate POM generation // ---------------------------------------------------------------------- - ArtifactFactory artifactFactory = (ArtifactFactory) lookup(ArtifactFactory.class.getName()); - Artifact archetypeArtifact = artifactFactory.createArtifact( - request.getArchetypeGroupId(), - request.getArchetypeArtifactId(), - request.getArchetypeVersion(), - Artifact.SCOPE_RUNTIME, - "jar"); + Artifact archetypeArtifact = new DefaultArtifact( + request.getArchetypeGroupId(), request.getArchetypeArtifactId(), "jar", request.getArchetypeVersion()); StringWriter writer = new StringWriter(); ClassLoader old = Thread.currentThread().getContextClassLoader(); Thread.currentThread() - .setContextClassLoader(getContextClassloader(archetypeArtifact, localRepository, remoteRepositories)); + .setContextClassLoader(getContextClassloader(archetypeArtifact, repositorySession, remoteRepositories)); try { VelocityComponent velocity = (VelocityComponent) lookup(VelocityComponent.class.getName()); @@ -188,9 +172,7 @@ public void testArchetype() throws Exception { MavenXpp3Reader reader = new MavenXpp3Reader(); generatedModel = reader.read(pomReader); - } catch (IOException e) { - throw new ArchetypeTemplateProcessingException("Error reading generated POM", e); - } catch (XmlPullParserException e) { + } catch (IOException | XmlPullParserException e) { throw new ArchetypeTemplateProcessingException("Error reading generated POM", e); } assertEquals( @@ -225,30 +207,15 @@ public void testArchetype() throws Exception { // Gets the classloader for this artifact's file. private ClassLoader getContextClassloader( - Artifact archetypeArtifact, ArtifactRepository localRepository, List remoteRepositories) + Artifact archetypeArtifact, + RepositorySystemSession repositorySystemSession, + List remoteRepositories) throws Exception { - ArtifactResolver artifactResolver = (ArtifactResolver) lookup(ArtifactResolver.class.getName()); - try { - artifactResolver.resolve(archetypeArtifact, remoteRepositories, localRepository); - } catch (ArtifactResolutionException e) { - throw new ArchetypeDescriptorException("Error attempting to download archetype: " + e.getMessage(), e); - } catch (ArtifactNotFoundException e) { - throw new ArchetypeNotFoundException("OldArchetype does not exist: " + e.getMessage(), e); - } - - URLClassLoader archetypeJarLoader; - try { - URL[] urls = new URL[1]; - - urls[0] = archetypeArtifact.getFile().toURI().toURL(); - - archetypeJarLoader = new URLClassLoader(urls); - } catch (IOException e) { - throw new ArchetypeDescriptorException( - "Error reading the " + OldArchetype.ARCHETYPE_DESCRIPTOR + " descriptor.", e); - } - - return archetypeJarLoader; + RepositorySystem repositorySystem = lookup(RepositorySystem.class); + ArtifactRequest request = new ArtifactRequest(archetypeArtifact, remoteRepositories, null); + ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, request); + URL[] urls = new URL[] {artifactResult.getArtifact().getFile().toURI().toURL()}; + return new URLClassLoader(urls); } public void testAddModuleToParentPOM() throws Exception { diff --git a/archetype-common/src/test/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSourceTest.java b/archetype-common/src/test/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSourceTest.java index e1290438..8e10f370 100644 --- a/archetype-common/src/test/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSourceTest.java +++ b/archetype-common/src/test/java/org/apache/maven/archetype/source/LocalCatalogArchetypeDataSourceTest.java @@ -43,8 +43,6 @@ import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; import org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.eclipse.aether.DefaultRepositorySystemSession; @@ -85,14 +83,12 @@ public void testLocalCatalog() throws Exception { ArchetypeManager archetype = lookup(ArchetypeManager.class); RepositorySystem repositorySystem = lookup(RepositorySystem.class); - ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( repositorySession, new LocalRepository(getTestFile("target/test-classes/repositories/test-catalog"))); repositorySession.setLocalRepositoryManager(localRepositoryManager); - buildingRequest.setRepositorySession(repositorySession); - ArchetypeCatalog result = archetype.getLocalCatalog(buildingRequest); + ArchetypeCatalog result = archetype.getLocalCatalog(repositorySession); assertEquals(1, result.getArchetypes().size()); assertEquals("groupId", result.getArchetypes().get(0).getGroupId()); 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 5cf4c091..537cc795 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 @@ -26,12 +26,6 @@ import org.apache.maven.archetype.ArchetypeManager; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; -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.DefaultRepositoryLayout; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; @@ -51,26 +45,13 @@ protected void customizeContainerConfiguration(ContainerConfiguration configurat public void testProjectGenerationFromAnArchetype() throws Exception { ArchetypeManager archetype = (ArchetypeManager) lookup(ArchetypeManager.ROLE); - // In the embedder the localRepository will be retrieved from the embedder itself and users won't - // have to go through this muck. - - ArtifactRepository localRepository = createRepository( - new File(getBasedir(), "target/test-classes/repositories/local") - .toURI() - .toURL() - .toExternalForm(), - "local-repo"); - - ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); RepositorySystem repositorySystem = lookup(RepositorySystem.class); LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( repositorySession, new LocalRepository("target/test-classes/repositories/central")); repositorySession.setLocalRepositoryManager(localRepositoryManager); - buildingRequest.setRepositorySession(repositorySession); - - ArchetypeCatalog catalog = archetype.getLocalCatalog(buildingRequest); + ArchetypeCatalog catalog = archetype.getLocalCatalog(repositorySession); System.err.println("archetypes => " + catalog.getArchetypes()); // Here I am just grabbing a OldArchetype but in a UI you would take the OldArchetype objects and present @@ -96,11 +77,11 @@ public void testProjectGenerationFromAnArchetype() throws Exception { ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest(selection) .setOutputDirectory(outputDirectory.getAbsolutePath()) - // .setLocalRepository(localRepository) .setGroupId(groupId) .setArtifactId(artifactId) .setVersion(version) - .setPackage(packageName); + .setPackage(packageName) + .setRepositorySession(repositorySession); Properties archetypeRequiredProperties = new Properties(); archetypeRequiredProperties.setProperty("property-with-default-1", "value-1"); @@ -114,7 +95,6 @@ public void testProjectGenerationFromAnArchetype() throws Exception { archetypeRequiredProperties.setProperty("property_underscored_1", "prop1"); archetypeRequiredProperties.setProperty("property_underscored-2", "prop2"); agr.setProperties(archetypeRequiredProperties); - agr.setProjectBuildingRequest(buildingRequest); // Then generate away! @@ -125,19 +105,4 @@ public void testProjectGenerationFromAnArchetype() throws Exception { fail(result.getCause().getMessage()); } } - - private ArtifactRepository createRepository(String url, String repositoryId) { - String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; - - String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; - - ArtifactRepositoryPolicy snapshotsPolicy = - new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); - - ArtifactRepositoryPolicy releasesPolicy = - new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); - - return new MavenArtifactRepository( - repositoryId, url, new DefaultRepositoryLayout(), snapshotsPolicy, releasesPolicy); - } } 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 b986145c..1eedbfe4 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 @@ -26,12 +26,6 @@ import org.apache.maven.archetype.ArchetypeManager; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.catalog.ArchetypeCatalog; -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.DefaultRepositoryLayout; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.FileUtils; @@ -53,12 +47,6 @@ protected void customizeContainerConfiguration(ContainerConfiguration configurat } public void testInternalCatalog() throws Exception { - ArtifactRepository localRepository = createRepository( - new File(getBasedir(), "target/test-classes/repositories/local") - .toURI() - .toURL() - .toExternalForm(), - "local-repo"); File outputDirectory = new File(getBasedir(), "target/internal-archetypes-projects"); outputDirectory.mkdirs(); @@ -78,22 +66,20 @@ public void testInternalCatalog() throws Exception { // this should be also default ... archetype.setRepository(CENTRAL); - ArchetypeGenerationRequest request = new ArchetypeGenerationRequest(archetype) - .setGroupId("org.apache.maven.archetypeManager.test") - .setArtifactId("archetypeManager" + count) - .setVersion("1.0-SNAPSHOT") - .setPackage("com.acme") - .setProperties(props) - .setOutputDirectory(outputDirectory.getPath()); - - ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); RepositorySystem repositorySystem = lookup(RepositorySystem.class); LocalRepositoryManager localRepositoryManager = repositorySystem.newLocalRepositoryManager( - repositorySession, new LocalRepository(localRepository.getBasedir())); + repositorySession, new LocalRepository("target/test-classes/repositories/local")); repositorySession.setLocalRepositoryManager(localRepositoryManager); - buildingRequest.setRepositorySession(repositorySession); - request.setProjectBuildingRequest(buildingRequest); + + ArchetypeGenerationRequest request = new ArchetypeGenerationRequest(archetype) + .setGroupId("org.apache.maven.archetype.test") + .setArtifactId("archetype" + count) + .setVersion("1.0-SNAPSHOT") + .setPackage("com.acme") + .setProperties(props) + .setOutputDirectory(outputDirectory.getPath()) + .setRepositorySession(repositorySession); ArchetypeGenerationResult generationResult = archetypeManager.generateProjectFromArchetype(request); @@ -104,19 +90,4 @@ public void testInternalCatalog() throws Exception { count++; } } - - private ArtifactRepository createRepository(String url, String repositoryId) { - String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; - - String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; - - ArtifactRepositoryPolicy snapshotsPolicy = - new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); - - ArtifactRepositoryPolicy releasesPolicy = - new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); - - return new MavenArtifactRepository( - repositoryId, url, new DefaultRepositoryLayout(), snapshotsPolicy, releasesPolicy); - } } diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java index 527f650b..dbd76efd 100644 --- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java +++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/CreateArchetypeFromProjectMojo.java @@ -30,7 +30,6 @@ import org.apache.maven.archetype.ArchetypeManager; import org.apache.maven.archetype.common.Constants; import org.apache.maven.archetype.ui.creation.ArchetypeCreationConfigurator; -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; @@ -144,9 +143,6 @@ public class CreateArchetypeFromProjectMojo extends AbstractMojo { @Parameter(property = "archetype.preserveCData") private boolean preserveCData = false; - @Parameter(defaultValue = "${localRepository}", readonly = true) - private ArtifactRepository localRepository; - /** * POMs in archetype are created with their initial parent. * This property is ignored when preserveCData is true. @@ -223,9 +219,6 @@ public class CreateArchetypeFromProjectMojo extends AbstractMojo { @Parameter(defaultValue = "${session}", readonly = true, required = true) private MavenSession session; - // @Parameter( defaultValue = "${session.settings}", readonly = true, required = true ) - // private File settingsXml; - @Override public void execute() throws MojoExecutionException, MojoFailureException { Properties executionProperties = session.getExecutionProperties(); @@ -237,7 +230,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { List languages = getLanguages(archetypeLanguages, propertyFile); Properties properties = configurator.configureArchetypeCreation( - project, Boolean.valueOf(interactive), executionProperties, propertyFile, languages); + project, interactive, executionProperties, propertyFile, languages); List filtereds = getFilteredExtensions(archetypeFilteredExtentions, propertyFile); @@ -250,8 +243,8 @@ public void execute() throws MojoExecutionException, MojoFailureException { /* This should be correctly handled */ .setPreserveCData(preserveCData) .setKeepParent(keepParent) .setPartialArchetype(partialArchetype) - .setLocalRepository(localRepository) - .setProjectBuildingRequest(session.getProjectBuildingRequest()) + .setLocalRepositoryBasedir( + session.getRepositorySession().getLocalRepository().getBasedir()) /* this should be resolved and asked for user to verify */ .setPackageName(packageName) .setPostPhase(archetypePostPhase) .setOutputDirectory(outputDirectory) 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 a46123f0..6cc53e07 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 @@ -173,9 +173,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { .setArchetypeVersion(archetypeVersion) .setOutputDirectory(outputDirectory.getAbsolutePath()) .setRemoteArtifactRepositories(project.getRemoteProjectRepositories()) + .setRepositorySession(session.getRepositorySession()) .setFilter(filter) - .setAskForDefaultPropertyValues(askForDefaultPropertyValues) - .setProjectBuildingRequest(session.getProjectBuildingRequest()); + .setAskForDefaultPropertyValues(askForDefaultPropertyValues); try { if (interactiveMode.booleanValue()) { 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 b39a536a..86e3015b 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 @@ -43,7 +43,6 @@ 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; @@ -542,7 +541,7 @@ private File setupParentProjects(File configFolder, File buildFolder) File archetypeFile; try { archetypeFile = getArchetypeFile(groupId, artifactId, version); - } catch (DownloadNotFoundException | DownloadException e) { + } catch (DownloadException e) { throw new MojoExecutionException("Could not resolve archetype artifact ", e); } Properties archetypeProperties = getProperties(archetypePomPropertiesFile); @@ -552,8 +551,7 @@ private File setupParentProjects(File configFolder, File buildFolder) return new File(buildFolder, request.getArtifactId()); } - private File getArchetypeFile(String groupId, String artifactId, String version) - throws DownloadNotFoundException, DownloadException { + private File getArchetypeFile(String groupId, String artifactId, String version) throws DownloadException { return downloader.download( groupId, artifactId, version, project.getRemoteProjectRepositories(), session.getRepositorySession()); } diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/UpdateLocalCatalogMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/UpdateLocalCatalogMojo.java index 1a03d2bd..127d1d57 100644 --- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/UpdateLocalCatalogMojo.java +++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/UpdateLocalCatalogMojo.java @@ -70,7 +70,7 @@ public void execute() throws MojoExecutionException { archetype.setDescription(project.getName()); } - File catalog = manager.updateLocalCatalog(session.getProjectBuildingRequest(), archetype); + File catalog = manager.updateLocalCatalog(session.getRepositorySession(), archetype); if (catalog != null) { getLog().info("Updated local archetypes catalog " + catalog); } 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 5eb7844c..186700b5 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 @@ -43,11 +43,9 @@ import org.apache.maven.archetype.exception.ArchetypeNotConfigured; import org.apache.maven.archetype.exception.ArchetypeNotDefined; import org.apache.maven.archetype.exception.UnknownArchetype; -import org.apache.maven.archetype.old.OldArchetype; 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.layout.ArtifactRepositoryLayout; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.context.Context; @@ -72,8 +70,6 @@ @Singleton public class DefaultArchetypeGenerationConfigurator extends AbstractLogEnabled implements ArchetypeGenerationConfigurator { - @Inject - OldArchetype oldArchetype; @Inject private ArchetypeArtifactManager archetypeArtifactManager; @@ -87,12 +83,6 @@ public class DefaultArchetypeGenerationConfigurator extends AbstractLogEnabled @Inject private VelocityComponent velocity; - /** - * Determines whether the layout is legacy or not. - */ - @Inject - private ArtifactRepositoryLayout defaultArtifactRepositoryLayout; - @Inject private RepositorySystem repositorySystem; @@ -121,8 +111,7 @@ public void configureArchetype( } } if (request.getArchetypeRepository() != null) { - RepositorySystemSession repositorySession = - request.getProjectBuildingRequest().getRepositorySession(); + RepositorySystemSession repositorySession = request.getRepositorySession(); RemoteRepository archetypeRepository = createRepository(repositorySession, request.getArchetypeRepository(), ad.getArtifactId() + "-repo"); repositories.add(archetypeRepository); @@ -132,11 +121,7 @@ public void configureArchetype( } if (!archetypeArtifactManager.exists( - ad.getGroupId(), - ad.getArtifactId(), - ad.getVersion(), - repositories, - request.getProjectBuildingRequest().getRepositorySession())) { + ad.getGroupId(), ad.getArtifactId(), ad.getVersion(), repositories, request.getRepositorySession())) { throw new UnknownArchetype("The desired archetype does not exist (" + ad.getGroupId() + ":" + ad.getArtifactId() + ":" + ad.getVersion() + ")"); } @@ -146,11 +131,7 @@ public void configureArchetype( ArchetypeConfiguration archetypeConfiguration; File archetypeFile = archetypeArtifactManager.getArchetypeFile( - ad.getGroupId(), - ad.getArtifactId(), - ad.getVersion(), - repositories, - request.getProjectBuildingRequest().getRepositorySession()); + ad.getGroupId(), ad.getArtifactId(), ad.getVersion(), repositories, request.getRepositorySession()); if (archetypeArtifactManager.isFileSetArchetype(archetypeFile)) { org.apache.maven.archetype.metadata.ArchetypeDescriptor archetypeDescriptor = archetypeArtifactManager.getFileSetArchetypeDescriptor(archetypeFile); 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 dab4f3ea..00c68022 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 @@ -22,7 +22,6 @@ import javax.inject.Named; import javax.inject.Singleton; -import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; @@ -32,14 +31,12 @@ import org.apache.maven.archetype.ArchetypeGenerationRequest; import org.apache.maven.archetype.ArchetypeManager; import org.apache.maven.archetype.catalog.Archetype; -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.ui.ArchetypeDefinition; -import org.apache.maven.project.ProjectBuildingRequest; import org.codehaus.plexus.components.interactivity.PrompterException; import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.repository.RemoteRepository; @Named("default") @Singleton @@ -58,8 +55,7 @@ public class DefaultArchetypeSelector extends AbstractLogEnabled implements Arch @Override public void selectArchetype(ArchetypeGenerationRequest request, Boolean interactiveMode, String catalogs) - throws ArchetypeNotDefined, UnknownArchetype, UnknownGroup, IOException, PrompterException, - ArchetypeSelectionFailure { + throws PrompterException, ArchetypeSelectionFailure { ArchetypeDefinition definition = new ArchetypeDefinition(request); if (definition.isDefined() && StringUtils.isNotEmpty(request.getArchetypeRepository())) { @@ -67,7 +63,8 @@ public void selectArchetype(ArchetypeGenerationRequest request, Boolean interact return; } - Map> archetypes = getArchetypesByCatalog(request.getProjectBuildingRequest(), catalogs); + Map> archetypes = getArchetypesByCatalog( + request.getRepositorySession(), request.getRemoteArtifactRepositories(), catalogs); if (StringUtils.isNotBlank(request.getFilter())) { // applying some filtering depending on filter parameter @@ -154,7 +151,7 @@ public void selectArchetype(ArchetypeGenerationRequest request, Boolean interact } private Map> getArchetypesByCatalog( - ProjectBuildingRequest buildingRequest, String catalogs) { + RepositorySystemSession repositorySession, List remoteRepositories, String catalogs) { if (catalogs == null) { throw new NullPointerException("Catalogs cannot be null"); } @@ -167,10 +164,11 @@ private Map> getArchetypesByCatalog( } else if ("local".equalsIgnoreCase(catalog)) { archetypes.put( "local", - archetypeManager.getLocalCatalog(buildingRequest).getArchetypes()); + archetypeManager.getLocalCatalog(repositorySession).getArchetypes()); } else if ("remote".equalsIgnoreCase(catalog)) { - List archetypesFromRemote = - archetypeManager.getRemoteCatalog(buildingRequest).getArchetypes(); + List archetypesFromRemote = archetypeManager + .getRemoteCatalog(repositorySession, remoteRepositories) + .getArchetypes(); if (!archetypesFromRemote.isEmpty()) { archetypes.put("remote", archetypesFromRemote); 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 5bece149..d507a54f 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 @@ -25,7 +25,6 @@ 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.project.DefaultProjectBuildingRequest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.easymock.EasyMock; @@ -111,7 +110,6 @@ 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"); @@ -129,7 +127,6 @@ 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(eq("groupName"), anyString(), isNull())) @@ -169,7 +166,6 @@ 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(eq("groupName"), anyString(), isNull())) @@ -209,7 +205,6 @@ 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(eq("groupName"), anyString(), isNull())) 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 f452b2f9..07bf672a 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 @@ -28,7 +28,6 @@ import org.apache.maven.archetype.exception.ArchetypeNotDefined; import org.apache.maven.archetype.exception.UnknownArchetype; import org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor; -import org.apache.maven.project.DefaultProjectBuildingRequest; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.components.interactivity.PrompterException; @@ -87,7 +86,6 @@ public void testOldArchetypeGeneratedFieldsInRequestBatchMode() 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"); @@ -109,7 +107,6 @@ public void testOldArchetypeGeneratedFieldsDefaultsBatchMode() 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"); @@ -129,7 +126,6 @@ public void testOldArchetypeGeneratedFieldsDefaultsMissingGroupId() 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 6d8b20bb..6b465063 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,6 @@ scm:git:https://gitbox.apache.org/repos/asf/maven-archetype.git 3.6.3 1.4.1 - 3.3.3 8 true @@ -190,17 +189,6 @@ maven-plugin-testing-harness 3.3.0 - - org.apache.maven.wagon - wagon-provider-api - ${wagonVersion} - provided - - - org.apache.maven.wagon - wagon-http - ${wagonVersion} - org.apache.maven.resolver maven-resolver-api