Search in sources :

Example 1 with Archetype

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);
    }
}
Also used : MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype) Archetype(org.apache.maven.archetype.catalog.Archetype) ArchetypeDataSourceException(org.apache.maven.archetype.source.ArchetypeDataSourceException) ArchetypeDataSource(org.apache.maven.archetype.source.ArchetypeDataSource) ArchetypeCatalog(org.apache.maven.archetype.catalog.ArchetypeCatalog)

Example 2 with Archetype

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);
    }
}
Also used : ArchetypeManager(org.eclipse.m2e.core.internal.archetype.ArchetypeManager) Table(org.eclipse.swt.widgets.Table) Archetype(org.apache.maven.archetype.catalog.Archetype) RequiredProperty(org.apache.maven.archetype.metadata.RequiredProperty) TableItem(org.eclipse.swt.widgets.TableItem) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository)

Example 3 with Archetype

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) Archetype(org.apache.maven.archetype.catalog.Archetype) Properties(java.util.Properties) IProject(org.eclipse.core.resources.IProject)

Example 4 with Archetype

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;
}
Also used : MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) Archetype(org.apache.maven.archetype.catalog.Archetype) ArchetypeGenerationRequest(org.apache.maven.archetype.ArchetypeGenerationRequest) ArchetypeGenerationResult(org.apache.maven.archetype.ArchetypeGenerationResult) Properties(java.util.Properties) Artifact(org.eclipse.aether.artifact.Artifact) CoreException(org.eclipse.core.runtime.CoreException) JSONException(org.json.JSONException)

Example 5 with Archetype

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;
}
Also used : Archetype(org.apache.maven.archetype.catalog.Archetype) HashMap(java.util.HashMap) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) ArtifactVersion(org.apache.maven.artifact.versioning.ArtifactVersion) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

Archetype (org.apache.maven.archetype.catalog.Archetype)30 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)12 File (java.io.File)10 List (java.util.List)10 ArrayList (java.util.ArrayList)8 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)8 Properties (java.util.Properties)7 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)7 MockControl (org.easymock.MockControl)7 ArchetypeCatalogXpp3Writer (org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer)6 UnknownArchetype (org.apache.maven.archetype.exception.UnknownArchetype)6 FileWriter (java.io.FileWriter)5 Writer (java.io.Writer)5 Map (java.util.Map)5 ArchetypeGenerationResult (org.apache.maven.archetype.ArchetypeGenerationResult)5 ArchetypeDefinition (org.apache.maven.archetype.ui.ArchetypeDefinition)5 Prompter (org.codehaus.plexus.components.interactivity.Prompter)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)4