]> git.saurik.com Git - android/aapt.git/blame - Bundle.h
Add --error-on-failed-insert option to aapt. do not merge.
[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),
b1bccba1 56 mIsOverlayPackage(false),
52ffc169 57 mAutoAddOverlay(false), mGenDependencies(false),
dddb1fc7
JG
58 mAssetSourceDir(NULL),
59 mCrunchedOutputDir(NULL), mProguardFile(NULL),
a534180c 60 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
5af43148 61 mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
53288885 62 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
bc7b4f40 63 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
54f200b0 64 mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
a1cc551d 65 mUseCrunchCache(false), mErrorOnFailedInsert(false), mOutputTextSymbols(NULL),
d4ee3b30 66 mArgc(0), mArgv(NULL)
a534180c
TAOSP
67 {}
68 ~Bundle(void) {}
69
70 /*
71 * Set the command value. Returns "false" if it was previously set.
72 */
73 Command getCommand(void) const { return mCmd; }
74 void setCommand(Command cmd) { mCmd = cmd; }
75
76 /*
77 * Command modifiers. Not all modifiers are appropriate for all
78 * commands.
79 */
80 bool getVerbose(void) const { return mVerbose; }
81 void setVerbose(bool val) { mVerbose = val; }
82 bool getAndroidList(void) const { return mAndroidList; }
83 void setAndroidList(bool val) { mAndroidList = val; }
84 bool getForce(void) const { return mForce; }
85 void setForce(bool val) { mForce = val; }
86 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
c5d0eefd 87 int getGrayscaleTolerance() const { return mGrayscaleTolerance; }
a534180c
TAOSP
88 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
89 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
90 bool getUpdate(void) const { return mUpdate; }
91 void setUpdate(bool val) { mUpdate = val; }
92 bool getExtending(void) const { return mExtending; }
93 void setExtending(bool val) { mExtending = val; }
94 bool getRequireLocalization(void) const { return mRequireLocalization; }
95 void setRequireLocalization(bool val) { mRequireLocalization = val; }
96 bool getPseudolocalize(void) const { return mPseudolocalize; }
97 void setPseudolocalize(bool val) { mPseudolocalize = val; }
5af43148 98 void setWantUTF16(bool val) { mWantUTF16 = val; }
7751daa4
DH
99 bool getValues(void) const { return mValues; }
100 void setValues(bool val) { mValues = val; }
a534180c
TAOSP
101 int getCompressionMethod(void) const { return mCompressionMethod; }
102 void setCompressionMethod(int val) { mCompressionMethod = val; }
1e8883fc
DZ
103 bool getJunkPath(void) const { return mJunkPath; }
104 void setJunkPath(bool val) { mJunkPath = val; }
a534180c
TAOSP
105 const char* getOutputAPKFile() const { return mOutputAPKFile; }
106 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
094e8965
JH
107 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
108 void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
af945cf3
DH
109 const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
110 void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
b1bccba1
MK
111 bool getIsOverlayPackage() const { return mIsOverlayPackage; }
112 void setIsOverlayPackage(bool val) { mIsOverlayPackage = val; }
636d3b70
XD
113 bool getAutoAddOverlay() { return mAutoAddOverlay; }
114 void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
52ffc169
JG
115 bool getGenDependencies() { return mGenDependencies; }
116 void setGenDependencies(bool val) { mGenDependencies = val; }
a1cc551d
XD
117 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
118 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
a534180c 119
4f41c7f7
DH
120 bool getUTF16StringsOption() {
121 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
122 }
123
1e8883fc
DZ
124 /*
125 * Input options.
a534180c
TAOSP
126 */
127 const char* getAssetSourceDir() const { return mAssetSourceDir; }
128 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
dddb1fc7
JG
129 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
130 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
6648ff78
JO
131 const char* getProguardFile() const { return mProguardFile; }
132 void setProguardFile(const char* file) { mProguardFile = file; }
a534180c
TAOSP
133 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
134 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
135 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
136 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
137 const char* getPublicOutputFile() const { return mPublicOutputFile; }
138 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
139 const char* getRClassDir() const { return mRClassDir; }
140 void setRClassDir(const char* dir) { mRClassDir = dir; }
141 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
142 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
e29f4ada
DH
143 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
144 void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } }
a534180c
TAOSP
145 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
146 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
147 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
148 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
149 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
150 void addJarFile(const char* file) { mJarFiles.add(file); }
151 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
152 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
153
5af43148
KR
154 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
155 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
7e486e33 156 const char* getMinSdkVersion() const { return mMinSdkVersion; }
5af43148 157 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
7e486e33
DH
158 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
159 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
160 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
161 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
162 const char* getVersionCode() const { return mVersionCode; }
163 void setVersionCode(const char* val) { mVersionCode = val; }
164 const char* getVersionName() const { return mVersionName; }
165 void setVersionName(const char* val) { mVersionName = val; }
fa19db5e
XD
166 const char* getCustomPackage() const { return mCustomPackage; }
167 void setCustomPackage(const char* val) { mCustomPackage = val; }
bc7b4f40
JG
168 const char* getExtraPackages() const { return mExtraPackages; }
169 void setExtraPackages(const char* val) { mExtraPackages = val; }
73412e58
FK
170 const char* getMaxResVersion() const { return mMaxResVersion; }
171 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
c5d0eefd 172 bool getDebugMode() const { return mDebugMode; }
f04c74b7 173 void setDebugMode(bool val) { mDebugMode = val; }
c5d0eefd 174 bool getNonConstantId() const { return mNonConstantId; }
54f200b0 175 void setNonConstantId(bool val) { mNonConstantId = val; }
b8ea3a3f
EF
176 const char* getProduct() const { return mProduct; }
177 void setProduct(const char * val) { mProduct = val; }
dddb1fc7 178 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
c5d0eefd 179 bool getUseCrunchCache() const { return mUseCrunchCache; }
d4ee3b30
XD
180 const char* getOutputTextSymbols() const { return mOutputTextSymbols; }
181 void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; }
1e8883fc 182
a534180c
TAOSP
183 /*
184 * Set and get the file specification.
185 *
186 * Note this does NOT make a copy of argv.
187 */
188 void setFileSpec(char* const argv[], int argc) {
189 mArgc = argc;
190 mArgv = argv;
191 }
192 int getFileSpecCount(void) const { return mArgc; }
193 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
194 void eatArgs(int n) {
195 if (n > mArgc) n = mArgc;
196 mArgv += n;
197 mArgc -= n;
198 }
199
200#if 0
201 /*
202 * Package count. Nothing to do with anything else here; this is
203 * just a convenient place to stuff it so we don't have to pass it
204 * around everywhere.
205 */
206 int getPackageCount(void) const { return mPackageCount; }
207 void setPackageCount(int val) { mPackageCount = val; }
208#endif
209
1bad9d29
KR
210 /* Certain features may only be available on a specific SDK level or
211 * above. SDK levels that have a non-numeric identifier are assumed
212 * to be newer than any SDK level that has a number designated.
5af43148 213 */
1bad9d29 214 bool isMinSdkAtLeast(int desired) {
5af43148
KR
215 /* If the application specifies a minSdkVersion in the manifest
216 * then use that. Otherwise, check what the user specified on
217 * the command line. If neither, it's not available since
218 * the minimum SDK version is assumed to be 1.
219 */
220 const char *minVer;
221 if (mManifestMinSdkVersion != NULL) {
222 minVer = mManifestMinSdkVersion;
223 } else if (mMinSdkVersion != NULL) {
224 minVer = mMinSdkVersion;
225 } else {
226 return false;
227 }
228
229 char *end;
230 int minSdkNum = (int)strtol(minVer, &end, 0);
231 if (*end == '\0') {
1bad9d29 232 if (minSdkNum < desired) {
5af43148
KR
233 return false;
234 }
235 }
236 return true;
237 }
238
a534180c
TAOSP
239private:
240 /* commands & modifiers */
241 Command mCmd;
242 bool mVerbose;
243 bool mAndroidList;
244 bool mForce;
245 int mGrayscaleTolerance;
246 bool mMakePackageDirs;
247 bool mUpdate;
248 bool mExtending;
249 bool mRequireLocalization;
250 bool mPseudolocalize;
5af43148 251 bool mWantUTF16;
7751daa4 252 bool mValues;
a534180c 253 int mCompressionMethod;
1e8883fc 254 bool mJunkPath;
a534180c 255 const char* mOutputAPKFile;
094e8965 256 const char* mManifestPackageNameOverride;
af945cf3 257 const char* mInstrumentationPackageNameOverride;
b1bccba1 258 bool mIsOverlayPackage;
636d3b70 259 bool mAutoAddOverlay;
52ffc169 260 bool mGenDependencies;
a534180c 261 const char* mAssetSourceDir;
dddb1fc7 262 const char* mCrunchedOutputDir;
6648ff78 263 const char* mProguardFile;
a534180c
TAOSP
264 const char* mAndroidManifestFile;
265 const char* mPublicOutputFile;
266 const char* mRClassDir;
267 const char* mResourceIntermediatesDir;
268 android::String8 mConfigurations;
e29f4ada 269 android::String8 mPreferredConfigurations;
a534180c
TAOSP
270 android::Vector<const char*> mPackageIncludes;
271 android::Vector<const char*> mJarFiles;
272 android::Vector<const char*> mNoCompressExtensions;
273 android::Vector<const char*> mResourceSourceDirs;
1e8883fc 274
5af43148 275 const char* mManifestMinSdkVersion;
7e486e33
DH
276 const char* mMinSdkVersion;
277 const char* mTargetSdkVersion;
278 const char* mMaxSdkVersion;
279 const char* mVersionCode;
280 const char* mVersionName;
fa19db5e 281 const char* mCustomPackage;
bc7b4f40 282 const char* mExtraPackages;
73412e58 283 const char* mMaxResVersion;
f04c74b7 284 bool mDebugMode;
54f200b0 285 bool mNonConstantId;
b8ea3a3f 286 const char* mProduct;
dddb1fc7 287 bool mUseCrunchCache;
a1cc551d 288 bool mErrorOnFailedInsert;
d4ee3b30 289 const char* mOutputTextSymbols;
1e8883fc 290
a534180c
TAOSP
291 /* file specification */
292 int mArgc;
293 char* const* mArgv;
294
295#if 0
296 /* misc stuff */
297 int mPackageCount;
298#endif
7dc0cd41 299
a534180c
TAOSP
300};
301
302#endif // __BUNDLE_H