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) {
|
} 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
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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;
|
|
||||||
|
|
||||||
for (int tentative = 0; tentative < 2 && xml == null; tentative++) {
|
|
||||||
|
|
||||||
// reset fetch error and fetch
|
|
||||||
mFetchError = null;
|
mFetchError = null;
|
||||||
xml = fetchUrl(url, monitor);
|
Exception[] exception = new Exception[] { null };
|
||||||
|
ByteArrayInputStream xml = fetchUrl(url, exception);
|
||||||
if (xml == null) {
|
boolean validated = false;
|
||||||
mDescription += String.format("\nFailed to fetch URL %1$s", url);
|
if (xml != null) {
|
||||||
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.
|
|
||||||
|
|
||||||
monitor.setDescription("Validate XML");
|
monitor.setDescription("Validate XML");
|
||||||
|
validated = validateXml(xml, url, monitor);
|
||||||
if (validateXml(xml, url, monitor)) {
|
|
||||||
// We got a valid XML, keep it and use it.
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we failed the first time and the URL doesn't explicitly end with
|
// If we failed the first time and the URL doesn't explicitly end with
|
||||||
// our filename, make another tentative. Otherwise abort.
|
// our filename, make another tentative after changing the URL.
|
||||||
if (tentative == 0 && !url.endsWith(SdkRepository.URL_DEFAULT_XML_FILE)) {
|
if (!validated && !url.endsWith(SdkRepository.URL_DEFAULT_XML_FILE)) {
|
||||||
if (!url.endsWith("/")) { //$NON-NLS-1$
|
if (!url.endsWith("/")) { //$NON-NLS-1$
|
||||||
url += "/"; //$NON-NLS-1$
|
url += "/"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
url += SdkRepository.URL_DEFAULT_XML_FILE;
|
url += SdkRepository.URL_DEFAULT_XML_FILE;
|
||||||
} else {
|
|
||||||
break;
|
xml = fetchUrl(url, exception);
|
||||||
|
if (xml != null) {
|
||||||
|
validated = validateXml(xml, url, monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Keep the modified URL
|
||||||
|
mUrl = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validated) {
|
||||||
|
mFetchError = "Failed to fetch URL";
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor.setResult("Failed to fetch URL %1$s, reason:", url, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user