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());
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations