SDK Updater: use separate license node in XML. Support extra packages.

This commit is contained in:
Raphael
2009-06-18 16:07:55 -07:00
parent 963aebaffa
commit 48c6578bb6
17 changed files with 582 additions and 157 deletions

View File

@@ -28,6 +28,7 @@ import org.w3c.dom.Node;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
/** /**
* Represents an add-on XML node in an SDK repository. * Represents an add-on XML node in an SDK repository.
@@ -64,13 +65,13 @@ public class AddonPackage extends Package {
* <p/> * <p/>
* This constructor should throw an exception if the package cannot be created. * This constructor should throw an exception if the package cannot be created.
*/ */
AddonPackage(RepoSource source, Node packageNode) { AddonPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
super(source, packageNode); super(source, packageNode, licenses);
mVendor = getXmlString(packageNode, SdkRepository.NODE_VENDOR); mVendor = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VENDOR);
mName = getXmlString(packageNode, SdkRepository.NODE_NAME); mName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_NAME);
mApiLevel = getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0); mApiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
mLibs = parseLibs(getFirstChild(packageNode, SdkRepository.NODE_LIBS)); mLibs = parseLibs(XmlParserUtils.getFirstChild(packageNode, SdkRepository.NODE_LIBS));
} }
/** /**
@@ -131,8 +132,8 @@ public class AddonPackage extends Package {
* Parses a <lib> element from a <libs> container. * Parses a <lib> element from a <libs> container.
*/ */
private Lib parseLib(Node libNode) { private Lib parseLib(Node libNode) {
return new Lib(getXmlString(libNode, SdkRepository.NODE_NAME), return new Lib(XmlParserUtils.getXmlString(libNode, SdkRepository.NODE_NAME),
getXmlString(libNode, SdkRepository.NODE_DESCRIPTION)); XmlParserUtils.getXmlString(libNode, SdkRepository.NODE_DESCRIPTION));
} }
/** Returns the vendor, a string, for add-on packages. */ /** Returns the vendor, a string, for add-on packages. */

View File

@@ -348,9 +348,18 @@ public class Archive implements IDescription {
SdkManager sdkManager, SdkManager sdkManager,
ITaskMonitor monitor) { ITaskMonitor monitor) {
Package pkg = getParentPackage();
File archiveFile = null; File archiveFile = null;
try { try {
String name = getParentPackage().getShortDescription(); String name = pkg.getShortDescription();
if (pkg instanceof ExtraPackage && !((ExtraPackage) pkg).isPathValid()) {
monitor.setResult("Skipping %1$s: %2$s is not a valid install path.",
name,
((ExtraPackage) pkg).getPath());
return false;
}
if (isLocal()) { if (isLocal()) {
// This should never happen. // This should never happen.

View File

@@ -25,6 +25,7 @@ import com.android.sdklib.repository.SdkRepository;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import java.io.File; import java.io.File;
import java.util.Map;
/** /**
* Represents a doc XML node in an SDK repository. * Represents a doc XML node in an SDK repository.
@@ -38,9 +39,9 @@ public class DocPackage extends Package {
* <p/> * <p/>
* This constructor should throw an exception if the package cannot be created. * This constructor should throw an exception if the package cannot be created.
*/ */
DocPackage(RepoSource source, Node packageNode) { DocPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
super(source, packageNode); super(source, packageNode, licenses);
mApiLevel = getXmlInt(packageNode, SdkRepository.NODE_API_LEVEL, 0); mApiLevel = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_API_LEVEL, 0);
} }
/** /**

View File

@@ -0,0 +1,144 @@
/*
* 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.SdkConstants;
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.io.File;
import java.util.Map;
/**
* Represents a extra XML node in an SDK repository.
*/
public class ExtraPackage extends Package {
private final String mPath;
/**
* Creates a new tool package from the attributes and elements of the given XML node.
* <p/>
* This constructor should throw an exception if the package cannot be created.
*/
ExtraPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
super(source, packageNode, licenses);
mPath = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_PATH);
}
/**
* 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.
*/
ExtraPackage(RepoSource source,
String path,
int revision,
String license,
String description,
String descUrl,
Os archiveOs,
Arch archiveArch,
String archiveOsPath) {
super(source,
revision,
license,
description,
descUrl,
archiveOs,
archiveArch,
archiveOsPath);
mPath = path;
}
/**
* Static helper to check if a given path is acceptable for an "extra" package.
*/
public boolean isPathValid() {
if (SdkConstants.FD_ADDONS.equals(mPath) ||
SdkConstants.FD_PLATFORMS.equals(mPath) ||
SdkConstants.FD_TOOLS.equals(mPath) ||
SdkConstants.FD_DOCS.equals(mPath)) {
return false;
}
return mPath != null && mPath.indexOf('/') == -1 && mPath.indexOf('\\') == -1;
}
/**
* The install folder name. It must be a single-segment path.
* The paths "add-ons", "platforms", "tools" and "docs" are reserved and cannot be used.
* This limitation cannot be written in the XML Schema and must be enforced here by using
* the method {@link #isPathValid()} *before* installing the package.
*/
public String getPath() {
return mPath;
}
/** Returns a short description for an {@link IDescription}. */
@Override
public String getShortDescription() {
return String.format("Extra %1$s package, revision %2$d", getPath(), getRevision());
}
/** Returns a long description for an {@link IDescription}. */
@Override
public String getLongDescription() {
return String.format("Extra %1$s package, revision %2$d.\n%3$s",
getPath(),
getRevision(),
super.getLongDescription());
}
/**
* Computes a potential installation folder if an archive of this package were
* to be installed right away in the given SDK root.
* <p/>
* A "tool" package should always be located in SDK/tools.
*
* @param osSdkRoot The OS path of the SDK root folder.
* @return A new {@link File} corresponding to the directory to use to install this package.
*/
@Override
public File getInstallFolder(String osSdkRoot) {
return new File(osSdkRoot, getPath());
}
/**
* Computes whether the given extra package is a suitable update for the current package.
* The base method checks the class type.
* The tools package also tests that the revision number is greater and the path is the
* same.
* <p/>
* An update is just that: a new package that supersedes the current one. If the new
* package has the same revision as the current one, it's not an update.
*
* @param replacementPackage The potential replacement package.
* @return True if the replacement package is a suitable update for this one.
*/
@Override
public boolean canBeUpdatedBy(Package replacementPackage) {
if (!super.canBeUpdatedBy(replacementPackage)) {
return false;
}
ExtraPackage newPkg = (ExtraPackage) replacementPackage;
return newPkg.getRevision() > this.getRevision() && newPkg.getPath().equals(this.getPath());
}
}

View File

@@ -35,6 +35,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -250,6 +251,22 @@ public class LocalSdkParser {
Node root = getFirstChild(doc, SdkRepository.NODE_SDK_REPOSITORY); Node root = getFirstChild(doc, SdkRepository.NODE_SDK_REPOSITORY);
if (root != null) { if (root != null) {
// Parse license definitions
HashMap<String, String> licenses = new HashMap<String, String>();
for (Node child = root.getFirstChild();
child != null;
child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
SdkRepository.NS_SDK_REPOSITORY.equals(child.getNamespaceURI()) &&
child.getLocalName().equals(SdkRepository.NODE_LICENSE)) {
Node id = child.getAttributes().getNamedItem(SdkRepository.ATTR_ID);
if (id != null) {
licenses.put(id.getNodeValue(), child.getTextContent());
}
}
}
// Parse packages
for (Node child = root.getFirstChild(); for (Node child = root.getFirstChild();
child != null; child != null;
child = child.getNextSibling()) { child = child.getNextSibling()) {
@@ -260,16 +277,16 @@ public class LocalSdkParser {
try { try {
if (SdkRepository.NODE_ADD_ON.equals(name)) { if (SdkRepository.NODE_ADD_ON.equals(name)) {
return new AddonPackage(null /*source*/, child); return new AddonPackage(null /*source*/, child, licenses);
} else if (SdkRepository.NODE_PLATFORM.equals(name)) { } else if (SdkRepository.NODE_PLATFORM.equals(name)) {
return new PlatformPackage(null /*source*/, child); return new PlatformPackage(null /*source*/, child, licenses);
} else if (SdkRepository.NODE_DOC.equals(name)) { } else if (SdkRepository.NODE_DOC.equals(name)) {
return new DocPackage(null /*source*/, child); return new DocPackage(null /*source*/, child, licenses);
} else if (SdkRepository.NODE_TOOL.equals(name)) { } else if (SdkRepository.NODE_TOOL.equals(name)) {
return new ToolPackage(null /*source*/, child); return new ToolPackage(null /*source*/, child, licenses);
} }
} catch (Exception e) { } catch (Exception e) {
// Ignore invalid packages // Ignore invalid packages

View File

@@ -25,6 +25,7 @@ import org.w3c.dom.Node;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map;
/** /**
* A {@link Package} is the base class for "something" that can be downloaded from * A {@link Package} is the base class for "something" that can be downloaded from
@@ -52,13 +53,15 @@ public abstract class Package implements IDescription {
* <p/> * <p/>
* This constructor should throw an exception if the package cannot be created. * This constructor should throw an exception if the package cannot be created.
*/ */
Package(RepoSource source, Node packageNode) { Package(RepoSource source, Node packageNode, Map<String,String> licenses) {
mSource = source; mSource = source;
mRevision = getXmlInt (packageNode, SdkRepository.NODE_REVISION, 0); mRevision = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_REVISION, 0);
mDescription = getXmlString(packageNode, SdkRepository.NODE_DESCRIPTION); mDescription = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_DESCRIPTION);
mDescUrl = getXmlString(packageNode, SdkRepository.NODE_DESC_URL); mDescUrl = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_DESC_URL);
mLicense = getXmlString(packageNode, SdkRepository.NODE_LICENSE);
mArchives = parseArchives(getFirstChild(packageNode, SdkRepository.NODE_ARCHIVES)); mLicense = parseLicense(packageNode, licenses);
mArchives = parseArchives(XmlParserUtils.getFirstChild(
packageNode, SdkRepository.NODE_ARCHIVES));
} }
/** /**
@@ -86,6 +89,24 @@ public abstract class Package implements IDescription {
archiveOsPath); archiveOsPath);
} }
/**
* Parses the uses-licence node of this package, if any, and returns the license
* definition if there's one. Returns null if there's no uses-license element or no
* license of this name defined.
*/
private String parseLicense(Node packageNode, Map<String, String> licenses) {
Node usesLicense = XmlParserUtils.getFirstChild(
packageNode, SdkRepository.NODE_USES_LICENSE);
if (usesLicense != null) {
Node ref = usesLicense.getAttributes().getNamedItem(SdkRepository.ATTR_REF);
if (ref != null) {
String licenseRef = ref.getNodeValue();
return licenses.get(licenseRef);
}
}
return null;
}
/** /**
* Parses an XML node to process the <archives> element. * Parses an XML node to process the <archives> element.
*/ */
@@ -114,13 +135,13 @@ public abstract class Package implements IDescription {
private Archive parseArchive(Node archiveNode) { private Archive parseArchive(Node archiveNode) {
Archive a = new Archive( Archive a = new Archive(
this, this,
(Os) getEnumAttribute(archiveNode, SdkRepository.ATTR_OS, (Os) XmlParserUtils.getEnumAttribute(archiveNode, SdkRepository.ATTR_OS,
Os.values(), null), Os.values(), null),
(Arch) getEnumAttribute(archiveNode, SdkRepository.ATTR_ARCH, (Arch) XmlParserUtils.getEnumAttribute(archiveNode, SdkRepository.ATTR_ARCH,
Arch.values(), Arch.ANY), Arch.values(), Arch.ANY),
getXmlString(archiveNode, SdkRepository.NODE_URL), XmlParserUtils.getXmlString(archiveNode, SdkRepository.NODE_URL),
getXmlLong(archiveNode, SdkRepository.NODE_SIZE, 0), XmlParserUtils.getXmlLong (archiveNode, SdkRepository.NODE_SIZE, 0),
getXmlString(archiveNode, SdkRepository.NODE_CHECKSUM) XmlParserUtils.getXmlString(archiveNode, SdkRepository.NODE_CHECKSUM)
); );
return a; return a;
@@ -224,85 +245,4 @@ public abstract class Package implements IDescription {
replacementPackage.getRevision() > this.getRevision(); replacementPackage.getRevision() > this.getRevision();
} }
//---
/**
* Returns the first child element with the given XML local name.
* If xmlLocalName is null, returns the very first child element.
*/
protected static Node getFirstChild(Node node, String xmlLocalName) {
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
SdkRepository.NS_SDK_REPOSITORY.equals(child.getNamespaceURI())) {
if (xmlLocalName == null || xmlLocalName.equals(child.getLocalName())) {
return child;
}
}
}
return null;
}
/**
* Retrieves the value of that XML element as a string.
* Returns an empty string when the element is missing.
*/
protected static String getXmlString(Node node, String xmlLocalName) {
Node child = getFirstChild(node, xmlLocalName);
return child == null ? "" : child.getTextContent(); //$NON-NLS-1$
}
/**
* Retrieves the value of that XML element as an integer.
* Returns the default value when the element is missing or is not an integer.
*/
protected static int getXmlInt(Node node, String xmlLocalName, int defaultValue) {
String s = getXmlString(node, xmlLocalName);
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Retrieves the value of that XML element as a long.
* Returns the default value when the element is missing or is not an integer.
*/
protected static long getXmlLong(Node node, String xmlLocalName, long defaultValue) {
String s = getXmlString(node, xmlLocalName);
try {
return Long.parseLong(s);
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Retrieve an attribute which value must match one of the given enums using a
* case-insensitive name match.
*
* Returns defaultValue if the attribute does not exist or its value does not match
* the given enum values.
*/
private Object getEnumAttribute(
Node archiveNode,
String attrName,
Object[] values,
Object defaultValue) {
Node attr = archiveNode.getAttributes().getNamedItem(attrName);
if (attr != null) {
String found = attr.getNodeValue();
for (Object value : values) {
if (value.toString().equalsIgnoreCase(found)) {
return value;
}
}
}
return defaultValue;
}
} }

View File

@@ -26,6 +26,7 @@ import com.android.sdklib.repository.SdkRepository;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import java.io.File; import java.io.File;
import java.util.Map;
/** /**
* Represents a platform XML node in an SDK repository. * Represents a platform XML node in an SDK repository.
@@ -40,10 +41,10 @@ public class PlatformPackage extends Package {
* <p/> * <p/>
* This constructor should throw an exception if the package cannot be created. * This constructor should throw an exception if the package cannot be created.
*/ */
PlatformPackage(RepoSource source, Node packageNode) { PlatformPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
super(source, packageNode); super(source, packageNode, licenses);
mVersion = getXmlString(packageNode, SdkRepository.NODE_VERSION); mVersion = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VERSION);
mApiLevel = getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0); mApiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
} }
/** /**

View File

@@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
@@ -248,6 +249,22 @@ public class RepoSource implements IDescription {
ArrayList<Package> packages = new ArrayList<Package>(); ArrayList<Package> packages = new ArrayList<Package>();
// Parse license definitions
HashMap<String, String> licenses = new HashMap<String, String>();
for (Node child = root.getFirstChild();
child != null;
child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
SdkRepository.NS_SDK_REPOSITORY.equals(child.getNamespaceURI()) &&
child.getLocalName().equals(SdkRepository.NODE_LICENSE)) {
Node id = child.getAttributes().getNamedItem(SdkRepository.ATTR_ID);
if (id != null) {
licenses.put(id.getNodeValue(), child.getTextContent());
}
}
}
// Parse packages
for (Node child = root.getFirstChild(); for (Node child = root.getFirstChild();
child != null; child != null;
child = child.getNextSibling()) { child = child.getNextSibling()) {
@@ -258,15 +275,18 @@ public class RepoSource implements IDescription {
try { try {
if (SdkRepository.NODE_ADD_ON.equals(name)) { if (SdkRepository.NODE_ADD_ON.equals(name)) {
p = new AddonPackage(this, child); p = new AddonPackage(this, child, licenses);
} else if (SdkRepository.NODE_EXTRA.equals(name)) {
p = new ExtraPackage(this, child, licenses);
} else if (!mAddonOnly) { } else if (!mAddonOnly) {
if (SdkRepository.NODE_PLATFORM.equals(name)) { if (SdkRepository.NODE_PLATFORM.equals(name)) {
p = new PlatformPackage(this, child); p = new PlatformPackage(this, child, licenses);
} else if (SdkRepository.NODE_DOC.equals(name)) { } else if (SdkRepository.NODE_DOC.equals(name)) {
p = new DocPackage(this, child); p = new DocPackage(this, child, licenses);
} else if (SdkRepository.NODE_TOOL.equals(name)) { } else if (SdkRepository.NODE_TOOL.equals(name)) {
p = new ToolPackage(this, child); p = new ToolPackage(this, child, licenses);
} }
} }

View File

@@ -24,6 +24,7 @@ import com.android.sdklib.internal.repository.Archive.Os;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import java.io.File; import java.io.File;
import java.util.Map;
/** /**
* Represents a tool XML node in an SDK repository. * Represents a tool XML node in an SDK repository.
@@ -35,8 +36,8 @@ public class ToolPackage extends Package {
* <p/> * <p/>
* This constructor should throw an exception if the package cannot be created. * This constructor should throw an exception if the package cannot be created.
*/ */
ToolPackage(RepoSource source, Node packageNode) { ToolPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
super(source, packageNode); super(source, packageNode, licenses);
} }
/** /**

View File

@@ -0,0 +1,108 @@
/*
* 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.repository.SdkRepository;
import org.w3c.dom.Node;
/**
* Misc utilities to help extracting elements and attributes out of an XML document.
*/
class XmlParserUtils {
/**
* Returns the first child element with the given XML local name.
* If xmlLocalName is null, returns the very first child element.
*/
public static Node getFirstChild(Node node, String xmlLocalName) {
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
SdkRepository.NS_SDK_REPOSITORY.equals(child.getNamespaceURI())) {
if (xmlLocalName == null || xmlLocalName.equals(child.getLocalName())) {
return child;
}
}
}
return null;
}
/**
* Retrieves the value of that XML element as a string.
* Returns an empty string when the element is missing.
*/
public static String getXmlString(Node node, String xmlLocalName) {
Node child = getFirstChild(node, xmlLocalName);
return child == null ? "" : child.getTextContent(); //$NON-NLS-1$
}
/**
* Retrieves the value of that XML element as an integer.
* Returns the default value when the element is missing or is not an integer.
*/
public static int getXmlInt(Node node, String xmlLocalName, int defaultValue) {
String s = getXmlString(node, xmlLocalName);
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Retrieves the value of that XML element as a long.
* Returns the default value when the element is missing or is not an integer.
*/
public static long getXmlLong(Node node, String xmlLocalName, long defaultValue) {
String s = getXmlString(node, xmlLocalName);
try {
return Long.parseLong(s);
} catch (NumberFormatException e) {
return defaultValue;
}
}
/**
* Retrieve an attribute which value must match one of the given enums using a
* case-insensitive name match.
*
* Returns defaultValue if the attribute does not exist or its value does not match
* the given enum values.
*/
public static Object getEnumAttribute(
Node archiveNode,
String attrName,
Object[] values,
Object defaultValue) {
Node attr = archiveNode.getAttributes().getNamedItem(attrName);
if (attr != null) {
String found = attr.getNodeValue();
for (Object value : values) {
if (value.toString().equalsIgnoreCase(found)) {
return value;
}
}
}
return defaultValue;
}
}

View File

@@ -43,11 +43,15 @@ public class SdkRepository {
public static final String NODE_TOOL = "tool"; //$NON-NLS-1$ public static final String NODE_TOOL = "tool"; //$NON-NLS-1$
/** A doc package. */ /** A doc package. */
public static final String NODE_DOC = "doc"; //$NON-NLS-1$ public static final String NODE_DOC = "doc"; //$NON-NLS-1$
/** An extra package. */
public static final String NODE_EXTRA = "extra"; //$NON-NLS-1$
/** The license definition. */
public static final String NODE_LICENSE = "license"; //$NON-NLS-1$
/** The optional uses-license for all packages (platform, add-on, tool, doc) or for a lib. */
public static final String NODE_USES_LICENSE = "uses-license"; //$NON-NLS-1$
/** The revision, an int > 0, for all packages (platform, add-on, tool, doc). */ /** The revision, an int > 0, for all packages (platform, add-on, tool, doc). */
public static final String NODE_REVISION = "revision"; //$NON-NLS-1$ public static final String NODE_REVISION = "revision"; //$NON-NLS-1$
/** The optional license for all packages (platform, add-on, tool, doc) or for a lib. */
public static final String NODE_LICENSE = "license"; //$NON-NLS-1$
/** The optional description for all packages (platform, add-on, tool, doc) or for a lib. */ /** The optional description for all packages (platform, add-on, tool, doc) or for a lib. */
public static final String NODE_DESCRIPTION = "description"; //$NON-NLS-1$ public static final String NODE_DESCRIPTION = "description"; //$NON-NLS-1$
/** The optional description URL for all packages (platform, add-on, tool, doc). */ /** The optional description URL for all packages (platform, add-on, tool, doc). */
@@ -67,6 +71,9 @@ public class SdkRepository {
/** A lib element in a libs container. */ /** A lib element in a libs container. */
public static final String NODE_LIB = "lib"; //$NON-NLS-1$ public static final String NODE_LIB = "lib"; //$NON-NLS-1$
/** The path, a string, for extra packages. */
public static final String NODE_PATH = "path"; //$NON-NLS-1$
/** The archives container, for all packages. */ /** The archives container, for all packages. */
public static final String NODE_ARCHIVES = "archives"; //$NON-NLS-1$ public static final String NODE_ARCHIVES = "archives"; //$NON-NLS-1$
/** An archive element, for the archives container. */ /** An archive element, for the archives container. */
@@ -86,6 +93,12 @@ public class SdkRepository {
/** An optional archive Architecture attribute. */ /** An optional archive Architecture attribute. */
public static final String ATTR_ARCH = "arch"; //$NON-NLS-1$ public static final String ATTR_ARCH = "arch"; //$NON-NLS-1$
/** A license definition ID. */
public static final String ATTR_ID = "id"; //$NON-NLS-1$
/** A license reference. */
public static final String ATTR_REF = "ref"; //$NON-NLS-1$
public static InputStream getXsdStream() { public static InputStream getXsdStream() {
return SdkRepository.class.getResourceAsStream("sdk-repository.xsd"); //$NON-NLS-1$ return SdkRepository.class.getResourceAsStream("sdk-repository.xsd"); //$NON-NLS-1$
} }

View File

@@ -40,7 +40,7 @@
<xsd:complexType> <xsd:complexType>
<xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:choice minOccurs="0" maxOccurs="unbounded">
<!-- The definition of an SDK platform package --> <!-- The definition of an SDK platform package. -->
<xsd:element name="platform"> <xsd:element name="platform">
<xsd:annotation> <xsd:annotation>
@@ -58,7 +58,7 @@
<xsd:element name="revision" type="xsd:positiveInteger" /> <xsd:element name="revision" type="xsd:positiveInteger" />
<!-- The optional license of this package. If present, users will have <!-- The optional license of this package. If present, users will have
to agree to it before downloading. --> to agree to it before downloading. -->
<xsd:element name="license" type="xsd:string" minOccurs="0" /> <xsd:element name="uses-license" type="sdk:licenseType" minOccurs="0" />
<!-- The optional description of this package. --> <!-- The optional description of this package. -->
<xsd:element name="description" type="xsd:string" minOccurs="0" /> <xsd:element name="description" type="xsd:string" minOccurs="0" />
<!-- The optional description URL of this package --> <!-- The optional description URL of this package -->
@@ -69,7 +69,8 @@
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<!-- The definition of an SDK Add-on package -->
<!-- The definition of an SDK Add-on package. -->
<xsd:element name="add-on"> <xsd:element name="add-on">
<xsd:annotation> <xsd:annotation>
@@ -89,7 +90,7 @@
<xsd:element name="revision" type="xsd:positiveInteger" /> <xsd:element name="revision" type="xsd:positiveInteger" />
<!-- The optional license of this package. If present, users will have <!-- The optional license of this package. If present, users will have
to agree to it before downloading. --> to agree to it before downloading. -->
<xsd:element name="license" type="xsd:string" minOccurs="0" /> <xsd:element name="uses-license" type="sdk:licenseType" minOccurs="0" />
<!-- The optional description of this package. --> <!-- The optional description of this package. -->
<xsd:element name="description" type="xsd:string" minOccurs="0" /> <xsd:element name="description" type="xsd:string" minOccurs="0" />
<!-- The optional description URL of this package --> <!-- The optional description URL of this package -->
@@ -119,7 +120,8 @@
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<!-- The definition of an SDK tool package -->
<!-- The definition of an SDK tool package. -->
<xsd:element name="tool"> <xsd:element name="tool">
<xsd:annotation> <xsd:annotation>
@@ -132,7 +134,7 @@
<xsd:element name="revision" type="xsd:positiveInteger" /> <xsd:element name="revision" type="xsd:positiveInteger" />
<!-- The optional license of this package. If present, users will have <!-- The optional license of this package. If present, users will have
to agree to it before downloading. --> to agree to it before downloading. -->
<xsd:element name="license" type="xsd:string" minOccurs="0" /> <xsd:element name="uses-license" type="sdk:licenseType" minOccurs="0" />
<!-- The optional description of this package. --> <!-- The optional description of this package. -->
<xsd:element name="description" type="xsd:string" minOccurs="0" /> <xsd:element name="description" type="xsd:string" minOccurs="0" />
<!-- The optional description URL of this package --> <!-- The optional description URL of this package -->
@@ -143,7 +145,8 @@
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<!-- The definition of an SDK doc package -->
<!-- The definition of an SDK doc package. -->
<xsd:element name="doc"> <xsd:element name="doc">
<xsd:annotation> <xsd:annotation>
@@ -159,7 +162,7 @@
<xsd:element name="revision" type="xsd:positiveInteger" /> <xsd:element name="revision" type="xsd:positiveInteger" />
<!-- The optional license of this package. If present, users will have <!-- The optional license of this package. If present, users will have
to agree to it before downloading. --> to agree to it before downloading. -->
<xsd:element name="license" type="xsd:string" minOccurs="0" /> <xsd:element name="uses-license" type="sdk:licenseType" minOccurs="0" />
<!-- The optional description of this package. --> <!-- The optional description of this package. -->
<xsd:element name="description" type="xsd:string" minOccurs="0" /> <xsd:element name="description" type="xsd:string" minOccurs="0" />
<!-- The optional description URL of this package --> <!-- The optional description URL of this package -->
@@ -169,10 +172,95 @@
</xsd:all> </xsd:all>
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<!-- The definition of an SDK extra package. This kind of package is for
"free" content and specifies in which fixed root directory it must be
installed.
-->
<xsd:element name="extra">
<xsd:annotation>
<xsd:documentation>
An SDK extra package. This kind of package is for "free"
content and specifies in which fixed root directory it must be
installed.
The paths "add-ons", "platforms", "tools" and "docs" are
reserved and cannot be used.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:all>
<!-- The install folder name. It must be a single-segment path.
The paths "add-ons", "platforms", "tools" and "docs" are
reserved and cannot be used.
-->
<xsd:element name="path">
<xsd:simpleType>
<xsd:restriction base="xsd:token">
<xsd:pattern value="[^/\\]+"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<!-- The revision, an int > 0, incremented each time a new
package is generated. -->
<xsd:element name="revision" type="xsd:positiveInteger" />
<!-- The optional license of this package. If present, users will have
to agree to it before downloading. -->
<xsd:element name="uses-license" type="sdk:licenseType" minOccurs="0" />
<!-- The optional description of this package. -->
<xsd:element name="description" type="xsd:string" minOccurs="0" />
<!-- The optional description URL of this package -->
<xsd:element name="desc-url" type="xsd:token" minOccurs="0" />
<!-- A list of file archives for this package. -->
<xsd:element name="archives" type="sdk:archivesType" />
</xsd:all>
</xsd:complexType>
</xsd:element>
<!-- The definition of a license to be referenced by the uses-license element. -->
<xsd:element name="license">
<xsd:annotation>
<xsd:documentation>
A license definition. Such a license must be used later as a reference
using a uses-license element in one of the package elements.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="type" type="xsd:token" fixed="text" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:choice> </xsd:choice>
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<!-- Type describing the license used by a package.
The license MUST be defined using a license node and referenced
using the ref attribute of the license element inside a package.
-->
<xsd:complexType name="licenseType">
<xsd:annotation>
<xsd:documentation>
Describes the license used by a package. The license MUST be defined
using a license node and referenced using the ref attribute of the
license element inside a package.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="ref" type="xsd:IDREF" />
</xsd:complexType>
<!-- A collection of files that can be downloaded for a given architecture. <!-- A collection of files that can be downloaded for a given architecture.
The <archives> node is mandatory in the repository elements and the The <archives> node is mandatory in the repository elements and the
collection must have at least one <archive> declared. collection must have at least one <archive> declared.
@@ -232,6 +320,7 @@
</xsd:sequence> </xsd:sequence>
</xsd:complexType> </xsd:complexType>
<!-- The definition of a file checksum --> <!-- The definition of a file checksum -->
<xsd:simpleType name="sha1Number"> <xsd:simpleType name="sha1Number">
@@ -254,4 +343,5 @@
</xsd:simpleContent> </xsd:simpleContent>
</xsd:complexType> </xsd:complexType>
</xsd:schema> </xsd:schema>

View File

@@ -16,6 +16,8 @@
package com.android.sdklib.repository; package com.android.sdklib.repository;
import com.android.sdklib.SdkConstants;
import org.xml.sax.ErrorHandler; import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
@@ -245,4 +247,57 @@ public class TestSdkRepository extends TestCase {
// If we get here, the validator has not failed as we expected it to. // If we get here, the validator has not failed as we expected it to.
fail(); fail();
} }
/** A document an unknown license id. */
public void testLicenseIdNotFound() throws Exception {
// we define a license named "lic1" and then reference "lic2" instead
String document = "<?xml version=\"1.0\"?>" +
"<r:sdk-repository xmlns:r=\"http://schemas.android.com/sdk/android/repository/1\" >" +
"<r:license id=\"lic1\"> some license </r:license> " +
"<r:tool> <r:uses-license ref=\"lic2\" /> <r:revision>1</r:revision> " +
"<r:archives> <r:archive os=\"any\"> <r:size>1</r:size> <r:checksum>2822ae37115ebf13412bbef91339ee0d9454525e</r:checksum> " +
"<r:url>url</r:url> </r:archive> </r:archives> </r:tool>" +
"</r:sdk-repository>";
Source source = new StreamSource(new StringReader(document));
// don't capture the validator errors, we want it to fail and catch the exception
Validator validator = getValidator(null);
try {
validator.validate(source);
} catch (SAXParseException e) {
// We expect a parse error referring to this grammar rule
assertRegex("cvc-id.1: There is no ID/IDREF binding for IDREF 'lic2'.*",
e.getMessage());
return;
}
// If we get here, the validator has not failed as we expected it to.
fail();
}
/** A document a slash in an extra path. */
public void testExtraPathWithSlash() throws Exception {
// we define a license named "lic1" and then reference "lic2" instead
String document = "<?xml version=\"1.0\"?>" +
"<r:sdk-repository xmlns:r=\"http://schemas.android.com/sdk/android/repository/1\" >" +
"<r:extra> <r:revision>1</r:revision> <r:path>path/cannot\\contain\\segments</r:path> " +
"<r:archives> <r:archive os=\"any\"> <r:size>1</r:size> <r:checksum>2822ae37115ebf13412bbef91339ee0d9454525e</r:checksum> " +
"<r:url>url</r:url> </r:archive> </r:archives> </r:extra>" +
"</r:sdk-repository>";
Source source = new StreamSource(new StringReader(document));
// don't capture the validator errors, we want it to fail and catch the exception
Validator validator = getValidator(null);
try {
validator.validate(source);
} catch (SAXParseException e) {
// We expect a parse error referring to this grammar rule
assertRegex("cvc-pattern-valid: Value 'path/cannot\\\\contain\\\\segments' is not facet-valid with respect to pattern.*",
e.getMessage());
return;
}
// If we get here, the validator has not failed as we expected it to.
fail();
}
} }

View File

@@ -18,6 +18,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sdk="http://schemas.android.com/sdk/android/repository/1"> xmlns:sdk="http://schemas.android.com/sdk/android/repository/1">
<!-- Define a couple of licenses. These will be referenced by uses-license later. -->
<sdk:license type="text" id="license1">
This is the license
for this platform.
</sdk:license>
<sdk:license id="license2">
Licenses are only of type 'text' right now, so this is implied.
</sdk:license>
<!-- Inner elements must be either platform, add-on, doc or tool. <!-- Inner elements must be either platform, add-on, doc or tool.
There can be 0 or more of each, in any order. --> There can be 0 or more of each, in any order. -->
@@ -25,9 +36,8 @@
<sdk:version>1.0</sdk:version> <sdk:version>1.0</sdk:version>
<sdk:api-level>1</sdk:api-level> <sdk:api-level>1</sdk:api-level>
<sdk:revision>3</sdk:revision> <sdk:revision>3</sdk:revision>
<sdk:uses-license ref="license1" />
<sdk:description>Some optional description</sdk:description> <sdk:description>Some optional description</sdk:description>
<sdk:license>This is the license
for this platform.</sdk:license>
<sdk:desc-url>http://www.example.com/platform1.html</sdk:desc-url> <sdk:desc-url>http://www.example.com/platform1.html</sdk:desc-url>
<!-- The archives node is mandatory and it cannot be empty. --> <!-- The archives node is mandatory and it cannot be empty. -->
<sdk:archives> <sdk:archives>
@@ -42,8 +52,8 @@
<sdk:doc> <sdk:doc>
<sdk:api-level>1</sdk:api-level> <sdk:api-level>1</sdk:api-level>
<sdk:revision>1</sdk:revision> <sdk:revision>1</sdk:revision>
<sdk:description>Some optional description</sdk:description>
<!-- the license element is not mandatory. --> <!-- the license element is not mandatory. -->
<sdk:description>Some optional description</sdk:description>
<sdk:desc-url>http://www.example.com/docs.html</sdk:desc-url> <sdk:desc-url>http://www.example.com/docs.html</sdk:desc-url>
<sdk:archives> <sdk:archives>
<sdk:archive os="any"> <sdk:archive os="any">
@@ -59,8 +69,7 @@
<sdk:api-level>1</sdk:api-level> <sdk:api-level>1</sdk:api-level>
<sdk:vendor>John Doe</sdk:vendor> <sdk:vendor>John Doe</sdk:vendor>
<sdk:revision>1</sdk:revision> <sdk:revision>1</sdk:revision>
<!-- license can be empty. --> <sdk:uses-license ref="license2" />
<sdk:license></sdk:license>
<sdk:description>Some optional description</sdk:description> <sdk:description>Some optional description</sdk:description>
<sdk:desc-url>http://www.example.com/myfirstaddon</sdk:desc-url> <sdk:desc-url>http://www.example.com/myfirstaddon</sdk:desc-url>
<sdk:archives> <sdk:archives>
@@ -87,7 +96,7 @@
<sdk:version>1.1</sdk:version> <sdk:version>1.1</sdk:version>
<sdk:api-level>2</sdk:api-level> <sdk:api-level>2</sdk:api-level>
<sdk:revision>12</sdk:revision> <sdk:revision>12</sdk:revision>
<sdk:license>This is the license for this package.</sdk:license> <sdk:uses-license ref="license1" />
<!-- sdk:description and sdk:desc-url are optional --> <!-- sdk:description and sdk:desc-url are optional -->
<sdk:archives> <sdk:archives>
<sdk:archive os="windows"> <sdk:archive os="windows">
@@ -145,14 +154,14 @@
<sdk:name>com.android.mymaps</sdk:name> <sdk:name>com.android.mymaps</sdk:name>
</sdk:lib> </sdk:lib>
</sdk:libs> </sdk:libs>
<sdk:license>This is the license for this package.</sdk:license> <sdk:uses-license ref="license2" />
</sdk:add-on> </sdk:add-on>
<sdk:tool> <sdk:tool>
<sdk:revision>1</sdk:revision> <sdk:revision>1</sdk:revision>
<sdk:description>Some optional description</sdk:description> <sdk:description>Some optional description</sdk:description>
<sdk:desc-url>http://www.example.com/tools.html</sdk:desc-url> <sdk:desc-url>http://www.example.com/tools.html</sdk:desc-url>
<sdk:license>This is the license for this package.</sdk:license> <sdk:uses-license ref="license1" />
<sdk:archives> <sdk:archives>
<sdk:archive os="any"> <sdk:archive os="any">
<sdk:size>65536</sdk:size> <sdk:size>65536</sdk:size>
@@ -165,7 +174,7 @@
<sdk:doc> <sdk:doc>
<sdk:api-level>2</sdk:api-level> <sdk:api-level>2</sdk:api-level>
<sdk:revision>42</sdk:revision> <sdk:revision>42</sdk:revision>
<sdk:license>This is the license for this package.</sdk:license> <sdk:uses-license ref="license2" />
<sdk:archives> <sdk:archives>
<sdk:archive os="windows"> <sdk:archive os="windows">
<sdk:size>65536</sdk:size> <sdk:size>65536</sdk:size>
@@ -187,7 +196,7 @@
<sdk:tool> <sdk:tool>
<sdk:revision>42</sdk:revision> <sdk:revision>42</sdk:revision>
<sdk:license>This is the license for this package.</sdk:license> <sdk:uses-license ref="license1" />
<sdk:archives> <sdk:archives>
<sdk:archive os="windows"> <sdk:archive os="windows">
<sdk:size>65536</sdk:size> <sdk:size>65536</sdk:size>
@@ -208,7 +217,7 @@
</sdk:tool> </sdk:tool>
<sdk:add-on> <sdk:add-on>
<sdk:license>This is the license for this package.</sdk:license> <sdk:uses-license ref="license2" />
<sdk:name>This add-on has no libraries</sdk:name> <sdk:name>This add-on has no libraries</sdk:name>
<sdk:api-level>4</sdk:api-level> <sdk:api-level>4</sdk:api-level>
<sdk:vendor>Joe Bar</sdk:vendor> <sdk:vendor>Joe Bar</sdk:vendor>
@@ -224,4 +233,19 @@
<sdk:libs /> <sdk:libs />
</sdk:add-on> </sdk:add-on>
<sdk:extra>
<sdk:path>usb_driver</sdk:path>
<sdk:uses-license ref="license2" />
<sdk:revision>43</sdk:revision>
<sdk:archives>
<sdk:archive os="any" arch="any">
<sdk:size>65536</sdk:size>
<sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
<sdk:url>distrib/extraduff.zip</sdk:url>
</sdk:archive>
</sdk:archives>
<sdk:description>An Extra package for the USB driver, it will install in $SDK/usb_driver</sdk:description>
<sdk:desc-url>http://www.example.com/extra.html</sdk:desc-url>
</sdk:extra>
</sdk:sdk-repository> </sdk:sdk-repository>

View File

@@ -19,6 +19,7 @@ package com.android.sdkuilib.internal.repository.icons;
import com.android.sdklib.internal.repository.AddonPackage; import com.android.sdklib.internal.repository.AddonPackage;
import com.android.sdklib.internal.repository.Archive; import com.android.sdklib.internal.repository.Archive;
import com.android.sdklib.internal.repository.DocPackage; import com.android.sdklib.internal.repository.DocPackage;
import com.android.sdklib.internal.repository.ExtraPackage;
import com.android.sdklib.internal.repository.Package; import com.android.sdklib.internal.repository.Package;
import com.android.sdklib.internal.repository.PlatformPackage; import com.android.sdklib.internal.repository.PlatformPackage;
import com.android.sdklib.internal.repository.RepoSource; import com.android.sdklib.internal.repository.RepoSource;
@@ -103,8 +104,8 @@ public class ImageFactory {
} else if (object instanceof DocPackage) { } else if (object instanceof DocPackage) {
return getImageByName("doc_icon16.png"); return getImageByName("doc_icon16.png");
} else if (object instanceof Package) { } else if (object instanceof ExtraPackage) {
return getImageByName("extra_pkg_icon16.png"); return getImageByName("extra_icon16.png");
} else if (object instanceof Archive) { } else if (object instanceof Archive) {
if (((Archive) object).isCompatible()) { if (((Archive) object).isCompatible()) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 485 B

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B