mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-68572 XSD importing cannot import BPMN 2.0 schemas
This commit is contained in:
+9
@@ -40,6 +40,7 @@ import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
|
||||
@@ -135,6 +136,14 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
return PathManagerEx.getTestDataPath();
|
||||
}
|
||||
|
||||
protected VirtualFile getVirtualFile(@NonNls String filePath) {
|
||||
String fullPath = getTestDataPath() + filePath;
|
||||
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
|
||||
assertNotNull("file " + fullPath + " not found", vFile);
|
||||
return vFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as configureByFile but text is provided directly.
|
||||
* @param fileName - name of the file.
|
||||
|
||||
+11
-24
@@ -250,7 +250,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
|
||||
resourceUrls.add(s);
|
||||
}
|
||||
|
||||
final List<String> newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager);
|
||||
final Set<String> newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager);
|
||||
for (String u : newLinks) {
|
||||
baseUrls.put(u, resourceUrl);
|
||||
if (!processedLinks.contains(u)) linksToProcess.add(u);
|
||||
@@ -390,8 +390,8 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
|
||||
return true;
|
||||
}
|
||||
|
||||
private static List<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context) {
|
||||
final List<String> result = new LinkedList<String>();
|
||||
private static Set<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context) {
|
||||
final Set<String> result = new LinkedHashSet<String>();
|
||||
if (context != null) {
|
||||
XmlEntityRefImpl.copyEntityCaches(file, context);
|
||||
}
|
||||
@@ -425,23 +425,13 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
|
||||
String schemaLocation = tag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT);
|
||||
|
||||
if (schemaLocation != null) {
|
||||
final PsiReference[] references = tag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT, null).getValueElement().getReferences();
|
||||
final PsiReference[] references = tag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT).getValueElement().getReferences();
|
||||
if (references.length > 0) {
|
||||
final String namespace = tag.getAttributeValue("namespace");
|
||||
|
||||
if (namespace != null && schemaLocation.indexOf('/') == -1) {
|
||||
result.add(namespace.substring(0, namespace.lastIndexOf('/') + 1) + schemaLocation);
|
||||
}
|
||||
else {
|
||||
result.add(schemaLocation);
|
||||
}
|
||||
result.add(schemaLocation);
|
||||
}
|
||||
}
|
||||
|
||||
final String prefix = tag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI);
|
||||
if (prefix != null) {
|
||||
else {
|
||||
schemaLocation = tag.getAttributeValue("schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI);
|
||||
|
||||
if (schemaLocation != null) {
|
||||
final StringTokenizer tokenizer = new StringTokenizer(schemaLocation);
|
||||
|
||||
@@ -449,10 +439,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
|
||||
tokenizer.nextToken();
|
||||
if (!tokenizer.hasMoreTokens()) break;
|
||||
String location = tokenizer.nextToken();
|
||||
|
||||
if (!result.contains(location)) {
|
||||
result.add(location);
|
||||
}
|
||||
result.add(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -467,10 +454,10 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<String> extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<List<String>>() {
|
||||
public static Set<String> extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<Set<String>>() {
|
||||
@Override
|
||||
public List<String> compute() {
|
||||
public Set<String> compute() {
|
||||
PsiFile file = psiManager.findFile(vFile);
|
||||
|
||||
if (file instanceof XmlFile) {
|
||||
@@ -478,7 +465,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
|
||||
return extractEmbeddedFileReferences((XmlFile)file, contextFile instanceof XmlFile ? (XmlFile)contextFile : null);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+32
-31
@@ -1,15 +1,17 @@
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.FetchExtResourceAction;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ExtractExternalResourceLinksTest extends CodeInsightTestCase {
|
||||
public class ExtractExternalResourceLinksTest extends LightCodeInsightTestCase {
|
||||
|
||||
protected static String getBasePath() {
|
||||
return "/quickFix/fetchExternalResources";
|
||||
@@ -18,13 +20,11 @@ public class ExtractExternalResourceLinksTest extends CodeInsightTestCase {
|
||||
public void testExtractionOfEmbeddedFiles() throws Exception {
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"1.dtd",
|
||||
new String[] {"xhtml-lat1.ent", "xhtml-symbol.ent", "xhtml-special.ent"}
|
||||
);
|
||||
"xhtml-lat1.ent", "xhtml-symbol.ent", "xhtml-special.ent");
|
||||
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"1.xsd",
|
||||
new String[] {"j2ee_1_4.xsd", "jsp_2_0.xsd"}
|
||||
);
|
||||
"j2ee_1_4.xsd", "jsp_2_0.xsd");
|
||||
|
||||
doExtractionOfEmbeddedFiles(
|
||||
new String[] { "2.dtd", "2.mod" },
|
||||
@@ -43,36 +43,36 @@ public class ExtractExternalResourceLinksTest extends CodeInsightTestCase {
|
||||
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"3.xsd",
|
||||
new String[] {"j2ee_1_4.xsd", "jsp_2_0.xsd"}
|
||||
);
|
||||
"j2ee_1_4.xsd", "jsp_2_0.xsd");
|
||||
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"4.xml",
|
||||
new String[] {
|
||||
"http://www.springframework.org/schema/beans/spring-beans.xsd",
|
||||
"http://www.springframework.org/schema/aop/spring-aop.xsd",
|
||||
"http://www.springframework.org/schema/tx/spring-tx.xsd"
|
||||
}
|
||||
);
|
||||
"http://www.springframework.org/schema/beans/spring-beans.xsd",
|
||||
"http://www.springframework.org/schema/aop/spring-aop.xsd",
|
||||
"http://www.springframework.org/schema/tx/spring-tx.xsd");
|
||||
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"5.xml",
|
||||
new String[] {
|
||||
"http://geronimo.apache.org/xml/ns/geronimo-naming-1.1.xsd",
|
||||
"http://geronimo.apache.org/xml/ns/geronimo-security-1.1.xsd",
|
||||
"http://geronimo.apache.org/xml/ns/geronimo-module-1.1.xsd"
|
||||
}
|
||||
);
|
||||
"geronimo-naming-1.1.xsd",
|
||||
"geronimo-security-1.1.xsd",
|
||||
"geronimo-module-1.1.xsd");
|
||||
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"6.xml",
|
||||
new String[] {
|
||||
"http://jboss.com/products/seam/components-1.2.xsd"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void doExtractionOfEmbeddedFiles(String shortFileName,String[] expectedFileNames) throws Exception {
|
||||
public void testSeamImport() throws Exception {
|
||||
doExtractionOfEmbeddedFiles(
|
||||
"6.xml",
|
||||
"http://jboss.com/products/seam/components-1.2.xsd");
|
||||
|
||||
}
|
||||
|
||||
public void testBPMN() throws Exception {
|
||||
doExtractionOfEmbeddedFiles("BPMN20.xsd",
|
||||
"BPMNDI.xsd", "Semantic.xsd");
|
||||
|
||||
}
|
||||
|
||||
private void doExtractionOfEmbeddedFiles(String shortFileName,String... expectedFileNames) throws Exception {
|
||||
doExtractionOfEmbeddedFiles(new String[] {shortFileName}, new String[][] {expectedFileNames} );
|
||||
}
|
||||
|
||||
@@ -85,15 +85,15 @@ public class ExtractExternalResourceLinksTest extends CodeInsightTestCase {
|
||||
int fileIndex = 0;
|
||||
|
||||
for(String[] expectedFileNameArray:expectedFileNames) {
|
||||
List<String> strings = FetchExtResourceAction.extractEmbeddedFileReferences(
|
||||
files.get(fileIndex), fileIndex != 0? files.get(0): null, getPsiManager()
|
||||
Set<String> strings = FetchExtResourceAction.extractEmbeddedFileReferences(
|
||||
files.get(fileIndex), fileIndex != 0 ? files.get(0) : null, getPsiManager()
|
||||
);
|
||||
|
||||
assertEquals(expectedFileNameArray.length,strings.size());
|
||||
assertEquals(expectedFileNameArray.length, strings.size());
|
||||
int index = 0;
|
||||
|
||||
for (final String string : strings) {
|
||||
assertEquals(string, expectedFileNameArray[index]);
|
||||
assertEquals(expectedFileNameArray[index], string);
|
||||
++index;
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ public class ExtractExternalResourceLinksTest extends CodeInsightTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/xml/tests/testData/";
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsd:schema elementFormDefault="qualified" attributeFormDefault="unqualified"
|
||||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
||||
targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL">
|
||||
|
||||
<xsd:import namespace="http://www.omg.org/spec/BPMN/20100524/DI" schemaLocation="BPMNDI.xsd"/>
|
||||
<xsd:include schemaLocation="Semantic.xsd"/>
|
||||
|
||||
<xsd:element name="definitions" type="tDefinitions"/>
|
||||
<xsd:complexType name="tDefinitions">
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="import" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xsd:element ref="extension" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xsd:element ref="rootElement" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xsd:element ref="bpmndi:BPMNDiagram" minOccurs="0" maxOccurs="unbounded"/>
|
||||
<xsd:element ref="relationship" minOccurs="0" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:ID" use="optional"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="targetNamespace" type="xsd:anyURI" use="required"/>
|
||||
<xsd:attribute name="expressionLanguage" type="xsd:anyURI" use="optional" default="http://www.w3.org/1999/XPath"/>
|
||||
<xsd:attribute name="typeLanguage" type="xsd:anyURI" use="optional" default="http://www.w3.org/2001/XMLSchema"/>
|
||||
<xsd:attribute name="exporter" type="xsd:string"/>
|
||||
<xsd:attribute name="exporterVersion" type="xsd:string"/>
|
||||
<xsd:anyAttribute namespace="##other" processContents="lax"/>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="import" type="tImport"/>
|
||||
<xsd:complexType name="tImport">
|
||||
<xsd:attribute name="namespace" type="xsd:anyURI" use="required"/>
|
||||
<xsd:attribute name="location" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="importType" type="xsd:anyURI" use="required"/>
|
||||
</xsd:complexType>
|
||||
|
||||
</xsd:schema>
|
||||
Reference in New Issue
Block a user