/**\r
* Represents an add-on XML node in an SDK repository.\r
*/\r
-public class AddonPackage extends Package {\r
+public class AddonPackage extends Package implements IPackageVersion {\r
\r
private static final String PROP_NAME = "Addon.Name"; //$NON-NLS-1$\r
private static final String PROP_VENDOR = "Addon.Vendor"; //$NON-NLS-1$\r
s = getShortDescription();\r
}\r
\r
- s += String.format(".\nRequires SDK Platform Android API %1$s.",\r
+ if (s.indexOf("revision") == -1) {\r
+ s += String.format("\nRevision %1$d", getRevision());\r
+ }\r
+\r
+ s += String.format("\nRequires SDK Platform Android API %1$s",\r
mVersion.getApiString());\r
return s;\r
}\r
/**\r
* Represents a doc XML node in an SDK repository.\r
*/\r
-public class DocPackage extends Package {\r
+public class DocPackage extends Package implements IPackageVersion {\r
\r
private final AndroidVersion mVersion;\r
\r
s = getShortDescription();\r
}\r
\r
- if (!s.endsWith(".")) {\r
- s += ".";\r
+ if (s.indexOf("revision") == -1) {\r
+ s += String.format("\nRevision %1$d", getRevision());\r
}\r
\r
return s;\r
public String getLongDescription() {\r
String s = getDescription();\r
if (s == null || s.length() == 0) {\r
- s = String.format("Extra %1$s package, revision %2$d",\r
- getPath(),\r
- getRevision());\r
+ s = String.format("Extra %1$s package", getPath());\r
+ }\r
+\r
+ if (s.indexOf("revision") == -1) {\r
+ s += String.format("\nRevision %1$d", getRevision());\r
}\r
\r
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {\r
- s += String.format(".\nRequires tools revision %1$d.", getMinToolsRevision());\r
+ s += String.format("\nRequires tools revision %1$d", getMinToolsRevision());\r
}\r
\r
return 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.AndroidVersion;\r
+\r
+/**\r
+ * Interface for packages that provide an {@link AndroidVersion}.\r
+ */\r
+public interface IPackageVersion {\r
+\r
+ /**\r
+ * Returns the version, for platform, add-on and doc packages.\r
+ * Can be 0 if this is a local package of unknown api-level.\r
+ */\r
+ public abstract AndroidVersion getVersion();\r
+}\r
/**\r
* Represents a platform XML node in an SDK repository.\r
*/\r
-public class PlatformPackage extends MinToolsPackage {\r
+public class PlatformPackage extends MinToolsPackage implements IPackageVersion {\r
\r
protected static final String PROP_VERSION = "Platform.Version"; //$NON-NLS-1$\r
\r
s = getShortDescription();\r
}\r
\r
- if (!s.endsWith(".")) {\r
- s += ".";\r
+ if (s.indexOf("revision") == -1) {\r
+ s += String.format("\nRevision %1$d", getRevision());\r
}\r
\r
return s;\r
/** Returns a long description for an {@link IDescription}. */\r
@Override\r
public String getLongDescription() {\r
- return getShortDescription() + ".";\r
+ String s = getDescription();\r
+ if (s == null || s.length() == 0) {\r
+ s = getShortDescription();\r
+ }\r
+\r
+ if (s.indexOf("revision") == -1) {\r
+ s += String.format("\nRevision %1$d", getRevision());\r
+ }\r
+\r
+ return s;\r
}\r
\r
/**\r
}\r
\r
/**\r
- * Set to true if this new archive is a dependency for <em>another</em> one that we\r
- * want to install.\r
+ * Adds an {@link ArchiveInfo} for which <em>this</em> package is a dependency.\r
+ * This means the package added here depends on this package.\r
*/\r
public void addDependencyFor(ArchiveInfo dependencyFor) {\r
- mDependencyFor.add(dependencyFor);\r
+ if (!mDependencyFor.contains(dependencyFor)) {\r
+ mDependencyFor.add(dependencyFor);\r
+ }\r
}\r
\r
public Collection<ArchiveInfo> getDependenciesFor() {\r
\r
package com.android.sdkuilib.internal.repository;\r
\r
+import com.android.sdklib.AndroidVersion;\r
import com.android.sdklib.SdkConstants;\r
import com.android.sdklib.internal.repository.Archive;\r
+import com.android.sdklib.internal.repository.IPackageVersion;\r
+import com.android.sdklib.internal.repository.Package;\r
import com.android.sdkuilib.internal.repository.icons.ImageFactory;\r
\r
import org.eclipse.jface.viewers.ISelection;\r
return;\r
}\r
\r
- Archive anew = ai.getNewArchive();\r
+ Archive aNew = ai.getNewArchive();\r
+ Package pNew = aNew.getParentPackage();\r
\r
mPackageText.setText(""); //$NON-NLS-1$\r
\r
addSectionTitle("Package Description\n");\r
- addText(anew.getParentPackage().getLongDescription(), "\n\n"); //$NON-NLS-1$\r
+ addText(pNew.getLongDescription(), "\n\n"); //$NON-NLS-1$\r
\r
- Archive aold = ai.getReplaced();\r
- if (aold != null) {\r
- addText(String.format("This update will replace revision %1$s with revision %2$s.\n\n",\r
- aold.getParentPackage().getRevision(),\r
- anew.getParentPackage().getRevision()));\r
+ Archive aOld = ai.getReplaced();\r
+ if (aOld != null) {\r
+ Package pOld = aOld.getParentPackage();\r
+\r
+ int rOld = pOld.getRevision();\r
+ int rNew = pNew.getRevision();\r
+\r
+ boolean showRev = true;\r
+\r
+ if (pNew instanceof IPackageVersion && pOld instanceof IPackageVersion) {\r
+ AndroidVersion vOld = ((IPackageVersion) pOld).getVersion();\r
+ AndroidVersion vNew = ((IPackageVersion) pNew).getVersion();\r
+\r
+ if (!vOld.equals(vNew)) {\r
+ // Versions are different, so indicate more than just the revision.\r
+ addText(String.format("This update will replace API %1$s revision %2$d with API %3$s revision %4$d.\n\n",\r
+ vOld.getApiString(), rOld,\r
+ vNew.getApiString(), rNew));\r
+ showRev = false;\r
+ }\r
+ }\r
+\r
+ if (showRev) {\r
+ addText(String.format("This update will replace revision %1$d with revision %2$d.\n\n",\r
+ rOld,\r
+ rNew));\r
+ }\r
}\r
\r
- ArchiveInfo adep = ai.getDependsOn();\r
- if (adep != null || ai.isDependencyFor()) {\r
+ ArchiveInfo aDep = ai.getDependsOn();\r
+ if (aDep != null || ai.isDependencyFor()) {\r
addSectionTitle("Dependencies\n");\r
\r
- if (adep != null) {\r
+ if (aDep != null) {\r
addText(String.format("This package depends on %1$s.\n\n",\r
- adep.getNewArchive().getParentPackage().getShortDescription()));\r
+ aDep.getNewArchive().getParentPackage().getShortDescription()));\r
}\r
\r
if (ai.isDependencyFor()) {\r
}\r
\r
addSectionTitle("Archive Description\n");\r
- addText(anew.getLongDescription(), "\n\n"); //$NON-NLS-1$\r
+ addText(aNew.getLongDescription(), "\n\n"); //$NON-NLS-1$\r
\r
- String license = anew.getParentPackage().getLicense();\r
+ String license = pNew.getLicense();\r
if (license != null) {\r
addSectionTitle("License\n");\r
addText(license.trim(), "\n"); //$NON-NLS-1$\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.DocPackage;\r
import com.android.sdklib.internal.repository.ExtraPackage;\r
+import com.android.sdklib.internal.repository.IPackageVersion;\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
public void addNewPlatforms(ArrayList<ArchiveInfo> archives,\r
RepoSources sources,\r
Package[] localPkgs) {\r
+\r
// Find the highest platform installed\r
float currentPlatformScore = 0;\r
float currentAddonScore = 0;\r
+ float currentDocScore = 0;\r
HashMap<String, Float> currentExtraScore = new HashMap<String, Float>();\r
for (Package p : localPkgs) {\r
int rev = p.getRevision();\r
int api = 0;\r
boolean isPreview = false;\r
- if (p instanceof PlatformPackage) {\r
- AndroidVersion vers = ((PlatformPackage) p).getVersion();\r
- api = vers.getApiLevel();\r
- isPreview = vers.isPreview();\r
- } else if (p instanceof AddonPackage) {\r
- AndroidVersion vers = ((AddonPackage) p).getVersion();\r
+ if (p instanceof IPackageVersion) {\r
+ AndroidVersion vers = ((IPackageVersion) p).getVersion();\r
api = vers.getApiLevel();\r
isPreview = vers.isPreview();\r
- } else if (!(p instanceof ExtraPackage)) {\r
- continue;\r
}\r
\r
// The score is 10*api + (1 if preview) + rev/100\r
currentAddonScore = Math.max(currentAddonScore, score);\r
} else if (p instanceof ExtraPackage) {\r
currentExtraScore.put(((ExtraPackage) p).getPath(), score);\r
+ } else if (p instanceof DocPackage) {\r
+ currentDocScore = Math.max(currentDocScore, score);\r
}\r
}\r
\r
ArrayList<Package> remotePkgs = new ArrayList<Package>();\r
fetchRemotePackages(remotePkgs, remoteSources);\r
\r
+ Package suggestedDoc = null;\r
+\r
for (Package p : remotePkgs) {\r
int rev = p.getRevision();\r
int api = 0;\r
boolean isPreview = false;\r
- if (p instanceof PlatformPackage) {\r
- AndroidVersion vers = ((PlatformPackage) p).getVersion();\r
- api = vers.getApiLevel();\r
- isPreview = vers.isPreview();\r
- } else if (p instanceof AddonPackage) {\r
- AndroidVersion vers = ((AddonPackage) p).getVersion();\r
+ if (p instanceof IPackageVersion) {\r
+ AndroidVersion vers = ((IPackageVersion) p).getVersion();\r
api = vers.getApiLevel();\r
isPreview = vers.isPreview();\r
- } else if (!(p instanceof ExtraPackage)) {\r
- continue;\r
}\r
\r
float score = api * 10 + (isPreview ? 1 : 0) + rev/100.f;\r
String key = ((ExtraPackage) p).getPath();\r
shouldAdd = !currentExtraScore.containsKey(key) ||\r
score > currentExtraScore.get(key).floatValue();\r
+ } else if (p instanceof DocPackage) {\r
+ // We don't want all the doc, only the most recent one\r
+ if (score > currentDocScore) {\r
+ suggestedDoc = p;\r
+ currentDocScore = score;\r
+ }\r
}\r
\r
if (shouldAdd) {\r
}\r
}\r
}\r
+\r
+ if (suggestedDoc != null) {\r
+ // We should suggest this package for installation.\r
+ for (Archive a : suggestedDoc.getArchives()) {\r
+ if (a.isCompatible()) {\r
+ insertArchive(a,\r
+ archives,\r
+ null /*selectedArchives*/,\r
+ remotePkgs,\r
+ remoteSources,\r
+ localPkgs,\r
+ true /*automated*/);\r
+ }\r
+ }\r
+ }\r
+\r
}\r
\r
/**\r
// Look in archives already scheduled for install\r
for (ArchiveInfo ai : outArchives) {\r
Package p = ai.getNewArchive().getParentPackage();\r
- if (p instanceof PlatformPackage) {\r
+ if (p instanceof ToolPackage) {\r
if (((ToolPackage) p).getRevision() >= rev) {\r
// The dependency is already scheduled for install, nothing else to do.\r
return ai;\r