]> git.saurik.com Git - android/aapt.git/blob - Bundle.h
am 72669b5f: am 13a0271c: Merge "Add aapt support for generating proguard rules for...
[android/aapt.git] / Bundle.h
1 //
2 // Copyright 2006 The Android Open Source Project
3 //
4 // State bundle. Used to pass around stuff like command-line args.
5 //
6 #ifndef __BUNDLE_H
7 #define __BUNDLE_H
8
9 #include <stdlib.h>
10 #include <utils/Log.h>
11 #include <utils/threads.h>
12 #include <utils/List.h>
13 #include <utils/Errors.h>
14 #include <utils/String8.h>
15 #include <utils/Vector.h>
16
17 enum {
18 SDK_CUPCAKE = 3,
19 SDK_DONUT = 4,
20 SDK_ECLAIR = 5,
21 SDK_ECLAIR_0_1 = 6,
22 SDK_MR1 = 7,
23 SDK_FROYO = 8,
24 SDK_HONEYCOMB_MR2 = 13,
25 SDK_ICE_CREAM_SANDWICH = 14,
26 SDK_ICE_CREAM_SANDWICH_MR1 = 15,
27 };
28
29 /*
30 * Things we can do.
31 */
32 typedef enum Command {
33 kCommandUnknown = 0,
34 kCommandVersion,
35 kCommandList,
36 kCommandDump,
37 kCommandAdd,
38 kCommandRemove,
39 kCommandPackage,
40 kCommandCrunch,
41 } Command;
42
43 /*
44 * Bundle of goodies, including everything specified on the command line.
45 */
46 class Bundle {
47 public:
48 Bundle(void)
49 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
50 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
51 mUpdate(false), mExtending(false),
52 mRequireLocalization(false), mPseudolocalize(false),
53 mWantUTF16(false), mValues(false),
54 mCompressionMethod(0), mOutputAPKFile(NULL),
55 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
56 mAutoAddOverlay(false), mGenDependencies(false),
57 mAssetSourceDir(NULL),
58 mCrunchedOutputDir(NULL), mProguardFile(NULL),
59 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
60 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
61 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
62 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
63 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
64 mUseCrunchCache(false), mArgc(0), mArgv(NULL)
65 {}
66 ~Bundle(void) {}
67
68 /*
69 * Set the command value. Returns "false" if it was previously set.
70 */
71 Command getCommand(void) const { return mCmd; }
72 void setCommand(Command cmd) { mCmd = cmd; }
73
74 /*
75 * Command modifiers. Not all modifiers are appropriate for all
76 * commands.
77 */
78 bool getVerbose(void) const { return mVerbose; }
79 void setVerbose(bool val) { mVerbose = val; }
80 bool getAndroidList(void) const { return mAndroidList; }
81 void setAndroidList(bool val) { mAndroidList = val; }
82 bool getForce(void) const { return mForce; }
83 void setForce(bool val) { mForce = val; }
84 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
85 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
86 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
87 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
88 bool getUpdate(void) const { return mUpdate; }
89 void setUpdate(bool val) { mUpdate = val; }
90 bool getExtending(void) const { return mExtending; }
91 void setExtending(bool val) { mExtending = val; }
92 bool getRequireLocalization(void) const { return mRequireLocalization; }
93 void setRequireLocalization(bool val) { mRequireLocalization = val; }
94 bool getPseudolocalize(void) const { return mPseudolocalize; }
95 void setPseudolocalize(bool val) { mPseudolocalize = val; }
96 void setWantUTF16(bool val) { mWantUTF16 = val; }
97 bool getValues(void) const { return mValues; }
98 void setValues(bool val) { mValues = val; }
99 int getCompressionMethod(void) const { return mCompressionMethod; }
100 void setCompressionMethod(int val) { mCompressionMethod = val; }
101 bool getJunkPath(void) const { return mJunkPath; }
102 void setJunkPath(bool val) { mJunkPath = val; }
103 const char* getOutputAPKFile() const { return mOutputAPKFile; }
104 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
105 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
106 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
107 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
108 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
109 bool getAutoAddOverlay() { return mAutoAddOverlay; }
110 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
111 bool getGenDependencies() { return mGenDependencies; }
112 void setGenDependencies(bool val) { mGenDependencies = val; }
113
114 bool getUTF16StringsOption() {
115 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
116 }
117
118 /*
119 * Input options.
120 */
121 const char* getAssetSourceDir() const { return mAssetSourceDir; }
122 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
123 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
124 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
125 const char* getProguardFile() const { return mProguardFile; }
126 void setProguardFile(const char* file) { mProguardFile = file; }
127 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
128 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
129 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
130 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
131 const char* getPublicOutputFile() const { return mPublicOutputFile; }
132 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
133 const char* getRClassDir() const { return mRClassDir; }
134 void setRClassDir(const char* dir) { mRClassDir = dir; }
135 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
136 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
137 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
138 void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } }
139 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
140 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
141 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
142 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
143 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
144 void addJarFile(const char* file) { mJarFiles.add(file); }
145 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
146 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
147
148 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
149 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
150 const char* getMinSdkVersion() const { return mMinSdkVersion; }
151 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
152 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
153 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
154 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
155 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
156 const char* getVersionCode() const { return mVersionCode; }
157 void setVersionCode(const char* val) { mVersionCode = val; }
158 const char* getVersionName() const { return mVersionName; }
159 void setVersionName(const char* val) { mVersionName = val; }
160 const char* getCustomPackage() const { return mCustomPackage; }
161 void setCustomPackage(const char* val) { mCustomPackage = val; }
162 const char* getExtraPackages() const { return mExtraPackages; }
163 void setExtraPackages(const char* val) { mExtraPackages = val; }
164 const char* getMaxResVersion() const { return mMaxResVersion; }
165 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
166 bool getDebugMode() const { return mDebugMode; }
167 void setDebugMode(bool val) { mDebugMode = val; }
168 bool getNonConstantId() const { return mNonConstantId; }
169 void setNonConstantId(bool val) { mNonConstantId = val; }
170 const char* getProduct() const { return mProduct; }
171 void setProduct(const char * val) { mProduct = val; }
172 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
173 bool getUseCrunchCache() const { return mUseCrunchCache; }
174
175 /*
176 * Set and get the file specification.
177 *
178 * Note this does NOT make a copy of argv.
179 */
180 void setFileSpec(char* const argv[], int argc) {
181 mArgc = argc;
182 mArgv = argv;
183 }
184 int getFileSpecCount(void) const { return mArgc; }
185 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
186 void eatArgs(int n) {
187 if (n > mArgc) n = mArgc;
188 mArgv += n;
189 mArgc -= n;
190 }
191
192 #if 0
193 /*
194 * Package count. Nothing to do with anything else here; this is
195 * just a convenient place to stuff it so we don't have to pass it
196 * around everywhere.
197 */
198 int getPackageCount(void) const { return mPackageCount; }
199 void setPackageCount(int val) { mPackageCount = val; }
200 #endif
201
202 /* Certain features may only be available on a specific SDK level or
203 * above. SDK levels that have a non-numeric identifier are assumed
204 * to be newer than any SDK level that has a number designated.
205 */
206 bool isMinSdkAtLeast(int desired) {
207 /* If the application specifies a minSdkVersion in the manifest
208 * then use that. Otherwise, check what the user specified on
209 * the command line. If neither, it's not available since
210 * the minimum SDK version is assumed to be 1.
211 */
212 const char *minVer;
213 if (mManifestMinSdkVersion != NULL) {
214 minVer = mManifestMinSdkVersion;
215 } else if (mMinSdkVersion != NULL) {
216 minVer = mMinSdkVersion;
217 } else {
218 return false;
219 }
220
221 char *end;
222 int minSdkNum = (int)strtol(minVer, &end, 0);
223 if (*end == '\0') {
224 if (minSdkNum < desired) {
225 return false;
226 }
227 }
228 return true;
229 }
230
231 private:
232 /* commands & modifiers */
233 Command mCmd;
234 bool mVerbose;
235 bool mAndroidList;
236 bool mForce;
237 int mGrayscaleTolerance;
238 bool mMakePackageDirs;
239 bool mUpdate;
240 bool mExtending;
241 bool mRequireLocalization;
242 bool mPseudolocalize;
243 bool mWantUTF16;
244 bool mValues;
245 int mCompressionMethod;
246 bool mJunkPath;
247 const char* mOutputAPKFile;
248 const char* mManifestPackageNameOverride;
249 const char* mInstrumentationPackageNameOverride;
250 bool mAutoAddOverlay;
251 bool mGenDependencies;
252 const char* mAssetSourceDir;
253 const char* mCrunchedOutputDir;
254 const char* mProguardFile;
255 const char* mAndroidManifestFile;
256 const char* mPublicOutputFile;
257 const char* mRClassDir;
258 const char* mResourceIntermediatesDir;
259 android::String8 mConfigurations;
260 android::String8 mPreferredConfigurations;
261 android::Vector<const char*> mPackageIncludes;
262 android::Vector<const char*> mJarFiles;
263 android::Vector<const char*> mNoCompressExtensions;
264 android::Vector<const char*> mResourceSourceDirs;
265
266 const char* mManifestMinSdkVersion;
267 const char* mMinSdkVersion;
268 const char* mTargetSdkVersion;
269 const char* mMaxSdkVersion;
270 const char* mVersionCode;
271 const char* mVersionName;
272 const char* mCustomPackage;
273 const char* mExtraPackages;
274 const char* mMaxResVersion;
275 bool mDebugMode;
276 bool mNonConstantId;
277 const char* mProduct;
278 bool mUseCrunchCache;
279
280 /* file specification */
281 int mArgc;
282 char* const* mArgv;
283
284 #if 0
285 /* misc stuff */
286 int mPackageCount;
287 #endif
288
289 };
290
291 #endif // __BUNDLE_H