Merge change 3691 into donut
* changes: SDK Updater: handle HTTP proxy settings, load & save.
This commit is contained in:
@@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
package com.android.sdkmanager.internal.repository;
|
package com.android.sdkmanager.internal.repository;
|
||||||
|
|
||||||
|
import com.android.prefs.AndroidLocation;
|
||||||
|
import com.android.prefs.AndroidLocation.AndroidLocationException;
|
||||||
|
import com.android.sdkuilib.internal.repository.ISettingsPage;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
@@ -24,6 +28,15 @@ import org.eclipse.swt.widgets.Composite;
|
|||||||
import org.eclipse.swt.widgets.Group;
|
import org.eclipse.swt.widgets.Group;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO list
|
* TODO list
|
||||||
@@ -31,7 +44,14 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
* - Actually use the settings.
|
* - Actually use the settings.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SettingsPage extends Composite {
|
public class SettingsPage extends Composite implements ISettingsPage {
|
||||||
|
|
||||||
|
private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/** Java system setting picked up by {@link URL} for http proxy port */
|
||||||
|
private static final String JAVA_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
|
||||||
|
/** Java system setting picked up by {@link URL} for http proxy host */
|
||||||
|
private static final String JAVA_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
|
||||||
|
|
||||||
private Group mProxySettingsGroup;
|
private Group mProxySettingsGroup;
|
||||||
private Group mPlaceholderGroup;
|
private Group mPlaceholderGroup;
|
||||||
@@ -79,8 +99,14 @@ public class SettingsPage extends Composite {
|
|||||||
mSomeMoreSettings.setText("Some more settings here");
|
mSomeMoreSettings.setText("Some more settings here");
|
||||||
|
|
||||||
mApplyButton = new Button(this, SWT.NONE);
|
mApplyButton = new Button(this, SWT.NONE);
|
||||||
|
mApplyButton.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void widgetSelected(SelectionEvent e) {
|
||||||
|
onApplySelected(); //$hide$
|
||||||
|
}
|
||||||
|
});
|
||||||
mApplyButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
mApplyButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
||||||
mApplyButton.setText("Apply");
|
mApplyButton.setText("Save && Apply");
|
||||||
|
|
||||||
postCreate(); //$hide$
|
postCreate(); //$hide$
|
||||||
}
|
}
|
||||||
@@ -104,6 +130,83 @@ public class SettingsPage extends Composite {
|
|||||||
private void postCreate() {
|
private void postCreate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onApplySelected() {
|
||||||
|
applySettings();
|
||||||
|
saveSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Java system properties for the HTTP proxy.
|
||||||
|
*/
|
||||||
|
public void applySettings() {
|
||||||
|
Properties props = System.getProperties();
|
||||||
|
props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
|
||||||
|
props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves settings.
|
||||||
|
*/
|
||||||
|
private void saveSettings() {
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText());
|
||||||
|
props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText());
|
||||||
|
|
||||||
|
FileWriter fw = null;
|
||||||
|
try {
|
||||||
|
String folder = AndroidLocation.getFolder();
|
||||||
|
File f = new File(folder, SETTINGS_FILENAME);
|
||||||
|
fw = new FileWriter(f);
|
||||||
|
|
||||||
|
props.store(fw, "## Settings for SdkManager"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
} catch (AndroidLocationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (fw != null) {
|
||||||
|
try {
|
||||||
|
fw.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load settings and puts them in the UI.
|
||||||
|
*/
|
||||||
|
public void loadSettings() {
|
||||||
|
FileReader fr = null;
|
||||||
|
try {
|
||||||
|
String folder = AndroidLocation.getFolder();
|
||||||
|
File f = new File(folder, SETTINGS_FILENAME);
|
||||||
|
if (f.exists()) {
|
||||||
|
fr = new FileReader(f);
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.load(fr);
|
||||||
|
|
||||||
|
mProxyServerText.setText(props.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
|
||||||
|
mProxyPortText.setText(props.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (AndroidLocationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (fr != null) {
|
||||||
|
try {
|
||||||
|
fr.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// End of hiding from SWT Designer
|
// End of hiding from SWT Designer
|
||||||
//$hide<<$
|
//$hide<<$
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* 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.android.sdkuilib.internal.repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface that a settings page must implement.
|
||||||
|
*/
|
||||||
|
public interface ISettingsPage {
|
||||||
|
|
||||||
|
/** Loads settings. Does not apply them. */
|
||||||
|
public abstract void loadSettings();
|
||||||
|
|
||||||
|
/** Applies current settings. */
|
||||||
|
public abstract void applySettings();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -23,7 +23,6 @@ import com.android.sdklib.internal.repository.Archive;
|
|||||||
import com.android.sdklib.internal.repository.ITask;
|
import com.android.sdklib.internal.repository.ITask;
|
||||||
import com.android.sdklib.internal.repository.ITaskMonitor;
|
import com.android.sdklib.internal.repository.ITaskMonitor;
|
||||||
import com.android.sdklib.internal.repository.RepoSource;
|
import com.android.sdklib.internal.repository.RepoSource;
|
||||||
import com.android.sdklib.internal.repository.RepoSources;
|
|
||||||
import com.android.sdklib.repository.SdkRepository;
|
import com.android.sdklib.repository.SdkRepository;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
@@ -227,6 +226,7 @@ public class UpdaterWindowImpl {
|
|||||||
// TODO read add-on sources from some file
|
// TODO read add-on sources from some file
|
||||||
setupSources();
|
setupSources();
|
||||||
scanLocalSdkFolders();
|
scanLocalSdkFolders();
|
||||||
|
initializeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- page switching ---
|
// --- page switching ---
|
||||||
@@ -334,6 +334,22 @@ public class UpdaterWindowImpl {
|
|||||||
mLocalPackagePage.setInput(mUpdaterData.getLocalSdkAdapter());
|
mLocalPackagePage.setInput(mUpdaterData.getLocalSdkAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes settings.
|
||||||
|
* Thist must be called after addExtraPages(), which created a settings page.
|
||||||
|
* Iterate through all the pages and it one is a setting page, load and apply these
|
||||||
|
* settings.
|
||||||
|
*/
|
||||||
|
private void initializeSettings() {
|
||||||
|
for (Object page : mPages) {
|
||||||
|
if (page instanceof ISettingsPage) {
|
||||||
|
ISettingsPage settingsPage = (ISettingsPage) page;
|
||||||
|
settingsPage.loadSettings();
|
||||||
|
settingsPage.applySettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install the list of given {@link Archive}s.
|
* Install the list of given {@link Archive}s.
|
||||||
* @param archives The archives to install. Incompatible ones will be skipped.
|
* @param archives The archives to install. Incompatible ones will be skipped.
|
||||||
|
|||||||
Reference in New Issue
Block a user