diff --git a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java index 498cfab09..b83ebc743 100755 --- a/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java +++ b/tools/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/RepoSource.java @@ -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; } diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSourcesAdapter.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSourcesAdapter.java index c22f4564f..18afd4211 100755 --- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSourcesAdapter.java +++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSourcesAdapter.java @@ -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) { diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java index 109000b02..62298d883 100755 --- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java +++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/UpdaterData.java @@ -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); diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java index d4c74d783..bd39c5e82 100755 --- a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java +++ b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/ImageFactory.java @@ -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"); diff --git a/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/error_icon16.png b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/error_icon16.png new file mode 100755 index 000000000..ccb4d0aa9 Binary files /dev/null and b/tools/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/icons/error_icon16.png differ