use of org.apache.maven.archetype.ArchetypeGenerationRequest in project liferay-ide by liferay.
the class NewMavenJSFModuleProjectProvider method createArchetypeProject.
protected IPath createArchetypeProject(NewLiferayJSFModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
IPath projectLocation = null;
String javaPackage = "com.example";
String projectName = op.getProjectName().content();
IPath location = PathBridge.create(op.getLocation().content());
if (location.lastSegment().equals(projectName)) {
// use parent dir since maven archetype will generate new dir under this
// location
location = location.removeLastSegments(1);
}
String groupId = op.getProjectName().content();
String artifactId = op.getProjectName().content();
String version = "1.0.0";
String archetypeArtifactId = op.getArchetype().content();
Archetype archetype = new Archetype();
String[] gav = archetypeArtifactId.split(":");
String archetypeVersion = gav[gav.length - 1];
archetype.setGroupId(gav[0]);
archetype.setArtifactId(gav[1]);
archetype.setVersion(archetypeVersion);
Artifact artifact = AetherUtil.getLatestAvailableArtifact(archetypeArtifactId);
Properties properties = new Properties();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
if (location == null) {
location = workspaceRoot.getLocation();
}
try {
MavenPluginActivator pluginActivator = MavenPluginActivator.getDefault();
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setTransferListener(pluginActivator.getMaven().createTransferListener(monitor));
request.setArchetypeGroupId(artifact.getGroupId());
request.setArchetypeArtifactId(artifact.getArtifactId());
request.setArchetypeVersion(artifact.getVersion());
request.setArchetypeRepository(AetherUtil.newCentralRepository().getUrl());
request.setGroupId(groupId);
request.setArtifactId(artifactId);
request.setVersion(version);
request.setPackage(javaPackage);
// the model does not have a package field
request.setLocalRepository(pluginActivator.getMaven().getLocalRepository());
request.setRemoteArtifactRepositories(pluginActivator.getMaven().getArtifactRepositories(true));
request.setProperties(properties);
request.setOutputDirectory(location.toPortableString());
ArchetypeGenerationResult result = _getArchetyper().generateProjectFromArchetype(request);
Exception cause = result.getCause();
if (cause != null) {
throw new CoreException(LiferayCore.createErrorStatus("Unable to create project from archetype."));
}
projectLocation = location.append(artifactId);
if (FileUtil.notExists(projectLocation)) {
throw new CoreException(LiferayCore.createErrorStatus("Can't create gradle JSF project. "));
}
} catch (Exception e) {
throw new CoreException(LiferayCore.createErrorStatus("Failed to create JSF project. ", e));
}
return projectLocation;
}
use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class DefaultArchetypeGenerationConfiguratorTest method testOldArchetypeGeneratedFieldsDefaultsBatchMode.
public void testOldArchetypeGeneratedFieldsDefaultsBatchMode() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined, ArchetypeGenerationConfigurationFailure, ArchetypeNotConfigured {
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");
configurator.configureArchetype(request, Boolean.FALSE, properties);
assertEquals("preset-groupId", request.getGroupId());
assertEquals("preset-artifactId", request.getArtifactId());
assertEquals("1.0-SNAPSHOT", request.getVersion());
assertEquals("preset-groupId", request.getPackage());
}
use of org.apache.maven.archetype.ArchetypeGenerationRequest in project maven-archetype by apache.
the class DefaultArchetypeSelectorTest method testArchetypeNotInRequestDefaults.
public void testArchetypeNotInRequestDefaults() 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(), createDefaultArchetypeDefinition());
control.setMatcher(createArgumentMatcher());
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 testArchetypeArtifactIdInRequest.
public void testArchetypeArtifactIdInRequest() throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype, ArchetypeNotDefined {
ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
request.setArchetypeArtifactId("preset-artifactId");
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(DefaultArchetypeSelector.DEFAULT_ARCHETYPE_GROUPID, request.getArchetypeGroupId());
assertEquals("preset-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 IntegrationTestMojo method processIntegrationTest.
private void processIntegrationTest(File goalFile, File archetypeFile) throws IntegrationTestFailure, MojoExecutionException {
getLog().info("Processing Archetype IT project: " + goalFile.getParentFile().getName());
try {
Properties properties = getProperties(goalFile);
File basedir = new File(goalFile.getParentFile(), "project");
FileUtils.deleteDirectory(basedir);
FileUtils.mkdir(basedir.toString());
basedir = setupParentProjects(goalFile.getParentFile().getParentFile(), basedir);
ArchetypeGenerationRequest request = generate(project.getGroupId(), project.getArtifactId(), project.getVersion(), archetypeFile, properties, basedir.toString());
File reference = new File(goalFile.getParentFile(), "reference");
if (reference.exists()) {
// compare generated project with reference
getLog().info("Comparing generated project with reference content: " + reference);
assertDirectoryEquals(reference, new File(basedir, request.getArtifactId()));
}
String goals = FileUtils.fileRead(goalFile);
if (StringUtils.isNotEmpty(goals)) {
invokePostArchetypeGenerationGoals(goals.trim(), new File(basedir, request.getArtifactId()), goalFile);
}
} catch (IOException ioe) {
throw new IntegrationTestFailure(ioe);
}
}
Aggregations