OSDN Git Service

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