]> git.saurik.com Git - android/aapt.git/blob - Bundle.h
a2c6a12ad9ddb15a61acae70b1dc01dd4cc83608
[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 /*
18 * Things we can do.
19 */
20 typedef enum Command {
21 kCommandUnknown = 0,
22 kCommandVersion,
23 kCommandList,
24 kCommandDump,
25 kCommandAdd,
26 kCommandRemove,
27 kCommandPackage,
28 } Command;
29
30 /*
31 * Bundle of goodies, including everything specified on the command line.
32 */
33 class Bundle {
34 public:
35 Bundle(void)
36 : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
37 mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
38 mUpdate(false), mExtending(false),
39 mRequireLocalization(false), mPseudolocalize(false),
40 mUTF8(false), mValues(false),
41 mCompressionMethod(0), mOutputAPKFile(NULL),
42 mAssetSourceDir(NULL), mProguardFile(NULL),
43 mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
44 mRClassDir(NULL), mResourceIntermediatesDir(NULL),
45 mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
46 mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL),
47 mArgc(0), mArgv(NULL)
48 {}
49 ~Bundle(void) {}
50
51 /*
52 * Set the command value. Returns "false" if it was previously set.
53 */
54 Command getCommand(void) const { return mCmd; }
55 void setCommand(Command cmd) { mCmd = cmd; }
56
57 /*
58 * Command modifiers. Not all modifiers are appropriate for all
59 * commands.
60 */
61 bool getVerbose(void) const { return mVerbose; }
62 void setVerbose(bool val) { mVerbose = val; }
63 bool getAndroidList(void) const { return mAndroidList; }
64 void setAndroidList(bool val) { mAndroidList = val; }
65 bool getForce(void) const { return mForce; }
66 void setForce(bool val) { mForce = val; }
67 void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
68 int getGrayscaleTolerance() { return mGrayscaleTolerance; }
69 bool getMakePackageDirs(void) const { return mMakePackageDirs; }
70 void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
71 bool getUpdate(void) const { return mUpdate; }
72 void setUpdate(bool val) { mUpdate = val; }
73 bool getExtending(void) const { return mExtending; }
74 void setExtending(bool val) { mExtending = val; }
75 bool getRequireLocalization(void) const { return mRequireLocalization; }
76 void setRequireLocalization(bool val) { mRequireLocalization = val; }
77 bool getPseudolocalize(void) const { return mPseudolocalize; }
78 void setPseudolocalize(bool val) { mPseudolocalize = val; }
79 bool getUTF8(void) const { return mUTF8; }
80 void setUTF8(bool val) { mUTF8 = val; }
81 bool getValues(void) const { return mValues; }
82 void setValues(bool val) { mValues = val; }
83 int getCompressionMethod(void) const { return mCompressionMethod; }
84 void setCompressionMethod(int val) { mCompressionMethod = val; }
85 bool getJunkPath(void) const { return mJunkPath; }
86 void setJunkPath(bool val) { mJunkPath = val; }
87 const char* getOutputAPKFile() const { return mOutputAPKFile; }
88 void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
89
90 /*
91 * Input options.
92 */
93 const char* getAssetSourceDir() const { return mAssetSourceDir; }
94 void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
95 const char* getProguardFile() const { return mProguardFile; }
96 void setProguardFile(const char* file) { mProguardFile = file; }
97 const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
98 void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
99 const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
100 void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
101 const char* getPublicOutputFile() const { return mPublicOutputFile; }
102 void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
103 const char* getRClassDir() const { return mRClassDir; }
104 void setRClassDir(const char* dir) { mRClassDir = dir; }
105 const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
106 void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
107 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
108 void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
109 const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
110 void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
111 const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
112 void addJarFile(const char* file) { mJarFiles.add(file); }
113 const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
114 void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
115
116 const char* getMinSdkVersion() const { return mMinSdkVersion; }
117 void setMinSdkVersion(const char* val) {
118 mMinSdkVersion = val;
119 setUTF8(isUTF8Available());
120 }
121 const char* getTargetSdkVersion() const { return mTargetSdkVersion; }
122 void setTargetSdkVersion(const char* val) { mTargetSdkVersion = val; }
123 const char* getMaxSdkVersion() const { return mMaxSdkVersion; }
124 void setMaxSdkVersion(const char* val) { mMaxSdkVersion = val; }
125 const char* getVersionCode() const { return mVersionCode; }
126 void setVersionCode(const char* val) { mVersionCode = val; }
127 const char* getVersionName() const { return mVersionName; }
128 void setVersionName(const char* val) { mVersionName = val; }
129 const char* getCustomPackage() const { return mCustomPackage; }
130 void setCustomPackage(const char* val) { mCustomPackage = val; }
131
132 /*
133 * Set and get the file specification.
134 *
135 * Note this does NOT make a copy of argv.
136 */
137 void setFileSpec(char* const argv[], int argc) {
138 mArgc = argc;
139 mArgv = argv;
140 }
141 int getFileSpecCount(void) const { return mArgc; }
142 const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
143 void eatArgs(int n) {
144 if (n > mArgc) n = mArgc;
145 mArgv += n;
146 mArgc -= n;
147 }
148
149 #if 0
150 /*
151 * Package count. Nothing to do with anything else here; this is
152 * just a convenient place to stuff it so we don't have to pass it
153 * around everywhere.
154 */
155 int getPackageCount(void) const { return mPackageCount; }
156 void setPackageCount(int val) { mPackageCount = val; }
157 #endif
158
159 private:
160 /* commands & modifiers */
161 Command mCmd;
162 bool mVerbose;
163 bool mAndroidList;
164 bool mForce;
165 int mGrayscaleTolerance;
166 bool mMakePackageDirs;
167 bool mUpdate;
168 bool mExtending;
169 bool mRequireLocalization;
170 bool mPseudolocalize;
171 bool mUTF8;
172 bool mValues;
173 int mCompressionMethod;
174 bool mJunkPath;
175 const char* mOutputAPKFile;
176 const char* mAssetSourceDir;
177 const char* mProguardFile;
178 const char* mAndroidManifestFile;
179 const char* mPublicOutputFile;
180 const char* mRClassDir;
181 const char* mResourceIntermediatesDir;
182 android::String8 mConfigurations;
183 android::Vector<const char*> mPackageIncludes;
184 android::Vector<const char*> mJarFiles;
185 android::Vector<const char*> mNoCompressExtensions;
186 android::Vector<const char*> mResourceSourceDirs;
187
188 const char* mMinSdkVersion;
189 const char* mTargetSdkVersion;
190 const char* mMaxSdkVersion;
191 const char* mVersionCode;
192 const char* mVersionName;
193 const char* mCustomPackage;
194
195 /* file specification */
196 int mArgc;
197 char* const* mArgv;
198
199 #if 0
200 /* misc stuff */
201 int mPackageCount;
202 #endif
203
204 /* UTF-8 is only available on APIs 7 or above or
205 * SDK levels that have code names.
206 */
207 bool isUTF8Available() {
208 char *end;
209 int minSdkNum = (int)strtol(mMinSdkVersion, &end, 0);
210 if (*end == '\0') {
211 if (minSdkNum < 7) {
212 return false;
213 }
214 }
215 return true;
216 }
217 };
218
219 #endif // __BUNDLE_H