use of org.apache.maven.archetype.ArchetypeGenerationResult in project maven-archetype by apache.
the class CreateProjectFromArchetypeMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
Properties executionProperties = session.getUserProperties();
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest().setArchetypeGroupId(archetypeGroupId).setArchetypeArtifactId(archetypeArtifactId).setArchetypeVersion(archetypeVersion).setOutputDirectory(basedir.getAbsolutePath()).setLocalRepository(localRepository).setRemoteArtifactRepositories(remoteArtifactRepositories).setFilter(filter).setProjectBuildingRequest(session.getProjectBuildingRequest());
try {
if (interactiveMode.booleanValue()) {
getLog().info("Generating project in Interactive mode");
} else {
getLog().info("Generating project in Batch mode");
}
selector.selectArchetype(request, interactiveMode, archetypeCatalog);
if (StringUtils.isBlank(request.getArchetypeArtifactId())) {
// no archetype found: stopping
return;
}
configurator.configureArchetype(request, interactiveMode, executionProperties);
ArchetypeGenerationResult generationResult = manager.generateProjectFromArchetype(request);
if (generationResult.getCause() != null) {
throw new MojoFailureException(generationResult.getCause(), generationResult.getCause().getMessage(), generationResult.getCause().getMessage());
}
} catch (MojoFailureException ex) {
throw ex;
} catch (Exception ex) {
throw (MojoFailureException) new MojoFailureException(ex.getMessage()).initCause(ex);
}
String artifactId = request.getArtifactId();
String postArchetypeGenerationGoals = request.getArchetypeGoals();
if (StringUtils.isEmpty(postArchetypeGenerationGoals)) {
postArchetypeGenerationGoals = goals;
}
if (StringUtils.isNotEmpty(postArchetypeGenerationGoals)) {
invokePostArchetypeGenerationGoals(postArchetypeGenerationGoals, artifactId);
}
}
use of org.apache.maven.archetype.ArchetypeGenerationResult 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.ArchetypeGenerationResult in project maven-archetype by apache.
the class DefaultArchetypeGeneratorTest method generateProjectFromArchetypeWithFailure.
private ArchetypeGenerationResult generateProjectFromArchetypeWithFailure(ArchetypeGenerationRequest request) throws Exception {
ArchetypeGenerationResult result = new ArchetypeGenerationResult();
generator.generateArchetype(request, result);
if (result.getCause() == null) {
fail("Exception must be thrown.");
}
return result;
}
use of org.apache.maven.archetype.ArchetypeGenerationResult in project maven-archetype by apache.
the class DefaultArchetypeGeneratorTest method generateProjectFromArchetype.
private void generateProjectFromArchetype(ArchetypeGenerationRequest request) throws Exception {
ArchetypeGenerationResult result = new ArchetypeGenerationResult();
generator.generateArchetype(request, result);
if (result.getCause() != null) {
throw result.getCause();
}
}
use of org.apache.maven.archetype.ArchetypeGenerationResult in project maven-archetype by apache.
the class DefaultArchetypeGeneratorTest method testArchetypeNotDefined.
public void testArchetypeNotDefined() throws Exception {
System.out.println("testArchetypeNotDefined");
Archetype archetype = new Archetype("archetypes", null, "1.0");
ArchetypeGenerationRequest request = createArchetypeGenerationRequest("generate-2", archetype);
ArchetypeGenerationResult result = generateProjectFromArchetypeWithFailure(request);
assertEquals("Exception not correct", "The archetype is not defined", result.getCause().getMessage());
}
Aggregations