Skip to content

Commit fcb53ba

Browse files
committed
Fixed user/pass preferences save for "manual" proxy settings.
There was an error in the following constants: PREF_PROXY_AUTO_USERNAME = "proxy.manual.username" PREF_PROXY_AUTO_PASSWORD = "proxy.manual.password" they should be set to "auto" and not "manual": PREF_PROXY_AUTO_USERNAME = "proxy.auto.username" PREF_PROXY_AUTO_PASSWORD = "proxy.auto.password" Changing the constants to the correct value now will fix the problem for future installations of the IDE but will produce an annoying side-effect for users upgrading from previous version of the IDE: they will lose their saved user and pass (because it was saved as "proxy.manual.*") and the IDE will suddenly stop working without any clear reason. To avoid this I've left the value to "proxy.manual.*" and removed the distinction from AUTO and MANUAL, so now we have only: PREF_PROXY_USERNAME = "proxy.manual.username" PREF_PROXY_PASSWORD = "proxy.manual.password" The corresponding textbox in the preference dialog will be filled based on the PROXY_TYPE selection.
1 parent b40f54a commit fcb53ba

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

app/src/cc/arduino/view/preferences/Preferences.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -840,10 +840,14 @@ private void savePreferencesData() {
840840
PreferencesData.set(Constants.PREF_PROXY_MANUAL_TYPE, manualProxyTypeButtonGroup.getSelection().getActionCommand());
841841
PreferencesData.set(Constants.PREF_PROXY_MANUAL_HOSTNAME, manualProxyHostName.getText());
842842
PreferencesData.set(Constants.PREF_PROXY_MANUAL_PORT, manualProxyPort.getText());
843-
PreferencesData.set(Constants.PREF_PROXY_MANUAL_USERNAME, manualProxyUsername.getText());
844-
PreferencesData.set(Constants.PREF_PROXY_MANUAL_PASSWORD, String.valueOf(manualProxyPassword.getPassword()));
845-
PreferencesData.set(Constants.PREF_PROXY_AUTO_USERNAME, autoProxyUsername.getText());
846-
PreferencesData.set(Constants.PREF_PROXY_AUTO_PASSWORD, String.valueOf(autoProxyPassword.getPassword()));
843+
if (PreferencesData.get(Constants.PREF_PROXY_TYPE).equals(Constants.PROXY_TYPE_MANUAL)) {
844+
PreferencesData.set(Constants.PREF_PROXY_USERNAME, manualProxyUsername.getText());
845+
PreferencesData.set(Constants.PREF_PROXY_PASSWORD, String.valueOf(manualProxyPassword.getPassword()));
846+
}
847+
if (PreferencesData.get(Constants.PREF_PROXY_TYPE).equals(Constants.PROXY_TYPE_AUTO)) {
848+
PreferencesData.set(Constants.PREF_PROXY_USERNAME, autoProxyUsername.getText());
849+
PreferencesData.set(Constants.PREF_PROXY_PASSWORD, String.valueOf(autoProxyPassword.getPassword()));
850+
}
847851
}
848852

849853
private void showPreferencesData() {
@@ -924,16 +928,16 @@ private void showPreferencesData() {
924928
if (!PreferencesData.get(Constants.PREF_PROXY_PAC_URL, "").isEmpty()) {
925929
autoProxyUsePAC.setSelected(true);
926930
autoProxyPACURL.setText(PreferencesData.get(Constants.PREF_PROXY_PAC_URL));
927-
autoProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_AUTO_USERNAME));
928-
autoProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_AUTO_PASSWORD));
931+
autoProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_USERNAME));
932+
autoProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_PASSWORD));
929933
}
930934
} else {
931935
manualProxy.setSelected(true);
932936
manualProxyFieldsSetEnabled(true);
933937
manualProxyHostName.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_HOSTNAME));
934938
manualProxyPort.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_PORT));
935-
manualProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_USERNAME));
936-
manualProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_MANUAL_PASSWORD));
939+
manualProxyUsername.setText(PreferencesData.get(Constants.PREF_PROXY_USERNAME));
940+
manualProxyPassword.setText(PreferencesData.get(Constants.PREF_PROXY_PASSWORD));
937941
}
938942

939943
String selectedManualProxyType = PreferencesData.get(Constants.PREF_PROXY_MANUAL_TYPE, Constants.PROXY_MANUAL_TYPE_HTTP);

app/test/cc/arduino/net/CustomProxySelectorTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public void testProxyPACHTTP() throws Exception {
8383
public void testProxyPACHTTPWithLogin() throws Exception {
8484
preferences.put(Constants.PREF_PROXY_TYPE, Constants.PROXY_TYPE_AUTO);
8585
preferences.put(Constants.PREF_PROXY_PAC_URL, CustomProxySelectorTest.class.getResource("proxy_http.pac").toExternalForm());
86-
preferences.put(Constants.PREF_PROXY_AUTO_USERNAME, "auto");
87-
preferences.put(Constants.PREF_PROXY_AUTO_PASSWORD, "autopassword");
86+
preferences.put(Constants.PREF_PROXY_USERNAME, "auto");
87+
preferences.put(Constants.PREF_PROXY_PASSWORD, "autopassword");
8888
CustomProxySelector proxySelector = new CustomProxySelector(preferences);
8989
Proxy proxy = proxySelector.getProxyFor(uri);
9090

@@ -154,8 +154,8 @@ public void testManualProxyWithLogin() throws Exception {
154154
preferences.put(Constants.PREF_PROXY_MANUAL_TYPE, Constants.PROXY_MANUAL_TYPE_HTTP);
155155
preferences.put(Constants.PREF_PROXY_MANUAL_HOSTNAME, "localhost");
156156
preferences.put(Constants.PREF_PROXY_MANUAL_PORT, "8080");
157-
preferences.put(Constants.PREF_PROXY_MANUAL_USERNAME, "username");
158-
preferences.put(Constants.PREF_PROXY_MANUAL_PASSWORD, "pwd");
157+
preferences.put(Constants.PREF_PROXY_USERNAME, "username");
158+
preferences.put(Constants.PREF_PROXY_PASSWORD, "pwd");
159159

160160
CustomProxySelector proxySelector = new CustomProxySelector(preferences);
161161
Proxy proxy = proxySelector.getProxyFor(uri);

arduino-core/src/cc/arduino/Constants.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ public class Constants {
5858
public static final String PREF_PROXY_PAC_URL = "proxy.pac.url";
5959
public static final String PREF_PROXY_MANUAL_HOSTNAME = "proxy.manual.hostname";
6060
public static final String PREF_PROXY_MANUAL_PORT = "proxy.manual.port";
61-
public static final String PREF_PROXY_MANUAL_USERNAME = "proxy.manual.username";
62-
public static final String PREF_PROXY_MANUAL_PASSWORD = "proxy.manual.password";
63-
public static final String PREF_PROXY_AUTO_USERNAME = "proxy.manual.username";
64-
public static final String PREF_PROXY_AUTO_PASSWORD = "proxy.manual.password";
61+
public static final String PREF_PROXY_USERNAME = "proxy.manual.username";
62+
public static final String PREF_PROXY_PASSWORD = "proxy.manual.password";
6563

6664
public static final String PACKAGE_INDEX_URL;
6765
public static final String LIBRARY_INDEX_URL;

arduino-core/src/cc/arduino/net/CustomProxySelector.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Proxy getProxyFor(URI uri) throws IOException, ScriptException, NoSuchMet
7575
}
7676

7777
private Proxy pacProxy(String pac, URI uri) throws IOException, ScriptException, NoSuchMethodException {
78-
setAuthenticator(preferences.get(Constants.PREF_PROXY_AUTO_USERNAME), preferences.get(Constants.PREF_PROXY_AUTO_PASSWORD));
78+
setAuthenticator(preferences.get(Constants.PREF_PROXY_USERNAME), preferences.get(Constants.PREF_PROXY_PASSWORD));
7979

8080
URLConnection urlConnection = new URL(pac).openConnection();
8181
urlConnection.connect();
@@ -141,7 +141,7 @@ private URL toUrl(URI uri) {
141141
}
142142

143143
private Proxy manualProxy() {
144-
setAuthenticator(preferences.get(Constants.PREF_PROXY_MANUAL_USERNAME), preferences.get(Constants.PREF_PROXY_MANUAL_PASSWORD));
144+
setAuthenticator(preferences.get(Constants.PREF_PROXY_USERNAME), preferences.get(Constants.PREF_PROXY_PASSWORD));
145145
Proxy.Type type = Proxy.Type.valueOf(preferences.get(Constants.PREF_PROXY_MANUAL_TYPE));
146146
return new Proxy(type, new InetSocketAddress(preferences.get(Constants.PREF_PROXY_MANUAL_HOSTNAME), Integer.valueOf(preferences.get(Constants.PREF_PROXY_MANUAL_PORT))));
147147
}

0 commit comments

Comments
 (0)