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

@@ -341,7 +341,7 @@ public class Archive implements IDescription {
*
* @return True if the archive was installed, false otherwise.
*/
public boolean install(String osSdkRoot, ITaskMonitor monitor) {
public boolean install(String osSdkRoot, boolean forceHttp, ITaskMonitor monitor) {
File archiveFile = null;
try {
@@ -362,7 +362,7 @@ public class Archive implements IDescription {
return false;
}
archiveFile = downloadFile(monitor);
archiveFile = downloadFile(monitor, forceHttp);
if (archiveFile != null) {
if (unarchive(osSdkRoot, archiveFile, monitor)) {
monitor.setResult("Installed: %1$s", name);
@@ -382,7 +382,7 @@ public class Archive implements IDescription {
* Downloads an archive and returns the temp file with it.
* Caller is responsible with deleting the temp file when done.
*/
private File downloadFile(ITaskMonitor monitor) {
private File downloadFile(ITaskMonitor monitor, boolean forceHttp) {
File tmpFileToDelete = null;
try {
@@ -414,6 +414,10 @@ public class Archive implements IDescription {
link = base + link;
}
if (forceHttp) {
link = link.replaceAll("https://", "http://"); //$NON-NLS-1$ //$NON-NLS-2$
}
if (fetchUrl(tmpFile, link, desc, monitor)) {
// Fetching was successful, don't delete the temp file here!
tmpFileToDelete = null;

View File

@@ -68,7 +68,7 @@ public class RepoSource implements IDescription {
}
/**
* Returns the list of known packages found by the last call to {@link #load(ITaskMonitor)}.
* Returns the list of known packages found by the last call to load().
* This is null when the source hasn't been loaded yet.
*/
public Package[] getPackages() {
@@ -77,7 +77,7 @@ public class RepoSource implements IDescription {
/**
* Clear the internal packages list. After this call, {@link #getPackages()} will return
* null till {@link #load(ITaskMonitor)} is called.
* null till load() is called.
*/
public void clearPackages() {
mPackages = null;
@@ -94,19 +94,24 @@ public class RepoSource implements IDescription {
/**
* Tries to fetch the repository index for the given URL.
*/
public void load(ITaskMonitor monitor) {
public void load(ITaskMonitor monitor, boolean forceHttp) {
monitor.setProgressMax(4);
setDefaultDescription();
monitor.setDescription("Fetching %1$s", mUrl);
String url = mUrl;
if (forceHttp) {
url = url.replaceAll("https://", "http://"); //$NON-NLS-1$ //$NON-NLS-2$
}
monitor.setDescription("Fetching %1$s", url);
monitor.incProgress(1);
String xml = fetchUrl(mUrl, monitor);
String xml = fetchUrl(url, monitor);
if (xml == null) {
mDescription += String.format("\nFailed to fetch URL %1$s", mUrl);
mDescription += String.format("\nFailed to fetch URL %1$s", url);
return;
}
@@ -114,7 +119,7 @@ public class RepoSource implements IDescription {
monitor.incProgress(1);
if (!validateXml(xml, monitor)) {
mDescription += String.format("\nFailed to validate XML at %1$s", mUrl);
mDescription += String.format("\nFailed to validate XML at %1$s", url);
return;
}

View File

@@ -24,19 +24,10 @@ import java.util.ArrayList;
public class RepoSources {
private ArrayList<RepoSource> mSources = new ArrayList<RepoSource>();
private ITaskFactory mTaskFactory;
public RepoSources() {
}
public void setTaskFactory(ITaskFactory taskFactory) {
mTaskFactory = taskFactory;
}
public ITaskFactory getTaskFactory() {
return mTaskFactory;
}
public void add(RepoSource source) {
mSources.add(source);
}