From c212341aae530be59a07f4a3f4b46ecd559b61f8 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 24 Feb 2015 09:40:50 +0100 Subject: [PATCH] ExternalResourceManagerImpl must not save defaults (standard ignored resources) --- .../idea/maven/dom/MavenSchemaProvider.java | 7 +- .../ExternalResourcesRootsProvider.java | 18 +- .../javaee/ExternalResourceManager.java | 33 +-- .../javaee/CoreExternalResourceManager.java | 26 +-- .../javaee/ExternalResourceManagerEx.java | 21 +- .../javaee/ExternalResourceManagerExImpl.java | 214 ++++++++++-------- .../com/intellij/javaee/ProjectResources.java | 4 +- .../javaee/ResourceRegistrarImpl.java | 13 +- 8 files changed, 186 insertions(+), 150 deletions(-) diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenSchemaProvider.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenSchemaProvider.java index 26df2720e259..f3bcf765e5f5 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenSchemaProvider.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/dom/MavenSchemaProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ import com.intellij.javaee.ExternalResourceManager; import com.intellij.javaee.ExternalResourceManagerEx; import com.intellij.javaee.ResourceRegistrar; import com.intellij.javaee.StandardResourceProvider; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -28,6 +28,7 @@ public class MavenSchemaProvider implements StandardResourceProvider { public static final String MAVEN_PROFILES_SCHEMA_URL = "http://maven.apache.org/xsd/profiles-1.0.0.xsd"; public static final String MAVEN_SETTINGS_SCHEMA_URL = "http://maven.apache.org/xsd/settings-1.0.0.xsd"; + @Override public void registerResources(ResourceRegistrar registrar) { registrar.addStdResource("http://maven.apache.org/maven-v4_0_0.xsd", "/schemas/maven-4.0.0.xsd", getClass()); registrar.addStdResource(MAVEN_PROJECT_SCHEMA_URL, "/schemas/maven-4.0.0.xsd", getClass()); @@ -41,7 +42,7 @@ public class MavenSchemaProvider implements StandardResourceProvider { String location = ((ExternalResourceManagerEx)ExternalResourceManager.getInstance()).getStdResource(url, null); assert location != null : "cannot find a standard resource for " + url; - VirtualFile result = VfsUtil.findRelativeFile(location, null); + VirtualFile result = VfsUtilCore.findRelativeFile(location, null); assert result != null : "cannot find a schema file for URL: " + url + " location: " + location; return result; diff --git a/xml/impl/src/com/intellij/javaee/ExternalResourcesRootsProvider.java b/xml/impl/src/com/intellij/javaee/ExternalResourcesRootsProvider.java index f629e3216c03..795feb38fec3 100644 --- a/xml/impl/src/com/intellij/javaee/ExternalResourcesRootsProvider.java +++ b/xml/impl/src/com/intellij/javaee/ExternalResourcesRootsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,9 @@ import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.IndexableSetContributor; +import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; -import java.util.Collection; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -33,16 +32,14 @@ import java.util.Set; * @author Dmitry Avdeev */ public class ExternalResourcesRootsProvider extends IndexableSetContributor { - private final NotNullLazyValue> myStandardResources = new NotNullLazyValue>() { @NotNull @Override protected Set compute() { ExternalResourceManagerExImpl manager = (ExternalResourceManagerExImpl)ExternalResourceManager.getInstance(); - Collection> resources = manager.getStandardResources(); - Set dirs = new HashSet(); - Set set = new HashSet(); - for (Map map : resources) { + Set dirs = new THashSet(); + Set set = new THashSet(); + for (Map map : manager.getStandardResources()) { for (ExternalResourceManagerExImpl.Resource resource : map.values()) { ExternalResourceManagerExImpl.Resource dir = new ExternalResourceManagerExImpl.Resource( resource.directoryName(), resource); @@ -61,8 +58,7 @@ public class ExternalResourcesRootsProvider extends IndexableSetContributor { @Override public Set getAdditionalRootsToIndex() { - - HashSet roots = new HashSet(); + Set roots = new THashSet(); for (String url : myStandardResources.getValue()) { VirtualFile file = VfsUtilCore.findRelativeFile(url, null); if (file != null) { @@ -73,7 +69,7 @@ public class ExternalResourcesRootsProvider extends IndexableSetContributor { String path = FetchExtResourceAction.getExternalResourcesPath(); VirtualFile extResources = LocalFileSystem.getInstance().findFileByPath(path); ContainerUtil.addIfNotNull(extResources, roots); - + return roots; } } diff --git a/xml/xml-psi-api/src/com/intellij/javaee/ExternalResourceManager.java b/xml/xml-psi-api/src/com/intellij/javaee/ExternalResourceManager.java index fb8d7dfae5e9..05f7d7c037ca 100644 --- a/xml/xml-psi-api/src/com/intellij/javaee/ExternalResourceManager.java +++ b/xml/xml-psi-api/src/com/intellij/javaee/ExternalResourceManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,30 +24,33 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * author: lesya - */ public abstract class ExternalResourceManager extends SimpleModificationTracker { public static ExternalResourceManager getInstance() { return ServiceManager.getService(ExternalResourceManager.class); } - public abstract void addResource(@NonNls String url, @NonNls String location); - public abstract void addResource(@NonNls String url, @NonNls String version, @NonNls String location); + public abstract void addResource(@NotNull @NonNls String url, @NonNls String location); - public abstract void removeResource(String url); - public abstract void removeResource(String url, String version); + public abstract void addResource(@NotNull @NonNls String url, @NonNls @Nullable String version, @NonNls String location); - /** @see #getResourceLocation(String, com.intellij.openapi.project.Project) */ + public abstract void removeResource(@NotNull String url); + + public abstract void removeResource(@NotNull String url, @Nullable String version); + + /** + * @see #getResourceLocation(String, com.intellij.openapi.project.Project) + */ @Deprecated - public abstract String getResourceLocation(@NonNls String url); - public abstract String getResourceLocation(@NonNls String url, String version); + public abstract String getResourceLocation(@NotNull @NonNls String url); - public abstract String getResourceLocation(@NonNls String url, @NotNull Project project); + public abstract String getResourceLocation(@NotNull @NonNls String url, @Nullable String version); + + public abstract String getResourceLocation(@NotNull @NonNls String url, @NotNull Project project); @Nullable - public abstract PsiFile getResourceLocation(@NotNull @NonNls String url, @NotNull PsiFile baseFile, String version); + public abstract PsiFile getResourceLocation(@NotNull @NonNls String url, @NotNull PsiFile baseFile, @Nullable String version); - public abstract String[] getResourceUrls(@Nullable FileType fileType, final boolean includeStandard); - public abstract String[] getResourceUrls(@Nullable FileType fileType, @NonNls String version, final boolean includeStandard); + public abstract String[] getResourceUrls(@Nullable FileType fileType, boolean includeStandard); + + public abstract String[] getResourceUrls(@Nullable FileType fileType, @NonNls @Nullable String version, boolean includeStandard); } diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java b/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java index 8e2202c697b4..c3ebfe17f070 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,17 +56,17 @@ public class CoreExternalResourceManager extends ExternalResourceManagerEx { } @Override - public void addIgnoredResource(String url) { + public void addIgnoredResource(@NotNull String url) { throw new UnsupportedOperationException(); } @Override - public void removeIgnoredResource(String url) { + public void removeIgnoredResource(@NotNull String url) { throw new UnsupportedOperationException(); } @Override - public boolean isIgnoredResource(String url) { + public boolean isIgnoredResource(@NotNull String url) { return false; } @@ -103,7 +103,7 @@ public class CoreExternalResourceManager extends ExternalResourceManagerEx { @Nullable @Override - public String getStdResource(String url, String version) { + public String getStdResource(@NotNull String url, @Nullable String version) { throw new UnsupportedOperationException(); } @@ -134,37 +134,37 @@ public class CoreExternalResourceManager extends ExternalResourceManagerEx { } @Override - public void addResource(@NonNls String url, @NonNls String location) { + public void addResource(@NotNull @NonNls String url, @NonNls String location) { throw new UnsupportedOperationException(); } @Override - public void addResource(@NonNls String url, @NonNls String version, @NonNls String location) { + public void addResource(@NotNull @NonNls String url, @NonNls String version, @NonNls String location) { throw new UnsupportedOperationException(); } @Override - public void removeResource(String url) { + public void removeResource(@NotNull String url) { throw new UnsupportedOperationException(); } @Override - public void removeResource(String url, String version) { + public void removeResource(@NotNull String url, @Nullable String version) { throw new UnsupportedOperationException(); } @Override - public String getResourceLocation(@NonNls String url) { + public String getResourceLocation(@NotNull @NonNls String url) { throw new UnsupportedOperationException(); } @Override - public String getResourceLocation(@NonNls String url, String version) { + public String getResourceLocation(@NotNull @NonNls String url, @Nullable String version) { throw new UnsupportedOperationException(); } @Override - public String getResourceLocation(@NonNls String url, @NotNull Project project) { + public String getResourceLocation(@NotNull @NonNls String url, @NotNull Project project) { throw new UnsupportedOperationException(); } @@ -180,7 +180,7 @@ public class CoreExternalResourceManager extends ExternalResourceManagerEx { } @Override - public String[] getResourceUrls(@Nullable FileType fileType, @NonNls String version, boolean includeStandard) { + public String[] getResourceUrls(@Nullable FileType fileType, @NotNull @NonNls String version, boolean includeStandard) { throw new UnsupportedOperationException(); } } diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java index 1432ea35365b..e8b7ee614536 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,10 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * author: lesya - */ public abstract class ExternalResourceManagerEx extends ExternalResourceManager { @NonNls public static final String STANDARD_SCHEMAS = "/standardSchemas/"; - public static ExternalResourceManagerEx getInstanceEx(){ + public static ExternalResourceManagerEx getInstanceEx() { return (ExternalResourceManagerEx)getInstance(); } @@ -36,15 +33,18 @@ public abstract class ExternalResourceManagerEx extends ExternalResourceManager public abstract void addResource(@NonNls String url, @NonNls String location, @NotNull Project project); public abstract String[] getAvailableUrls(); + public abstract String[] getAvailableUrls(Project project); public abstract void clearAllResources(); + public abstract void clearAllResources(Project project); - public abstract void addIgnoredResource(String url); - public abstract void removeIgnoredResource(String url); + public abstract void addIgnoredResource(@NotNull String url); - public abstract boolean isIgnoredResource(String url); + public abstract void removeIgnoredResource(@NotNull String url); + + public abstract boolean isIgnoredResource(@NotNull String url); public abstract String[] getIgnoredResources(); @@ -53,12 +53,14 @@ public abstract class ExternalResourceManagerEx extends ExternalResourceManager public abstract void removeExternalResourceListener(ExternalResourceListener listener); public abstract boolean isUserResource(VirtualFile file); + public abstract boolean isStandardResource(VirtualFile file); @Nullable public abstract String getUserResource(Project project, String url, String version); + @Nullable - public abstract String getStdResource(String url, String version); + public abstract String getStdResource(@NotNull String url, @Nullable String version); @NotNull public abstract String getDefaultHtmlDoctype(@NotNull Project project); @@ -66,6 +68,7 @@ public abstract class ExternalResourceManagerEx extends ExternalResourceManager public abstract void setDefaultHtmlDoctype(@NotNull String defaultHtmlDoctype, @NotNull Project project); public abstract String getCatalogPropertiesFile(); + public abstract void setCatalogPropertiesFile(@Nullable String filePath); public abstract long getModificationCount(@NotNull Project project); diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java index a9a1980f80bc..93829e962d63 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,23 +21,21 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.*; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.AtomicNotNullLazyValue; -import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.NotNullLazyKey; -import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.xml.XmlFile; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.HashMap; import com.intellij.xml.Html5SchemaProvider; import com.intellij.xml.XmlSchemaProvider; import com.intellij.xml.util.XmlUtil; +import gnu.trove.THashMap; +import gnu.trove.THashSet; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -61,12 +59,13 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp @NonNls public static final String JAVAEE_NS = "http://java.sun.com/xml/ns/javaee/"; private static final String CATALOG_PROPERTIES_ELEMENT = "CATALOG_PROPERTIES"; - private final Map> myResources = new HashMap>(); - private final Set myResourceLocations = new HashSet(); + private final Map> myResources = new THashMap>(); + private final Set myResourceLocations = new THashSet(); - private final Set myIgnoredResources = new HashSet(); + private final Set myIgnoredResources = new TreeSet(); + private final Set myStandardIgnoredResources = new TreeSet(); - private final AtomicNotNullLazyValue>> myStdResources = new AtomicNotNullLazyValue>>() { + private final NotNullLazyValue>> myStandardResources = new AtomicNotNullLazyValue>>() { @NotNull @Override protected Map> compute() { @@ -82,15 +81,14 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp protected Map> computeStdResources() { ResourceRegistrarImpl registrar = new ResourceRegistrarImpl(); - for (StandardResourceProvider provider : Extensions.getExtensions(StandardResourceProvider.EP_NAME)) { + for (StandardResourceProvider provider : StandardResourceProvider.EP_NAME.getExtensions()) { provider.registerResources(registrar); } - StandardResourceEP[] extensions = Extensions.getExtensions(StandardResourceEP.EP_NAME); - for (StandardResourceEP extension : extensions) { + for (StandardResourceEP extension : StandardResourceEP.EP_NAME.getExtensions()) { registrar.addStdResource(extension.url, extension.version, extension.resourcePath, null, extension.getLoaderForClass()); } - myIgnoredResources.addAll(registrar.getIgnored()); + myStandardIgnoredResources.addAll(registrar.getIgnored()); return registrar.getResources(); } @@ -100,7 +98,8 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp @NonNls private static final String LOCATION_ATTR = "location"; @NonNls private static final String IGNORED_RESOURCE_ELEMENT = "ignored-resource"; @NonNls private static final String HTML_DEFAULT_DOCTYPE_ELEMENT = "default-html-doctype"; - private static final String DEFAULT_VERSION = null; + + private static final String DEFAULT_VERSION = ""; @Override public boolean isStandardResource(VirtualFile file) { @@ -114,42 +113,41 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } @Nullable - static Map getMap(@NotNull final Map> resources, - @Nullable final String version, - final boolean create) { + static Map getMap(@NotNull Map> resources, @Nullable String version, boolean create) { + version = StringUtil.notNullize(version, DEFAULT_VERSION); Map map = resources.get(version); if (map == null) { if (create) { - map = ContainerUtil.newHashMap(); + map = new THashMap(); resources.put(version, map); } - else if (version == null || !version.equals(DEFAULT_VERSION)) { + else if (!version.equals(DEFAULT_VERSION)) { map = resources.get(DEFAULT_VERSION); } } - return map; } @Override - public String getResourceLocation(String url) { + public String getResourceLocation(@NotNull String url) { return getResourceLocation(url, DEFAULT_VERSION); } @Override - public String getResourceLocation(@NonNls String url, String version) { - String result = getUserResource(url, version); + public String getResourceLocation(@NotNull @NonNls String url, @Nullable String version) { + String result = getUserResource(url, StringUtil.notNullize(version, DEFAULT_VERSION)); if (result == null) { XMLCatalogManager manager = getCatalogManager(); if (manager != null) { result = manager.resolve(url); } - } - if (result == null) { - result = getStdResource(url, version); - } - if (result == null) { - result = url; + + if (result == null) { + result = getStdResource(url, version); + if (result == null) { + return url; + } + } } return result; } @@ -163,8 +161,8 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp @Override @Nullable - public String getStdResource(String url, String version) { - Map map = getMap(myStdResources.getValue(), version, false); + public String getStdResource(@NotNull String url, @Nullable String version) { + Map map = getMap(myStandardResources.getValue(), version, false); if (map != null) { Resource resource = map.get(url); return resource == null ? null : resource.getResourceUrl(); @@ -175,13 +173,13 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } @Nullable - private String getUserResource(String url, String version) { + private String getUserResource(@NotNull String url, @Nullable String version) { Map map = getMap(myResources, version, false); return map != null ? map.get(url) : null; } @Override - public String getResourceLocation(@NonNls String url, @NotNull Project project) { + public String getResourceLocation(@NotNull @NonNls String url, @NotNull Project project) { String location = getProjectResources(project).getResourceLocation(url); return location == null || location.equals(url) ? getResourceLocation(url) : location; } @@ -203,28 +201,27 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } @Override - public String[] getResourceUrls(FileType fileType, final boolean includeStandard) { + public String[] getResourceUrls(FileType fileType, boolean includeStandard) { return getResourceUrls(fileType, DEFAULT_VERSION, includeStandard); } @Override - public String[] getResourceUrls(@Nullable final FileType fileType, @NonNls final String version, final boolean includeStandard) { - final List result = new LinkedList(); + public String[] getResourceUrls(@Nullable FileType fileType, @Nullable @NonNls String version, boolean includeStandard) { + List result = new LinkedList(); addResourcesFromMap(result, version, myResources); if (includeStandard) { - addResourcesFromMap(result, version, myStdResources.getValue()); + addResourcesFromMap(result, version, myStandardResources.getValue()); } return ArrayUtil.toStringArray(result); } - private static void addResourcesFromMap(final List result, - String version, - Map> resourcesMap) { + private static void addResourcesFromMap(@NotNull List result, @Nullable String version, @NotNull Map> resourcesMap) { Map resources = getMap(resourcesMap, version, false); - if (resources == null) return; - result.addAll(resources.keySet()); + if (resources != null) { + result.addAll(resources.keySet()); + } } @TestOnly @@ -249,19 +246,19 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp }); } @Override - public void addResource(String url, String location) { + public void addResource(@NotNull String url, String location) { addResource(url, DEFAULT_VERSION, location); } @Override - public void addResource(@NonNls String url, @NonNls String version, @NonNls String location) { + public void addResource(@NotNull @NonNls String url, @NonNls String version, @NonNls String location) { ApplicationManager.getApplication().assertWriteAccessAllowed(); addSilently(url, version, location); fireExternalResourceChanged(); } - private void addSilently(String url, String version, String location) { - final Map map = getMap(myResources, version, true); + private void addSilently(@NotNull String url, @Nullable String version, String location) { + Map map = getMap(myResources, version, true); assert map != null; map.put(url, location); myResourceLocations.add(location); @@ -269,12 +266,12 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } @Override - public void removeResource(String url) { + public void removeResource(@NotNull String url) { removeResource(url, DEFAULT_VERSION); } @Override - public void removeResource(String url, String version) { + public void removeResource(@NotNull String url, @Nullable String version) { ApplicationManager.getApplication().assertWriteAccessAllowed(); Map map = getMap(myResources, version, false); if (map != null) { @@ -299,7 +296,7 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp @Override public String[] getAvailableUrls() { - Set urls = new HashSet(); + Set urls = new THashSet(); for (Map map : myResources.values()) { urls.addAll(map.keySet()); } @@ -327,19 +324,29 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } @Override - public void addIgnoredResource(String url) { + public void addIgnoredResource(@NotNull String url) { ApplicationManager.getApplication().assertWriteAccessAllowed(); - addIgnoredSilently(url); - fireExternalResourceChanged(); + if (addIgnoredSilently(url)) { + fireExternalResourceChanged(); + } } - private void addIgnoredSilently(String url) { - myIgnoredResources.add(url); - incModificationCount(); + private boolean addIgnoredSilently(@NotNull String url) { + if (myStandardIgnoredResources.contains(url)) { + return false; + } + + if (myIgnoredResources.add(url)) { + incModificationCount(); + return true; + } + else { + return false; + } } @Override - public void removeIgnoredResource(String url) { + public void removeIgnoredResource(@NotNull String url) { ApplicationManager.getApplication().assertWriteAccessAllowed(); if (myIgnoredResources.remove(url)) { incModificationCount(); @@ -348,23 +355,38 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } @Override - public boolean isIgnoredResource(String url) { - myStdResources.getValue(); // ensure ignored resources are loaded - return myIgnoredResources.contains(url) || isImplicitNamespaceDescriptor(url); + public boolean isIgnoredResource(@NotNull String url) { + if (myIgnoredResources.contains(url)) { + return true; + } + + // ensure ignored resources are loaded + myStandardResources.getValue(); + return myStandardIgnoredResources.contains(url) || isImplicitNamespaceDescriptor(url); } - private static boolean isImplicitNamespaceDescriptor(String url) { - for (ImplicitNamespaceDescriptorProvider namespaceDescriptorProvider : Extensions - .getExtensions(ImplicitNamespaceDescriptorProvider.EP_NAME)) { - if (namespaceDescriptorProvider.getNamespaceDescriptor(null, url, null) != null) return true; + private static boolean isImplicitNamespaceDescriptor(@NotNull String url) { + for (ImplicitNamespaceDescriptorProvider provider : ImplicitNamespaceDescriptorProvider.EP_NAME.getExtensions()) { + if (provider.getNamespaceDescriptor(null, url, null) != null) { + return true; + } } return false; } @Override public String[] getIgnoredResources() { - myStdResources.getValue(); // ensure ignored resources are loaded - return ArrayUtil.toStringArray(myIgnoredResources); + // ensure ignored resources are loaded + myStandardResources.getValue(); + + if (myIgnoredResources.isEmpty()) { + return ArrayUtil.toStringArray(myStandardIgnoredResources); + } + + Set set = new THashSet(myIgnoredResources.size() + myStandardIgnoredResources.size()); + set.addAll(myIgnoredResources); + set.addAll(myStandardIgnoredResources); + return ArrayUtil.toStringArray(set); } @Override @@ -372,25 +394,34 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp return getProjectResources(project).getModificationCount(); } - @Nullable @Override public Element getState() { Element element = new Element("state"); - final String[] urls = getAvailableUrls(); - for (String url : urls) { - if (url == null) continue; - String location = getResourceLocation(url); - if (location == null) continue; - final Element e = new Element(RESOURCE_ELEMENT); + Set urls = new TreeSet(); + for (Map map : myResources.values()) { + urls.addAll(map.keySet()); + } + + for (String url : urls) { + if (url == null) { + continue; + } + + String location = getResourceLocation(url); + if (location == null) { + continue; + } + + Element e = new Element(RESOURCE_ELEMENT); e.setAttribute(URL_ATTR, url); e.setAttribute(LOCATION_ATTR, location.replace(File.separatorChar, '/')); element.addContent(e); } - final String[] ignoredResources = getIgnoredResources(); - for (String ignoredResource : ignoredResources) { + myIgnoredResources.removeAll(myStandardIgnoredResources); + for (String ignoredResource : myIgnoredResources) { Element e = new Element(IGNORED_RESOURCE_ELEMENT); e.setAttribute(URL_ATTR, ignoredResource); element.addContent(e); @@ -406,30 +437,33 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp properties.setText(myCatalogPropertiesFile); element.addContent(properties); } - final ReplacePathToMacroMap macroReplacements = new ReplacePathToMacroMap(); + + ReplacePathToMacroMap macroReplacements = new ReplacePathToMacroMap(); PathMacrosImpl.getInstanceEx().addMacroReplacements(macroReplacements); macroReplacements.substitute(element, SystemInfo.isFileSystemCaseSensitive); return element; } @Override - public void loadState(Element element) { - final ExpandMacroToPathMap macroExpands = new ExpandMacroToPathMap(); + public void loadState(Element state) { + ExpandMacroToPathMap macroExpands = new ExpandMacroToPathMap(); PathMacrosImpl.getInstanceEx().addMacroExpands(macroExpands); - macroExpands.substitute(element, SystemInfo.isFileSystemCaseSensitive); + macroExpands.substitute(state, SystemInfo.isFileSystemCaseSensitive); incModificationCount(); - for (final Object o1 : element.getChildren(RESOURCE_ELEMENT)) { - Element e = (Element)o1; - addSilently(e.getAttributeValue(URL_ATTR), DEFAULT_VERSION, e.getAttributeValue(LOCATION_ATTR).replace('/', File.separatorChar)); + for (Element element : state.getChildren(RESOURCE_ELEMENT)) { + String url = element.getAttributeValue(URL_ATTR); + if (!StringUtil.isEmpty(url)) { + addSilently(url, DEFAULT_VERSION, element.getAttributeValue(LOCATION_ATTR).replace('/', File.separatorChar)); + } } - for (final Object o : element.getChildren(IGNORED_RESOURCE_ELEMENT)) { - Element e = (Element)o; - addIgnoredSilently(e.getAttributeValue(URL_ATTR)); + myIgnoredResources.clear(); + for (Element element : state.getChildren(IGNORED_RESOURCE_ELEMENT)) { + addIgnoredSilently(element.getAttributeValue(URL_ATTR)); } - Element child = element.getChild(HTML_DEFAULT_DOCTYPE_ELEMENT); + Element child = state.getChild(HTML_DEFAULT_DOCTYPE_ELEMENT); if (child != null) { String text = child.getText(); if (FileUtil.toSystemIndependentName(text).endsWith(".jar!/resources/html5-schema/html5.rnc")) { @@ -437,13 +471,12 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } myDefaultHtmlDoctype = text; } - Element catalogElement = element.getChild(CATALOG_PROPERTIES_ELEMENT); + Element catalogElement = state.getChild(CATALOG_PROPERTIES_ELEMENT); if (catalogElement != null) { myCatalogPropertiesFile = catalogElement.getTextTrim(); } } - @Override public void addExternalResourceListener(ExternalResourceListener listener) { myListeners.add(listener); @@ -461,10 +494,9 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } Collection> getStandardResources() { - return myStdResources.getValue().values(); + return myStandardResources.getValue().values(); } - private static final NotNullLazyKey INSTANCE_CACHE = ServiceManager.createLazyKey(ExternalResourceManagerExImpl.class); private static ExternalResourceManagerExImpl getProjectResources(Project project) { diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ProjectResources.java b/xml/xml-psi-impl/src/com/intellij/javaee/ProjectResources.java index 4b9541b0ebe2..7f4a69b1847a 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ProjectResources.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/ProjectResources.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.intellij.javaee; -import com.intellij.application.options.PathMacrosImpl; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.components.StoragePathMacros; @@ -29,6 +28,7 @@ import java.util.Map; */ @State(name = "ProjectResources", storages = {@Storage(file = StoragePathMacros.PROJECT_FILE)}) public class ProjectResources extends ExternalResourceManagerExImpl { + @NotNull @Override protected Map> computeStdResources() { return Collections.emptyMap(); diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ResourceRegistrarImpl.java b/xml/xml-psi-impl/src/com/intellij/javaee/ResourceRegistrarImpl.java index a0fa57929f14..37462e2410b1 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ResourceRegistrarImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/ResourceRegistrarImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.javaee; -import com.intellij.util.containers.HashMap; +import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -28,8 +28,7 @@ import java.util.Map; * @author Dmitry Avdeev */ public class ResourceRegistrarImpl implements ResourceRegistrar { - - private final Map> myResources = new HashMap>(); + private final Map> myResources = new THashMap>(); private final List myIgnored = new ArrayList(); @Override @@ -43,7 +42,7 @@ public class ResourceRegistrarImpl implements ResourceRegistrar { } public void addStdResource(@NonNls String resource, @NonNls String version, @NonNls String fileName, @Nullable Class klass, @Nullable ClassLoader classLoader) { - final Map map = ExternalResourceManagerExImpl.getMap(myResources, version, true); + Map map = ExternalResourceManagerExImpl.getMap(myResources, version, true); assert map != null; resource = new String(resource); // enforce copying; todo remove after final migration to JDK 1.7 map.put(resource, new ExternalResourceManagerExImpl.Resource(fileName, klass, classLoader)); @@ -75,10 +74,12 @@ public class ResourceRegistrarImpl implements ResourceRegistrar { addStdResource(resource, version, ExternalResourceManagerEx.STANDARD_SCHEMAS + fileName, clazz); } + @NotNull public Map> getResources() { return myResources; } + @NotNull public List getIgnored() { return myIgnored; }