SDK Manager: extra packages must respect min-tools-rev too.
SDK BUG 2040986 Change-Id: I2fb42327ff6d474fd8ad58fcd0725af3972ea026
This commit is contained in:
@@ -31,10 +31,9 @@ import java.util.Properties;
|
||||
/**
|
||||
* Represents a extra XML node in an SDK repository.
|
||||
*/
|
||||
public class ExtraPackage extends Package {
|
||||
public class ExtraPackage extends MinToolsPackage {
|
||||
|
||||
private static final String PROP_PATH = "Extra.Path"; //$NON-NLS-1$
|
||||
private static final String PROP_MIN_TOOLS_REV = "Extra.MinToolsRev"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The install folder name. It must be a single-segment path.
|
||||
@@ -44,18 +43,6 @@ public class ExtraPackage extends Package {
|
||||
*/
|
||||
private final String mPath;
|
||||
|
||||
/**
|
||||
* The minimal revision of the tools package required by this extra package, if > 0,
|
||||
* or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
|
||||
*/
|
||||
private final int mMinToolsRevision;
|
||||
|
||||
/**
|
||||
* The value of {@link #mMinToolsRevision} when the {@link SdkRepository#NODE_MIN_TOOLS_REV}
|
||||
* was not specified in the XML source.
|
||||
*/
|
||||
public static final int MIN_TOOLS_REV_NOT_SPECIFIED = 0;
|
||||
|
||||
/**
|
||||
* Creates a new tool package from the attributes and elements of the given XML node.
|
||||
* <p/>
|
||||
@@ -63,9 +50,8 @@ public class ExtraPackage extends Package {
|
||||
*/
|
||||
ExtraPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
|
||||
super(source, packageNode, licenses);
|
||||
|
||||
mPath = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_PATH);
|
||||
mMinToolsRevision = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_MIN_TOOLS_REV,
|
||||
MIN_TOOLS_REV_NOT_SPECIFIED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,11 +80,9 @@ public class ExtraPackage extends Package {
|
||||
archiveOs,
|
||||
archiveArch,
|
||||
archiveOsPath);
|
||||
|
||||
// The path argument comes before whatever could be in the properties
|
||||
mPath = path != null ? path : getProperty(props, PROP_PATH, path);
|
||||
|
||||
mMinToolsRevision = Integer.parseInt(getProperty(props, PROP_MIN_TOOLS_REV,
|
||||
Integer.toString(MIN_TOOLS_REV_NOT_SPECIFIED)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,8 +95,8 @@ public class ExtraPackage extends Package {
|
||||
|
||||
props.setProperty(PROP_PATH, mPath);
|
||||
|
||||
if (mMinToolsRevision != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
props.setProperty(PROP_MIN_TOOLS_REV, Integer.toString(mMinToolsRevision));
|
||||
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
props.setProperty(PROP_MIN_TOOLS_REV, Integer.toString(getMinToolsRevision()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,14 +123,6 @@ public class ExtraPackage extends Package {
|
||||
return mPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimal revision of the tools package required by this extra package, if > 0,
|
||||
* or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
|
||||
*/
|
||||
public int getMinToolsRevision() {
|
||||
return mMinToolsRevision;
|
||||
}
|
||||
|
||||
/** Returns a short description for an {@link IDescription}. */
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
@@ -176,8 +152,8 @@ public class ExtraPackage extends Package {
|
||||
name,
|
||||
getRevision());
|
||||
|
||||
if (mMinToolsRevision != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
s += String.format(" (tools rev: %1$d)", mMinToolsRevision);
|
||||
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
s += String.format(" (tools rev: %1$d)", getMinToolsRevision());
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -190,8 +166,8 @@ public class ExtraPackage extends Package {
|
||||
getPath(),
|
||||
getRevision());
|
||||
|
||||
if (mMinToolsRevision != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
s += String.format(" (min tools rev.: %1$d)", mMinToolsRevision);
|
||||
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
s += String.format(" (min tools rev.: %1$d)", getMinToolsRevision());
|
||||
}
|
||||
|
||||
s += ".";
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.sdklib.internal.repository;
|
||||
|
||||
import com.android.sdklib.internal.repository.Archive.Arch;
|
||||
import com.android.sdklib.internal.repository.Archive.Os;
|
||||
import com.android.sdklib.repository.SdkRepository;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Represents an XML node in an SDK repository that has a min-tools-rev requirement.
|
||||
* This is either a {@link PlatformPackage} or an {@link ExtraPackage}.
|
||||
*/
|
||||
public abstract class MinToolsPackage extends Package {
|
||||
|
||||
protected static final String PROP_MIN_TOOLS_REV = "Platform.MinToolsRev"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* The minimal revision of the tools package required by this extra package, if > 0,
|
||||
* or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
|
||||
*/
|
||||
private final int mMinToolsRevision;
|
||||
|
||||
/**
|
||||
* The value of {@link #mMinToolsRevision} when the {@link SdkRepository#NODE_MIN_TOOLS_REV}
|
||||
* was not specified in the XML source.
|
||||
*/
|
||||
public static final int MIN_TOOLS_REV_NOT_SPECIFIED = 0;
|
||||
|
||||
/**
|
||||
* Creates a new package from the attributes and elements of the given XML node.
|
||||
* <p/>
|
||||
* This constructor should throw an exception if the package cannot be created.
|
||||
*/
|
||||
MinToolsPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
|
||||
super(source, packageNode, licenses);
|
||||
|
||||
mMinToolsRevision = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_MIN_TOOLS_REV,
|
||||
MIN_TOOLS_REV_NOT_SPECIFIED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually create a new package with one archive and the given attributes.
|
||||
* This is used to create packages from local directories in which case there must be
|
||||
* one archive which URL is the actual target location.
|
||||
* <p/>
|
||||
* Properties from props are used first when possible, e.g. if props is non null.
|
||||
* <p/>
|
||||
* By design, this creates a package with one and only one archive.
|
||||
*/
|
||||
public MinToolsPackage(
|
||||
RepoSource source,
|
||||
Properties props,
|
||||
int revision,
|
||||
String license,
|
||||
String description,
|
||||
String descUrl,
|
||||
Os archiveOs,
|
||||
Arch archiveArch,
|
||||
String archiveOsPath) {
|
||||
super(source, props, revision, license, description, descUrl,
|
||||
archiveOs, archiveArch, archiveOsPath);
|
||||
|
||||
mMinToolsRevision = Integer.parseInt(getProperty(props, PROP_MIN_TOOLS_REV,
|
||||
Integer.toString(MIN_TOOLS_REV_NOT_SPECIFIED)));
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimal revision of the tools package required by this extra package, if > 0,
|
||||
* or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
|
||||
*/
|
||||
public int getMinToolsRevision() {
|
||||
return mMinToolsRevision;
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,9 @@ import java.util.Properties;
|
||||
/**
|
||||
* Represents a platform XML node in an SDK repository.
|
||||
*/
|
||||
public class PlatformPackage extends Package {
|
||||
public class PlatformPackage extends MinToolsPackage {
|
||||
|
||||
protected static final String PROP_VERSION = "Platform.Version"; //$NON-NLS-1$
|
||||
protected static final String PROP_MIN_TOOLS_REV = "Platform.MinToolsRev"; //$NON-NLS-1$
|
||||
|
||||
/** The package version, for platform, add-on and doc packages. */
|
||||
private final AndroidVersion mVersion;
|
||||
@@ -44,18 +43,6 @@ public class PlatformPackage extends Package {
|
||||
/** The version, a string, for platform packages. */
|
||||
private final String mVersionName;
|
||||
|
||||
/**
|
||||
* The minimal revision of the tools package required by this extra package, if > 0,
|
||||
* or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
|
||||
*/
|
||||
private final int mMinToolsRevision;
|
||||
|
||||
/**
|
||||
* The value of {@link #mMinToolsRevision} when the {@link SdkRepository#NODE_MIN_TOOLS_REV}
|
||||
* was not specified in the XML source.
|
||||
*/
|
||||
public static final int MIN_TOOLS_REV_NOT_SPECIFIED = 0;
|
||||
|
||||
/**
|
||||
* Creates a new platform package from the attributes and elements of the given XML node.
|
||||
* <p/>
|
||||
@@ -63,6 +50,7 @@ public class PlatformPackage extends Package {
|
||||
*/
|
||||
PlatformPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
|
||||
super(source, packageNode, licenses);
|
||||
|
||||
mVersionName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VERSION);
|
||||
int apiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
|
||||
String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_CODENAME);
|
||||
@@ -70,9 +58,6 @@ public class PlatformPackage extends Package {
|
||||
codeName = null;
|
||||
}
|
||||
mVersion = new AndroidVersion(apiLevel, codeName);
|
||||
|
||||
mMinToolsRevision = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_MIN_TOOLS_REV,
|
||||
MIN_TOOLS_REV_NOT_SPECIFIED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,9 +82,6 @@ public class PlatformPackage extends Package {
|
||||
|
||||
mVersion = target.getVersion();
|
||||
mVersionName = target.getVersionName();
|
||||
|
||||
mMinToolsRevision = Integer.parseInt(getProperty(props, PROP_MIN_TOOLS_REV,
|
||||
Integer.toString(MIN_TOOLS_REV_NOT_SPECIFIED)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,8 +98,8 @@ public class PlatformPackage extends Package {
|
||||
props.setProperty(PROP_VERSION, mVersionName);
|
||||
}
|
||||
|
||||
if (mMinToolsRevision != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
props.setProperty(PROP_MIN_TOOLS_REV, Integer.toString(mMinToolsRevision));
|
||||
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
props.setProperty(PROP_MIN_TOOLS_REV, Integer.toString(getMinToolsRevision()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,14 +113,6 @@ public class PlatformPackage extends Package {
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimal revision of the tools package required by this extra package, if > 0,
|
||||
* or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
|
||||
*/
|
||||
public int getMinToolsRevision() {
|
||||
return mMinToolsRevision;
|
||||
}
|
||||
|
||||
/** Returns a short description for an {@link IDescription}. */
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
@@ -152,8 +126,8 @@ public class PlatformPackage extends Package {
|
||||
mVersion.getApiLevel());
|
||||
}
|
||||
|
||||
if (mMinToolsRevision != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
s += String.format(" (tools rev: %1$d)", mMinToolsRevision);
|
||||
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
s += String.format(" (tools rev: %1$d)", getMinToolsRevision());
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
@@ -536,7 +536,7 @@ final class UpdateChooserDialog extends Dialog {
|
||||
// If there's no selection, just find the first missing dependency of any accepted
|
||||
// package.
|
||||
for (ArchiveInfo ai2 : mArchives) {
|
||||
if (ai2.isAccepted()) {
|
||||
if (ai2.isAccepted()) {
|
||||
ArchiveInfo adep = ai2.getDependsOn();
|
||||
if (adep != null && !adep.isAccepted()) {
|
||||
error = String.format("Package '%1$s' depends on '%2$s'",
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.sdkuilib.internal.repository;
|
||||
import com.android.sdklib.AndroidVersion;
|
||||
import com.android.sdklib.internal.repository.AddonPackage;
|
||||
import com.android.sdklib.internal.repository.Archive;
|
||||
import com.android.sdklib.internal.repository.MinToolsPackage;
|
||||
import com.android.sdklib.internal.repository.Package;
|
||||
import com.android.sdklib.internal.repository.PlatformPackage;
|
||||
import com.android.sdklib.internal.repository.RepoSource;
|
||||
@@ -142,34 +143,36 @@ class UpdaterLogic {
|
||||
if (pkg instanceof AddonPackage) {
|
||||
AddonPackage addon = (AddonPackage) pkg;
|
||||
|
||||
return findAddonDependency(
|
||||
return findPlatformDependency(
|
||||
addon, outArchives, selectedArchives, remotePkgs, localPkgs);
|
||||
|
||||
} else if (pkg instanceof PlatformPackage) {
|
||||
PlatformPackage platform = (PlatformPackage) pkg;
|
||||
} else if (pkg instanceof MinToolsPackage) {
|
||||
MinToolsPackage platformOrExtra = (MinToolsPackage) pkg;
|
||||
|
||||
return findPlatformDependency(
|
||||
platform, outArchives, selectedArchives, remotePkgs, localPkgs);
|
||||
return findToolsDependency(
|
||||
platformOrExtra, outArchives, selectedArchives, remotePkgs, localPkgs);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A platform can have a min-tools-rev, in which case it depends on having a tools package
|
||||
* of the requested revision.
|
||||
* Resolves dependencies on tools.
|
||||
*
|
||||
* A platform or an extra package can both have a min-tools-rev, in which case it
|
||||
* depends on having a tools package of the requested revision.
|
||||
* Finds the tools dependency. If found, add it to the list of things to install.
|
||||
* Returns the archive info dependency, if any.
|
||||
*/
|
||||
protected ArchiveInfo findPlatformDependency(PlatformPackage platform,
|
||||
protected ArchiveInfo findToolsDependency(MinToolsPackage platformOrExtra,
|
||||
ArrayList<ArchiveInfo> outArchives,
|
||||
Collection<Archive> selectedArchives,
|
||||
ArrayList<Package> remotePkgs,
|
||||
Package[] localPkgs) {
|
||||
// This is the requirement to match.
|
||||
int rev = platform.getMinToolsRevision();
|
||||
int rev = platformOrExtra.getMinToolsRevision();
|
||||
|
||||
if (rev == PlatformPackage.MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
if (rev == MinToolsPackage.MIN_TOOLS_REV_NOT_SPECIFIED) {
|
||||
// Well actually there's no requirement.
|
||||
return null;
|
||||
}
|
||||
@@ -234,11 +237,13 @@ class UpdaterLogic {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves dependencies on platform.
|
||||
*
|
||||
* An addon depends on having a platform with the same API version.
|
||||
* Finds the platform dependency. If found, add it to the list of things to install.
|
||||
* Returns the archive info dependency, if any.
|
||||
*/
|
||||
protected ArchiveInfo findAddonDependency(AddonPackage addon,
|
||||
protected ArchiveInfo findPlatformDependency(AddonPackage addon,
|
||||
ArrayList<ArchiveInfo> outArchives,
|
||||
Collection<Archive> selectedArchives,
|
||||
ArrayList<Package> remotePkgs,
|
||||
|
||||
@@ -59,13 +59,13 @@ public class UpdaterLogicTest extends TestCase {
|
||||
|
||||
// a2 depends on p2, which is not in the locals
|
||||
Package[] locals = { p1, a1 };
|
||||
assertNull(mul.findAddonDependency(a2, out, selected, remote, locals));
|
||||
assertNull(mul.findPlatformDependency(a2, out, selected, remote, locals));
|
||||
assertEquals(0, out.size());
|
||||
|
||||
// p2 is now selected, and should be scheduled for install in out
|
||||
Archive p2_archive = p2.getArchives()[0];
|
||||
selected.add(p2_archive);
|
||||
ArchiveInfo ai2 = mul.findAddonDependency(a2, out, selected, remote, locals);
|
||||
ArchiveInfo ai2 = mul.findPlatformDependency(a2, out, selected, remote, locals);
|
||||
assertNotNull(ai2);
|
||||
assertSame(p2_archive, ai2.getNewArchive());
|
||||
assertEquals(1, out.size());
|
||||
@@ -86,13 +86,13 @@ public class UpdaterLogicTest extends TestCase {
|
||||
|
||||
// p2 depends on t2, which is not locally installed
|
||||
Package[] locals = { t1 };
|
||||
assertNull(mul.findPlatformDependency(p2, out, selected, remote, locals));
|
||||
assertNull(mul.findToolsDependency(p2, out, selected, remote, locals));
|
||||
assertEquals(0, out.size());
|
||||
|
||||
// t2 is now selected and can be used as a dependency
|
||||
Archive t2_archive = t2.getArchives()[0];
|
||||
selected.add(t2_archive);
|
||||
ArchiveInfo ai2 = mul.findPlatformDependency(p2, out, selected, remote, locals);
|
||||
ArchiveInfo ai2 = mul.findToolsDependency(p2, out, selected, remote, locals);
|
||||
assertNotNull(ai2);
|
||||
assertSame(t2_archive, ai2.getNewArchive());
|
||||
assertEquals(1, out.size());
|
||||
|
||||
Reference in New Issue
Block a user