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:
@@ -51,6 +51,7 @@ public class RepoSource implements IDescription {
|
||||
|
||||
private Package[] mPackages;
|
||||
private String mDescription;
|
||||
private String mFetchError;
|
||||
|
||||
/**
|
||||
* 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$
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -104,6 +113,8 @@ public class RepoSource implements IDescription {
|
||||
monitor.setProgressMax(4);
|
||||
|
||||
setDefaultDescription();
|
||||
mFetchError = null; // reset fetch error
|
||||
|
||||
|
||||
String url = mUrl;
|
||||
if (forceHttp) {
|
||||
@@ -117,6 +128,8 @@ public class RepoSource implements IDescription {
|
||||
|
||||
if (xml == null) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -125,6 +138,8 @@ public class RepoSource implements IDescription {
|
||||
|
||||
if (!validateXml(xml, monitor)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,10 +36,28 @@ import org.eclipse.swt.graphics.Image;
|
||||
*
|
||||
* This implementation is UI dependent.
|
||||
*/
|
||||
class RepoSourcesAdapter {
|
||||
public class RepoSourcesAdapter {
|
||||
|
||||
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) {
|
||||
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. */
|
||||
@Override
|
||||
@@ -119,8 +137,7 @@ class RepoSourcesAdapter {
|
||||
final RepoSource source = (RepoSource) parentElement;
|
||||
Package[] packages = source.getPackages();
|
||||
|
||||
if (packages == null) {
|
||||
|
||||
if (packages == null && source.getFetchError() == null) {
|
||||
final boolean forceHttp = mUpdaterData.getSettingsController().getForceHttp();
|
||||
|
||||
mUpdaterData.getTaskFactory().start("Loading Source", new ITask() {
|
||||
@@ -133,6 +150,9 @@ class RepoSourcesAdapter {
|
||||
}
|
||||
if (packages != null) {
|
||||
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) {
|
||||
|
||||
@@ -359,7 +359,9 @@ class UpdaterData {
|
||||
RepoSource[] sources = mSources.getSources();
|
||||
monitor.setProgressMax(sources.length);
|
||||
for (RepoSource source : sources) {
|
||||
if (forceFetching || source.getPackages() != null) {
|
||||
if (forceFetching ||
|
||||
source.getPackages() != null ||
|
||||
source.getFetchError() != null) {
|
||||
source.load(monitor.createSubMonitor(1), forceHttp);
|
||||
}
|
||||
monitor.incProgress(1);
|
||||
|
||||
@@ -24,6 +24,7 @@ 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.ToolPackage;
|
||||
import com.android.sdkuilib.internal.repository.RepoSourcesAdapter;
|
||||
|
||||
import org.eclipse.swt.SWTException;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
@@ -92,6 +93,9 @@ public class ImageFactory {
|
||||
if (object instanceof RepoSource) {
|
||||
return getImageByName("source_icon16.png");
|
||||
|
||||
} else if (object instanceof RepoSourcesAdapter.RepoSourceError) {
|
||||
return getImageByName("error_icon16.png");
|
||||
|
||||
} else if (object instanceof PlatformPackage) {
|
||||
return getImageByName("android_icon_16.png");
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 626 B |
Reference in New Issue
Block a user