use of org.apache.maven.artifact.repository.ArtifactRepository in project pom-manipulation-ext by release-engineering.
the class MavenLocationExpanderTest method mirrorAdjustsLocationURLs.
@Test
public void mirrorAdjustsLocationURLs() throws Exception {
final Mirror mirror = new Mirror();
mirror.setId("test-mirror");
mirror.setMirrorOf("*");
mirror.setUrl("http://nowhere.com");
final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
final ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
final ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
final File localRepo = File.createTempFile("local.repo.", ".dir");
localRepo.deleteOnExit();
final ArtifactRepository local = new MavenArtifactRepository("local", localRepo.toURI().toString(), layout, snapshots, releases);
final ArtifactRepository remote = new MavenArtifactRepository("remote", "http:///repo.maven.apache.org/maven2", layout, snapshots, releases);
final Settings settings = new Settings();
settings.addMirror(mirror);
final MavenLocationExpander ex = new MavenLocationExpander(Collections.<Location>emptyList(), Collections.<ArtifactRepository>singletonList(remote), local, new DefaultMirrorSelector(), settings, Collections.<String>emptyList());
final List<Location> result = ex.expand(MavenLocationExpander.EXPANSION_TARGET);
assertThat(result.size(), equalTo(2));
final Iterator<Location> iterator = result.iterator();
Location loc = iterator.next();
assertThat(loc.getName(), equalTo(local.getId()));
assertThat(loc.getUri(), equalTo(local.getUrl()));
loc = iterator.next();
assertThat(loc.getName(), equalTo(mirror.getId()));
assertThat(loc.getUri(), equalTo(mirror.getUrl()));
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project pom-manipulation-ext by release-engineering.
the class VersioningCalculatorTest method setupSession.
private VersioningState setupSession(final Properties properties, final Map<ProjectRef, String[]> versionMap) throws Exception {
final ArtifactRepository ar = new MavenArtifactRepository("test", "http://repo.maven.apache.org/maven2", new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties(properties).setRemoteRepositories(Arrays.asList(ar));
final PlexusContainer container = new DefaultPlexusContainer();
final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult());
session = new ManipulationSession();
session.setMavenSession(mavenSession);
final VersioningState state = new VersioningState(properties);
session.setState(state);
final Map<String, byte[]> dataMap = new HashMap<>();
if (versionMap != null && !versionMap.isEmpty()) {
for (final Map.Entry<ProjectRef, String[]> entry : versionMap.entrySet()) {
final String path = toMetadataPath(entry.getKey());
final byte[] data = setupMetadataVersions(entry.getValue());
dataMap.put(path, data);
}
}
final Location mdLoc = MavenLocationExpander.EXPANSION_TARGET;
final Transport mdTrans = new StubTransport(dataMap);
modder = new TestVersionCalculator(new ManipulationSession(), mdLoc, mdTrans, temp.newFolder("galley-cache"));
return state;
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-archetype by apache.
the class ArchetyperRoundtripIT method testArchetyper.
public void testArchetyper() throws Exception {
ArchetypeManager archetype = (ArchetypeManager) lookup(ArchetypeManager.ROLE);
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
ArtifactRepository localRepository = createRepository(new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "repositories" + File.separator + "local").toURI().toURL().toExternalForm(), "local-repo");
ArtifactRepository centralRepository = createRepository(new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "repositories" + File.separator + "central").toURI().toURL().toExternalForm(), "central-repo");
// (1) create a project from scratch
// (2) create an archetype from the project
// (3) create our own archetype catalog properties in memory
// (4) create our own archetype catalog describing the archetype we just created
// (5) deploy the archetype we just created
// (6) create a project form the archetype we just created
// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
// (1) create a project from scratch
// File sourceProject = new File( getBasedir( ), "target/test-classes/projects/roundtrip-1-project" );
File workingProject = new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "projects" + File.separator + "roundtrip-1-project");
FileUtils.forceDelete(new File(workingProject, "target"));
// (2) create an archetype from the project
File pom = new File(workingProject, "pom.xml");
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepository.getBasedir()));
buildingRequest.setRepositorySession(repositorySession);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
Properties properties = new Properties();
properties.setProperty("someProperty", "someValue");
ArchetypeCreationRequest acr = new ArchetypeCreationRequest().setProject(project).setLocalRepository(localRepository).setProperties(properties).setPostPhase("package");
ArchetypeCreationResult creationResult = archetype.createArchetypeFromProject(acr);
if (creationResult.getCause() != null) {
throw creationResult.getCause();
}
// (3) create our own archetype catalog properties in memory
File catalogDirectory = new File(getBasedir(), "target" + File.separator + "catalog");
catalogDirectory.mkdirs();
File catalogFile = new File(catalogDirectory, "archetype-catalog.xml");
// (5) install the archetype we just created
File generatedArchetypeDirectory = new File(project.getBasedir(), "target" + File.separator + "generated-sources" + File.separator + "archetype");
File generatedArchetypePom = new File(generatedArchetypeDirectory, "pom.xml");
ProjectBuildingResult buildingResult = projectBuilder.build(generatedArchetypePom, buildingRequest);
MavenProject generatedArchetypeProject = projectBuilder.build(generatedArchetypePom, buildingRequest).getProject();
ModelInterpolator modelInterpolator = (ModelInterpolator) lookup(ModelInterpolator.ROLE);
Model generatedArchetypeModel = modelInterpolator.interpolate(generatedArchetypeProject.getModel(), generatedArchetypePom.getParentFile(), new DefaultProjectBuilderConfiguration(), true);
File archetypeDirectory = new File(generatedArchetypeDirectory, "src" + File.separator + "main" + File.separator + "resources");
File archetypeArchive = archetype.archiveArchetype(archetypeDirectory, new File(generatedArchetypeModel.getBuild().getDirectory()), generatedArchetypeModel.getBuild().getFinalName());
String baseName = StringUtils.replace(generatedArchetypeProject.getGroupId(), ".", File.separator) + File.separator + generatedArchetypeProject.getArtifactId() + File.separator + generatedArchetypeProject.getVersion() + File.separator + generatedArchetypeProject.getBuild().getFinalName();
File archetypeInRepository = new File(centralRepository.getBasedir(), baseName + ".jar");
File archetypePomInRepository = new File(centralRepository.getBasedir(), baseName + ".pom");
archetypeInRepository.getParentFile().mkdirs();
FileUtils.copyFile(archetypeArchive, archetypeInRepository);
FileUtils.copyFile(generatedArchetypePom, archetypePomInRepository);
// (4) create our own archetype catalog describing the archetype we just created
ArchetypeCatalog catalog = new ArchetypeCatalog();
Archetype generatedArchetype = new Archetype();
generatedArchetype.setGroupId(generatedArchetypeProject.getGroupId());
generatedArchetype.setArtifactId(generatedArchetypeProject.getArtifactId());
generatedArchetype.setVersion(generatedArchetypeProject.getVersion());
generatedArchetype.setRepository("http://localhost:" + port + "/repo");
catalog.addArchetype(generatedArchetype);
ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();
Writer writer = new FileWriter(catalogFile);
catalogWriter.write(writer, catalog);
IOUtils.closeQuietly(writer);
// (6) create a project form the archetype we just created
String outputDirectory = new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "projects" + File.separator + "roundtrip-1-recreatedproject").getAbsolutePath();
FileUtils.forceDelete(outputDirectory);
ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest().setArchetypeGroupId(generatedArchetypeProject.getGroupId()).setArchetypeArtifactId(generatedArchetypeProject.getArtifactId()).setArchetypeVersion(generatedArchetypeProject.getVersion()).setGroupId("com.mycompany").setArtifactId("myapp").setVersion("1.0-SNAPSHOT").setPackage("com.mycompany.myapp").setProperties(properties).setOutputDirectory(outputDirectory).setLocalRepository(localRepository).setArchetypeRepository("http://localhost:" + port + "/repo/").setProjectBuildingRequest(buildingRequest);
ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(agr);
if (generationResult.getCause() != null) {
throw generationResult.getCause();
}
// ASSERT symbol_pound replacement (archetype-180 archetype-183)
String content = FileUtils.fileRead(outputDirectory + File.separator + "myapp" + File.separator + "src" + File.separator + "main" + File.separator + "java" + File.separator + "com" + File.separator + "mycompany" + File.separator + "myapp" + File.separator + "App.java");
System.err.println("content=" + content);
assertTrue(content.indexOf("//A #\\{some}") > 0);
assertTrue(content.indexOf("//B #{some}") > 0);
assertTrue(content.indexOf("//C #{some other}") > 0);
assertTrue(content.indexOf("//D \\#{some other}") > 0);
assertTrue(content.indexOf("//E #{}") > 0);
assertTrue(content.indexOf("//F {some}") > 0);
assertTrue(content.indexOf("//G ${someOtherProperty}") > 0);
assertTrue(content.indexOf("//H ${someValue}") > 0);
assertTrue(content.indexOf("/*") > 0);
assertTrue(content.indexOf(" A #\\{some}") > 0);
assertTrue(content.indexOf(" B #{some}") > 0);
assertTrue(content.indexOf(" C #{some other}") > 0);
assertTrue(content.indexOf(" D \\#{some other}") > 0);
assertTrue(content.indexOf(" E #{}") > 0);
assertTrue(content.indexOf(" F {some}") > 0);
assertTrue(content.indexOf(" G ${someOtherProperty}") > 0);
assertTrue(content.indexOf(" H ${someValue}") > 0);
// Assert symbol_dollar archetype-138
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-archetype by apache.
the class RoundtripMultiModuleIT method testArchetyper.
public void testArchetyper() throws Exception {
ArchetypeManager archetype = (ArchetypeManager) lookup(ArchetypeManager.ROLE);
ProjectBuilder projectBuilder = lookup(ProjectBuilder.class);
ArtifactRepository localRepository = createRepository(new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "repositories" + File.separator + "local").toURI().toURL().toExternalForm(), "local-repo");
ArtifactRepository centralRepository = createRepository(new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "repositories" + File.separator + "central").toURI().toURL().toExternalForm(), "central-repo");
// (1) create a project from scratch
// (2) create an archetype from the project
// (3) create our own archetype catalog properties in memory
// (4) create our own archetype catalog describing the archetype we just created
// (5) deploy the archetype we just created
// (6) create a project form the archetype we just created
// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
// (1) create a project from scratch
// File sourceProject = new File( getBasedir( ), "target/test-classes/projects/roundtrip-1-project" );
File workingProject = new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "projects" + File.separator + "roundtrip-multi");
FileUtils.forceDelete(new File(workingProject, "target"));
// (2) create an archetype from the project
File pom = new File(workingProject, "pom.xml");
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepository.getBasedir()));
buildingRequest.setRepositorySession(repositorySession);
MavenProject project = projectBuilder.build(pom, buildingRequest).getProject();
ModelInterpolator modelInterpolator = (ModelInterpolator) lookup(ModelInterpolator.ROLE);
ArchetypeCreationRequest acr = new ArchetypeCreationRequest().setProject(project).setLocalRepository(localRepository).setFiltereds(Constants.DEFAULT_FILTERED_EXTENSIONS).setLanguages(Constants.DEFAULT_LANGUAGES).setPostPhase("package");
ArchetypeCreationResult creationResult = archetype.createArchetypeFromProject(acr);
if (creationResult.getCause() != null) {
throw creationResult.getCause();
} else {
assertArchetypeCreated(workingProject);
}
// (3) create our own archetype catalog properties in memory
File catalogDirectory = new File(getBasedir(), "target" + File.separator + "catalog");
File catalogFile = new File(catalogDirectory, "archetype-catalog.xml");
File catalogProperties = new File(catalogDirectory, "archetype-catalog.properties");
catalogDirectory.mkdirs();
Properties p = new Properties();
p.setProperty("sources", "catalog");
p.setProperty("catalog.file", catalogFile.getAbsolutePath());
OutputStream os = new FileOutputStream(catalogProperties);
p.store(os, "Generated catalog properties");
// (5) install the archetype we just created
File generatedArchetypeDirectory = new File(project.getBasedir(), "target" + File.separator + "generated-sources" + File.separator + "archetype");
File generatedArchetypePom = new File(generatedArchetypeDirectory, "pom.xml");
MavenProject generatedArchetypeProject = projectBuilder.build(generatedArchetypePom, buildingRequest).getProject();
Model generatedModel = modelInterpolator.interpolate(generatedArchetypeProject.getModel(), generatedArchetypePom.getParentFile(), new DefaultProjectBuilderConfiguration(), true);
File archetypeDirectory = new File(generatedArchetypeDirectory, "src" + File.separator + "main" + File.separator + "resources");
File archetypeArchive = archetype.archiveArchetype(archetypeDirectory, new File(generatedModel.getBuild().getDirectory()), generatedModel.getBuild().getFinalName());
String baseName = StringUtils.replace(generatedArchetypeProject.getGroupId(), ".", File.separator) + File.separator + generatedArchetypeProject.getArtifactId() + File.separator + generatedArchetypeProject.getVersion() + File.separator + generatedModel.getBuild().getFinalName();
File archetypeInRepository = new File(centralRepository.getBasedir(), baseName + ".jar");
File archetypePomInRepository = new File(centralRepository.getBasedir(), baseName + ".pom");
archetypeInRepository.getParentFile().mkdirs();
FileUtils.copyFile(archetypeArchive, archetypeInRepository);
FileUtils.copyFile(generatedArchetypePom, archetypePomInRepository);
// (4) create our own archetype catalog describing the archetype we just created
ArchetypeCatalog catalog = new ArchetypeCatalog();
Archetype generatedArchetype = new Archetype();
generatedArchetype.setGroupId(generatedArchetypeProject.getGroupId());
generatedArchetype.setArtifactId(generatedArchetypeProject.getArtifactId());
generatedArchetype.setVersion(generatedArchetypeProject.getVersion());
generatedArchetype.setRepository("http://localhost:" + port + "/repo");
catalog.addArchetype(generatedArchetype);
ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();
Writer writer = new FileWriter(catalogFile);
catalogWriter.write(writer, catalog);
IOUtils.closeQuietly(writer);
// (6) create a project form the archetype we just created
String outputDirectory = new File(getBasedir(), "target" + File.separator + "test-classes" + File.separator + "projects" + File.separator + "roundtrip-multi-recreated").getAbsolutePath();
FileUtils.forceDelete(outputDirectory);
ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest().setArchetypeGroupId(generatedArchetypeProject.getGroupId()).setArchetypeArtifactId(generatedArchetypeProject.getArtifactId()).setArchetypeVersion(generatedArchetypeProject.getVersion()).setGroupId("com.mycompany").setArtifactId("myapp").setVersion("1.0-SNAPSHOT").setPackage("com.mycompany.myapp").setOutputDirectory(outputDirectory).setLocalRepository(localRepository).setArchetypeRepository("http://localhost:" + port + "/repo/").setProjectBuildingRequest(buildingRequest);
ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype(agr);
if (generationResult.getCause() != null) {
fail(generationResult.getCause().getMessage());
}
String myapp = outputDirectory + File.separator + "myapp" + File.separator;
assertTrue(new File(myapp + "myapp-api", ".classpath").exists());
assertTrue(new File(myapp + "myapp-cli", ".classpath").exists());
assertTrue(new File(myapp + "myapp-core", ".classpath").exists());
assertTrue(new File(myapp + "myapp-model", ".classpath").exists());
assertTrue(new File(myapp + File.separator + "myapp-stores" + File.separator + "myapp-store-memory", ".classpath").exists());
assertTrue(new File(myapp + "myapp-stores" + File.separator + "myapp-store-xstream", ".classpath").exists());
assertTrue(new File(myapp + "myapp-api", ".checkstyle").exists());
assertTrue(new File(myapp + "myapp-cli", ".checkstyle").exists());
assertTrue(new File(myapp + "myapp-core", ".checkstyle").exists());
assertTrue(new File(myapp + "myapp-model", ".checkstyle").exists());
assertTrue(new File(myapp + "myapp-stores" + File.separator + "myapp-store-memory", ".checkstyle").exists());
assertTrue(new File(myapp + "myapp-stores" + File.separator + "myapp-store-xstream", ".checkstyle").exists());
}
use of org.apache.maven.artifact.repository.ArtifactRepository in project maven-archetype by apache.
the class DefaultArchetypeGenerator method getArchetypeFile.
private File getArchetypeFile(ArchetypeGenerationRequest request, ArtifactRepository localRepository) throws IOException, ArchetypeException, XmlPullParserException, DocumentException {
if (!isArchetypeDefined(request)) {
throw new ArchetypeNotDefined("The archetype is not defined");
}
List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>();
ArtifactRepository remoteRepo = null;
if (request != null && request.getArchetypeRepository() != null) {
remoteRepo = createRepository(request.getArchetypeRepository(), request.getArchetypeArtifactId() + "-repo");
repos.add(remoteRepo);
}
if (!archetypeArtifactManager.exists(request.getArchetypeGroupId(), request.getArchetypeArtifactId(), request.getArchetypeVersion(), remoteRepo, localRepository, repos, request.getProjectBuildingRequest())) {
throw new UnknownArchetype("The desired archetype does not exist (" + request.getArchetypeGroupId() + ":" + request.getArchetypeArtifactId() + ":" + request.getArchetypeVersion() + ")");
}
File archetypeFile = archetypeArtifactManager.getArchetypeFile(request.getArchetypeGroupId(), request.getArchetypeArtifactId(), request.getArchetypeVersion(), remoteRepo, localRepository, repos, request.getProjectBuildingRequest());
return archetypeFile;
}
Aggregations