Search in sources :

Example 11 with MavenArchetype

use of org.jetbrains.idea.maven.model.MavenArchetype in project intellij-community by JetBrains.

the class MavenArchetypesStep method archetypeMayBeChanged.

private void archetypeMayBeChanged() {
    MavenArchetype selectedArchetype = getSelectedArchetype();
    if (((myBuilder.getArchetype() == null) != (selectedArchetype == null))) {
        myBuilder.setArchetype(selectedArchetype);
        skipUpdateUI = true;
        try {
            if (myStep != null) {
                myStep.fireStateChanged();
            }
        } finally {
            skipUpdateUI = false;
        }
    }
}
Also used : MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype)

Example 12 with MavenArchetype

use of org.jetbrains.idea.maven.model.MavenArchetype in project intellij-community by JetBrains.

the class SelectPropertiesStep method updateStep.

@Override
public void updateStep() {
    MavenArchetype archetype = myBuilder.getArchetype();
    Map<String, String> props = new LinkedHashMap<>();
    MavenId projectId = myBuilder.getProjectId();
    props.put("groupId", projectId.getGroupId());
    props.put("artifactId", projectId.getArtifactId());
    props.put("version", projectId.getVersion());
    props.put("archetypeGroupId", archetype.groupId);
    props.put("archetypeArtifactId", archetype.artifactId);
    props.put("archetypeVersion", archetype.version);
    if (archetype.repository != null)
        props.put("archetypeRepository", archetype.repository);
    myMavenPropertiesPanel.setDataFromMap(props);
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with MavenArchetype

use of org.jetbrains.idea.maven.model.MavenArchetype in project intellij-community by JetBrains.

the class MavenModuleBuilderTest method testAddingParentAndInheritWhenGeneratingFromArchetype.

public void testAddingParentAndInheritWhenGeneratingFromArchetype() throws Exception {
    if (!hasMavenInstallation())
        return;
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>");
    setModuleNameAndRoot("module", getProjectPath() + "/module");
    setParentProject(myProjectPom);
    setInheritedOptions(true, true);
    setArchetype(new MavenArchetype("org.apache.maven.archetypes", "maven-archetype-quickstart", "1.0", null, null));
    createNewModule(new MavenId("org.foo", "module", "1.0"));
    assertEquals("<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "    <parent>\n" + "        <artifactId>project</artifactId>\n" + "        <groupId>test</groupId>\n" + "        <version>1</version>\n" + "    </parent>\n" + "    <modelVersion>4.0.0</modelVersion>\n" + "\n" + "    <artifactId>module</artifactId>\n" + "    <packaging>jar</packaging>\n" + "\n" + "    <name>module</name>\n" + "    <url>http://maven.apache.org</url>\n" + "\n" + "    <properties>\n" + "        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n" + "    </properties>\n" + "\n" + "    <dependencies>\n" + "        <dependency>\n" + "            <groupId>junit</groupId>\n" + "            <artifactId>junit</artifactId>\n" + "            <version>3.8.1</version>\n" + "            <scope>test</scope>\n" + "        </dependency>\n" + "    </dependencies>\n" + "</project>\n", VfsUtil.loadText(myProjectRoot.findFileByRelativePath("module/pom.xml")));
}
Also used : MavenId(org.jetbrains.idea.maven.model.MavenId) MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype)

Example 14 with MavenArchetype

use of org.jetbrains.idea.maven.model.MavenArchetype in project intellij-community by JetBrains.

the class MavenIndicesManager method loadUserArchetypes.

private void loadUserArchetypes() {
    try {
        Path file = getUserArchetypesFile();
        if (!PathKt.exists(file)) {
            return;
        }
        // Store artifact to set to remove duplicate created by old IDEA (https://youtrack.jetbrains.com/issue/IDEA-72105)
        Collection<MavenArchetype> result = new LinkedHashSet<>();
        List<Element> children = JdomKt.loadElement(file).getChildren(ELEMENT_ARCHETYPE);
        for (int i = children.size() - 1; i >= 0; i--) {
            Element each = children.get(i);
            String groupId = each.getAttributeValue(ELEMENT_GROUP_ID);
            String artifactId = each.getAttributeValue(ELEMENT_ARTIFACT_ID);
            String version = each.getAttributeValue(ELEMENT_VERSION);
            String repository = each.getAttributeValue(ELEMENT_REPOSITORY);
            String description = each.getAttributeValue(ELEMENT_DESCRIPTION);
            if (StringUtil.isEmptyOrSpaces(groupId) || StringUtil.isEmptyOrSpaces(artifactId) || StringUtil.isEmptyOrSpaces(version)) {
                continue;
            }
            result.add(new MavenArchetype(groupId, artifactId, version, repository, description));
        }
        ArrayList<MavenArchetype> listResult = new ArrayList<>(result);
        Collections.reverse(listResult);
        myUserArchetypes = listResult;
    } catch (IOException | JDOMException e) {
        MavenLog.LOG.warn(e);
    }
}
Also used : Path(java.nio.file.Path) Element(org.jdom.Element) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype)

Example 15 with MavenArchetype

use of org.jetbrains.idea.maven.model.MavenArchetype in project intellij-community by JetBrains.

the class MavenIndicesManager method saveUserArchetypes.

private void saveUserArchetypes() {
    Element root = new Element(ELEMENT_ARCHETYPES);
    for (MavenArchetype each : myUserArchetypes) {
        Element childElement = new Element(ELEMENT_ARCHETYPE);
        childElement.setAttribute(ELEMENT_GROUP_ID, each.groupId);
        childElement.setAttribute(ELEMENT_ARTIFACT_ID, each.artifactId);
        childElement.setAttribute(ELEMENT_VERSION, each.version);
        if (each.repository != null) {
            childElement.setAttribute(ELEMENT_REPOSITORY, each.repository);
        }
        if (each.description != null) {
            childElement.setAttribute(ELEMENT_DESCRIPTION, each.description);
        }
        root.addContent(childElement);
    }
    try {
        JdomKt.write(root, getUserArchetypesFile());
    } catch (IOException e) {
        MavenLog.LOG.warn(e);
    }
}
Also used : Element(org.jdom.Element) IOException(java.io.IOException) MavenArchetype(org.jetbrains.idea.maven.model.MavenArchetype)

Aggregations

MavenArchetype (org.jetbrains.idea.maven.model.MavenArchetype)16 MavenId (org.jetbrains.idea.maven.model.MavenId)3 IOException (java.io.IOException)2 Archetype (org.apache.maven.archetype.catalog.Archetype)2 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)2 ArchetypeDataSource (org.apache.maven.archetype.source.ArchetypeDataSource)2 ArchetypeDataSourceException (org.apache.maven.archetype.source.ArchetypeDataSourceException)2 Element (org.jdom.Element)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 JDOMException (org.jdom.JDOMException)1 MavenProject (org.jetbrains.idea.maven.project.MavenProject)1