mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
AppletConfiguration — don't save defaults (initial, not all default values are skipped)
This commit is contained in:
+16
-2
@@ -17,11 +17,15 @@ package com.intellij.debugger.impl;
|
||||
|
||||
import com.intellij.debugger.settings.DebuggerSettings;
|
||||
import com.intellij.execution.configurations.DebuggingRunnerData;
|
||||
import com.intellij.execution.configurations.RunnerSettingsEx;
|
||||
import com.intellij.execution.configurations.RunnerSettings;
|
||||
import com.intellij.util.xmlb.SmartSerializer;
|
||||
import com.intellij.util.xmlb.annotations.OptionTag;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jdom.Element;
|
||||
|
||||
public class GenericDebuggerRunnerSettings implements DebuggingRunnerData, RunnerSettings {
|
||||
private final SmartSerializer mySerializer = new SmartSerializer();
|
||||
|
||||
public class GenericDebuggerRunnerSettings extends RunnerSettingsEx implements DebuggingRunnerData {
|
||||
@Transient
|
||||
@Deprecated
|
||||
public String DEBUG_PORT = "";
|
||||
@@ -60,4 +64,14 @@ public class GenericDebuggerRunnerSettings extends RunnerSettingsEx implements D
|
||||
public void setTransport(int transport) {
|
||||
TRANSPORT = transport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(Element element) {
|
||||
mySerializer.readExternal(this, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(Element element) {
|
||||
mySerializer.writeExternal(this, element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.intellij.openapi.options.SettingsEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.DefaultJDOMExternalizer;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -36,6 +35,8 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.util.xmlb.SmartSerializer;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -60,6 +61,7 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
private AppletParameter[] myAppletParameters;
|
||||
public boolean ALTERNATIVE_JRE_PATH_ENABLED;
|
||||
public String ALTERNATIVE_JRE_PATH;
|
||||
|
||||
@NonNls
|
||||
protected static final String NAME_ATTR = "name";
|
||||
@NonNls
|
||||
@@ -67,8 +69,12 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
@NonNls
|
||||
protected static final String PARAMETER_ELEMENT_NAME = "parameter";
|
||||
|
||||
public AppletConfiguration(final Project project, ConfigurationFactory factory) {
|
||||
private final SmartSerializer mySerializer;
|
||||
|
||||
public AppletConfiguration(@NotNull Project project, ConfigurationFactory factory) {
|
||||
super(new JavaRunConfigurationModule(project, false), factory);
|
||||
|
||||
mySerializer = new SmartSerializer(project.isDefault(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,14 +140,15 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPolicyFile(final String localPath) {
|
||||
POLICY_FILE = ExternalizablePath.urlValue(localPath);
|
||||
}
|
||||
|
||||
@Transient
|
||||
public String getPolicyFile() {
|
||||
return ExternalizablePath.localPathValue(POLICY_FILE);
|
||||
}
|
||||
|
||||
public void setPolicyFile(final String localPath) {
|
||||
POLICY_FILE = ExternalizablePath.urlValue(localPath);
|
||||
}
|
||||
|
||||
public static class AppletParameter {
|
||||
public String myName;
|
||||
public String myValue;
|
||||
@@ -185,7 +192,7 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
|
||||
@Override
|
||||
public void readExternal(final Element parentNode) throws InvalidDataException {
|
||||
DefaultJDOMExternalizer.readExternal(this, parentNode);
|
||||
mySerializer.readExternal(this, parentNode);
|
||||
readModule(parentNode);
|
||||
final ArrayList<AppletParameter> parameters = new ArrayList<AppletParameter>();
|
||||
for (final Element element : parentNode.getChildren(PARAMETER_ELEMENT_NAME)) {
|
||||
@@ -194,10 +201,15 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
myAppletParameters = parameters.toArray(new AppletParameter[parameters.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNewSerializationUsed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeExternal(final Element parentNode) throws WriteExternalException {
|
||||
writeModule(parentNode);
|
||||
DefaultJDOMExternalizer.writeExternal(this, parentNode);
|
||||
mySerializer.writeExternal(this, parentNode);
|
||||
if (myAppletParameters != null) {
|
||||
for (AppletParameter myAppletParameter : myAppletParameters) {
|
||||
final Element element = new Element(PARAMETER_ELEMENT_NAME);
|
||||
@@ -263,11 +275,12 @@ public class AppletConfiguration extends ModuleBasedConfiguration<JavaRunConfigu
|
||||
throw new RuntimeConfigurationWarning("URL " + HTML_FILE_NAME + " is not valid: " + ex.getLocalizedMessage());
|
||||
}
|
||||
|
||||
@Transient
|
||||
public AppletParameter[] getAppletParameters() {
|
||||
return myAppletParameters;
|
||||
}
|
||||
|
||||
public void setAppletParameters(final AppletParameter[] appletParameters) {
|
||||
public void setAppletParameters(AppletParameter[] appletParameters) {
|
||||
myAppletParameters = appletParameters;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ package com.intellij.execution.configurations;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -39,6 +40,7 @@ public abstract class LocatableConfigurationBase extends RunConfigurationBase im
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isGeneratedName() {
|
||||
return suggestedName() != null && myNameIsGenerated;
|
||||
}
|
||||
|
||||
+19
-5
@@ -24,6 +24,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Transient;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -100,6 +102,7 @@ public abstract class RunConfigurationBase extends UserDataHolderBase
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public final String getName() {
|
||||
return myName;
|
||||
}
|
||||
@@ -235,14 +238,22 @@ public abstract class RunConfigurationBase extends UserDataHolderBase
|
||||
if (myFileOutputPath != null || mySaveOutput) {
|
||||
element.addContent(fileOutputPathElement);
|
||||
}
|
||||
if (myShowConsoleOnStdOut) {//default value shouldn't be written
|
||||
element.setAttribute(SHOW_CONSOLE_ON_STD_OUT, String.valueOf(true));
|
||||
}
|
||||
if (myShowConsoleOnStdErr) {//default value shouldn't be written
|
||||
element.setAttribute(SHOW_CONSOLE_ON_STD_ERR, String.valueOf(true));
|
||||
|
||||
if (!isNewSerializationUsed()) {
|
||||
if (myShowConsoleOnStdOut) {//default value shouldn't be written
|
||||
element.setAttribute(SHOW_CONSOLE_ON_STD_OUT, String.valueOf(true));
|
||||
}
|
||||
if (myShowConsoleOnStdErr) {//default value shouldn't be written
|
||||
element.setAttribute(SHOW_CONSOLE_ON_STD_ERR, String.valueOf(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isNewSerializationUsed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public boolean isSaveOutputToFile() {
|
||||
return mySaveOutput;
|
||||
}
|
||||
@@ -251,6 +262,7 @@ public abstract class RunConfigurationBase extends UserDataHolderBase
|
||||
mySaveOutput = redirectOutput;
|
||||
}
|
||||
|
||||
@Attribute(SHOW_CONSOLE_ON_STD_OUT)
|
||||
public boolean isShowConsoleOnStdOut() {
|
||||
return myShowConsoleOnStdOut;
|
||||
}
|
||||
@@ -259,6 +271,7 @@ public abstract class RunConfigurationBase extends UserDataHolderBase
|
||||
myShowConsoleOnStdOut = showConsoleOnStdOut;
|
||||
}
|
||||
|
||||
@Attribute(SHOW_CONSOLE_ON_STD_ERR)
|
||||
public boolean isShowConsoleOnStdErr() {
|
||||
return myShowConsoleOnStdErr;
|
||||
}
|
||||
@@ -267,6 +280,7 @@ public abstract class RunConfigurationBase extends UserDataHolderBase
|
||||
myShowConsoleOnStdErr = showConsoleOnStdErr;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public String getOutputFilePath() {
|
||||
return myFileOutputPath;
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.intellij.execution.configurations;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class RunnerSettingsEx implements RunnerSettings {
|
||||
private final Set<String> mySerializedAccessorNameTracker = new THashSet<String>();
|
||||
private final SkipDefaultValuesSerializationFilters mySerializationFilter = new SkipDefaultValuesSerializationFilters() {
|
||||
@Override
|
||||
protected boolean accepts(@NotNull Accessor accessor, @NotNull Object bean, @Nullable Object beanValue) {
|
||||
if (mySerializedAccessorNameTracker.contains(accessor.getName())) {
|
||||
return true;
|
||||
}
|
||||
return super.accepts(accessor, bean, beanValue);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public final void readExternal(Element element) {
|
||||
mySerializedAccessorNameTracker.clear();
|
||||
XmlSerializer.deserializeInto(this, element, mySerializedAccessorNameTracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void writeExternal(Element element) {
|
||||
XmlSerializer.serializeInto(this, element, mySerializationFilter);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ public class SkipEmptySerializationFilter extends SerializationFilterBase {
|
||||
}
|
||||
|
||||
if (Boolean.FALSE.equals(beanValue) ||
|
||||
(beanValue instanceof String && ((String)beanValue).isEmpty()) ||
|
||||
(beanValue instanceof Map && ((Map)beanValue).isEmpty()) ||
|
||||
(beanValue instanceof Collection && ((Collection)beanValue).isEmpty())) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.util.xmlb;
|
||||
|
||||
import com.intellij.util.ThreeState;
|
||||
import gnu.trove.THashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public final class SmartSerializer {
|
||||
private final Set<String> mySerializedAccessorNameTracker;
|
||||
private final SerializationFilter mySerializationFilter;
|
||||
|
||||
public SmartSerializer(boolean trackSerializedNames, boolean useSkipEmptySerializationFilter) {
|
||||
mySerializedAccessorNameTracker = trackSerializedNames ? new THashSet<String>() : null;
|
||||
|
||||
mySerializationFilter = useSkipEmptySerializationFilter ?
|
||||
new SkipEmptySerializationFilter() {
|
||||
@Override
|
||||
protected ThreeState accepts(@NotNull String name, @NotNull Object beanValue) {
|
||||
return mySerializedAccessorNameTracker != null && mySerializedAccessorNameTracker.contains(name) ? ThreeState.YES : ThreeState.UNSURE;
|
||||
}
|
||||
} :
|
||||
new SkipDefaultValuesSerializationFilters() {
|
||||
@Override
|
||||
protected boolean accepts(@NotNull Accessor accessor, @NotNull Object bean, @Nullable Object beanValue) {
|
||||
if (mySerializedAccessorNameTracker != null && mySerializedAccessorNameTracker.contains(accessor.getName())) {
|
||||
return true;
|
||||
}
|
||||
return super.accepts(accessor, bean, beanValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public SmartSerializer() {
|
||||
this(true, false);
|
||||
}
|
||||
|
||||
public void readExternal(@NotNull Object bean, @NotNull Element element) {
|
||||
if (mySerializedAccessorNameTracker != null) {
|
||||
mySerializedAccessorNameTracker.clear();
|
||||
}
|
||||
XmlSerializer.deserializeInto(bean, element, mySerializedAccessorNameTracker);
|
||||
}
|
||||
|
||||
public void writeExternal(@NotNull Object bean, @NotNull Element element) {
|
||||
XmlSerializer.serializeInto(bean, element, mySerializationFilter);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user