SDK Updater: provide a "force http" setting.

Note that the setting operates on every source by converting
the https:// links into http:// before fetching the sources
or the archives.

This also reorganize some things: the RepoSourceAdapter now
takes the UpdaterData as parameter (so both Adapters work the
same) and the label/contentProviders are nested classes instead
of static classes. Cleanup some stuff that was no longer useful
such as the RepoSources.TaskFactory (it's in UpdaterData already).

With this change I can install from the dl site over http at home!
This commit is contained in:
Raphael
2009-06-11 21:45:07 -07:00
parent f3eed7385c
commit 18a6ab32be
9 changed files with 119 additions and 80 deletions

View File

@@ -24,10 +24,12 @@ import java.util.Properties;
*/
public interface ISettingsPage {
/** Java system setting picked up by {@link URL} for http proxy port */
public static final String JAVA_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
/** Java system setting picked up by {@link URL} for http proxy host */
public static final String JAVA_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
/** Java system setting picked up by {@link URL} for http proxy port. Type: String. */
public static final String KEY_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$
/** Java system setting picked up by {@link URL} for http proxy host. Type: String. */
public static final String KEY_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$
/** Setting to force using http:// instead of https:// connections. Type: Boolean. */
public static final String KEY_FORCE_HTTP = "sdkman.force.http"; //$NON-NLS-1$
/** Loads settings from the given {@link Properties} container and update the page UI. */
public abstract void loadSettings(Properties in_settings);

View File

@@ -25,7 +25,6 @@ import com.android.sdklib.internal.repository.ITaskMonitor;
import com.android.sdklib.internal.repository.Package;
import com.android.sdklib.internal.repository.PlatformPackage;
import com.android.sdklib.internal.repository.RepoSource;
import com.android.sdklib.internal.repository.RepoSources;
import com.android.sdklib.internal.repository.ToolPackage;
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
@@ -43,18 +42,10 @@ import org.eclipse.swt.graphics.Image;
*/
class RepoSourcesAdapter {
private final RepoSources mRepoSources;
private ImageFactory mImageFactory;
private final UpdaterData mUpdaterData;
public RepoSourcesAdapter(RepoSources repoSources) {
mRepoSources = repoSources;
}
/**
* Set the image factory used by the label provider.
*/
public void setImageFactory(ImageFactory imageFactory) {
mImageFactory = imageFactory;
public RepoSourcesAdapter(UpdaterData updaterData) {
mUpdaterData = updaterData;
}
public ILabelProvider getLabelProvider() {
@@ -74,30 +65,32 @@ class RepoSourcesAdapter {
@Override
public Image getImage(Object element) {
if (mImageFactory != null) {
ImageFactory imgFactory = mUpdaterData.getImageFactory();
if (imgFactory != null) {
if (element instanceof RepoSource) {
return mImageFactory.getImage("source_icon16.png");
return imgFactory.getImage("source_icon16.png");
} else if (element instanceof PlatformPackage) {
return mImageFactory.getImage("red_ball_icon16.png");
return imgFactory.getImage("red_ball_icon16.png");
} else if (element instanceof AddonPackage) {
return mImageFactory.getImage("green_ball_icon16.png");
return imgFactory.getImage("green_ball_icon16.png");
} else if (element instanceof ToolPackage) {
return mImageFactory.getImage("blue_ball_icon16.png");
return imgFactory.getImage("blue_ball_icon16.png");
} else if (element instanceof DocPackage) {
return mImageFactory.getImage("purple_ball_icon16.png");
return imgFactory.getImage("purple_ball_icon16.png");
} else if (element instanceof Package) {
return mImageFactory.getImage("gray_ball_icon16.png");
return imgFactory.getImage("gray_ball_icon16.png");
} else if (element instanceof Archive) {
if (((Archive) element).isCompatible()) {
return mImageFactory.getImage("archive_icon16.png");
return imgFactory.getImage("archive_icon16.png");
} else {
return mImageFactory.getImage("incompat_icon16.png");
return imgFactory.getImage("incompat_icon16.png");
}
}
}
@@ -117,9 +110,7 @@ class RepoSourcesAdapter {
// ------------
private static class TreeContentProvider implements ITreeContentProvider {
private RepoSourcesAdapter mInput;
private class TreeContentProvider implements ITreeContentProvider {
// Called when the viewer is disposed
public void dispose() {
@@ -128,9 +119,7 @@ class RepoSourcesAdapter {
// Called when the input is set or changed on the provider
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
assert newInput == null || newInput instanceof RepoSourcesAdapter;
mInput = (RepoSourcesAdapter) newInput;
// pass
assert newInput == RepoSourcesAdapter.this;
}
/**
@@ -151,8 +140,8 @@ class RepoSourcesAdapter {
* For a {@link Package}, returns an array of {@link Archive}s.
*/
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof RepoSourcesAdapter) {
return ((RepoSourcesAdapter) parentElement).mRepoSources.getSources().toArray();
if (parentElement == RepoSourcesAdapter.this) {
return mUpdaterData.getSources().getSources().toArray();
} else if (parentElement instanceof RepoSource) {
final RepoSource source = (RepoSource) parentElement;
@@ -160,9 +149,11 @@ class RepoSourcesAdapter {
if (packages == null) {
mInput.mRepoSources.getTaskFactory().start("Loading Source", new ITask() {
final boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp();
mUpdaterData.getTaskFactory().start("Loading Source", new ITask() {
public void run(ITaskMonitor monitor) {
source.load(monitor);
source.load(monitor, forceHttp);
}
});
@@ -186,7 +177,7 @@ class RepoSourcesAdapter {
public Object getParent(Object element) {
if (element instanceof RepoSource) {
return mInput;
return RepoSourcesAdapter.this;
} else if (element instanceof Package) {
return ((Package) element).getParentSource();

View File

@@ -39,6 +39,14 @@ public class SettingsController {
public SettingsController() {
}
//--- Access to settings ------------
public boolean getForceHttp() {
return Boolean.parseBoolean(mProperties.getProperty(ISettingsPage.KEY_FORCE_HTTP));
}
//--- Controller methods -------------
/**
* Associate the given {@link ISettingsPage} with this {@link SettingsController}.
*
@@ -133,10 +141,10 @@ public class SettingsController {
*/
public void applySettings() {
Properties props = System.getProperties();
props.put(ISettingsPage.JAVA_HTTP_PROXY_HOST,
mProperties.getProperty(ISettingsPage.JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
props.put(ISettingsPage.JAVA_HTTP_PROXY_PORT,
mProperties.getProperty(ISettingsPage.JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
props.setProperty(ISettingsPage.KEY_HTTP_PROXY_HOST,
mProperties.getProperty(ISettingsPage.KEY_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
props.setProperty(ISettingsPage.KEY_HTTP_PROXY_PORT,
mProperties.getProperty(ISettingsPage.KEY_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
}
}

View File

@@ -51,7 +51,7 @@ class UpdaterData {
private final RepoSources mSources = new RepoSources();
private final LocalSdkAdapter mLocalSdkAdapter = new LocalSdkAdapter(this);
private final RepoSourcesAdapter mSourcesAdapter = new RepoSourcesAdapter(mSources);
private final RepoSourcesAdapter mSourcesAdapter = new RepoSourcesAdapter(this);
private ImageFactory mImageFactory;
@@ -85,6 +85,10 @@ class UpdaterData {
mTaskFactory = taskFactory;
}
public ITaskFactory getTaskFactory() {
return mTaskFactory;
}
public void setUserCanChangeSdkRoot(boolean userCanChangeSdkRoot) {
mUserCanChangeSdkRoot = userCanChangeSdkRoot;
}
@@ -115,7 +119,6 @@ class UpdaterData {
public void setImageFactory(ImageFactory imageFactory) {
mImageFactory = imageFactory;
mSourcesAdapter.setImageFactory(imageFactory);
}
public ImageFactory getImageFactory() {
@@ -216,6 +219,8 @@ class UpdaterData {
throw new IllegalArgumentException("Task Factory is null");
}
final boolean forceHttp = getSettingsController().getForceHttp();
// TODO filter the archive list to: a/ display a list of what is going to be installed,
// b/ display licenses and c/ check that the selected packages are actually upgrades
// or ask user to confirm downgrades. All this should be done in a separate class+window
@@ -237,7 +242,7 @@ class UpdaterData {
break;
}
if (archive.install(mOsSdkRoot, monitor)) {
if (archive.install(mOsSdkRoot, forceHttp, monitor)) {
numInstalled++;
}
@@ -299,13 +304,15 @@ class UpdaterData {
public void refreshSources(final boolean forceFetching, ITaskMonitor monitor) {
assert mTaskFactory != null;
final boolean forceHttp = getSettingsController().getForceHttp();
ITask task = new ITask() {
public void run(ITaskMonitor monitor) {
ArrayList<RepoSource> sources = mSources.getSources();
monitor.setProgressMax(sources.size());
for (RepoSource source : sources) {
if (forceFetching || source.getPackages() != null) {
source.load(monitor.createSubMonitor(1));
source.load(monitor.createSubMonitor(1), forceHttp);
}
monitor.incProgress(1);

View File

@@ -302,8 +302,6 @@ public class UpdaterWindowImpl {
* Used to initialize the sources.
*/
private void setupSources() {
mUpdaterData.getSources().setTaskFactory(mTaskFactory);
mUpdaterData.getSources().add(
new RepoSource(SdkRepository.URL_GOOGLE_SDK_REPO_SITE, false /* addonOnly */));
@@ -315,7 +313,6 @@ public class UpdaterWindowImpl {
}
}
mRemotePackagesPage.onSdkChange();
}