]> git.saurik.com Git - android/aapt.git/blob - Bundle.h
Add --error-on-failed-insert option to aapt.
[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), mJunkPath(false), 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), mErrorOnFailedInsert(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 bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
114 void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
115
116 bool getUTF16StringsOption() {
117 return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
118 }
119
120 /*
121 * Input options.
122 */
123 const char* getAssetSourceDir() const { return mAssetSourceDir; }
124 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
125 const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
126 void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
127 const char* getProguardFile() const { return mProguardFile; }
128 void setProguardFile(const char* file) { mProguardFile = file; }
129 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
130 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
131 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
132 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
133 const char* getPublicOutputFile() const { return mPublicOutputFile; }
134 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
135 const char* getRClassDir() const { return mRClassDir; }
136 void setRClassDir(const char* dir) { mRClassDir = dir; }
137 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
138 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
139 const char* getPreferredConfigurations() const { return mPreferredConfigurations.size() > 0 ? mPreferredConfigurations.string() : NULL; }
140 void addPreferredConfigurations(const char* val) { if (mPreferredConfigurations.size() > 0) { mPreferredConfigurations.append(","); mPreferredConfigurations.append(val); } else { mPreferredConfigurations = val; } }
141 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
142 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
143 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
144 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
145 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
146 void addJarFile(const char* file) { mJarFiles.add(file); }
147 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
148 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
149
150 const char* getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
151 void setManifestMinSdkVersion(const char* val) { mManifestMinSdkVersion = val; }
152 const char* getMinSdkVersion() const { return mMinSdkVersion; }
153 void setMinSdkVersion(const char* val) { mMinSdkVersion = val; }
154 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
155 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
156 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
157 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
158 const char* getVersionCode() const { return mVersionCode; }
159 void setVersionCode(const char* val) { mVersionCode = val; }
160 const char* getVersionName() const { return mVersionName; }
161 void setVersionName(const char* val) { mVersionName = val; }
162 const char* getCustomPackage() const { return mCustomPackage; }
163 void setCustomPackage(const char* val) { mCustomPackage = val; }
164 const char* getExtraPackages() const { return mExtraPackages; }
165 void setExtraPackages(const char* val) { mExtraPackages = val; }
166 const char* getMaxResVersion() const { return mMaxResVersion; }
167 void setMaxResVersion(const char * val) { mMaxResVersion = val; }
168 bool getDebugMode() const { return mDebugMode; }
169 void setDebugMode(bool val) { mDebugMode = val; }
170 bool getNonConstantId() const { return mNonConstantId; }
171 void setNonConstantId(bool val) { mNonConstantId = val; }
172 const char* getProduct() const { return mProduct; }
173 void setProduct(const char * val) { mProduct = val; }
174 void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
175 bool getUseCrunchCache() const { return mUseCrunchCache; }
176
177 /*
178 * Set and get the file specification.
179 *
180 * Note this does NOT make a copy of argv.
181 */
182 void setFileSpec(char* const argv[], int argc) {
183 mArgc = argc;
184 mArgv = argv;
185 }
186 int getFileSpecCount(void) const { return mArgc; }
187 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
188 void eatArgs(int n) {
189 if (n > mArgc) n = mArgc;
190 mArgv += n;
191 mArgc -= n;
192 }
193
194 #if 0
195 /*
196 * Package count. Nothing to do with anything else here; this is
197 * just a convenient place to stuff it so we don't have to pass it
198 * around everywhere.
199 */
200 int getPackageCount(void) const { return mPackageCount; }
201 void setPackageCount(int val) { mPackageCount = val; }
202 #endif
203
204 /* Certain features may only be available on a specific SDK level or
205 * above. SDK levels that have a non-numeric identifier are assumed
206 * to be newer than any SDK level that has a number designated.
207 */
208 bool isMinSdkAtLeast(int desired) {
209 /* If the application specifies a minSdkVersion in the manifest
210 * then use that. Otherwise, check what the user specified on
211 * the command line. If neither, it's not available since
212 * the minimum SDK version is assumed to be 1.
213 */
214 const char *minVer;
215 if (mManifestMinSdkVersion != NULL) {
216 minVer = mManifestMinSdkVersion;
217 } else if (mMinSdkVersion != NULL) {
218 minVer = mMinSdkVersion;
219 } else {
220 return false;
221 }
222
223 char *end;
224 int minSdkNum = (int)strtol(minVer, &end, 0);
225 if (*end == '\0') {
226 if (minSdkNum < desired) {
227 return false;
228 }
229 }
230 return true;
231 }
232
233 private:
234 /* commands & modifiers */
235 Command mCmd;
236 bool mVerbose;
237 bool mAndroidList;
238 bool mForce;
239 int mGrayscaleTolerance;
240 bool mMakePackageDirs;
241 bool mUpdate;
242 bool mExtending;
243 bool mRequireLocalization;
244 bool mPseudolocalize;
245 bool mWantUTF16;
246 bool mValues;
247 int mCompressionMethod;
248 bool mJunkPath;
249 const char* mOutputAPKFile;
250 const char* mManifestPackageNameOverride;
251 const char* mInstrumentationPackageNameOverride;
252 bool mAutoAddOverlay;
253 bool mGenDependencies;
254 const char* mAssetSourceDir;
255 const char* mCrunchedOutputDir;
256 const char* mProguardFile;
257 const char* mAndroidManifestFile;
258 const char* mPublicOutputFile;
259 const char* mRClassDir;
260 const char* mResourceIntermediatesDir;
261 android::String8 mConfigurations;
262 android::String8 mPreferredConfigurations;
263 android::Vector<const char*> mPackageIncludes;
264 android::Vector<const char*> mJarFiles;
265 android::Vector<const char*> mNoCompressExtensions;
266 android::Vector<const char*> mResourceSourceDirs;
267
268 const char* mManifestMinSdkVersion;
269 const char* mMinSdkVersion;
270 const char* mTargetSdkVersion;
271 const char* mMaxSdkVersion;
272 const char* mVersionCode;
273 const char* mVersionName;
274 const char* mCustomPackage;
275 const char* mExtraPackages;
276 const char* mMaxResVersion;
277 bool mDebugMode;
278 bool mNonConstantId;
279 const char* mProduct;
280 bool mUseCrunchCache;
281 bool mErrorOnFailedInsert;
282
283 /* file specification */
284 int mArgc;
285 char* const* mArgv;
286
287 #if 0
288 /* misc stuff */
289 int mPackageCount;
290 #endif
291
292 };
293
294 #endif // __BUNDLE_H