project templates schema

This commit is contained in:
Dmitry Avdeev
2013-02-01 12:55:09 +04:00
parent b6aba4ea01
commit 949110f10a
4 changed files with 57 additions and 11 deletions
@@ -1,8 +1,7 @@
<templates>
<template>
<name>Java Hello World</name>
<description><![CDATA[ Simple Java "Hello World" application. ]]>
</description>
<description><![CDATA[ Simple Java "Hello World" application. ]]></description>
<path>HelloWorld.zip</path>
</template>
</templates>
@@ -0,0 +1,13 @@
<template-groups xmlns="http://www.jetbrains.com/projectTemplates">
<group>
<name>Spring</name>
<path>Spring</path>
<template>
<name>Spring Core</name>
<description><![CDATA[ A simple console application with Spring Framework 3.2. ]]></description>
<path>SpringApp</path>
<input-field>IJ_BASE_PACKAGE</input-field>
<input-field>IJ_APPLICATION_SERVER</input-field>
</template>
</group>
</template-groups>
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.jetbrains.com/projectTemplates">
<xs:element name="template-groups" type="template-groupsType"/>
<xs:complexType name="groupType">
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="path"/>
<xs:element type="templateType" name="template"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="templateType">
<xs:sequence>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="description"/>
<xs:element type="xs:string" name="path"/>
<xs:element name="input-field" maxOccurs="unbounded" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="IJ_BASE_PACKAGE"/>
<xs:enumeration value="IJ_APPLICATION_SERVER"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="template-groupsType">
<xs:sequence>
<xs:element type="groupType" name="group"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
@@ -34,6 +34,7 @@ import com.intellij.util.containers.MultiMap;
import com.intellij.util.net.HttpConfigurable;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -52,6 +53,7 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
private static final String URL = "http://download.jetbrains.com/idea/project_templates/";
private static final String SAMPLES_GALLERY = "Samples Gallery";
private static final Namespace NAMESPACE = Namespace.getNamespace("http://www.jetbrains.com/projectTemplates");
private final ClearableLazyValue<MultiMap<String, ProjectTemplate>> myTemplates = new ClearableLazyValue<MultiMap<String, ProjectTemplate>>() {
@NotNull
@Override
@@ -104,14 +106,14 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
public static MultiMap<String, ProjectTemplate> createFromText(String text) throws IOException, JDOMException {
Element rootElement = JDOMUtil.loadDocument(text).getRootElement();
List<Element> groups = rootElement.getChildren("group");
List<Element> groups = rootElement.getChildren("group", NAMESPACE);
MultiMap<String, ProjectTemplate> map = new MultiMap<String, ProjectTemplate>();
if (groups.isEmpty()) { // sample gallery by default
map.put(SAMPLES_GALLERY, createGroupTemplates(rootElement));
map.put(SAMPLES_GALLERY, createGroupTemplates(rootElement, Namespace.NO_NAMESPACE));
}
else {
for (Element group : groups) {
map.put(group.getChildText("name"), createGroupTemplates(group));
map.put(group.getChildText("name", NAMESPACE), createGroupTemplates(group, NAMESPACE));
}
}
@@ -119,14 +121,14 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
}
@SuppressWarnings("unchecked")
private static List<ProjectTemplate> createGroupTemplates(Element groupElement) {
List<Element> elements = groupElement.getChildren("template");
private static List<ProjectTemplate> createGroupTemplates(Element groupElement, final Namespace ns) {
List<Element> elements = groupElement.getChildren("template", ns);
return ContainerUtil.mapNotNull(elements, new NullableFunction<Element, ProjectTemplate>() {
@Override
public ProjectTemplate fun(final Element element) {
List<Element> plugins = element.getChildren("requiredPlugin");
List<Element> plugins = element.getChildren("requiredPlugin", ns);
for (Element plugin : plugins) {
String id = plugin.getTextTrim();
if (!PluginManager.isPluginInstalled(PluginId.getId(id))) {
@@ -135,7 +137,7 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
}
String type = element.getChildText("moduleType");
final ModuleType moduleType = ModuleTypeManager.getInstance().findByID(type);
return new ArchivedProjectTemplate(element.getChildTextTrim("name")) {
return new ArchivedProjectTemplate(element.getChildTextTrim("name", ns)) {
@Override
protected ModuleType getModuleType() {
return moduleType;
@@ -143,7 +145,7 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
@Override
public ZipInputStream getStream() throws IOException {
String path = element.getChildText("path");
String path = element.getChildText("path", ns);
final HttpURLConnection connection = getConnection(path);
return new ZipInputStream(connection.getInputStream()) {
@Override
@@ -157,7 +159,7 @@ public class RemoteTemplatesFactory extends ProjectTemplatesFactory {
@Nullable
@Override
public String getDescription() {
return element.getChildTextTrim("description");
return element.getChildTextTrim("description", ns);
}
};
}