• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.sdklib.internal.repository;
18 
19 import com.android.sdklib.internal.repository.Archive.Arch;
20 import com.android.sdklib.internal.repository.Archive.Os;
21 import com.android.sdklib.repository.SdkRepository;
22 
23 import org.w3c.dom.Node;
24 
25 import java.util.Map;
26 import java.util.Properties;
27 
28 /**
29  * Represents an XML node in an SDK repository that has a min-tools-rev requirement.
30  * This is either a {@link PlatformPackage} or an {@link ExtraPackage}.
31  */
32 public abstract class MinToolsPackage extends Package {
33 
34     protected static final String PROP_MIN_TOOLS_REV = "Platform.MinToolsRev";  //$NON-NLS-1$
35 
36     /**
37      * The minimal revision of the tools package required by this extra package, if > 0,
38      * or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
39      */
40     private final int mMinToolsRevision;
41 
42     /**
43      * The value of {@link #mMinToolsRevision} when the {@link SdkRepository#NODE_MIN_TOOLS_REV}
44      * was not specified in the XML source.
45      */
46     public static final int MIN_TOOLS_REV_NOT_SPECIFIED = 0;
47 
48     /**
49      * Creates a new package from the attributes and elements of the given XML node.
50      * <p/>
51      * This constructor should throw an exception if the package cannot be created.
52      */
MinToolsPackage(RepoSource source, Node packageNode, Map<String,String> licenses)53     MinToolsPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
54         super(source, packageNode, licenses);
55 
56         mMinToolsRevision = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_MIN_TOOLS_REV,
57                 MIN_TOOLS_REV_NOT_SPECIFIED);
58     }
59 
60     /**
61      * Manually create a new package with one archive and the given attributes.
62      * This is used to create packages from local directories in which case there must be
63      * one archive which URL is the actual target location.
64      * <p/>
65      * Properties from props are used first when possible, e.g. if props is non null.
66      * <p/>
67      * By design, this creates a package with one and only one archive.
68      */
MinToolsPackage( RepoSource source, Properties props, int revision, String license, String description, String descUrl, Os archiveOs, Arch archiveArch, String archiveOsPath)69     public MinToolsPackage(
70             RepoSource source,
71             Properties props,
72             int revision,
73             String license,
74             String description,
75             String descUrl,
76             Os archiveOs,
77             Arch archiveArch,
78             String archiveOsPath) {
79         super(source, props, revision, license, description, descUrl,
80                 archiveOs, archiveArch, archiveOsPath);
81 
82         mMinToolsRevision = Integer.parseInt(getProperty(props, PROP_MIN_TOOLS_REV,
83                 Integer.toString(MIN_TOOLS_REV_NOT_SPECIFIED)));
84     }
85 
86     /**
87      * The minimal revision of the tools package required by this extra package, if > 0,
88      * or {@link #MIN_TOOLS_REV_NOT_SPECIFIED} if there is no such requirement.
89      */
getMinToolsRevision()90     public int getMinToolsRevision() {
91         return mMinToolsRevision;
92     }
93 }
94