SDK Updater: properly update/install doc. (do not merge)

This contains the following changes:
- a new interface IPackageVersion for all Package classes that can
  provide an AndroidVersion getVersion().
- fixes the "update sdk" where the local repo has no doc by suggesting
  to install the most up-to-date doc.
- fixes a bad cast in the UpdaterLogic.
- normalizes the long descriptions but adding the revision if not
  present.
- fixes an edge case when displaying the very long description of the
  docs package, i.e. need to indicate it is upgraded due to a version
  change.

SDK BUG 2192352
This commit is contained in:
Raphael
2009-10-15 16:44:18 -07:00
committed by Xavier Ducrohet
parent af49663340
commit 5cff81bb58
9 changed files with 138 additions and 46 deletions

View File

@@ -35,7 +35,7 @@ import java.util.Properties;
/**
* Represents an add-on XML node in an SDK repository.
*/
public class AddonPackage extends Package {
public class AddonPackage extends Package implements IPackageVersion {
private static final String PROP_NAME = "Addon.Name"; //$NON-NLS-1$
private static final String PROP_VENDOR = "Addon.Vendor"; //$NON-NLS-1$
@@ -209,7 +209,11 @@ public class AddonPackage extends Package {
s = getShortDescription();
}
s += String.format(".\nRequires SDK Platform Android API %1$s.",
if (s.indexOf("revision") == -1) {
s += String.format("\nRevision %1$d", getRevision());
}
s += String.format("\nRequires SDK Platform Android API %1$s",
mVersion.getApiString());
return s;
}

View File

@@ -32,7 +32,7 @@ import java.util.Properties;
/**
* Represents a doc XML node in an SDK repository.
*/
public class DocPackage extends Package {
public class DocPackage extends Package implements IPackageVersion {
private final AndroidVersion mVersion;
@@ -126,8 +126,8 @@ public class DocPackage extends Package {
s = getShortDescription();
}
if (!s.endsWith(".")) {
s += ".";
if (s.indexOf("revision") == -1) {
s += String.format("\nRevision %1$d", getRevision());
}
return s;

View File

@@ -165,13 +165,15 @@ public class ExtraPackage extends MinToolsPackage {
public String getLongDescription() {
String s = getDescription();
if (s == null || s.length() == 0) {
s = String.format("Extra %1$s package, revision %2$d",
getPath(),
getRevision());
s = String.format("Extra %1$s package", getPath());
}
if (s.indexOf("revision") == -1) {
s += String.format("\nRevision %1$d", getRevision());
}
if (getMinToolsRevision() != MIN_TOOLS_REV_NOT_SPECIFIED) {
s += String.format(".\nRequires tools revision %1$d.", getMinToolsRevision());
s += String.format("\nRequires tools revision %1$d", getMinToolsRevision());
}
return s;

View File

@@ -0,0 +1,31 @@
/*
* 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.AndroidVersion;
/**
* Interface for packages that provide an {@link AndroidVersion}.
*/
public interface IPackageVersion {
/**
* Returns the version, for platform, add-on and doc packages.
* Can be 0 if this is a local package of unknown api-level.
*/
public abstract AndroidVersion getVersion();
}

View File

@@ -33,7 +33,7 @@ import java.util.Properties;
/**
* Represents a platform XML node in an SDK repository.
*/
public class PlatformPackage extends MinToolsPackage {
public class PlatformPackage extends MinToolsPackage implements IPackageVersion {
protected static final String PROP_VERSION = "Platform.Version"; //$NON-NLS-1$
@@ -145,8 +145,8 @@ public class PlatformPackage extends MinToolsPackage {
s = getShortDescription();
}
if (!s.endsWith(".")) {
s += ".";
if (s.indexOf("revision") == -1) {
s += String.format("\nRevision %1$d", getRevision());
}
return s;

View File

@@ -78,7 +78,16 @@ public class ToolPackage extends Package {
/** Returns a long description for an {@link IDescription}. */
@Override
public String getLongDescription() {
return getShortDescription() + ".";
String s = getDescription();
if (s == null || s.length() == 0) {
s = getShortDescription();
}
if (s.indexOf("revision") == -1) {
s += String.format("\nRevision %1$d", getRevision());
}
return s;
}
/**

View File

@@ -94,12 +94,14 @@ class ArchiveInfo {
}
/**
* Set to true if this new archive is a dependency for <em>another</em> one that we
* want to install.
* Adds an {@link ArchiveInfo} for which <em>this</em> package is a dependency.
* This means the package added here depends on this package.
*/
public void addDependencyFor(ArchiveInfo dependencyFor) {
if (!mDependencyFor.contains(dependencyFor)) {
mDependencyFor.add(dependencyFor);
}
}
public Collection<ArchiveInfo> getDependenciesFor() {
return mDependencyFor;

View File

@@ -16,8 +16,11 @@
package com.android.sdkuilib.internal.repository;
import com.android.sdklib.AndroidVersion;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.internal.repository.Archive;
import com.android.sdklib.internal.repository.IPackageVersion;
import com.android.sdklib.internal.repository.Package;
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
import org.eclipse.jface.viewers.ISelection;
@@ -457,27 +460,50 @@ final class UpdateChooserDialog extends Dialog {
mPackageText.setText("Please select a package.");
return;
}
Archive aNew = ai.getNewArchive();
Package pNew = aNew.getParentPackage();
mPackageText.setText(""); //$NON-NLS-1$
addSectionTitle("Package Description\n");
addSectionTitle("Package Description\n");
addText(pNew.getLongDescription(), "\n\n"); //$NON-NLS-1$
Archive aold = ai.getReplaced();
if (aold != null) {
addText(String.format("This update will replace revision %1$s with revision %2$s.\n\n",
aold.getParentPackage().getRevision(),
Archive aOld = ai.getReplaced();
if (aOld != null) {
Package pOld = aOld.getParentPackage();
int rOld = pOld.getRevision();
int rNew = pNew.getRevision();
boolean showRev = true;
if (pNew instanceof IPackageVersion && pOld instanceof IPackageVersion) {
AndroidVersion vOld = ((IPackageVersion) pOld).getVersion();
AndroidVersion vNew = ((IPackageVersion) pNew).getVersion();
if (!vOld.equals(vNew)) {
// Versions are different, so indicate more than just the revision.
addText(String.format("This update will replace API %1$s revision %2$d with API %3$s revision %4$d.\n\n",
vOld.getApiString(), rOld,
vNew.getApiString(), rNew));
showRev = false;
}
}
ArchiveInfo adep = ai.getDependsOn();
if (showRev) {
addText(String.format("This update will replace revision %1$d with revision %2$d.\n\n",
rOld,
rNew));
}
}
ArchiveInfo aDep = ai.getDependsOn();
if (aDep != null || ai.isDependencyFor()) {
addSectionTitle("Dependencies\n");
if (aDep != null) {
addText(String.format("This package depends on %1$s.\n\n",
addText(String.format("This package depends on %1$s.\n\n",
aDep.getNewArchive().getParentPackage().getShortDescription()));
}
@@ -491,9 +517,9 @@ final class UpdateChooserDialog extends Dialog {
}
}
addSectionTitle("Archive Description\n");
addSectionTitle("Archive Description\n");
addText(aNew.getLongDescription(), "\n\n"); //$NON-NLS-1$
String license = pNew.getLicense();
if (license != null) {
addSectionTitle("License\n");

View File

@@ -19,7 +19,9 @@ 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.DocPackage;
import com.android.sdklib.internal.repository.ExtraPackage;
import com.android.sdklib.internal.repository.IPackageVersion;
import com.android.sdklib.internal.repository.MinToolsPackage;
import com.android.sdklib.internal.repository.Package;
import com.android.sdklib.internal.repository.PlatformPackage;
@@ -81,24 +83,20 @@ class UpdaterLogic {
public void addNewPlatforms(ArrayList<ArchiveInfo> archives,
RepoSources sources,
Package[] localPkgs) {
// Find the highest platform installed
float currentPlatformScore = 0;
float currentAddonScore = 0;
float currentDocScore = 0;
HashMap<String, Float> currentExtraScore = new HashMap<String, Float>();
for (Package p : localPkgs) {
int rev = p.getRevision();
int api = 0;
boolean isPreview = false;
if (p instanceof PlatformPackage) {
AndroidVersion vers = ((PlatformPackage) p).getVersion();
if (p instanceof IPackageVersion) {
AndroidVersion vers = ((IPackageVersion) p).getVersion();
api = vers.getApiLevel();
isPreview = vers.isPreview();
} else if (p instanceof AddonPackage) {
AndroidVersion vers = ((AddonPackage) p).getVersion();
api = vers.getApiLevel();
isPreview = vers.isPreview();
} else if (!(p instanceof ExtraPackage)) {
continue;
}
// The score is 10*api + (1 if preview) + rev/100
@@ -112,6 +110,8 @@ class UpdaterLogic {
currentAddonScore = Math.max(currentAddonScore, score);
} else if (p instanceof ExtraPackage) {
currentExtraScore.put(((ExtraPackage) p).getPath(), score);
} else if (p instanceof DocPackage) {
currentDocScore = Math.max(currentDocScore, score);
}
}
@@ -119,20 +119,16 @@ class UpdaterLogic {
ArrayList<Package> remotePkgs = new ArrayList<Package>();
fetchRemotePackages(remotePkgs, remoteSources);
Package suggestedDoc = null;
for (Package p : remotePkgs) {
int rev = p.getRevision();
int api = 0;
boolean isPreview = false;
if (p instanceof PlatformPackage) {
AndroidVersion vers = ((PlatformPackage) p).getVersion();
if (p instanceof IPackageVersion) {
AndroidVersion vers = ((IPackageVersion) p).getVersion();
api = vers.getApiLevel();
isPreview = vers.isPreview();
} else if (p instanceof AddonPackage) {
AndroidVersion vers = ((AddonPackage) p).getVersion();
api = vers.getApiLevel();
isPreview = vers.isPreview();
} else if (!(p instanceof ExtraPackage)) {
continue;
}
float score = api * 10 + (isPreview ? 1 : 0) + rev/100.f;
@@ -146,6 +142,12 @@ class UpdaterLogic {
String key = ((ExtraPackage) p).getPath();
shouldAdd = !currentExtraScore.containsKey(key) ||
score > currentExtraScore.get(key).floatValue();
} else if (p instanceof DocPackage) {
// We don't want all the doc, only the most recent one
if (score > currentDocScore) {
suggestedDoc = p;
currentDocScore = score;
}
}
if (shouldAdd) {
@@ -163,6 +165,22 @@ class UpdaterLogic {
}
}
}
if (suggestedDoc != null) {
// We should suggest this package for installation.
for (Archive a : suggestedDoc.getArchives()) {
if (a.isCompatible()) {
insertArchive(a,
archives,
null /*selectedArchives*/,
remotePkgs,
remoteSources,
localPkgs,
true /*automated*/);
}
}
}
}
/**
@@ -319,7 +337,7 @@ class UpdaterLogic {
// Look in archives already scheduled for install
for (ArchiveInfo ai : outArchives) {
Package p = ai.getNewArchive().getParentPackage();
if (p instanceof PlatformPackage) {
if (p instanceof ToolPackage) {
if (((ToolPackage) p).getRevision() >= rev) {
// The dependency is already scheduled for install, nothing else to do.
return ai;