SDK Updater: Better handling of fetch errors.

The remote page now shows fetch errors in the tree.
Using refresh tries to reload error sources.
This commit is contained in:
Raphael
2009-06-29 22:25:08 -07:00
parent fc614476e4
commit ee763d1307
5 changed files with 46 additions and 5 deletions

View File

@@ -51,6 +51,7 @@ public class RepoSource implements IDescription {
private Package[] mPackages; private Package[] mPackages;
private String mDescription; private String mDescription;
private String mFetchError;
/** /**
* Constructs a new source for the given repository URL. * Constructs a new source for the given repository URL.
@@ -96,6 +97,14 @@ public class RepoSource implements IDescription {
return mDescription == null ? "" : mDescription; //$NON-NLS-1$ return mDescription == null ? "" : mDescription; //$NON-NLS-1$
} }
/**
* Returns the last fetch error description.
* If there was no error, returns null.
*/
public String getFetchError() {
return mFetchError;
}
/** /**
* Tries to fetch the repository index for the given URL. * Tries to fetch the repository index for the given URL.
*/ */
@@ -104,6 +113,8 @@ public class RepoSource implements IDescription {
monitor.setProgressMax(4); monitor.setProgressMax(4);
setDefaultDescription(); setDefaultDescription();
mFetchError = null; // reset fetch error
String url = mUrl; String url = mUrl;
if (forceHttp) { if (forceHttp) {
@@ -117,6 +128,8 @@ public class RepoSource implements IDescription {
if (xml == null) { if (xml == null) {
mDescription += String.format("\nFailed to fetch URL %1$s", url); mDescription += String.format("\nFailed to fetch URL %1$s", url);
mFetchError = "Failed to fetch URL";
monitor.setResult("Failed to fetch URL %1$s", url);
return; return;
} }
@@ -125,6 +138,8 @@ public class RepoSource implements IDescription {
if (!validateXml(xml, monitor)) { if (!validateXml(xml, monitor)) {
mDescription += String.format("\nFailed to validate XML at %1$s", url); mDescription += String.format("\nFailed to validate XML at %1$s", url);
mFetchError = "Failed to validate XML";
monitor.setResult("\nFailed to validate XML at %1$s", url);
return; return;
} }

View File

@@ -36,10 +36,28 @@ import org.eclipse.swt.graphics.Image;
* *
* This implementation is UI dependent. * This implementation is UI dependent.
*/ */
class RepoSourcesAdapter { public class RepoSourcesAdapter {
private final UpdaterData mUpdaterData; private final UpdaterData mUpdaterData;
public static class RepoSourceError implements IDescription {
private final RepoSource mSource;
public RepoSourceError(RepoSource source) {
mSource = source;
}
public String getLongDescription() {
return mSource.getLongDescription();
}
public String getShortDescription() {
return mSource.getFetchError();
}
}
public RepoSourcesAdapter(UpdaterData updaterData) { public RepoSourcesAdapter(UpdaterData updaterData) {
mUpdaterData = updaterData; mUpdaterData = updaterData;
} }
@@ -55,7 +73,7 @@ class RepoSourcesAdapter {
// ------------ // ------------
public class ViewerLabelProvider extends LabelProvider { private class ViewerLabelProvider extends LabelProvider {
/** Returns an image appropriate for this element. */ /** Returns an image appropriate for this element. */
@Override @Override
@@ -119,8 +137,7 @@ class RepoSourcesAdapter {
final RepoSource source = (RepoSource) parentElement; final RepoSource source = (RepoSource) parentElement;
Package[] packages = source.getPackages(); Package[] packages = source.getPackages();
if (packages == null) { if (packages == null && source.getFetchError() == null) {
final boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp(); final boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp();
mUpdaterData.getTaskFactory().start("Loading Source", new ITask() { mUpdaterData.getTaskFactory().start("Loading Source", new ITask() {
@@ -133,6 +150,9 @@ class RepoSourcesAdapter {
} }
if (packages != null) { if (packages != null) {
return packages; return packages;
} else if (source.getFetchError() != null) {
// Return a dummy entry to display the fetch error
return new Object[] { new RepoSourceError(source) };
} }
} else if (parentElement instanceof Package) { } else if (parentElement instanceof Package) {

View File

@@ -359,7 +359,9 @@ class UpdaterData {
RepoSource[] sources = mSources.getSources(); RepoSource[] sources = mSources.getSources();
monitor.setProgressMax(sources.length); monitor.setProgressMax(sources.length);
for (RepoSource source : sources) { for (RepoSource source : sources) {
if (forceFetching || source.getPackages() != null) { if (forceFetching ||
source.getPackages() != null ||
source.getFetchError() != null) {
source.load(monitor.createSubMonitor(1), forceHttp); source.load(monitor.createSubMonitor(1), forceHttp);
} }
monitor.incProgress(1); monitor.incProgress(1);

View File

@@ -24,6 +24,7 @@ import com.android.sdklib.internal.repository.Package;
import com.android.sdklib.internal.repository.PlatformPackage; import com.android.sdklib.internal.repository.PlatformPackage;
import com.android.sdklib.internal.repository.RepoSource; import com.android.sdklib.internal.repository.RepoSource;
import com.android.sdklib.internal.repository.ToolPackage; import com.android.sdklib.internal.repository.ToolPackage;
import com.android.sdkuilib.internal.repository.RepoSourcesAdapter;
import org.eclipse.swt.SWTException; import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
@@ -92,6 +93,9 @@ public class ImageFactory {
if (object instanceof RepoSource) { if (object instanceof RepoSource) {
return getImageByName("source_icon16.png"); return getImageByName("source_icon16.png");
} else if (object instanceof RepoSourcesAdapter.RepoSourceError) {
return getImageByName("error_icon16.png");
} else if (object instanceof PlatformPackage) { } else if (object instanceof PlatformPackage) {
return getImageByName("android_icon_16.png"); return getImageByName("android_icon_16.png");

Binary file not shown.

After

Width:  |  Height:  |  Size: 626 B