]> git.saurik.com Git - android/aapt.git/blame - Bundle.h
am ac9f5057: am 996b073e: Fix length of pattern.
[android/aapt.git] / Bundle.h
CommitLineData
a534180c
TAOSP
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>
79e5d372
MA
10#include <utils/Log.h>
11#include <utils/threads.h>
12#include <utils/List.h>
13#include <utils/Errors.h>
a534180c
TAOSP
14#include <utils/String8.h>
15#include <utils/Vector.h>
16
4f41c7f7
DH
17enum {
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
a534180c
TAOSP
29/*
30 * Things we can do.
31 */
32typedef enum Command {
33 kCommandUnknown = 0,
34 kCommandVersion,
35 kCommandList,
36 kCommandDump,
37 kCommandAdd,
38 kCommandRemove,
39 kCommandPackage,
dddb1fc7 40 kCommandCrunch,
a534180c
TAOSP
41} Command;
42
43/*
44 * Bundle of goodies, including everything specified on the command line.
45 */
46class Bundle {
47public:
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),
5af43148 53 mWantUTF16(false), mValues(false),
af945cf3
DH
54 mCompressionMethod(0), mOutputAPKFile(NULL),
55 mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
52ffc169 56 mAutoAddOverlay(false), mGenDependencies(false),
dddb1fc7
JG
57 mAssetSourceDir(NULL),
58 mCrunchedOutputDir(NULL), mProguardFile(NULL),
a534180c 59 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
5af43148 60 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
53288885 61 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
bc7b4f40 62 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
54f200b0 63 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
dddb1fc7 64 mUseCrunchCache(false), mArgc(0), mArgv(NULL)
a534180c
TAOSP
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; }
c5d0eefd 85 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
a534180c
TAOSP
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; }
5af43148 96 void setWantUTF16(bool val) { mWantUTF16 = val; }
7751daa4
DH
97 bool getValues(void) const { return mValues; }
98 void setValues(bool val) { mValues = val; }
a534180c
TAOSP
99 int getCompressionMethod(void) const { return mCompressionMethod; }
100 void setCompressionMethod(int val) { mCompressionMethod = val; }
1e8883fc
DZ
101 bool getJunkPath(void) const { return mJunkPath; }
102 void setJunkPath(bool val) { mJunkPath = val; }
a534180c
TAOSP
103 const char* getOutputAPKFile() const { return mOutputAPKFile; }
104 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
094e8965
JH
105 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
106 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
af945cf3
DH
107 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
108 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
636d3b70
XD
109 bool getAutoAddOverlay() { return mAutoAddOverlay; }
110 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
52ffc169
JG
111 bool getGenDependencies() { return mGenDependencies; }
112 void setGenDependencies(bool val) { mGenDependencies = val; }
a534180c 113
4f41c7f7
DH
114 bool getUTF16StringsOption() {
115 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
116 }
117
1e8883fc
DZ
118 /*
119 * Input options.
a534180c
TAOSP
120 */
121 const char* getAssetSourceDir() const { return mAssetSourceDir; }
122 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
dddb1fc7
JG
123 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
124 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
6648ff78
JO
125 const char* getProguardFile() const { return mProguardFile; }
126 void setProguardFile(const char* file) { mProguardFile = file; }
a534180c
TAOSP
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; } }
e29f4ada
DH
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; } }
a534180c
TAOSP
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
5af43148
KR
148 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
149 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
7e486e33 150 const char* getMinSdkVersion() const { return mMinSdkVersion; }
5af43148 151 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
7e486e33
DH
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; }
fa19db5e
XD
160 const char* getCustomPackage() const { return mCustomPackage; }
161 void setCustomPackage(const char* val) { mCustomPackage = val; }
bc7b4f40
JG
162 const char* getExtraPackages() const { return mExtraPackages; }
163 void setExtraPackages(const char* val) { mExtraPackages = val; }
73412e58
FK
164 const char* getMaxResVersion() const { return mMaxResVersion; }
165 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
c5d0eefd 166 bool getDebugMode() const { return mDebugMode; }
f04c74b7 167 void setDebugMode(bool val) { mDebugMode = val; }
c5d0eefd 168 bool getNonConstantId() const { return mNonConstantId; }
54f200b0 169 void setNonConstantId(bool val) { mNonConstantId = val; }
b8ea3a3f
EF
170 const char* getProduct() const { return mProduct; }
171 void setProduct(const char * val) { mProduct = val; }
dddb1fc7 172 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
c5d0eefd 173 bool getUseCrunchCache() const { return mUseCrunchCache; }
1e8883fc 174
a534180c
TAOSP
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
1bad9d29
KR
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.
5af43148 205 */
1bad9d29 206 bool isMinSdkAtLeast(int desired) {
5af43148
KR
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') {
1bad9d29 224 if (minSdkNum < desired) {
5af43148
KR
225 return false;
226 }
227 }
228 return true;
229 }
230
a534180c
TAOSP
231private:
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;
5af43148 243 bool mWantUTF16;
7751daa4 244 bool mValues;
a534180c 245 int mCompressionMethod;
1e8883fc 246 bool mJunkPath;
a534180c 247 const char* mOutputAPKFile;
094e8965 248 const char* mManifestPackageNameOverride;
af945cf3 249 const char* mInstrumentationPackageNameOverride;
636d3b70 250 bool mAutoAddOverlay;
52ffc169 251 bool mGenDependencies;
a534180c 252 const char* mAssetSourceDir;
dddb1fc7 253 const char* mCrunchedOutputDir;
6648ff78 254 const char* mProguardFile;
a534180c
TAOSP
255 const char* mAndroidManifestFile;
256 const char* mPublicOutputFile;
257 const char* mRClassDir;
258 const char* mResourceIntermediatesDir;
259 android::String8 mConfigurations;
e29f4ada 260 android::String8 mPreferredConfigurations;
a534180c
TAOSP
261 android::Vector<const char*> mPackageIncludes;
262 android::Vector<const char*> mJarFiles;
263 android::Vector<const char*> mNoCompressExtensions;
264 android::Vector<const char*> mResourceSourceDirs;
1e8883fc 265
5af43148 266 const char* mManifestMinSdkVersion;
7e486e33
DH
267 const char* mMinSdkVersion;
268 const char* mTargetSdkVersion;
269 const char* mMaxSdkVersion;
270 const char* mVersionCode;
271 const char* mVersionName;
fa19db5e 272 const char* mCustomPackage;
bc7b4f40 273 const char* mExtraPackages;
73412e58 274 const char* mMaxResVersion;
f04c74b7 275 bool mDebugMode;
54f200b0 276 bool mNonConstantId;
b8ea3a3f 277 const char* mProduct;
dddb1fc7 278 bool mUseCrunchCache;
1e8883fc 279
a534180c
TAOSP
280 /* file specification */
281 int mArgc;
282 char* const* mArgv;
283
284#if 0
285 /* misc stuff */
286 int mPackageCount;
287#endif
7dc0cd41 288
a534180c
TAOSP
289};
290
291#endif // __BUNDLE_H