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 8d4f01930be9..a14fc74f2577 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 @@ -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 processedLinks = new HashSet(); Map baseUrls = new HashMap(); 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 newLinks = extractEmbeddedFileReferences(virtualFile, contextFile, psiManager); + final Set 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 extractEmbeddedFileReferences(XmlFile file, XmlFile context) { + private static Set extractEmbeddedFileReferences(XmlFile file, XmlFile context, final String url) { final Set result = new LinkedHashSet(); 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 extractEmbeddedFileReferences(final VirtualFile vFile, @Nullable final VirtualFile contextVFile, final PsiManager psiManager) { + public static Set extractEmbeddedFileReferences(final VirtualFile vFile, + @Nullable final VirtualFile contextVFile, + final PsiManager psiManager, + final String url) { return ApplicationManager.getApplication().runReadAction(new Computable>() { @Override public Set 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(); 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 5e2852142e09..96f752a4f2a1 100644 --- a/xml/tests/src/com/intellij/codeInsight/daemon/quickFix/ExtractExternalResourceLinksTest.java +++ b/xml/tests/src/com/intellij/codeInsight/daemon/quickFix/ExtractExternalResourceLinksTest.java @@ -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 files = new ArrayList(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 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; diff --git a/xml/tests/testData/quickFix/fetchExternalResources/5.xml b/xml/tests/testData/quickFix/fetchExternalResources/5.xml deleted file mode 100644 index 6937441f9025..000000000000 --- a/xml/tests/testData/quickFix/fetchExternalResources/5.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/xml/tests/testData/quickFix/fetchExternalResources/web-1.1.xsd b/xml/tests/testData/quickFix/fetchExternalResources/web-1.1.xsd new file mode 100644 index 000000000000..8f72440da72a --- /dev/null +++ b/xml/tests/testData/quickFix/fetchExternalResources/web-1.1.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file