OSDN Git Service

merge from donut
[android-x86/development.git] / tools / sdkmanager / libs / sdklib / src / com / android / sdklib / PlatformTarget.java
1 /*
2  * Copyright (C) 2008 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;
18
19 import java.io.File;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.Map;
23
24 /**
25  * Represents a platform target in the SDK.
26  */
27 final class PlatformTarget implements IAndroidTarget {
28     /** String used to get a hash to the platform target */
29     private final static String PLATFORM_HASH = "android-%s";
30
31     private final static String PLATFORM_VENDOR = "Android Open Source Project";
32
33     private final static String PLATFORM_NAME = "Android %s";
34     private final static String PLATFORM_NAME_PREVIEW = "Android %s (Preview)";
35
36     private final String mLocation;
37     private final String mName;
38     private final AndroidVersion mVersion;
39     private final String mVersionName;
40     private final int mRevision;
41     private final Map<String, String> mProperties;
42     private final Map<Integer, String> mPaths = new HashMap<Integer, String>();
43     private String[] mSkins;
44
45
46     PlatformTarget(String location, Map<String, String> properties,
47             int apiLevel, String codeName, String versionName, int revision) {
48         if (location.endsWith(File.separator) == false) {
49             location = location + File.separator;
50         }
51         mLocation = location;
52         mProperties = Collections.unmodifiableMap(properties);
53         mVersion = new AndroidVersion(apiLevel, codeName);
54         mVersionName = versionName;
55         mRevision = revision;
56
57         if (mVersion.isPreview()) {
58             mName =  String.format(PLATFORM_NAME_PREVIEW, mVersionName);
59         } else {
60             mName = String.format(PLATFORM_NAME, mVersionName);
61         }
62
63         // pre-build the path to the platform components
64         mPaths.put(ANDROID_JAR, mLocation + SdkConstants.FN_FRAMEWORK_LIBRARY);
65         mPaths.put(SOURCES, mLocation + SdkConstants.FD_ANDROID_SOURCES);
66         mPaths.put(ANDROID_AIDL, mLocation + SdkConstants.FN_FRAMEWORK_AIDL);
67         mPaths.put(IMAGES, mLocation + SdkConstants.OS_IMAGES_FOLDER);
68         mPaths.put(SAMPLES, mLocation + SdkConstants.OS_PLATFORM_SAMPLES_FOLDER);
69         mPaths.put(SKINS, mLocation + SdkConstants.OS_SKINS_FOLDER);
70         mPaths.put(TEMPLATES, mLocation + SdkConstants.OS_PLATFORM_TEMPLATES_FOLDER);
71         mPaths.put(DATA, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER);
72         mPaths.put(ATTRIBUTES, mLocation + SdkConstants.OS_PLATFORM_ATTRS_XML);
73         mPaths.put(MANIFEST_ATTRIBUTES, mLocation + SdkConstants.OS_PLATFORM_ATTRS_MANIFEST_XML);
74         mPaths.put(RESOURCES, mLocation + SdkConstants.OS_PLATFORM_RESOURCES_FOLDER);
75         mPaths.put(FONTS, mLocation + SdkConstants.OS_PLATFORM_FONTS_FOLDER);
76         mPaths.put(LAYOUT_LIB, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER +
77                 SdkConstants.FN_LAYOUTLIB_JAR);
78         mPaths.put(WIDGETS, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER +
79                 SdkConstants.FN_WIDGETS);
80         mPaths.put(ACTIONS_ACTIVITY, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER +
81                 SdkConstants.FN_INTENT_ACTIONS_ACTIVITY);
82         mPaths.put(ACTIONS_BROADCAST, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER +
83                 SdkConstants.FN_INTENT_ACTIONS_BROADCAST);
84         mPaths.put(ACTIONS_SERVICE, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER +
85                 SdkConstants.FN_INTENT_ACTIONS_SERVICE);
86         mPaths.put(CATEGORIES, mLocation + SdkConstants.OS_PLATFORM_DATA_FOLDER +
87                 SdkConstants.FN_INTENT_CATEGORIES);
88         mPaths.put(AAPT, mLocation + SdkConstants.OS_SDK_TOOLS_FOLDER + SdkConstants.FN_AAPT);
89         mPaths.put(AIDL, mLocation + SdkConstants.OS_SDK_TOOLS_FOLDER + SdkConstants.FN_AIDL);
90         mPaths.put(DX, mLocation + SdkConstants.OS_SDK_TOOLS_FOLDER + SdkConstants.FN_DX);
91         mPaths.put(DX_JAR, mLocation + SdkConstants.OS_SDK_TOOLS_LIB_FOLDER +
92                 SdkConstants.FN_DX_JAR);
93     }
94
95     public String getLocation() {
96         return mLocation;
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * For Platform, the vendor name is always "Android".
103      *
104      * @see com.android.sdklib.IAndroidTarget#getVendor()
105      */
106     public String getVendor() {
107         return PLATFORM_VENDOR;
108     }
109
110     public String getName() {
111         return mName;
112     }
113
114     public String getFullName() {
115         return mName;
116     }
117
118     public String getClasspathName() {
119         return mName;
120     }
121
122     /*
123      * (non-Javadoc)
124      *
125      * Description for the Android platform is dynamically generated.
126      *
127      * @see com.android.sdklib.IAndroidTarget#getDescription()
128      */
129     public String getDescription() {
130         return String.format("Standard Android platform %s", mVersionName);
131     }
132
133     public AndroidVersion getVersion() {
134         return mVersion;
135     }
136
137     public String getVersionName() {
138         return mVersionName;
139     }
140
141     public int getRevision() {
142         return mRevision;
143     }
144
145     public boolean isPlatform() {
146         return true;
147     }
148
149     public IAndroidTarget getParent() {
150         return null;
151     }
152
153     public String getPath(int pathId) {
154         return mPaths.get(pathId);
155     }
156
157     public String[] getSkins() {
158         return mSkins;
159     }
160
161     public String getDefaultSkin() {
162         // at this time, this is the default skin for all the platform.
163         return "HVGA";
164     }
165
166     /**
167      * Always returns null, as a standard platform ha no optional libraries.
168      *
169      * {@inheritDoc}
170      * @see com.android.sdklib.IAndroidTarget#getOptionalLibraries()
171      */
172     public IOptionalLibrary[] getOptionalLibraries() {
173         return null;
174     }
175
176     /**
177      * Currently always return a fixed list with "android.test.runner" in it.
178      * <p/>
179      * TODO change the fixed library list to be build-dependent later.
180      * {@inheritDoc}
181      */
182     public String[] getPlatformLibraries() {
183         return new String[] { SdkConstants.ANDROID_TEST_RUNNER_LIB };
184     }
185
186     /**
187      * The platform has no USB Vendor Id: always return {@link IAndroidTarget#NO_USB_ID}.
188      * {@inheritDoc}
189      */
190     public int getUsbVendorId() {
191         return NO_USB_ID;
192     }
193
194     public boolean isCompatibleBaseFor(IAndroidTarget target) {
195         // basic test
196         if (target == this) {
197             return true;
198         }
199
200         // if the platform has a codename (ie it's a preview of an upcoming platform), then
201         // both platforms must be exactly identical.
202         if (mVersion.getCodename() != null) {
203             return mVersion.equals(target.getVersion());
204         }
205
206         // target is compatible wit the receiver as long as its api version number is greater or
207         // equal.
208         return target.getVersion().getApiLevel() >= mVersion.getApiLevel();
209     }
210
211     public String hashString() {
212         return String.format(PLATFORM_HASH, mVersion.getApiString());
213     }
214
215     @Override
216     public int hashCode() {
217         return hashString().hashCode();
218     }
219
220     @Override
221     public boolean equals(Object obj) {
222         if (obj instanceof PlatformTarget) {
223             PlatformTarget platform = (PlatformTarget)obj;
224
225             return mVersion.equals(platform.getVersion());
226         }
227
228         return false;
229     }
230
231     /*
232      * Always return -1 if the object we compare to is an addon.
233      * Otherwise, compare api level.
234      * (non-Javadoc)
235      * @see java.lang.Comparable#compareTo(java.lang.Object)
236      */
237     public int compareTo(IAndroidTarget target) {
238         if (target.isPlatform() == false) {
239             return -1;
240         }
241
242         int apiDiff = mVersion.getApiLevel() - target.getVersion().getApiLevel();
243
244         if (mVersion.getCodename() != null && apiDiff == 0) {
245             if (target.getVersion().getCodename() == null) {
246                 return +1; // preview showed last
247             }
248             return mVersion.getCodename().compareTo(target.getVersion().getCodename());
249         }
250
251         return apiDiff;
252     }
253
254     // ---- platform only methods.
255
256     public String getProperty(String name) {
257         return mProperties.get(name);
258     }
259
260     public Map<String, String> getProperties() {
261         return mProperties; // mProperties is unmodifiable.
262     }
263
264     void setSkins(String[] skins) {
265         mSkins = skins;
266     }
267 }