ExternalResourceManagerImpl must not save defaults (standard ignored resources)

This commit is contained in:
Vladimir Krivosheev
2015-02-24 09:43:04 +01:00
parent dfc658ce18
commit c212341aae
8 changed files with 186 additions and 150 deletions
@@ -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;
@@ -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<Set<String>> myStandardResources = new NotNullLazyValue<Set<String>>() {
@NotNull
@Override
protected Set<String> compute() {
ExternalResourceManagerExImpl manager = (ExternalResourceManagerExImpl)ExternalResourceManager.getInstance();
Collection<Map<String, ExternalResourceManagerExImpl.Resource>> resources = manager.getStandardResources();
Set<ExternalResourceManagerExImpl.Resource> dirs = new HashSet<ExternalResourceManagerExImpl.Resource>();
Set<String> set = new HashSet<String>();
for (Map<String, ExternalResourceManagerExImpl.Resource> map : resources) {
Set<ExternalResourceManagerExImpl.Resource> dirs = new THashSet<ExternalResourceManagerExImpl.Resource>();
Set<String> set = new THashSet<String>();
for (Map<String, ExternalResourceManagerExImpl.Resource> 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<VirtualFile> getAdditionalRootsToIndex() {
HashSet<VirtualFile> roots = new HashSet<VirtualFile>();
Set<VirtualFile> roots = new THashSet<VirtualFile>();
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;
}
}
@@ -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);
}
@@ -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();
}
}
@@ -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);
@@ -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<String, Map<String, String>> myResources = new HashMap<String, Map<String, String>>();
private final Set<String> myResourceLocations = new HashSet<String>();
private final Map<String, Map<String, String>> myResources = new THashMap<String, Map<String, String>>();
private final Set<String> myResourceLocations = new THashSet<String>();
private final Set<String> myIgnoredResources = new HashSet<String>();
private final Set<String> myIgnoredResources = new TreeSet<String>();
private final Set<String> myStandardIgnoredResources = new TreeSet<String>();
private final AtomicNotNullLazyValue<Map<String, Map<String, Resource>>> myStdResources = new AtomicNotNullLazyValue<Map<String, Map<String, Resource>>>() {
private final NotNullLazyValue<Map<String, Map<String, Resource>>> myStandardResources = new AtomicNotNullLazyValue<Map<String, Map<String, Resource>>>() {
@NotNull
@Override
protected Map<String, Map<String, Resource>> compute() {
@@ -82,15 +81,14 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
protected Map<String, Map<String, Resource>> 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 <T> Map<String, T> getMap(@NotNull final Map<String, Map<String, T>> resources,
@Nullable final String version,
final boolean create) {
static <T> Map<String, T> getMap(@NotNull Map<String, Map<String, T>> resources, @Nullable String version, boolean create) {
version = StringUtil.notNullize(version, DEFAULT_VERSION);
Map<String, T> map = resources.get(version);
if (map == null) {
if (create) {
map = ContainerUtil.newHashMap();
map = new THashMap<String, T>();
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<String, Resource> map = getMap(myStdResources.getValue(), version, false);
public String getStdResource(@NotNull String url, @Nullable String version) {
Map<String, Resource> 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<String, String> 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<String> result = new LinkedList<String>();
public String[] getResourceUrls(@Nullable FileType fileType, @Nullable @NonNls String version, boolean includeStandard) {
List<String> result = new LinkedList<String>();
addResourcesFromMap(result, version, myResources);
if (includeStandard) {
addResourcesFromMap(result, version, myStdResources.getValue());
addResourcesFromMap(result, version, myStandardResources.getValue());
}
return ArrayUtil.toStringArray(result);
}
private static <T> void addResourcesFromMap(final List<String> result,
String version,
Map<String, Map<String, T>> resourcesMap) {
private static <T> void addResourcesFromMap(@NotNull List<String> result, @Nullable String version, @NotNull Map<String, Map<String, T>> resourcesMap) {
Map<String, T> 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<String, String> map = getMap(myResources, version, true);
private void addSilently(@NotNull String url, @Nullable String version, String location) {
Map<String, String> 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<String, String> map = getMap(myResources, version, false);
if (map != null) {
@@ -299,7 +296,7 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
@Override
public String[] getAvailableUrls() {
Set<String> urls = new HashSet<String>();
Set<String> urls = new THashSet<String>();
for (Map<String, String> 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<String> set = new THashSet<String>(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<String> urls = new TreeSet<String>();
for (Map<String, String> 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<Map<String, Resource>> getStandardResources() {
return myStdResources.getValue().values();
return myStandardResources.getValue().values();
}
private static final NotNullLazyKey<ExternalResourceManagerExImpl, Project> INSTANCE_CACHE = ServiceManager.createLazyKey(ExternalResourceManagerExImpl.class);
private static ExternalResourceManagerExImpl getProjectResources(Project project) {
@@ -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<String, Map<String, Resource>> computeStdResources() {
return Collections.emptyMap();
@@ -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<String, Map<String, ExternalResourceManagerExImpl.Resource>> myResources = new HashMap<String, Map<String, ExternalResourceManagerExImpl.Resource>>();
private final Map<String, Map<String, ExternalResourceManagerExImpl.Resource>> myResources = new THashMap<String, Map<String, ExternalResourceManagerExImpl.Resource>>();
private final List<String> myIgnored = new ArrayList<String>();
@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<String, ExternalResourceManagerExImpl.Resource> map = ExternalResourceManagerExImpl.getMap(myResources, version, true);
Map<String, ExternalResourceManagerExImpl.Resource> 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<String, Map<String, ExternalResourceManagerExImpl.Resource>> getResources() {
return myResources;
}
@NotNull
public List<String> getIgnored() {
return myIgnored;
}