From 8cbd84c1c44cb1c9a85ba778bd9a84d1e80ddca3 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Wed, 27 Mar 2013 19:18:36 +0400 Subject: [PATCH] IDEA-68572 XSD importing cannot import BPMN 2.0 schemas --- .../LightPlatformCodeInsightTestCase.java | 9 +++ .../impl/quickfix/FetchExtResourceAction.java | 35 ++++------- .../ExtractExternalResourceLinksTest.java | 63 ++++++++++--------- .../fetchExternalResources/BPMN20.xsd | 37 +++++++++++ 4 files changed, 89 insertions(+), 55 deletions(-) create mode 100644 xml/tests/testData/quickFix/fetchExternalResources/BPMN20.xsd diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java index d2265d4254c4..c8b6e6a58108 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java @@ -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. diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java index 916f8f7eb730..c931ba5bff5f 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/FetchExtResourceAction.java @@ -250,7 +250,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat resourceUrls.add(s); } - final List newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager); + final Set 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 extractEmbeddedFileReferences(XmlFile file, XmlFile context) { - final List result = new LinkedList(); + private static Set extractEmbeddedFileReferences(XmlFile file, XmlFile context) { + final Set result = new LinkedHashSet(); 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 extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) { - return ApplicationManager.getApplication().runReadAction(new Computable>() { + public static Set extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) { + return ApplicationManager.getApplication().runReadAction(new Computable>() { @Override - public List compute() { + public Set 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(); } }); } diff --git a/xml/tests/src/com/intellij/codeInsight/daemon/quickFix/ExtractExternalResourceLinksTest.java b/xml/tests/src/com/intellij/codeInsight/daemon/quickFix/ExtractExternalResourceLinksTest.java index 85b1069a8fd5..5e2852142e09 100644 --- a/xml/tests/src/com/intellij/codeInsight/daemon/quickFix/ExtractExternalResourceLinksTest.java +++ b/xml/tests/src/com/intellij/codeInsight/daemon/quickFix/ExtractExternalResourceLinksTest.java @@ -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 strings = FetchExtResourceAction.extractEmbeddedFileReferences( - files.get(fileIndex), fileIndex != 0? files.get(0): null, getPsiManager() + Set 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/"; diff --git a/xml/tests/testData/quickFix/fetchExternalResources/BPMN20.xsd b/xml/tests/testData/quickFix/fetchExternalResources/BPMN20.xsd new file mode 100644 index 000000000000..5fe48e8566ff --- /dev/null +++ b/xml/tests/testData/quickFix/fetchExternalResources/BPMN20.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file