2 // Copyright 2006 The Android Open Source Project
4 // State bundle. Used to pass around stuff like command-line args.
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>
20 typedef enum Command
{
31 * Bundle of goodies, including everything specified on the command line.
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), mEncodingSpecified(false), mValues(false),
41 mCompressionMethod(0), mOutputAPKFile(NULL
), mManifestPackageNameOverride(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
),
52 * Set the command value. Returns "false" if it was previously set.
54 Command
getCommand(void) const { return mCmd
; }
55 void setCommand(Command cmd
) { mCmd
= cmd
; }
58 * Command modifiers. Not all modifiers are appropriate for all
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 getEncodingSpecified(void) const { return mEncodingSpecified
; }
82 void setEncodingSpecified(bool val
) { mEncodingSpecified
= val
; }
83 bool getValues(void) const { return mValues
; }
84 void setValues(bool val
) { mValues
= val
; }
85 int getCompressionMethod(void) const { return mCompressionMethod
; }
86 void setCompressionMethod(int val
) { mCompressionMethod
= val
; }
87 bool getJunkPath(void) const { return mJunkPath
; }
88 void setJunkPath(bool val
) { mJunkPath
= val
; }
89 const char* getOutputAPKFile() const { return mOutputAPKFile
; }
90 void setOutputAPKFile(const char* val
) { mOutputAPKFile
= val
; }
91 const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride
; }
92 void setManifestPackageNameOverride(const char * val
) { mManifestPackageNameOverride
= val
; }
97 const char* getAssetSourceDir() const { return mAssetSourceDir
; }
98 void setAssetSourceDir(const char* dir
) { mAssetSourceDir
= dir
; }
99 const char* getProguardFile() const { return mProguardFile
; }
100 void setProguardFile(const char* file
) { mProguardFile
= file
; }
101 const android::Vector
<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs
; }
102 void addResourceSourceDir(const char* dir
) { mResourceSourceDirs
.insertAt(dir
,0); }
103 const char* getAndroidManifestFile() const { return mAndroidManifestFile
; }
104 void setAndroidManifestFile(const char* file
) { mAndroidManifestFile
= file
; }
105 const char* getPublicOutputFile() const { return mPublicOutputFile
; }
106 void setPublicOutputFile(const char* file
) { mPublicOutputFile
= file
; }
107 const char* getRClassDir() const { return mRClassDir
; }
108 void setRClassDir(const char* dir
) { mRClassDir
= dir
; }
109 const char* getConfigurations() const { return mConfigurations
.size() > 0 ? mConfigurations
.string() : NULL
; }
110 void addConfigurations(const char* val
) { if (mConfigurations
.size() > 0) { mConfigurations
.append(","); mConfigurations
.append(val
); } else { mConfigurations
= val
; } }
111 const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir
; }
112 void setResourceIntermediatesDir(const char* dir
) { mResourceIntermediatesDir
= dir
; }
113 const android::Vector
<const char*>& getPackageIncludes() const { return mPackageIncludes
; }
114 void addPackageInclude(const char* file
) { mPackageIncludes
.add(file
); }
115 const android::Vector
<const char*>& getJarFiles() const { return mJarFiles
; }
116 void addJarFile(const char* file
) { mJarFiles
.add(file
); }
117 const android::Vector
<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions
; }
118 void addNoCompressExtension(const char* ext
) { mNoCompressExtensions
.add(ext
); }
120 const char* getMinSdkVersion() const { return mMinSdkVersion
; }
121 void setMinSdkVersion(const char* val
) {
122 mMinSdkVersion
= val
;
123 if (!mEncodingSpecified
) {
124 setUTF8(isUTF8Available());
127 const char* getTargetSdkVersion() const { return mTargetSdkVersion
; }
128 void setTargetSdkVersion(const char* val
) { mTargetSdkVersion
= val
; }
129 const char* getMaxSdkVersion() const { return mMaxSdkVersion
; }
130 void setMaxSdkVersion(const char* val
) { mMaxSdkVersion
= val
; }
131 const char* getVersionCode() const { return mVersionCode
; }
132 void setVersionCode(const char* val
) { mVersionCode
= val
; }
133 const char* getVersionName() const { return mVersionName
; }
134 void setVersionName(const char* val
) { mVersionName
= val
; }
135 const char* getCustomPackage() const { return mCustomPackage
; }
136 void setCustomPackage(const char* val
) { mCustomPackage
= val
; }
139 * Set and get the file specification.
141 * Note this does NOT make a copy of argv.
143 void setFileSpec(char* const argv
[], int argc
) {
147 int getFileSpecCount(void) const { return mArgc
; }
148 const char* getFileSpecEntry(int idx
) const { return mArgv
[idx
]; }
149 void eatArgs(int n
) {
150 if (n
> mArgc
) n
= mArgc
;
157 * Package count. Nothing to do with anything else here; this is
158 * just a convenient place to stuff it so we don't have to pass it
161 int getPackageCount(void) const { return mPackageCount
; }
162 void setPackageCount(int val
) { mPackageCount
= val
; }
166 /* commands & modifiers */
171 int mGrayscaleTolerance
;
172 bool mMakePackageDirs
;
175 bool mRequireLocalization
;
176 bool mPseudolocalize
;
178 bool mEncodingSpecified
;
180 int mCompressionMethod
;
182 const char* mOutputAPKFile
;
183 const char* mManifestPackageNameOverride
;
184 const char* mAssetSourceDir
;
185 const char* mProguardFile
;
186 const char* mAndroidManifestFile
;
187 const char* mPublicOutputFile
;
188 const char* mRClassDir
;
189 const char* mResourceIntermediatesDir
;
190 android::String8 mConfigurations
;
191 android::Vector
<const char*> mPackageIncludes
;
192 android::Vector
<const char*> mJarFiles
;
193 android::Vector
<const char*> mNoCompressExtensions
;
194 android::Vector
<const char*> mResourceSourceDirs
;
196 const char* mMinSdkVersion
;
197 const char* mTargetSdkVersion
;
198 const char* mMaxSdkVersion
;
199 const char* mVersionCode
;
200 const char* mVersionName
;
201 const char* mCustomPackage
;
203 /* file specification */
212 /* UTF-8 is only available on APIs 7 or above or
213 * SDK levels that have code names.
215 bool isUTF8Available() {
217 int minSdkNum
= (int)strtol(mMinSdkVersion
, &end
, 0);