use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-archetype by apache.
the class RemoteCatalogArchetypeDataSource method downloadCatalog.
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();
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-archetype by apache.
the class ArchetypeGenerationTest method testProjectGenerationFromAnArchetype.
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();
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager("target/test-classes/repositories/central"));
buildingRequest.setRepositorySession(repositorySession);
ArchetypeCatalog catalog = archetype.getLocalCatalog(buildingRequest);
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
// them to the user.
Archetype selection = (Archetype) catalog.getArchetypes().get(catalog.getArchetypes().size() - 1);
System.err.println("Selected OldArchetype = " + selection);
// Now you will present a dialog, or whatever, and grab the following values.
String groupId = "com.mycompany";
String artifactId = "app";
String version = "1.0.0";
String packageName = "org.mycompany.app";
// With the selected OldArchetype and the parameters you can create a generation request as follows:
File outputDirectory = new File(getBasedir(), "target/test-classes/projects/archetyper-generate-1");
FileUtils.forceDelete(outputDirectory);
ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest(selection).setOutputDirectory(outputDirectory.getAbsolutePath()).setLocalRepository(localRepository).setGroupId(groupId).setArtifactId(artifactId).setVersion(version).setPackage(packageName);
Properties archetypeRequiredProperties = new Properties();
archetypeRequiredProperties.setProperty("property-with-default-1", "value-1");
archetypeRequiredProperties.setProperty("property-with-default-2", "value-2");
archetypeRequiredProperties.setProperty("property-with-default-3", "value-3");
archetypeRequiredProperties.setProperty("property-with-default-4", "value-4");
archetypeRequiredProperties.setProperty("property-without-default-1", "some-value-1");
archetypeRequiredProperties.setProperty("property-without-default-2", "some-value-2");
archetypeRequiredProperties.setProperty("property-without-default-3", "some-value-3");
archetypeRequiredProperties.setProperty("property-without-default-4", "some-value-4");
archetypeRequiredProperties.setProperty("property_underscored_1", "prop1");
archetypeRequiredProperties.setProperty("property_underscored-2", "prop2");
agr.setProperties(archetypeRequiredProperties);
agr.setProjectBuildingRequest(buildingRequest);
// Then generate away!
ArchetypeGenerationResult result = archetype.generateProjectFromArchetype(agr);
if (result.getCause() != null) {
result.getCause().printStackTrace(System.err);
fail(result.getCause().getMessage());
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-archetype by apache.
the class InternalCatalogArchetypesVerificationTest method testInternalCatalog.
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();
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).setGroupId("org.apache.maven.archetype.test").setArtifactId("archetype" + count).setVersion("1.0-SNAPSHOT").setPackage("com.acme").setOutputDirectory(outputDirectory.getPath()).setLocalRepository(localRepository);
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepository.getBasedir()));
buildingRequest.setRepositorySession(repositorySession);
request.setProjectBuildingRequest(buildingRequest);
ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(request);
assertTrue("Archetype wasn't generated successfully", generationResult.getCause() == null);
count++;
}
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class DefaultAssemblyArchiverTest method testCreateArchiver_ShouldConfigureArchiver.
@Test
public void testCreateArchiver_ShouldConfigureArchiver() throws NoSuchArchiverException, ArchiverException {
final EasyMockSupport mm = new EasyMockSupport();
final MockAndControlForAssemblyArchiver macArchiverManager = new MockAndControlForAssemblyArchiver(mm);
final TestArchiverWithConfig archiver = new TestArchiverWithConfig();
macArchiverManager.expectGetArchiver("dummy", archiver);
final AssemblerConfigurationSource configSource = mm.createMock(AssemblerConfigurationSource.class);
final String simpleConfig = "value";
expect(configSource.getArchiverConfig()).andReturn("<configuration><simpleConfig>" + simpleConfig + "</simpleConfig></configuration>").anyTimes();
final MavenProject project = new MavenProject(new Model());
expect(configSource.getProject()).andReturn(project).anyTimes();
expect(configSource.getMavenSession()).andReturn(null).anyTimes();
expect(configSource.isDryRun()).andReturn(false).anyTimes();
expect(configSource.getWorkingDirectory()).andReturn(new File(".")).anyTimes();
expect(configSource.isUpdateOnly()).andReturn(false).anyTimes();
final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
expect(configSource.getLocalRepository()).andReturn(lr).anyTimes();
expect(configSource.isIgnorePermissions()).andReturn(true);
setupInterpolators(configSource, project);
mm.replayAll();
final DefaultAssemblyArchiver subject = createSubject(macArchiverManager, new ArrayList<AssemblyArchiverPhase>(), null);
subject.createArchiver("dummy", false, "finalName", configSource, null, false, null);
assertEquals(simpleConfig, archiver.getSimpleConfig());
mm.verifyAll();
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-plugins by apache.
the class AssemblyInterpolatorTest method testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId.
public void testShouldResolveContextValueBeforeModelPropertyOrModelGroupIdInAssemblyId() throws AssemblyInterpolationException, InvalidAssemblerConfigurationException, AssemblyReadException, IOException {
final Model model = new Model();
model.setArtifactId("artifact-id");
model.setGroupId("group.id");
model.setVersion("1");
model.setPackaging("jar");
final Properties props = new Properties();
props.setProperty("groupId", "other.id");
model.setProperties(props);
final Assembly assembly = new Assembly();
assembly.setId("assembly.${groupId}");
final EasyMockSupport mm = new EasyMockSupport();
final MavenSession session = mm.createMock(MavenSession.class);
final Properties execProps = new Properties();
execProps.setProperty("groupId", "still.another.id");
expect(session.getExecutionProperties()).andReturn(execProps).anyTimes();
expect(session.getUserProperties()).andReturn(new Properties()).anyTimes();
final PojoConfigSource cs = new PojoConfigSource();
final ArtifactRepository lr = mm.createMock(ArtifactRepository.class);
cs.setLocalRepository(lr);
cs.setMavenSession(session);
cs.setRootInterpolator(FixedStringSearchInterpolator.create());
cs.setEnvironmentInterpolator(FixedStringSearchInterpolator.create(new PropertiesBasedValueSource(execProps)));
cs.setEnvInterpolator(FixedStringSearchInterpolator.empty());
expect(lr.getBasedir()).andReturn("/path/to/local/repo").anyTimes();
mm.replayAll();
final MavenProject project = new MavenProject(model);
cs.setMavenProject(project);
final Assembly result = roundTripInterpolation(assembly, cs);
assertEquals("assembly.still.another.id", result.getId());
mm.verifyAll();
mm.resetAll();
}
Aggregations