2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.sdklib;
20 import java.util.Collections;
21 import java.util.HashMap;
25 * Represents a platform target in the SDK.
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";
31 private final static String PLATFORM_VENDOR = "Android Open Source Project";
33 private final static String PLATFORM_NAME = "Android %s";
34 private final static String PLATFORM_NAME_PREVIEW = "Android %s (Preview)";
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;
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;
52 mProperties = Collections.unmodifiableMap(properties);
53 mVersion = new AndroidVersion(apiLevel, codeName);
54 mVersionName = versionName;
57 if (mVersion.isPreview()) {
58 mName = String.format(PLATFORM_NAME_PREVIEW, mVersionName);
60 mName = String.format(PLATFORM_NAME, mVersionName);
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);
95 public String getLocation() {
102 * For Platform, the vendor name is always "Android".
104 * @see com.android.sdklib.IAndroidTarget#getVendor()
106 public String getVendor() {
107 return PLATFORM_VENDOR;
110 public String getName() {
114 public String getFullName() {
118 public String getClasspathName() {
125 * Description for the Android platform is dynamically generated.
127 * @see com.android.sdklib.IAndroidTarget#getDescription()
129 public String getDescription() {
130 return String.format("Standard Android platform %s", mVersionName);
133 public AndroidVersion getVersion() {
137 public String getVersionName() {
141 public int getRevision() {
145 public boolean isPlatform() {
149 public IAndroidTarget getParent() {
153 public String getPath(int pathId) {
154 return mPaths.get(pathId);
157 public String[] getSkins() {
161 public String getDefaultSkin() {
162 // at this time, this is the default skin for all the platform.
167 * Always returns null, as a standard platform ha no optional libraries.
170 * @see com.android.sdklib.IAndroidTarget#getOptionalLibraries()
172 public IOptionalLibrary[] getOptionalLibraries() {
177 * Currently always return a fixed list with "android.test.runner" in it.
179 * TODO change the fixed library list to be build-dependent later.
182 public String[] getPlatformLibraries() {
183 return new String[] { SdkConstants.ANDROID_TEST_RUNNER_LIB };
187 * The platform has no USB Vendor Id: always return {@link IAndroidTarget#NO_USB_ID}.
190 public int getUsbVendorId() {
194 public boolean isCompatibleBaseFor(IAndroidTarget target) {
196 if (target == this) {
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());
206 // target is compatible wit the receiver as long as its api version number is greater or
208 return target.getVersion().getApiLevel() >= mVersion.getApiLevel();
211 public String hashString() {
212 return String.format(PLATFORM_HASH, mVersion.getApiString());
216 public int hashCode() {
217 return hashString().hashCode();
221 public boolean equals(Object obj) {
222 if (obj instanceof PlatformTarget) {
223 PlatformTarget platform = (PlatformTarget)obj;
225 return mVersion.equals(platform.getVersion());
232 * Always return -1 if the object we compare to is an addon.
233 * Otherwise, compare api level.
235 * @see java.lang.Comparable#compareTo(java.lang.Object)
237 public int compareTo(IAndroidTarget target) {
238 if (target.isPlatform() == false) {
242 int apiDiff = mVersion.getApiLevel() - target.getVersion().getApiLevel();
244 if (mVersion.getCodename() != null && apiDiff == 0) {
245 if (target.getVersion().getCodename() == null) {
246 return +1; // preview showed last
248 return mVersion.getCodename().compareTo(target.getVersion().getCodename());
254 // ---- platform only methods.
256 public String getProperty(String name) {
257 return mProperties.get(name);
260 public Map<String, String> getProperties() {
261 return mProperties; // mProperties is unmodifiable.
264 void setSkins(String[] skins) {