mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix profiles_settings.xml serialization
This commit is contained in:
+8
-4
@@ -63,8 +63,10 @@ internal class ProjectInspectionManagerTest {
|
||||
projectInspectionProfileManager.setRootProfile(null)
|
||||
val doNotUseProjectProfileState = """
|
||||
<state>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</state>""".trimIndent()
|
||||
assertThat(projectInspectionProfileManager.state).isEqualTo(doNotUseProjectProfileState)
|
||||
|
||||
@@ -74,8 +76,10 @@ internal class ProjectInspectionManagerTest {
|
||||
assertThat(file).exists()
|
||||
val doNotUseProjectProfileData = """
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>""".trimIndent()
|
||||
assertThat(file.readText()).isEqualTo(doNotUseProjectProfileData)
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@
|
||||
<item name='org.jdom.Element org.jdom.Attribute getAttribute(java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||
</item>
|
||||
<item name='org.jdom.Element org.jdom.Element getChild(java.lang.String)'>
|
||||
<annotation name='org.jetbrains.annotations.Nullable'/>
|
||||
</item>
|
||||
<item name='org.jdom.Element org.jdom.Element setAttribute(java.lang.String, java.lang.String) 0'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
|
||||
+4
-4
@@ -134,7 +134,7 @@ public class SeverityRegistrar implements Comparator<HighlightSeverity> {
|
||||
}
|
||||
|
||||
|
||||
public void readExternal(Element element) {
|
||||
public void readExternal(@NotNull Element element) {
|
||||
myMap.clear();
|
||||
myRendererColors.clear();
|
||||
for (Element infoElement : element.getChildren(INFO_TAG)) {
|
||||
@@ -150,8 +150,9 @@ public class SeverityRegistrar implements Comparator<HighlightSeverity> {
|
||||
final List<HighlightSeverity> knownSeverities = getDefaultOrder();
|
||||
for (String name : myReadOrder) {
|
||||
HighlightSeverity severity = getSeverity(name);
|
||||
if (severity == null || !knownSeverities.contains(severity)) continue;
|
||||
read.add(severity);
|
||||
if (severity != null && knownSeverities.contains(severity)) {
|
||||
read.add(severity);
|
||||
}
|
||||
}
|
||||
OrderMap orderMap = fromList(read);
|
||||
if (orderMap.isEmpty()) {
|
||||
@@ -292,7 +293,6 @@ public class SeverityRegistrar implements Comparator<HighlightSeverity> {
|
||||
return o1 - o2;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private OrderMap getOrderMap() {
|
||||
OrderMap orderMap;
|
||||
|
||||
+5
-6
@@ -832,16 +832,15 @@ public class InspectionProfileImpl extends ProfileEx implements ModifiableModel,
|
||||
myDescription = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convert(@NotNull Element element, @NotNull Project project) {
|
||||
initInspectionTools(project);
|
||||
final Element scopes = element.getChild(ProjectInspectionProfileManagerImplKt.SCOPES);
|
||||
final Element scopes = element.getChild("scopes");
|
||||
if (scopes == null) {
|
||||
return;
|
||||
}
|
||||
final List children = scopes.getChildren(SCOPE);
|
||||
for (Object s : children) {
|
||||
Element scopeElement = (Element)s;
|
||||
|
||||
initInspectionTools(project);
|
||||
|
||||
for (Element scopeElement : scopes.getChildren(SCOPE)) {
|
||||
final String profile = scopeElement.getAttributeValue(ProjectInspectionProfileManagerImplKt.PROFILE);
|
||||
if (profile != null) {
|
||||
final InspectionProfileImpl inspectionProfile = (InspectionProfileImpl)getProfileManager().getProfile(profile);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.profile;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.profile.codeInspection.ProjectInspectionProfileManagerImplKt;
|
||||
import com.intellij.util.xmlb.SmartSerializer;
|
||||
import com.intellij.util.xmlb.annotations.OptionTag;
|
||||
@@ -120,9 +119,6 @@ public abstract class ProfileEx implements Profile {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void convert(@NotNull Element element, @NotNull Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void copyFrom(@NotNull Profile profile) {
|
||||
readExternal(serializeProfile(profile));
|
||||
|
||||
+26
-16
@@ -31,6 +31,7 @@ import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.ProjectManagerListener
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.packageDependencies.DependencyValidationManager
|
||||
import com.intellij.profile.Profile
|
||||
@@ -40,12 +41,10 @@ import com.intellij.util.ui.UIUtil
|
||||
import com.intellij.util.xmlb.Accessor
|
||||
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters
|
||||
import com.intellij.util.xmlb.XmlSerializer
|
||||
import gnu.trove.THashSet
|
||||
import org.jdom.Element
|
||||
import java.util.function.Function
|
||||
|
||||
const val PROFILE = "profile"
|
||||
const val SCOPES = "scopes"
|
||||
|
||||
private const val VERSION = "1.0"
|
||||
private const val SCOPE = "scope"
|
||||
@@ -178,24 +177,29 @@ class ProjectInspectionProfileManagerImpl(val project: Project,
|
||||
}
|
||||
|
||||
@Synchronized override fun loadState(state: Element) {
|
||||
try {
|
||||
severityRegistrar.readExternal(state)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
LOG.error(e)
|
||||
val data = state.getChild("settings")
|
||||
|
||||
val newState = State()
|
||||
|
||||
data?.let {
|
||||
try {
|
||||
severityRegistrar.readExternal(it)
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
LOG.error(e)
|
||||
}
|
||||
|
||||
XmlSerializer.deserializeInto(newState, it)
|
||||
}
|
||||
|
||||
val profileKeys = THashSet<String>()
|
||||
profileKeys.addAll(schemeManager.allSchemeNames)
|
||||
val newState = State()
|
||||
XmlSerializer.deserializeInto(newState, state)
|
||||
this.state = newState
|
||||
if (state.getChild("version")?.getAttributeValue("value") != VERSION) {
|
||||
for (o in state.getChildren("option")) {
|
||||
|
||||
if (data != null && data.getChild("version")?.getAttributeValue("value") != VERSION) {
|
||||
for (o in data.getChildren("option")) {
|
||||
if (o.getAttributeValue("name") == "USE_PROJECT_LEVEL_SETTINGS") {
|
||||
if (o.getAttributeValue("value").toBoolean()) {
|
||||
if (newState.projectProfile != null) {
|
||||
currentProfile.convert(state, project)
|
||||
currentProfile.convert(data, project)
|
||||
}
|
||||
}
|
||||
break
|
||||
@@ -205,14 +209,20 @@ class ProjectInspectionProfileManagerImpl(val project: Project,
|
||||
}
|
||||
|
||||
@Synchronized override fun getState(): Element? {
|
||||
val result = Element("state")
|
||||
val result = Element("settings")
|
||||
XmlSerializer.serializeInto(this.state, result, skipDefaultsSerializationFilter)
|
||||
if (!result.children.isEmpty()) {
|
||||
result.addContent(Element("version").setAttribute("value", VERSION))
|
||||
}
|
||||
|
||||
severityRegistrar.writeExternal(result)
|
||||
return result
|
||||
if (JDOMUtil.isEmpty(result)) {
|
||||
result.name = "state"
|
||||
return result
|
||||
}
|
||||
else {
|
||||
return Element("state").addContent(result)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getScopesManager() = scopeManager
|
||||
|
||||
Reference in New Issue
Block a user