SDK Updater: Fix to allow install from directory URL (i.e. auto-guess the

repository.xml correctly.)

BUG 2039080

Also removed some misc Eclipse 3.5 warnings.
This commit is contained in:
Raphael
2009-08-06 12:51:22 -07:00
parent 531749469d
commit 26cdbb788a
4 changed files with 47 additions and 51 deletions

View File

@@ -174,7 +174,7 @@ public class AndroidVersion {
} else if (obj instanceof String) { } else if (obj instanceof String) {
// if we have a code name, this must match. // if we have a code name, this must match.
if (mCodename != null) { if (mCodename != null) {
return mCodename.equals((String)obj); return mCodename.equals(obj);
} }
// else we try to convert to a int and compare to the api level // else we try to convert to a int and compare to the api level

View File

@@ -23,6 +23,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.commons.compress.archivers.zip.ZipFile;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -572,6 +573,10 @@ public class Archive implements IDescription {
return true; return true;
} catch (FileNotFoundException e) {
// The FNF message is just the URL. Make it a bit more useful.
monitor.setResult("File not found: %1$s", e.getMessage());
} catch (Exception e) { } catch (Exception e) {
monitor.setResult(e.getMessage()); monitor.setResult(e.getMessage());
@@ -723,8 +728,7 @@ public class Archive implements IDescription {
byte[] buf = new byte[65536]; byte[] buf = new byte[65536];
Enumeration<ZipArchiveEntry> entries = Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
(Enumeration<ZipArchiveEntry>)zipFile.getEntries();
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement(); ZipArchiveEntry entry = entries.nextElement();

View File

@@ -332,7 +332,7 @@ public abstract class Package implements IDescription {
* current one, it's not an update. * current one, it's not an update.
* *
* @param replacementPackage The potential replacement package. * @param replacementPackage The potential replacement package.
* @return * @return One of the {@link UpdateInfo} values.
* *
* @see #sameItemAs(Package) * @see #sameItemAs(Package)
*/ */

View File

@@ -47,7 +47,7 @@ import javax.xml.validation.Validator;
*/ */
public class RepoSource implements IDescription { public class RepoSource implements IDescription {
private final String mUrl; private String mUrl;
private final boolean mUserSource; private final boolean mUserSource;
private Package[] mPackages; private Package[] mPackages;
@@ -132,55 +132,51 @@ public class RepoSource implements IDescription {
monitor.setDescription("Fetching %1$s", url); monitor.setDescription("Fetching %1$s", url);
monitor.incProgress(1); monitor.incProgress(1);
ByteArrayInputStream xml = null; mFetchError = null;
Exception[] exception = new Exception[] { null };
ByteArrayInputStream xml = fetchUrl(url, exception);
boolean validated = false;
if (xml != null) {
monitor.setDescription("Validate XML");
validated = validateXml(xml, url, monitor);
}
for (int tentative = 0; tentative < 2 && xml == null; tentative++) { // If we failed the first time and the URL doesn't explicitly end with
// our filename, make another tentative after changing the URL.
if (!validated && !url.endsWith(SdkRepository.URL_DEFAULT_XML_FILE)) {
if (!url.endsWith("/")) { //$NON-NLS-1$
url += "/"; //$NON-NLS-1$
}
url += SdkRepository.URL_DEFAULT_XML_FILE;
// reset fetch error and fetch xml = fetchUrl(url, exception);
mFetchError = null; if (xml != null) {
xml = fetchUrl(url, monitor); validated = validateXml(xml, url, monitor);
}
if (xml == null) { if (validated) {
mDescription += String.format("\nFailed to fetch URL %1$s", url); // If the second tentative succeeded, indicate it in the console
mFetchError = "Failed to fetch URL"; // with the URL that worked.
monitor.setResult("Failed to fetch URL %1$s", url); monitor.setResult("Repository found at %1$s", url);
} else {
// We got a document. It might not be XML or it might not be valid.
monitor.setDescription("Validate XML"); // Keep the modified URL
mUrl = url;
}
}
if (validateXml(xml, url, monitor)) { if (!validated) {
// We got a valid XML, keep it and use it. mFetchError = "Failed to fetch URL";
if (tentative > 0) { String reason = "Unknown";
// If the second tentative succeeded, indicate it in the console, if (exception[0] != null) {
// otherwise the user will only see the first failure if (exception[0] instanceof FileNotFoundException) {
// message and will think the whole thing failed. This also reason = "File not found";
// indicates we modifed the URL. } else if (exception[0].getMessage() != null) {
monitor.setResult("Repository found instead at %1$s", url); reason = exception[0].getMessage();
}
break;
} else {
mDescription += String.format("\nFailed to validate XML at %1$s", url);
mFetchError = "Failed to validate XML";
monitor.setResult("Failed to validate XML at %1$s", url);
// forget this XML, it wasn't any good.
xml = null;
} }
} }
// If we failed the first time and the URL doesn't explicitly end with monitor.setResult("Failed to fetch URL %1$s, reason:", url, reason);
// our filename, make another tentative. Otherwise abort.
if (tentative == 0 && !url.endsWith(SdkRepository.URL_DEFAULT_XML_FILE)) {
if (!url.endsWith("/")) { //$NON-NLS-1$
url += "/"; //$NON-NLS-1$
}
url += SdkRepository.URL_DEFAULT_XML_FILE;
} else {
break;
}
} }
monitor.incProgress(1); monitor.incProgress(1);
@@ -219,7 +215,7 @@ public class RepoSource implements IDescription {
* Java URL Reader: http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html * Java URL Reader: http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html
* Java set Proxy: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html * Java set Proxy: http://java.sun.com/docs/books/tutorial/networking/urls/_setProxy.html
*/ */
private ByteArrayInputStream fetchUrl(String urlString, ITaskMonitor monitor) { private ByteArrayInputStream fetchUrl(String urlString, Exception[] outException) {
URL url; URL url;
try { try {
url = new URL(urlString); url = new URL(urlString);
@@ -255,12 +251,8 @@ public class RepoSource implements IDescription {
} }
} }
} catch (FileNotFoundException e) {
// The FNF message is just the URL. Make it a bit more useful.
monitor.setResult("File not found: %1$s", e.getMessage());
} catch (IOException e) { } catch (IOException e) {
monitor.setResult(e.getMessage()); outException[0] = e;
} }
return null; return null;