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:
@@ -174,7 +174,7 @@ public class AndroidVersion {
|
||||
} else if (obj instanceof String) {
|
||||
// if we have a code name, this must match.
|
||||
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
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -572,6 +573,10 @@ public class Archive implements IDescription {
|
||||
|
||||
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) {
|
||||
monitor.setResult(e.getMessage());
|
||||
|
||||
@@ -723,8 +728,7 @@ public class Archive implements IDescription {
|
||||
|
||||
byte[] buf = new byte[65536];
|
||||
|
||||
Enumeration<ZipArchiveEntry> entries =
|
||||
(Enumeration<ZipArchiveEntry>)zipFile.getEntries();
|
||||
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipArchiveEntry entry = entries.nextElement();
|
||||
|
||||
|
||||
@@ -332,7 +332,7 @@ public abstract class Package implements IDescription {
|
||||
* current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return
|
||||
* @return One of the {@link UpdateInfo} values.
|
||||
*
|
||||
* @see #sameItemAs(Package)
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ import javax.xml.validation.Validator;
|
||||
*/
|
||||
public class RepoSource implements IDescription {
|
||||
|
||||
private final String mUrl;
|
||||
private String mUrl;
|
||||
private final boolean mUserSource;
|
||||
|
||||
private Package[] mPackages;
|
||||
@@ -132,55 +132,51 @@ public class RepoSource implements IDescription {
|
||||
monitor.setDescription("Fetching %1$s", url);
|
||||
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
|
||||
mFetchError = null;
|
||||
xml = fetchUrl(url, monitor);
|
||||
xml = fetchUrl(url, exception);
|
||||
if (xml != null) {
|
||||
validated = validateXml(xml, url, monitor);
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
// We got a document. It might not be XML or it might not be valid.
|
||||
if (validated) {
|
||||
// If the second tentative succeeded, indicate it in the console
|
||||
// with the URL that worked.
|
||||
monitor.setResult("Repository found at %1$s", url);
|
||||
|
||||
monitor.setDescription("Validate XML");
|
||||
// Keep the modified URL
|
||||
mUrl = url;
|
||||
}
|
||||
}
|
||||
|
||||
if (validateXml(xml, url, monitor)) {
|
||||
// We got a valid XML, keep it and use it.
|
||||
if (!validated) {
|
||||
mFetchError = "Failed to fetch URL";
|
||||
|
||||
if (tentative > 0) {
|
||||
// If the second tentative succeeded, indicate it in the console,
|
||||
// otherwise the user will only see the first failure
|
||||
// message and will think the whole thing failed. This also
|
||||
// indicates we modifed the URL.
|
||||
monitor.setResult("Repository found instead at %1$s", url);
|
||||
}
|
||||
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;
|
||||
String reason = "Unknown";
|
||||
if (exception[0] != null) {
|
||||
if (exception[0] instanceof FileNotFoundException) {
|
||||
reason = "File not found";
|
||||
} else if (exception[0].getMessage() != null) {
|
||||
reason = exception[0].getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// If we failed the first time and the URL doesn't explicitly end with
|
||||
// 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.setResult("Failed to fetch URL %1$s, reason:", url, reason);
|
||||
}
|
||||
|
||||
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 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;
|
||||
try {
|
||||
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) {
|
||||
monitor.setResult(e.getMessage());
|
||||
outException[0] = e;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user