use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class IntegrationTestMojo method setupParentProjects.
private File setupParentProjects(File configFolder, File buildFolder) throws IOException, MojoExecutionException, IntegrationTestFailure {
// look for 'archetype.pom.properties'
File archetypePomPropertiesFile = new File(configFolder, "archetype.pom.properties");
if (!archetypePomPropertiesFile.exists()) {
getLog().debug("No 'archetype.pom.properties' file found in " + configFolder);
return buildFolder;
}
// go up to the parent configuration folder
buildFolder = setupParentProjects(configFolder.getParentFile(), buildFolder);
Properties archetypePomProperties = loadProperties(archetypePomPropertiesFile);
String groupId = archetypePomProperties.getProperty(Constants.GROUP_ID);
if (StringUtils.isEmpty(groupId)) {
throw new MojoExecutionException("Property " + Constants.GROUP_ID + " not set in " + archetypePomPropertiesFile);
}
String artifactId = archetypePomProperties.getProperty(Constants.ARTIFACT_ID);
if (StringUtils.isEmpty(artifactId)) {
throw new MojoExecutionException("Property " + Constants.ARTIFACT_ID + " not set in " + archetypePomPropertiesFile);
}
String version = archetypePomProperties.getProperty(Constants.VERSION);
if (StringUtils.isEmpty(version)) {
throw new MojoExecutionException("Property " + Constants.VERSION + " not set in " + archetypePomPropertiesFile);
}
File archetypeFile;
try {
archetypeFile = getArchetypeFile(groupId, artifactId, version);
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Could not resolve archetype artifact ", e);
}
Properties archetypeProperties = getProperties(archetypePomPropertiesFile);
getLog().info("Setting up parent project in " + buildFolder);
ArchetypeGenerationRequest request = generate(groupId, artifactId, version, archetypeFile, archetypeProperties, buildFolder.toString());
return new File(buildFolder, request.getArtifactId());
}
use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class IntegrationTestMojo method generate.
private ArchetypeGenerationRequest generate(String archetypeGroupId, String archetypeArtifactId, String archetypeVersion, File archetypeFile, Properties properties, String basedir) throws IntegrationTestFailure {
// @formatter:off
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest().setArchetypeGroupId(archetypeGroupId).setArchetypeArtifactId(archetypeArtifactId).setArchetypeVersion(archetypeVersion).setGroupId(properties.getProperty(Constants.GROUP_ID)).setArtifactId(properties.getProperty(Constants.ARTIFACT_ID)).setVersion(properties.getProperty(Constants.VERSION)).setPackage(properties.getProperty(Constants.PACKAGE)).setOutputDirectory(basedir).setProperties(properties);
// @formatter:on
ArchetypeGenerationResult result = new ArchetypeGenerationResult();
archetypeGenerator.generateArchetype(request, archetypeFile, result);
if (result.getCause() != null) {
if (result.getCause() instanceof ArchetypeNotConfigured) {
ArchetypeNotConfigured anc = (ArchetypeNotConfigured) result.getCause();
throw new IntegrationTestFailure("Missing required properties in archetype.properties: " + StringUtils.join(anc.getMissingProperties().iterator(), ", "), anc);
}
throw new IntegrationTestFailure(result.getCause().getMessage(), result.getCause());
}
return request;
}
use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class DefaultArchetypeGeneratorTest method createArchetypeGenerationRequest.
private ArchetypeGenerationRequest createArchetypeGenerationRequest(String project, Archetype archetype) {
outputDirectory = getBasedir() + "/target/test-classes/projects/" + project;
projectDirectory = new File(outputDirectory, "file-value");
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setLocalRepository(localRepository);
request.setArchetypeRepository(remoteRepository);
request.setOutputDirectory(outputDirectory);
request.setArchetypeGroupId(archetype.groupId);
request.setArchetypeArtifactId(archetype.artifactId);
request.setArchetypeVersion(archetype.version);
request.setGroupId("file-value");
request.setArtifactId("file-value");
request.setVersion("file-value");
request.setPackage("file.value.package");
request.setProperties(ADDITIONAL_PROPERTIES);
ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepository.getBasedir()));
buildingRequest.setRepositorySession(repositorySession);
request.setProjectBuildingRequest(buildingRequest);
return request;
}
use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class DefaultArchetypeGeneratorTest method testGenerateArchetypeCompleteWithoutParent.
public void testGenerateArchetypeCompleteWithoutParent() throws Exception {
System.out.println("testGenerateArchetypeCompleteWithoutParent");
ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-4", ARCHETYPE_BASIC);
FileUtils.forceDelete(projectDirectory);
generateProjectFromArchetype(request);
assertTemplateContent("src/main/java/file/value/package/App.java");
assertTemplateContent("src/main/java/file/value/package/inner/package/App2.java");
assertTemplateContent("src/main/c/file/value/package/App.c");
assertTemplateContent("src/test/java/file/value/package/AppTest.java");
assertTemplateContent("src/test/c/file/value/package/AppTest.c");
assertTemplateContent("src/main/resources/App.properties");
assertTemplateContent("src/main/resources/inner/dir/App2.properties");
assertTemplateContent("src/main/mdo/App.mdo");
assertTemplateContent("src/test/resources/AppTest.properties");
assertTemplateContent("src/test/mdo/AppTest.mdo");
Model model = readPom(new File(projectDirectory, "pom.xml"));
assertNull(model.getParent());
assertEquals("file-value", model.getGroupId());
assertEquals("file-value", model.getArtifactId());
assertEquals("file-value", model.getVersion());
}
use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class DefaultArchetypeGeneratorTest method testGenerateArchetypePartialOnChild.
public void testGenerateArchetypePartialOnChild() throws Exception {
System.out.println("testGenerateArchetypePartialOnChild");
ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-8", ARCHETYPE_PARTIAL);
File parentProjectFile = getProjectFile();
File parentProjectFileSample = getProjectSampleFile();
copy(parentProjectFileSample, parentProjectFile);
File projectFile = new File(projectDirectory, "pom.xml");
File projectFileSample = new File(projectDirectory, "pom.xml.sample");
copy(projectFileSample, projectFile);
FileUtils.forceDelete(new File(projectDirectory, "src"));
generateProjectFromArchetype(request);
Model model = readPom(projectFile);
assertNotNull(model.getParent());
assertEquals("org.apache.maven.archetype", model.getGroupId());
assertEquals("file-value", model.getArtifactId());
assertEquals("1.0-SNAPSHOT", model.getVersion());
assertTrue(model.getModules().isEmpty());
assertFalse(model.getDependencies().isEmpty());
assertFalse(model.getBuild().getPlugins().isEmpty());
assertFalse(model.getReporting().getPlugins().isEmpty());
}
Aggregations