use of org.apache.maven.archetype.catalog.Archetype in project intellij-community by JetBrains.
the class Maven3ServerIndexerImpl method doCollectArchetypes.
private void doCollectArchetypes(String roleHint, Set<MavenArchetype> result) throws RemoteException {
try {
ArchetypeDataSource source = myEmbedder.getComponent(ArchetypeDataSource.class, roleHint);
ArchetypeCatalog archetypeCatalog = source.getArchetypeCatalog(new Properties());
for (Archetype each : archetypeCatalog.getArchetypes()) {
result.add(MavenModelConverter.convertArchetype(each));
}
} catch (ArchetypeDataSourceException e) {
Maven3ServerGlobals.getLogger().warn(e);
}
}
use of org.apache.maven.archetype.catalog.Archetype in project sling by apache.
the class ArchetypeParametersWizardPage method initialize.
@SuppressWarnings("unchecked")
private void initialize() {
if (propertiesTable == null) {
return;
}
Archetype archetype = parent.getChooseArchetypePage().getSelectedArchetype();
if (archetype == null) {
return;
}
try {
ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
ArtifactRepository remoteArchetypeRepository = archetypeManager.getArchetypeRepository(archetype);
properties = (List<RequiredProperty>) archetypeManager.getRequiredProperties(archetype, remoteArchetypeRepository, null);
Table table = propertiesViewer.getTable();
table.setItemCount(properties.size());
int i = 0;
for (Iterator<RequiredProperty> it = properties.iterator(); it.hasNext(); ) {
RequiredProperty rp = it.next();
TableItem item = table.getItem(i++);
if (!rp.getKey().equals(item.getText())) {
// then create it - otherwise, reuse it
item.setText(0, rp.getKey());
item.setText(1, "");
item.setData(item);
}
}
} catch (Exception e) {
throw new RuntimeException("Could not process archetype: " + e.getMessage(), e);
}
}
use of org.apache.maven.archetype.catalog.Archetype in project sling by apache.
the class AbstractNewMavenBasedSlingApplicationWizard method createProjects.
@Override
protected List<IProject> createProjects(IProgressMonitor monitor) throws CoreException {
IPath location = chooseArchetypePage.getLocation();
Archetype archetype = chooseArchetypePage.getSelectedArchetype();
String groupId = archetypeParametersPage.getGroupId();
String artifactId = archetypeParametersPage.getArtifactId();
String version = archetypeParametersPage.getVersion();
String javaPackage = archetypeParametersPage.getJavaPackage();
Properties properties = archetypeParametersPage.getProperties();
ProjectImportConfiguration configuration = new ProjectImportConfiguration();
IProject existingProject = ResourcesPlugin.getWorkspace().getRoot().getProject(artifactId);
if (existingProject != null && existingProject.exists()) {
throw new IllegalStateException("A project with the name " + artifactId + " already exists.");
}
advance(monitor, 1);
List<IProject> projects = MavenPlugin.getProjectConfigurationManager().createArchetypeProjects(location, archetype, groupId, artifactId, version, javaPackage, properties, configuration, new NullProgressMonitor());
monitor.worked(3);
return projects;
}
use of org.apache.maven.archetype.catalog.Archetype 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.catalog.Archetype in project maven-archetype by apache.
the class DefaultArchetypeSelectionQueryer method selectVersion.
private Archetype selectVersion(Map<String, List<Archetype>> catalogs, String groupId, String artifactId) throws PrompterException {
SortedMap<ArtifactVersion, Archetype> archetypeVersionsMap = new TreeMap<ArtifactVersion, Archetype>();
for (Map.Entry<String, List<Archetype>> entry : catalogs.entrySet()) {
for (Archetype archetype : entry.getValue()) {
if (!groupId.equals(archetype.getGroupId()) || !artifactId.equals(archetype.getArtifactId())) {
continue;
}
ArtifactVersion version = new DefaultArtifactVersion(archetype.getVersion());
// don't override the first catalog containing a defined version of the artifact
if (!archetypeVersionsMap.containsKey(version)) {
archetypeVersionsMap.put(version, archetype);
}
}
}
if (archetypeVersionsMap.size() == 1) {
return archetypeVersionsMap.values().iterator().next();
}
// let the user choose between available versions
StringBuilder query = new StringBuilder("Choose " + groupId + ":" + artifactId + " version: \n");
List<String> answers = new ArrayList<String>();
Map<String, Archetype> answerMap = new HashMap<String, Archetype>();
int counter = 1;
String mapKey = null;
for (Map.Entry<ArtifactVersion, Archetype> entry : archetypeVersionsMap.entrySet()) {
ArtifactVersion version = entry.getKey();
Archetype archetype = entry.getValue();
mapKey = String.valueOf(counter);
query.append(mapKey + ": " + version + "\n");
answers.add(mapKey);
answerMap.put(mapKey, archetype);
counter++;
}
query.append("Choose a number: ");
Archetype archetype = null;
do {
String answer = prompter.prompt(query.toString(), answers, mapKey);
archetype = answerMap.get(answer);
} while (archetype == null);
return archetype;
}
Aggregations