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