IDEA-123615 (Proxy settings are not exported)

This commit is contained in:
Bas Leijdekkers
2014-04-10 11:50:01 +02:00
parent 36825935ed
commit efacd0106f
2 changed files with 38 additions and 12 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 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.
@@ -17,6 +17,7 @@ package com.intellij.util.net;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.options.ShowSettingsUtil;
@@ -40,6 +41,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.*;
@@ -55,10 +57,13 @@ import java.util.*;
@State(
name = "HttpConfigurable",
storages = {
@Storage( file = StoragePathMacros.APP_CONFIG + "/other.xml")
}
@Storage( file = StoragePathMacros.APP_CONFIG + "/other.xml" ),
@Storage( file = StoragePathMacros.APP_CONFIG + "/proxy.settings.xml" )
},
storageChooser = HttpConfigurable.StorageChooser.class
)
public class HttpConfigurable implements PersistentStateComponent<HttpConfigurable>, ApplicationComponent, JDOMExternalizable {
public class HttpConfigurable implements PersistentStateComponent<HttpConfigurable>, ApplicationComponent, JDOMExternalizable,
ExportableApplicationComponent {
private static final Logger LOG = Logger.getInstance("#com.intellij.util.net.HttpConfigurable");
public boolean PROXY_TYPE_IS_SOCKS = false;
public boolean USE_HTTP_PROXY = false;
@@ -329,7 +334,7 @@ public class HttpConfigurable implements PersistentStateComponent<HttpConfigurab
}
/**
* todo [all] It is NOT nessesary to call anything if you obey common IDEA proxy settings;
* todo [all] It is NOT necessary to call anything if you obey common IDEA proxy settings;
* todo if you want to define your own behaviour, refer to {@link com.intellij.util.proxy.CommonProxy}
*
* also, this method is useful in a way that it test connection to the host [through proxy]
@@ -478,6 +483,32 @@ public class HttpConfigurable implements PersistentStateComponent<HttpConfigurab
}
}
@NotNull
@Override
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("proxy.settings")};
}
@NotNull
@Override
public String getPresentableName() {
return "Proxy Settings";
}
public static class StorageChooser implements StateStorageChooser<HttpConfigurable> {
@Override
public Storage[] selectStorages(Storage[] storages, HttpConfigurable component, StateStorageOperation operation) {
if (operation == StateStorageOperation.WRITE) {
for (Storage storage : storages) {
if (storage.file().equals(StoragePathMacros.APP_CONFIG + "/proxy.settings.xml")) {
return new Storage[] {storage};
}
}
}
return storages;
}
}
public static class ProxyInfo {
public boolean myStore;
public String myUsername;
@@ -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.
@@ -21,7 +21,6 @@ import com.intellij.openapi.components.StorageId;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizable;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.util.xmlb.Accessor;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
@@ -93,11 +92,7 @@ class DefaultStateSerializer {
//assert mergeInto == null;
return (T)stateElement;
}
else if (JDOMExternalizable.class.isAssignableFrom(stateClass)) {
if (mergeInto != null) {
String elementText = JDOMUtil.writeElement(stateElement, "\n");
LOG.error("State is " + stateClass.getName() + ", merge into is " + mergeInto.toString() + ", state element text is " + elementText);
}
else if (JDOMExternalizable.class.isAssignableFrom(stateClass) && mergeInto == null) {
try {
final T t = stateClass.newInstance();
try {