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