Search in sources :

Example 16 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeGenerationConfiguratorTest method testOldArchetypeGeneratedFieldsInRequestBatchMode.

public void testOldArchetypeGeneratedFieldsInRequestBatchMode() throws PrompterException, ArchetypeGenerationConfigurationFailure, IOException, ArchetypeNotConfigured, UnknownArchetype, ArchetypeNotDefined {
    ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
    request.setArchetypeGroupId("archetypeGroupId");
    request.setArchetypeArtifactId("archetypeArtifactId");
    request.setArchetypeVersion("archetypeVersion");
    Properties properties = new Properties();
    properties.setProperty("groupId", "preset-groupId");
    properties.setProperty("artifactId", "preset-artifactId");
    properties.setProperty("version", "preset-gen-version");
    properties.setProperty("package", "preset-gen-package");
    configurator.configureArchetype(request, Boolean.FALSE, properties);
    assertEquals("preset-groupId", request.getGroupId());
    assertEquals("preset-artifactId", request.getArtifactId());
    assertEquals("preset-gen-version", request.getVersion());
    assertEquals("preset-gen-package", request.getPackage());
}
Also used : ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) Properties(java.util.Properties)

Example 17 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeSelectorTest method testArchetypeCoordinatesInRequest.

public void testArchetypeCoordinatesInRequest() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined {
    ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
    request.setArchetypeArtifactId("preset-artifactId");
    request.setArchetypeGroupId("preset-groupId");
    request.setArchetypeVersion("preset-version");
    MockControl control = MockControl.createControl(ArchetypeSelectionQueryer.class);
    ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
    // expect it to not be called
    control.replay();
    selector.setArchetypeSelectionQueryer(queryer);
    selector.selectArchetype(request, Boolean.TRUE, "");
    control.verify();
    assertEquals("preset-groupId", request.getArchetypeGroupId());
    assertEquals("preset-artifactId", request.getArchetypeArtifactId());
    assertEquals("preset-version", request.getArchetypeVersion());
}
Also used : MockControl(org.easymock.MockControl) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest)

Example 18 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeSelectorTest method testArchetypeArtifactIdNotInRequest.

public void testArchetypeArtifactIdNotInRequest() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined {
    ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
    MockControl control = MockControl.createControl(ArchetypeSelectionQueryer.class);
    ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
    queryer.selectArchetype(Collections.<String, List<Archetype>>emptyMap(), new ArchetypeDefinition());
    control.setMatcher(MockControl.ALWAYS_MATCHER);
    Archetype archetype = new Archetype();
    archetype.setArtifactId("set-artifactId");
    archetype.setGroupId("set-groupId");
    archetype.setVersion("set-version");
    control.setReturnValue(archetype);
    control.replay();
    selector.setArchetypeSelectionQueryer(queryer);
    selector.selectArchetype(request, Boolean.TRUE, "");
    control.verify();
    assertEquals("set-groupId", request.getArchetypeGroupId());
    assertEquals("set-artifactId", request.getArchetypeArtifactId());
    assertEquals("set-version", request.getArchetypeVersion());
}
Also used : ArchetypeDefinition(org.apache.maven.archetype.ui.ArchetypeDefinition) MockControl(org.easymock.MockControl) Archetype(org.apache.maven.archetype.catalog.Archetype) UnknownArchetype(org.apache.maven.archetype.exception.UnknownArchetype) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest)

Example 19 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.

the class DefaultArchetypeSelectorTest method testArchetypeNotInRequestDefaultsInBatchMode.

public void testArchetypeNotInRequestDefaultsInBatchMode() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined {
    ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
    MockControl control = MockControl.createControl(ArchetypeSelectionQueryer.class);
    ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
    // expect it to not be called
    control.replay();
    selector.setArchetypeSelectionQueryer(queryer);
    selector.selectArchetype(request, Boolean.FALSE, "");
    control.verify();
    assertEquals(DefaultArchetypeSelector.DEFAULT_ARCHETYPE_GROUPID, request.getArchetypeGroupId());
    assertEquals(DefaultArchetypeSelector.DEFAULT_ARCHETYPE_ARTIFACTID, request.getArchetypeArtifactId());
    assertEquals(DefaultArchetypeSelector.DEFAULT_ARCHETYPE_VERSION, request.getArchetypeVersion());
}
Also used : MockControl(org.easymock.MockControl) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest)

Example 20 with ArchetypeGenerationRequest

use of org.apache.maven.archetype.ArchetypeGenerationRequest 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)

Aggregations

ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)33 File (java.io.File)19 Model (org.apache.maven.model.Model)14 Properties (java.util.Properties)13 ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)10 Archetype (org.apache.maven.archetype.catalog.Archetype)8 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)7 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)7 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)7 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)7 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)5 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)5 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)5 MockControl (org.easymock.MockControl)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