mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
PathMacros as application service, get rid of NamedComponent, NamedJDOMExternalizable, RoamingTypeDisabled
This commit is contained in:
@@ -20,8 +20,10 @@ import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* @deprecated to remove in IDEA 14
|
||||
*/
|
||||
public class JDOMExternalizableAdapter implements PersistentStateComponent<Element> {
|
||||
|
||||
|
||||
@@ -151,6 +151,9 @@
|
||||
|
||||
<applicationService serviceImplementation="com.intellij.internal.statistic.UsageTrigger"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.openapi.application.PathMacros"
|
||||
serviceImplementation="com.intellij.application.options.PathMacrosImpl"/>
|
||||
|
||||
<projectService serviceInterface="com.intellij.openapi.vfs.ReadonlyStatusHandler"
|
||||
serviceImplementation="com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.startup.StartupManager"
|
||||
|
||||
@@ -69,11 +69,6 @@
|
||||
<implementation-class>com.intellij.openapi.command.impl.DocumentReferenceManagerImpl</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.openapi.application.PathMacros</interface-class>
|
||||
<implementation-class>com.intellij.application.options.PathMacrosImpl</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.ide.ui.LafManager</interface-class>
|
||||
<implementation-class>com.intellij.ide.ui.laf.LafManagerImpl</implementation-class>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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,15 +15,15 @@
|
||||
*/
|
||||
package com.intellij.openapi.application;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class PathMacros {
|
||||
|
||||
public static PathMacros getInstance() {
|
||||
return ApplicationManager.getApplication().getComponent(PathMacros.class);
|
||||
return ServiceManager.getService(PathMacros.class);
|
||||
}
|
||||
|
||||
public abstract Set<String> getAllMacroNames();
|
||||
@@ -33,9 +33,7 @@ public abstract class PathMacros {
|
||||
public abstract void setMacro(String name, String value);
|
||||
|
||||
/**
|
||||
* Obsolete macros that are to be removed gently from the project files. They can be read, but not written again. Not persisted.
|
||||
* @param name
|
||||
* @param value
|
||||
* Obsolete macros that are to be removed gently from the project files. They can be read, but not written again. Not persisted
|
||||
*/
|
||||
public abstract void addLegacyMacro(@NotNull String name, @NotNull String value);
|
||||
|
||||
|
||||
+51
-58
@@ -15,41 +15,43 @@
|
||||
*/
|
||||
package com.intellij.application.options;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathMacros;
|
||||
import com.intellij.openapi.components.ExpandMacroToPathMap;
|
||||
import com.intellij.openapi.components.NamedComponent;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.NamedJDOMExternalizable;
|
||||
import com.intellij.openapi.util.RoamingTypeDisabled;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.hash.LinkedHashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.serialization.JpsGlobalLoader;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJDOMExternalizable, RoamingTypeDisabled {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.application.options.PathMacrosImpl");
|
||||
@State(
|
||||
name = "PathMacrosImpl",
|
||||
roamingType = RoamingType.DISABLED,
|
||||
storages = {
|
||||
@Storage(file = StoragePathMacros.APP_CONFIG + "/path.macros.xml")
|
||||
}
|
||||
)
|
||||
public class PathMacrosImpl extends PathMacros implements PersistentStateComponent<Element> {
|
||||
private static final Logger LOG = Logger.getInstance(PathMacrosImpl.class);
|
||||
|
||||
private final Map<String, String> myLegacyMacros = new HashMap<String, String>();
|
||||
private final Map<String, String> myMacros = new HashMap<String, String>();
|
||||
private final Map<String, String> myMacros = new LinkedHashMap<String, String>();
|
||||
private int myModificationStamp = 0;
|
||||
private final ReentrantReadWriteLock myLock = new ReentrantReadWriteLock();
|
||||
private final List<String> myIgnoredMacros = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
|
||||
public static final String MACRO_ELEMENT = JpsGlobalLoader.PathVariablesSerializer.MACRO_TAG;
|
||||
public static final String NAME_ATTR = JpsGlobalLoader.PathVariablesSerializer.NAME_ATTRIBUTE;
|
||||
public static final String VALUE_ATTR = JpsGlobalLoader.PathVariablesSerializer.VALUE_ATTRIBUTE;
|
||||
private static final String MACRO_ELEMENT = JpsGlobalLoader.PathVariablesSerializer.MACRO_TAG;
|
||||
private static final String NAME_ATTR = JpsGlobalLoader.PathVariablesSerializer.NAME_ATTRIBUTE;
|
||||
private static final String VALUE_ATTR = JpsGlobalLoader.PathVariablesSerializer.VALUE_ATTRIBUTE;
|
||||
|
||||
@NonNls
|
||||
public static final String IGNORED_MACRO_ELEMENT = "ignoredMacro";
|
||||
@@ -75,6 +77,7 @@ public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJ
|
||||
SYSTEM_MACROS.add(USER_HOME_MACRO_NAME);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
private static final Set<String> ourToolsMacros = ContainerUtil.immutableSet(
|
||||
"ClasspathEntry",
|
||||
"Classpath",
|
||||
@@ -138,18 +141,7 @@ public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJ
|
||||
}
|
||||
|
||||
public static PathMacrosImpl getInstanceEx() {
|
||||
return (PathMacrosImpl)ApplicationManager.getApplication().getComponent(PathMacros.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "PathMacrosImpl";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExternalFileName() {
|
||||
return EXT_FILE_NAME;
|
||||
return (PathMacrosImpl)getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -286,8 +278,37 @@ public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJ
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void readExternal(Element element) throws InvalidDataException {
|
||||
public Element getState() {
|
||||
try {
|
||||
Element element = new Element("state");
|
||||
myLock.writeLock().lock();
|
||||
|
||||
for (Map.Entry<String, String> entry : myMacros.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (!StringUtil.isEmptyOrSpaces(value)) {
|
||||
final Element macro = new Element(MACRO_ELEMENT);
|
||||
macro.setAttribute(NAME_ATTR, entry.getKey());
|
||||
macro.setAttribute(VALUE_ATTR, value);
|
||||
element.addContent(macro);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String macro : myIgnoredMacros) {
|
||||
final Element macroElement = new Element(IGNORED_MACRO_ELEMENT);
|
||||
macroElement.setAttribute(NAME_ATTR, macro);
|
||||
element.addContent(macroElement);
|
||||
}
|
||||
return element;
|
||||
}
|
||||
finally {
|
||||
myLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element element) {
|
||||
try {
|
||||
myLock.writeLock().lock();
|
||||
|
||||
@@ -297,7 +318,7 @@ public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJ
|
||||
final String name = macro.getAttributeValue(NAME_ATTR);
|
||||
String value = macro.getAttributeValue(VALUE_ATTR);
|
||||
if (name == null || value == null) {
|
||||
throw new InvalidDataException();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SYSTEM_MACROS.contains(name)) {
|
||||
@@ -326,33 +347,6 @@ public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJ
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
try {
|
||||
myLock.writeLock().lock();
|
||||
|
||||
final Set<Map.Entry<String, String>> entries = myMacros.entrySet();
|
||||
for (Map.Entry<String, String> entry : entries) {
|
||||
final String value = entry.getValue();
|
||||
if (value != null && !value.trim().isEmpty()) {
|
||||
final Element macro = new Element(MACRO_ELEMENT);
|
||||
macro.setAttribute(NAME_ATTR, entry.getKey());
|
||||
macro.setAttribute(VALUE_ATTR, value);
|
||||
element.addContent(macro);
|
||||
}
|
||||
}
|
||||
|
||||
for (final String macro : myIgnoredMacros) {
|
||||
final Element macroElement = new Element(IGNORED_MACRO_ELEMENT);
|
||||
macroElement.setAttribute(NAME_ATTR, macro);
|
||||
element.addContent(macroElement);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
myLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void addMacroReplacements(ReplacePathToMacroMap result) {
|
||||
for (final String name : getUserMacroNames()) {
|
||||
final String value = getValue(name);
|
||||
@@ -360,7 +354,6 @@ public class PathMacrosImpl extends PathMacros implements NamedComponent, NamedJ
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addMacroExpands(ExpandMacroToPathMap result) {
|
||||
for (final String name : getUserMacroNames()) {
|
||||
final String value = getValue(name);
|
||||
|
||||
@@ -24,7 +24,10 @@ 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.*;
|
||||
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.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -46,9 +49,9 @@ import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
@State(name = "ExternalResourceManagerImpl",
|
||||
storages = {@Storage( file = StoragePathMacros.APP_CONFIG + "/other.xml")})
|
||||
public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx implements JDOMExternalizable {
|
||||
static final Logger LOG = Logger.getInstance("#com.intellij.j2ee.openapi.impl.ExternalResourceManagerImpl");
|
||||
storages = {@Storage(file = StoragePathMacros.APP_CONFIG + "/other.xml")})
|
||||
public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx implements PersistentStateComponent<Element> {
|
||||
static final Logger LOG = Logger.getInstance(ExternalResourceManagerExImpl.class);
|
||||
|
||||
@NonNls public static final String J2EE_1_3 = "http://java.sun.com/dtd/";
|
||||
@NonNls public static final String J2EE_1_2 = "http://java.sun.com/j2ee/dtds/";
|
||||
@@ -92,7 +95,6 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
|
||||
}
|
||||
|
||||
private final List<ExternalResourceListener> myListeners = ContainerUtil.createLockFreeCopyOnWriteList();
|
||||
private final PathMacrosImpl myPathMacros;
|
||||
@NonNls private static final String RESOURCE_ELEMENT = "resource";
|
||||
@NonNls private static final String URL_ATTR = "url";
|
||||
@NonNls private static final String LOCATION_ATTR = "location";
|
||||
@@ -100,10 +102,6 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
|
||||
@NonNls private static final String HTML_DEFAULT_DOCTYPE_ELEMENT = "default-html-doctype";
|
||||
private static final String DEFAULT_VERSION = null;
|
||||
|
||||
public ExternalResourceManagerExImpl(@NotNull PathMacrosImpl pathMacros) {
|
||||
myPathMacros = pathMacros;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStandardResource(VirtualFile file) {
|
||||
VirtualFile parent = file.getParent();
|
||||
@@ -374,39 +372,11 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
|
||||
return getProjectResources(project).getModificationCount();
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
final ExpandMacroToPathMap macroExpands = new ExpandMacroToPathMap();
|
||||
myPathMacros.addMacroExpands(macroExpands);
|
||||
macroExpands.substitute(element, 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 (final Object o : element.getChildren(IGNORED_RESOURCE_ELEMENT)) {
|
||||
Element e = (Element)o;
|
||||
addIgnoredSilently(e.getAttributeValue(URL_ATTR));
|
||||
}
|
||||
|
||||
Element child = element.getChild(HTML_DEFAULT_DOCTYPE_ELEMENT);
|
||||
if (child != null) {
|
||||
String text = child.getText();
|
||||
if (FileUtil.toSystemIndependentName(text).endsWith(".jar!/resources/html5-schema/html5.rnc")) {
|
||||
text = HTML5_DOCTYPE_ELEMENT;
|
||||
}
|
||||
myDefaultHtmlDoctype = text;
|
||||
}
|
||||
Element catalogElement = element.getChild(CATALOG_PROPERTIES_ELEMENT);
|
||||
if (catalogElement != null) {
|
||||
myCatalogPropertiesFile = catalogElement.getTextTrim();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
final String[] urls = getAvailableUrls();
|
||||
for (String url : urls) {
|
||||
if (url == null) continue;
|
||||
@@ -440,8 +410,41 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
|
||||
final 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();
|
||||
PathMacrosImpl.getInstanceEx().addMacroExpands(macroExpands);
|
||||
macroExpands.substitute(element, 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 (final Object o : element.getChildren(IGNORED_RESOURCE_ELEMENT)) {
|
||||
Element e = (Element)o;
|
||||
addIgnoredSilently(e.getAttributeValue(URL_ATTR));
|
||||
}
|
||||
|
||||
Element child = element.getChild(HTML_DEFAULT_DOCTYPE_ELEMENT);
|
||||
if (child != null) {
|
||||
String text = child.getText();
|
||||
if (FileUtil.toSystemIndependentName(text).endsWith(".jar!/resources/html5-schema/html5.rnc")) {
|
||||
text = HTML5_DOCTYPE_ELEMENT;
|
||||
}
|
||||
myDefaultHtmlDoctype = text;
|
||||
}
|
||||
Element catalogElement = element.getChild(CATALOG_PROPERTIES_ELEMENT);
|
||||
if (catalogElement != null) {
|
||||
myCatalogPropertiesFile = catalogElement.getTextTrim();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addExternalResourceListener(ExternalResourceListener listener) {
|
||||
myListeners.add(listener);
|
||||
@@ -465,7 +468,7 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp
|
||||
|
||||
private static final NotNullLazyKey<ExternalResourceManagerExImpl, Project> INSTANCE_CACHE = ServiceManager.createLazyKey(ExternalResourceManagerExImpl.class);
|
||||
|
||||
private ExternalResourceManagerExImpl getProjectResources(Project project) {
|
||||
private static ExternalResourceManagerExImpl getProjectResources(Project project) {
|
||||
return INSTANCE_CACHE.getValue(project);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,42 +16,21 @@
|
||||
package com.intellij.javaee;
|
||||
|
||||
import com.intellij.application.options.PathMacrosImpl;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.components.StoragePathMacros;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.util.JDOMExternalizableAdapter;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
@State(name = "ProjectResources", storages = {@Storage( file = StoragePathMacros.PROJECT_FILE)})
|
||||
public class ProjectResources extends ExternalResourceManagerExImpl implements PersistentStateComponent<Element>, JDOMExternalizable {
|
||||
private final JDOMExternalizableAdapter myAdapter;
|
||||
|
||||
public ProjectResources(@NotNull PathMacrosImpl pathMacros) {
|
||||
super(pathMacros);
|
||||
myAdapter = new JDOMExternalizableAdapter(this, "ProjectResources");
|
||||
}
|
||||
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
@State(name = "ProjectResources", storages = {@Storage(file = StoragePathMacros.PROJECT_FILE)})
|
||||
public class ProjectResources extends ExternalResourceManagerExImpl {
|
||||
@Override
|
||||
protected Map<String, Map<String, Resource>> computeStdResources() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
return myAdapter.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
myAdapter.loadState(state);
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class XmlCoreEnvironment {
|
||||
appEnvironment.addExtension(StandardResourceProvider.EP_NAME, new InternalResourceProvider());
|
||||
|
||||
appEnvironment.registerApplicationComponent(PathMacros.class, new PathMacrosImpl());
|
||||
appEnvironment.registerApplicationService(ExternalResourceManager.class, new ExternalResourceManagerExImpl(PathMacrosImpl.getInstanceEx()));
|
||||
appEnvironment.registerApplicationService(ExternalResourceManager.class, new ExternalResourceManagerExImpl());
|
||||
appEnvironment.registerApplicationService(XmlFoldingSettings.class, new XmlFoldingSettings());
|
||||
Language[] myLanguages = new Language[]{XMLLanguage.INSTANCE, HTMLLanguage.INSTANCE, XHTMLLanguage.INSTANCE, DTDLanguage.INSTANCE};
|
||||
for (Language myLanguage : myLanguages) {
|
||||
@@ -137,8 +137,7 @@ public class XmlCoreEnvironment {
|
||||
public static class ProjectEnvironment {
|
||||
public ProjectEnvironment(CoreProjectEnvironment projectEnvironment) {
|
||||
projectEnvironment.getProject().registerService(XmlElementFactory.class, new XmlElementFactoryImpl(projectEnvironment.getProject()));
|
||||
projectEnvironment.getProject().registerService(ExternalResourceManagerExImpl.class,
|
||||
new ProjectResources(PathMacrosImpl.getInstanceEx()));
|
||||
projectEnvironment.getProject().registerService(ExternalResourceManagerExImpl.class, new ProjectResources());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user