| /* |
| * 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.test; |
| |
| import java.io.File; |
| import java.util.Collections; |
| |
| import org.apache.maven.archetype.ArchetypeGenerationRequest; |
| import org.apache.maven.archetype.ArchetypeGenerationResult; |
| 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.MavenArtifactRepository; |
| import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; |
| import org.apache.maven.project.DefaultProjectBuildingRequest; |
| import org.apache.maven.project.ProjectBuildingRequest; |
| import org.apache.maven.repository.internal.MavenRepositorySystemUtils; |
| import org.codehaus.plexus.ContainerConfiguration; |
| import org.codehaus.plexus.PlexusConstants; |
| import org.codehaus.plexus.PlexusTestCase; |
| import org.codehaus.plexus.util.FileUtils; |
| import org.eclipse.aether.DefaultRepositorySystemSession; |
| import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; |
| import org.eclipse.aether.repository.LocalRepository; |
| |
| /** |
| * |
| * @author rafale |
| */ |
| public class InternalCatalogArchetypesVerificationTest extends PlexusTestCase { |
| private static final String CENTRAL = "https://repo.maven.apache.org/maven2"; |
| |
| @Override |
| protected void customizeContainerConfiguration(final ContainerConfiguration configuration) { |
| configuration.setAutoWiring(true).setClassPathScanning(PlexusConstants.SCANNING_INDEX); |
| } |
| |
| public void testInternalCatalog() throws Exception { |
| DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); |
| session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory() |
| .newInstance( |
| session, |
| new LocalRepository(new File(getBasedir(), "target/test-classes/repositories/local")))); |
| |
| File outputDirectory = new File(getBasedir(), "target/internal-archetypes-projects"); |
| outputDirectory.mkdirs(); |
| FileUtils.cleanDirectory(outputDirectory); |
| |
| ArchetypeManager archetype = (ArchetypeManager) lookup(ArchetypeManager.class.getName()); |
| |
| ArchetypeCatalog catalog = archetype.getInternalCatalog(); |
| |
| int count = 1; |
| for (Archetype a : catalog.getArchetypes()) { |
| Archetype ar = new Archetype(); |
| ar.setGroupId(a.getGroupId()); |
| ar.setArtifactId(a.getArtifactId()); |
| ar.setVersion(a.getVersion()); |
| ar.setDescription(a.getDescription()); |
| ar.setGoals(a.getGoals()); |
| ar.setProperties(a.getProperties()); |
| ar.setRepository(a.getRepository()); |
| if (ar.getRepository() == null) { |
| ar.setRepository(CENTRAL); |
| } |
| |
| ArchetypeGenerationRequest request = new ArchetypeGenerationRequest(ar) |
| .setRepositorySystemSession(session) |
| .setGroupId("org.apache.maven.archetype.test") |
| .setArtifactId("archetype" + count) |
| .setVersion("1.0-SNAPSHOT") |
| .setPackage("com.acme") |
| .setOutputDirectory(outputDirectory.getPath()); |
| |
| ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(); |
| buildingRequest.setRepositorySession(session); |
| |
| MavenArtifactRepository central = new MavenArtifactRepository(); |
| central.setId("central"); |
| central.setUrl(CENTRAL); |
| central.setLayout(new DefaultRepositoryLayout()); |
| buildingRequest.setRemoteRepositories(Collections.singletonList(central)); |
| request.setProjectBuildingRequest(buildingRequest); |
| |
| ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(request); |
| |
| assertTrue("Archetype wasn't generated successfully", generationResult.getCause() == null); |
| |
| count++; |
| } |
| } |
| } |