Search in sources :

Example 6 with ArchetypeGenerationResult

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);
    }
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult) Properties(java.util.Properties) MavenInvocationException(org.apache.maven.shared.invoker.MavenInvocationException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 7 with ArchetypeGenerationResult

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;
}
Also used : ArchetypeNotConfigured(org.apache.maven.archetype.exception.ArchetypeNotConfigured) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult)

Example 8 with ArchetypeGenerationResult

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;
}
Also used : ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult)

Example 9 with ArchetypeGenerationResult

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();
    }
}
Also used : ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult)

Example 10 with ArchetypeGenerationResult

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());
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult)

Aggregations

ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)12 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)10 Properties (java.util.Properties)7 Archetype (org.apache.maven.archetype.catalog.Archetype)6 File (java.io.File)5 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)5 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)5 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)5 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)5 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)5 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)5 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)5 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)5 FileWriter (java.io.FileWriter)3 Writer (java.io.Writer)3 ArchetypeCreationRequest (org.apache.maven.archetype.ArchetypeCreationRequest)3 ArchetypeCreationResult (org.apache.maven.archetype.ArchetypeCreationResult)3 ArchetypeCatalogXpp3Writer (org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer)3 Model (org.apache.maven.model.Model)3 DefaultProjectBuilderConfiguration (org.apache.maven.project.DefaultProjectBuilderConfiguration)3