SDK Updater: Support local archives
- Change Archive to have a "isLocal" mode. - In local mode, Archive.getLocalOsPath gives the install folder. - In remote mode, Archive.getUrl gives the download URL. - Implement delete on local archive. - Started refreshing all sources. Need to revamp the progress dialog to share it accross methods first.
This commit is contained in:
@@ -76,7 +76,8 @@ public class AddonPackage extends Package {
|
||||
/**
|
||||
* Creates a new platform package based on an actual {@link IAndroidTarget} (which
|
||||
* {@link IAndroidTarget#isPlatform()} false) from the {@link SdkManager}.
|
||||
* This is used to list local SDK folders.
|
||||
* This is used to list local SDK folders in which case there is one archive which
|
||||
* URL is the actual target location.
|
||||
*/
|
||||
AddonPackage(IAndroidTarget target) {
|
||||
super( null, //source
|
||||
@@ -86,9 +87,7 @@ public class AddonPackage extends Package {
|
||||
null, //descUrl
|
||||
Os.getCurrentOs(), //archiveOs
|
||||
Arch.getCurrentArch(), //archiveArch
|
||||
"", //archiveUrl //$NON-NLS-1$
|
||||
0, //archiveSize
|
||||
null //archiveChecksum
|
||||
target.getLocation() //archiveOsPath
|
||||
);
|
||||
|
||||
mApiLevel = target.getApiVersionNumber();
|
||||
|
||||
@@ -154,17 +154,43 @@ public class Archive implements IDescription {
|
||||
private final String mChecksum;
|
||||
private final ChecksumType mChecksumType = ChecksumType.SHA1;
|
||||
private final Package mPackage;
|
||||
private final String mLocalOsPath;
|
||||
private final boolean mIsLocal;
|
||||
|
||||
/**
|
||||
* Creates a new archive.
|
||||
* Creates a new remote archive.
|
||||
*/
|
||||
Archive(Package pkg, Os os, Arch arch, String url, long size, String checksum) {
|
||||
mPackage = pkg;
|
||||
mOs = os;
|
||||
mArch = arch;
|
||||
mUrl = url;
|
||||
mLocalOsPath = null;
|
||||
mSize = size;
|
||||
mChecksum = checksum;
|
||||
mIsLocal = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new local archive.
|
||||
*/
|
||||
Archive(Package pkg, Os os, Arch arch, String localOsPath) {
|
||||
mPackage = pkg;
|
||||
mOs = os;
|
||||
mArch = arch;
|
||||
mUrl = null;
|
||||
mLocalOsPath = localOsPath;
|
||||
mSize = 0;
|
||||
mChecksum = "";
|
||||
mIsLocal = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a locally installed archive.
|
||||
* Returns false if this is a remote archive that needs to be downloaded.
|
||||
*/
|
||||
public boolean isLocal() {
|
||||
return mIsLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,12 +226,22 @@ public class Archive implements IDescription {
|
||||
|
||||
/**
|
||||
* Returns the download archive URL, either absolute or relative to the repository xml.
|
||||
* For a local installed folder, an URL is frabricated from the folder path.
|
||||
* Always return null for a local installed folder.
|
||||
* @see #getLocalOsPath()
|
||||
*/
|
||||
public String getUrl() {
|
||||
return mUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local OS folder where a local archive is installed.
|
||||
* Always return null for remote archives.
|
||||
* @see #getUrl()
|
||||
*/
|
||||
public String getLocalOsPath() {
|
||||
return mLocalOsPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the archive {@link Os} enum.
|
||||
* Can be null for a local installed folder on an unknown OS.
|
||||
@@ -290,6 +326,15 @@ public class Archive implements IDescription {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the archive folder if this is a local archive.
|
||||
*/
|
||||
public void deleteLocal() {
|
||||
if (isLocal()) {
|
||||
deleteFileOrFolder(new File(getLocalOsPath()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Install this {@link Archive}s.
|
||||
* The archive will be skipped if it is incompatible.
|
||||
@@ -302,7 +347,14 @@ public class Archive implements IDescription {
|
||||
try {
|
||||
String name = getParentPackage().getShortDescription();
|
||||
|
||||
// TODO: we should not see this test fail if we had the filter UI above.
|
||||
if (isLocal()) {
|
||||
// This should never happen.
|
||||
monitor.setResult("Skipping already installed archive: %1$s for %2$s",
|
||||
name,
|
||||
getOsDescription());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isCompatible()) {
|
||||
monitor.setResult("Skipping incompatible archive: %1$s for %2$s",
|
||||
name,
|
||||
|
||||
@@ -44,7 +44,8 @@ public class DocPackage extends Package {
|
||||
|
||||
/**
|
||||
* Manually create a new package with one archive and the given attributes.
|
||||
* This is used to create packages from local directories.
|
||||
* This is used to create packages from local directories in which case there must be
|
||||
* one archive which URL is the actual target location.
|
||||
*/
|
||||
DocPackage(RepoSource source,
|
||||
int apiLevel,
|
||||
@@ -54,9 +55,7 @@ public class DocPackage extends Package {
|
||||
String descUrl,
|
||||
Os archiveOs,
|
||||
Arch archiveArch,
|
||||
String archiveUrl,
|
||||
long archiveSize,
|
||||
String archiveChecksum) {
|
||||
String archiveOsPath) {
|
||||
super(source,
|
||||
revision,
|
||||
license,
|
||||
@@ -64,9 +63,7 @@ public class DocPackage extends Package {
|
||||
descUrl,
|
||||
archiveOs,
|
||||
archiveArch,
|
||||
archiveUrl,
|
||||
archiveSize,
|
||||
archiveChecksum);
|
||||
archiveOsPath);
|
||||
mApiLevel = apiLevel;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -60,7 +59,7 @@ public class LocalSdkParser {
|
||||
private Package[] mPackages;
|
||||
|
||||
public LocalSdkParser() {
|
||||
// TODO Auto-generated constructor stub
|
||||
// pass
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,9 +171,7 @@ public class LocalSdkParser {
|
||||
null, //descUrl
|
||||
Os.getCurrentOs(), //archiveOs
|
||||
Arch.getCurrentArch(), //archiveArch
|
||||
"", //archiveUrl //$NON-NLS-1$
|
||||
0, //archiveSize
|
||||
null //archiveChecksum
|
||||
toolFolder.getPath() //archiveOsPath
|
||||
);
|
||||
}
|
||||
|
||||
@@ -219,13 +216,6 @@ public class LocalSdkParser {
|
||||
// Create a pkg if we don't have one yet.
|
||||
|
||||
if (pkg == null) {
|
||||
String url = null;
|
||||
try {
|
||||
url = docFolder.toURI().toURL().toString();
|
||||
} catch (MalformedURLException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
pkg = new DocPackage(
|
||||
null, //source
|
||||
0, //apiLevel
|
||||
@@ -235,9 +225,7 @@ public class LocalSdkParser {
|
||||
null, //descUrl
|
||||
Os.getCurrentOs(), //archiveOs
|
||||
Arch.getCurrentArch(), //archiveArch
|
||||
url, //archiveUrl
|
||||
0, //archiveSize
|
||||
null //archiveChecksum
|
||||
docFolder.getPath() //archiveOsPath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ public abstract class Package implements IDescription {
|
||||
|
||||
/**
|
||||
* Manually create a new package with one archive and the given attributes.
|
||||
* This is used to create packages from local directories.
|
||||
* This is used to create packages from local directories in which case there must be
|
||||
* one archive which URL is the actual target location.
|
||||
*/
|
||||
public Package(RepoSource source,
|
||||
int revision,
|
||||
@@ -71,9 +72,7 @@ public abstract class Package implements IDescription {
|
||||
String descUrl,
|
||||
Os archiveOs,
|
||||
Arch archiveArch,
|
||||
String archiveUrl,
|
||||
long archiveSize,
|
||||
String archiveChecksum) {
|
||||
String archiveOsPath) {
|
||||
mSource = source;
|
||||
mRevision = revision;
|
||||
mLicense = license;
|
||||
@@ -83,9 +82,7 @@ public abstract class Package implements IDescription {
|
||||
mArchives[0] = new Archive(this,
|
||||
archiveOs,
|
||||
archiveArch,
|
||||
archiveUrl,
|
||||
archiveSize,
|
||||
archiveChecksum);
|
||||
archiveOsPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,7 +49,8 @@ public class PlatformPackage extends Package {
|
||||
/**
|
||||
* Creates a new platform package based on an actual {@link IAndroidTarget} (which
|
||||
* must have {@link IAndroidTarget#isPlatform()} true) from the {@link SdkManager}.
|
||||
* This is used to list local SDK folders.
|
||||
* This is used to list local SDK folders in which case there is one archive which
|
||||
* URL is the actual target location.
|
||||
*/
|
||||
PlatformPackage(IAndroidTarget target) {
|
||||
super( null, //source
|
||||
@@ -59,9 +60,7 @@ public class PlatformPackage extends Package {
|
||||
null, //descUrl
|
||||
Os.getCurrentOs(), //archiveOs
|
||||
Arch.getCurrentArch(), //archiveArch
|
||||
"", //archiveUrl //$NON-NLS-1$
|
||||
0, //archiveSize
|
||||
null //archiveChecksum
|
||||
target.getLocation() //archiveOsPath
|
||||
);
|
||||
|
||||
mApiLevel = target.getApiVersionNumber();
|
||||
|
||||
@@ -40,7 +40,8 @@ public class ToolPackage extends Package {
|
||||
|
||||
/**
|
||||
* Manually create a new package with one archive and the given attributes.
|
||||
* This is used to create packages from local directories.
|
||||
* This is used to create packages from local directories in which case there must be
|
||||
* one archive which URL is the actual target location.
|
||||
*/
|
||||
ToolPackage(RepoSource source,
|
||||
int revision,
|
||||
@@ -49,9 +50,7 @@ public class ToolPackage extends Package {
|
||||
String descUrl,
|
||||
Os archiveOs,
|
||||
Arch archiveArch,
|
||||
String archiveUrl,
|
||||
long archiveSize,
|
||||
String archiveChecksum) {
|
||||
String archiveOsPath) {
|
||||
super(source,
|
||||
revision,
|
||||
license,
|
||||
@@ -59,9 +58,7 @@ public class ToolPackage extends Package {
|
||||
descUrl,
|
||||
archiveOs,
|
||||
archiveArch,
|
||||
archiveUrl,
|
||||
archiveSize,
|
||||
archiveChecksum);
|
||||
archiveOsPath);
|
||||
}
|
||||
|
||||
/** Returns a short description for an {@link IDescription}. */
|
||||
|
||||
Reference in New Issue
Block a user