IDEA-68572 XSD importing cannot import BPMN 2.0 schemas: geronimo case fixed & tested

This commit is contained in:
Dmitry Avdeev
2013-04-03 16:44:34 +04:00
parent da565e7ce0
commit 44f37d66f1
4 changed files with 61 additions and 84 deletions
@@ -34,6 +34,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
@@ -210,7 +211,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
Set<String> processedLinks = new HashSet<String>();
Map<String, String> baseUrls = new HashMap<String, String>();
VirtualFile contextFile = virtualFile;
linksToProcess.addAll(extractEmbeddedFileReferences(virtualFile, null, psiManager));
linksToProcess.addAll(extractEmbeddedFileReferences(virtualFile, null, psiManager, url));
while (!linksToProcess.isEmpty()) {
String s = linksToProcess.iterator().next();
@@ -250,7 +251,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
resourceUrls.add(s);
}
final Set<String> newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager);
final Set<String> newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager, resourceUrl);
for (String u : newLinks) {
baseUrls.put(u, resourceUrl);
if (!processedLinks.contains(u)) linksToProcess.add(u);
@@ -391,7 +392,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
return true;
}
private static Set<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context) {
private static Set<String> extractEmbeddedFileReferences(XmlFile file, XmlFile context, final String url) {
final Set<String> result = new LinkedHashSet<String>();
if (context != null) {
XmlEntityRefImpl.copyEntityCaches(file, context);
@@ -428,9 +429,11 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
if (schemaLocation != null) {
final PsiReference[] references = tag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT).getValueElement().getReferences();
if (references.length > 0) {
String extension = FileUtilRt.getExtension(new File(url).getName());
final String namespace = tag.getAttributeValue("namespace");
if (namespace != null && schemaLocation.indexOf('/') == -1) {
if (namespace != null &&
schemaLocation.indexOf('/') == -1 &&
!extension.equals(FileUtilRt.getExtension(schemaLocation))) {
result.add(namespace.substring(0, namespace.lastIndexOf('/') + 1) + schemaLocation);
}
else {
@@ -462,7 +465,10 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
return result;
}
public static Set<String> extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) {
public static Set<String> extractEmbeddedFileReferences(final VirtualFile vFile,
@Nullable final VirtualFile contextVFile,
final PsiManager psiManager,
final String url) {
return ApplicationManager.getApplication().runReadAction(new Computable<Set<String>>() {
@Override
public Set<String> compute() {
@@ -470,7 +476,7 @@ public class FetchExtResourceAction extends BaseExtResourceAction implements Wat
if (file instanceof XmlFile) {
PsiFile contextFile = contextVFile != null ? psiManager.findFile(contextVFile) : null;
return extractEmbeddedFileReferences((XmlFile)file, contextFile instanceof XmlFile ? (XmlFile)contextFile : null);
return extractEmbeddedFileReferences((XmlFile)file, contextFile instanceof XmlFile ? (XmlFile)contextFile : null, url);
}
return Collections.emptySet();
@@ -1,6 +1,7 @@
package com.intellij.codeInsight.daemon.quickFix;
import com.intellij.codeInsight.daemon.impl.quickfix.FetchExtResourceAction;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.testFramework.PlatformTestUtil;
@@ -51,12 +52,6 @@ public class ExtractExternalResourceLinksTest extends LightCodeInsightTestCase {
"http://www.springframework.org/schema/aop/spring-aop.xsd",
"http://www.springframework.org/schema/tx/spring-tx.xsd");
doExtractionOfEmbeddedFiles(
"5.xml",
"geronimo-naming-1.1.xsd",
"geronimo-security-1.1.xsd",
"geronimo-module-1.1.xsd");
}
public void testSeamImport() throws Exception {
@@ -72,22 +67,33 @@ public class ExtractExternalResourceLinksTest extends LightCodeInsightTestCase {
}
public void testGeronimo() throws Exception {
doExtractionOfEmbeddedFiles("web-1.1",
"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");
}
private void doExtractionOfEmbeddedFiles(String shortFileName,String... expectedFileNames) throws Exception {
doExtractionOfEmbeddedFiles(new String[] {shortFileName}, new String[][] {expectedFileNames} );
}
private void doExtractionOfEmbeddedFiles(String[] shortFileName,String[][] expectedFileNames) throws Exception {
final List<VirtualFile> files = new ArrayList<VirtualFile>(shortFileName.length);
for(String s:shortFileName) {
for(String s: shortFileName) {
if (FileUtilRt.getExtension(s).length() < 3) {
s += ".xsd";
}
files.add(getVirtualFile( getBasePath() + "/"+ s ));
}
int fileIndex = 0;
for(String[] expectedFileNameArray:expectedFileNames) {
for (int i = 0; i < expectedFileNames.length; i++) {
String[] expectedFileNameArray = expectedFileNames[i];
Set<String> strings = FetchExtResourceAction.extractEmbeddedFileReferences(
files.get(fileIndex), fileIndex != 0 ? files.get(0) : null, getPsiManager()
);
files.get(fileIndex), fileIndex != 0 ? files.get(0) : null, getPsiManager(),
shortFileName[i]);
assertEquals(expectedFileNameArray.length, strings.size());
int index = 0;
@@ -1,67 +0,0 @@
<!-- "Fetch External Resource" "true" -->
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2004-2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<xs:schema
xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
targetNamespace="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0">
<xs:import namespace="http://geronimo.apache.org/xml/ns/naming-1.1" schemaLocation="geronimo-naming-1.1.xsd"/>
<xs:import namespace="http://geronimo.apache.org/xml/ns/security-1.1" schemaLocation="geronimo-security-1.1.xsd"/>
<xs:import namespace="http://geronimo.apache.org/xml/ns/deployment-1.1" schemaLocation="geronimo-module-1.1.xsd"/>
<xs:element name="web-app" type="web:web-appType"/>
<xs:complexType name="web-appType">
<xs:sequence>
<xs:element ref="sys:environment" minOccurs="0"/>
<xs:element name="context-root" type="xs:string" minOccurs="0"/>
<!--<xs:element name="context-priority-classloader" type="xs:boolean" minOccurs="0"/>-->
<xs:element ref="naming:web-container" minOccurs="0"/>
<xs:element name="container-config" type="web:container-configType" minOccurs="0"/>
<xs:group ref="naming:jndiEnvironmentRefsGroup"/>
<xs:element ref="naming:message-destination" minOccurs="0" maxOccurs="unbounded"/>
<xs:sequence minOccurs="0">
<xs:element name="security-realm-name" type="xs:string"/>
<xs:element ref="security:security" minOccurs="0"/>
</xs:sequence>
<xs:element ref="sys:gbean" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="container-configType">
<xs:sequence>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
@@ -0,0 +1,32 @@
<xs:schema xmlns:web="http://geronimo.apache.org/xml/ns/j2ee/web-1.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"
xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://geronimo.apache.org/xml/ns/j2ee/web-1.1"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
<xs:import namespace="http://geronimo.apache.org/xml/ns/naming-1.1" schemaLocation="geronimo-naming-1.1.xsd"/>
<xs:import namespace="http://geronimo.apache.org/xml/ns/security-1.1" schemaLocation="geronimo-security-1.1.xsd"/>
<xs:import namespace="http://geronimo.apache.org/xml/ns/deployment-1.1" schemaLocation="geronimo-module-1.1.xsd"/>
<xs:element name="web-app" type="web:web-appType"/>
<xs:complexType name="web-appType">
<xs:sequence>
<xs:element ref="sys:environment" minOccurs="0"/>
<xs:element name="context-root" type="xs:string" minOccurs="0"/>
<!--
<xs:element name="context-priority-classloader" type="xs:boolean" minOccurs="0"/>
-->
<xs:element ref="naming:web-container" minOccurs="0"/>
<xs:element name="container-config" type="web:container-configType" minOccurs="0"/>
<xs:group ref="naming:jndiEnvironmentRefsGroup"/>
<xs:element ref="naming:message-destination" minOccurs="0" maxOccurs="unbounded"/>
<xs:sequence minOccurs="0">
<xs:element name="security-realm-name" type="xs:string"/>
<xs:element ref="security:security" minOccurs="0"/>
</xs:sequence>
<xs:element ref="sys:gbean" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="container-configType">
<xs:sequence>
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>