Home | History | Annotate | Download | only in aapt
      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     SDK_L = 21,
     28 };
     29 
     30 /*
     31  * Things we can do.
     32  */
     33 typedef enum Command {
     34     kCommandUnknown = 0,
     35     kCommandVersion,
     36     kCommandList,
     37     kCommandDump,
     38     kCommandAdd,
     39     kCommandRemove,
     40     kCommandPackage,
     41     kCommandCrunch,
     42     kCommandSingleCrunch,
     43     kCommandDaemon
     44 } Command;
     45 
     46 /*
     47  * Pseudolocalization methods
     48  */
     49 typedef enum PseudolocalizationMethod {
     50     NO_PSEUDOLOCALIZATION = 0,
     51     PSEUDO_ACCENTED,
     52     PSEUDO_BIDI,
     53 } PseudolocalizationMethod;
     54 
     55 /*
     56  * Bundle of goodies, including everything specified on the command line.
     57  */
     58 class Bundle {
     59 public:
     60     Bundle(void)
     61         : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
     62           mForce(false), mGrayscaleTolerance(0), mMakePackageDirs(false),
     63           mUpdate(false), mExtending(false),
     64           mRequireLocalization(false), mPseudolocalize(NO_PSEUDOLOCALIZATION),
     65           mWantUTF16(false), mValues(false), mIncludeMetaData(false),
     66           mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
     67           mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
     68           mAutoAddOverlay(false), mGenDependencies(false),
     69           mCrunchedOutputDir(NULL), mProguardFile(NULL),
     70           mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
     71           mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
     72           mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
     73           mVersionCode(NULL), mVersionName(NULL), mReplaceVersion(false), mCustomPackage(NULL),
     74           mExtraPackages(NULL), mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false),
     75           mProduct(NULL), mUseCrunchCache(false), mErrorOnFailedInsert(false),
     76           mErrorOnMissingConfigEntry(false), mOutputTextSymbols(NULL),
     77           mSingleCrunchInputFile(NULL), mSingleCrunchOutputFile(NULL),
     78           mBuildSharedLibrary(false),
     79           mArgc(0), mArgv(NULL)
     80         {}
     81     ~Bundle(void) {}
     82 
     83     /*
     84      * Set the command value.  Returns "false" if it was previously set.
     85      */
     86     Command getCommand(void) const { return mCmd; }
     87     void setCommand(Command cmd) { mCmd = cmd; }
     88 
     89     /*
     90      * Command modifiers.  Not all modifiers are appropriate for all
     91      * commands.
     92      */
     93     bool getVerbose(void) const { return mVerbose; }
     94     void setVerbose(bool val) { mVerbose = val; }
     95     bool getAndroidList(void) const { return mAndroidList; }
     96     void setAndroidList(bool val) { mAndroidList = val; }
     97     bool getForce(void) const { return mForce; }
     98     void setForce(bool val) { mForce = val; }
     99     void setGrayscaleTolerance(int val) { mGrayscaleTolerance = val; }
    100     int  getGrayscaleTolerance() const { return mGrayscaleTolerance; }
    101     bool getMakePackageDirs(void) const { return mMakePackageDirs; }
    102     void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
    103     bool getUpdate(void) const { return mUpdate; }
    104     void setUpdate(bool val) { mUpdate = val; }
    105     bool getExtending(void) const { return mExtending; }
    106     void setExtending(bool val) { mExtending = val; }
    107     bool getRequireLocalization(void) const { return mRequireLocalization; }
    108     void setRequireLocalization(bool val) { mRequireLocalization = val; }
    109     short getPseudolocalize(void) const { return mPseudolocalize; }
    110     void setPseudolocalize(short val) { mPseudolocalize = val; }
    111     void setWantUTF16(bool val) { mWantUTF16 = val; }
    112     bool getValues(void) const { return mValues; }
    113     void setValues(bool val) { mValues = val; }
    114     bool getIncludeMetaData(void) const { return mIncludeMetaData; }
    115     void setIncludeMetaData(bool val) { mIncludeMetaData = val; }
    116     int getCompressionMethod(void) const { return mCompressionMethod; }
    117     void setCompressionMethod(int val) { mCompressionMethod = val; }
    118     bool getJunkPath(void) const { return mJunkPath; }
    119     void setJunkPath(bool val) { mJunkPath = val; }
    120     const char* getOutputAPKFile() const { return mOutputAPKFile; }
    121     void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
    122     const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
    123     void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
    124     const char* getInstrumentationPackageNameOverride() const { return mInstrumentationPackageNameOverride; }
    125     void setInstrumentationPackageNameOverride(const char * val) { mInstrumentationPackageNameOverride = val; }
    126     bool getAutoAddOverlay() { return mAutoAddOverlay; }
    127     void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
    128     bool getGenDependencies() { return mGenDependencies; }
    129     void setGenDependencies(bool val) { mGenDependencies = val; }
    130     bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
    131     void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
    132     bool getErrorOnMissingConfigEntry() { return mErrorOnMissingConfigEntry; }
    133     void setErrorOnMissingConfigEntry(bool val) { mErrorOnMissingConfigEntry = val; }
    134     const android::String8& getPlatformBuildVersionCode() { return mPlatformVersionCode; }
    135     void setPlatformBuildVersionCode(const android::String8& code) { mPlatformVersionCode = code; }
    136     const android::String8& getPlatformBuildVersionName() { return mPlatformVersionName; }
    137     void setPlatformBuildVersionName(const android::String8& name) { mPlatformVersionName = name; }
    138 
    139     bool getUTF16StringsOption() {
    140         return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
    141     }
    142 
    143     /*
    144      * Input options.
    145      */
    146     const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; }
    147     void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); }
    148     const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
    149     void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
    150     const char* getProguardFile() const { return mProguardFile; }
    151     void setProguardFile(const char* file) { mProguardFile = file; }
    152     const android::Vector<const char*>& getResourceSourceDirs() const { return mResourceSourceDirs; }
    153     void addResourceSourceDir(const char* dir) { mResourceSourceDirs.insertAt(dir,0); }
    154     const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
    155     void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
    156     const char* getPublicOutputFile() const { return mPublicOutputFile; }
    157     void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
    158     const char* getRClassDir() const { return mRClassDir; }
    159     void setRClassDir(const char* dir) { mRClassDir = dir; }
    160     const android::String8& getConfigurations() const { return mConfigurations; }
    161     void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
    162     const android::String8& getPreferredDensity() const { return mPreferredDensity; }
    163     void setPreferredDensity(const char* val) { mPreferredDensity = val; }
    164     void addSplitConfigurations(const char* val) { mPartialConfigurations.add(android::String8(val)); }
    165     const android::Vector<android::String8>& getSplitConfigurations() const { return mPartialConfigurations; }
    166     const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
    167     void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
    168     const android::Vector<android::String8>& getPackageIncludes() const { return mPackageIncludes; }
    169     void addPackageInclude(const char* file) { mPackageIncludes.add(android::String8(file)); }
    170     const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
    171     void addJarFile(const char* file) { mJarFiles.add(file); }
    172     const android::Vector<const char*>& getNoCompressExtensions() const { return mNoCompressExtensions; }
    173     void addNoCompressExtension(const char* ext) { mNoCompressExtensions.add(ext); }
    174     void setFeatureOfPackage(const char* str) { mFeatureOfPackage = str; }
    175     const android::String8& getFeatureOfPackage() const { return mFeatureOfPackage; }
    176     void setFeatureAfterPackage(const char* str) { mFeatureAfterPackage = str; }
    177     const android::String8& getFeatureAfterPackage() const { return mFeatureAfterPackage; }
    178 
    179     const char*  getManifestMinSdkVersion() const { return mManifestMinSdkVersion; }
    180     void setManifestMinSdkVersion(const char*  val) { mManifestMinSdkVersion = val; }
    181     const char*  getMinSdkVersion() const { return mMinSdkVersion; }
    182     void setMinSdkVersion(const char*  val) { mMinSdkVersion = val; }
    183     const char*  getTargetSdkVersion() const { return mTargetSdkVersion; }
    184     void setTargetSdkVersion(const char*  val) { mTargetSdkVersion = val; }
    185     const char*  getMaxSdkVersion() const { return mMaxSdkVersion; }
    186     void setMaxSdkVersion(const char*  val) { mMaxSdkVersion = val; }
    187     const char*  getVersionCode() const { return mVersionCode; }
    188     void setVersionCode(const char*  val) { mVersionCode = val; }
    189     const char* getVersionName() const { return mVersionName; }
    190     void setVersionName(const char* val) { mVersionName = val; }
    191     bool getReplaceVersion() { return mReplaceVersion; }
    192     void setReplaceVersion(bool val) { mReplaceVersion = val; }
    193     const char* getCustomPackage() const { return mCustomPackage; }
    194     void setCustomPackage(const char* val) { mCustomPackage = val; }
    195     const char* getExtraPackages() const { return mExtraPackages; }
    196     void setExtraPackages(const char* val) { mExtraPackages = val; }
    197     const char* getMaxResVersion() const { return mMaxResVersion; }
    198     void setMaxResVersion(const char * val) { mMaxResVersion = val; }
    199     bool getDebugMode() const { return mDebugMode; }
    200     void setDebugMode(bool val) { mDebugMode = val; }
    201     bool getNonConstantId() const { return mNonConstantId; }
    202     void setNonConstantId(bool val) { mNonConstantId = val; }
    203     const char* getProduct() const { return mProduct; }
    204     void setProduct(const char * val) { mProduct = val; }
    205     void setUseCrunchCache(bool val) { mUseCrunchCache = val; }
    206     bool getUseCrunchCache() const { return mUseCrunchCache; }
    207     const char* getOutputTextSymbols() const { return mOutputTextSymbols; }
    208     void setOutputTextSymbols(const char* val) { mOutputTextSymbols = val; }
    209     const char* getSingleCrunchInputFile() const { return mSingleCrunchInputFile; }
    210     void setSingleCrunchInputFile(const char* val) { mSingleCrunchInputFile = val; }
    211     const char* getSingleCrunchOutputFile() const { return mSingleCrunchOutputFile; }
    212     void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; }
    213     bool getBuildSharedLibrary() const { return mBuildSharedLibrary; }
    214     void setBuildSharedLibrary(bool val) { mBuildSharedLibrary = val; }
    215 
    216     /*
    217      * Set and get the file specification.
    218      *
    219      * Note this does NOT make a copy of argv.
    220      */
    221     void setFileSpec(char* const argv[], int argc) {
    222         mArgc = argc;
    223         mArgv = argv;
    224     }
    225     int getFileSpecCount(void) const { return mArgc; }
    226     const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
    227     void eatArgs(int n) {
    228         if (n > mArgc) n = mArgc;
    229         mArgv += n;
    230         mArgc -= n;
    231     }
    232 
    233 #if 0
    234     /*
    235      * Package count.  Nothing to do with anything else here; this is
    236      * just a convenient place to stuff it so we don't have to pass it
    237      * around everywhere.
    238      */
    239     int getPackageCount(void) const { return mPackageCount; }
    240     void setPackageCount(int val) { mPackageCount = val; }
    241 #endif
    242 
    243     /* Certain features may only be available on a specific SDK level or
    244      * above. SDK levels that have a non-numeric identifier are assumed
    245      * to be newer than any SDK level that has a number designated.
    246      */
    247     bool isMinSdkAtLeast(int desired) {
    248         /* If the application specifies a minSdkVersion in the manifest
    249          * then use that. Otherwise, check what the user specified on
    250          * the command line. If neither, it's not available since
    251          * the minimum SDK version is assumed to be 1.
    252          */
    253         const char *minVer;
    254         if (mManifestMinSdkVersion != NULL) {
    255             minVer = mManifestMinSdkVersion;
    256         } else if (mMinSdkVersion != NULL) {
    257             minVer = mMinSdkVersion;
    258         } else {
    259             return false;
    260         }
    261 
    262         char *end;
    263         int minSdkNum = (int)strtol(minVer, &end, 0);
    264         if (*end == '\0') {
    265             if (minSdkNum < desired) {
    266                 return false;
    267             }
    268         }
    269         return true;
    270     }
    271 
    272 private:
    273     /* commands & modifiers */
    274     Command     mCmd;
    275     bool        mVerbose;
    276     bool        mAndroidList;
    277     bool        mForce;
    278     int         mGrayscaleTolerance;
    279     bool        mMakePackageDirs;
    280     bool        mUpdate;
    281     bool        mExtending;
    282     bool        mRequireLocalization;
    283     short       mPseudolocalize;
    284     bool        mWantUTF16;
    285     bool        mValues;
    286     bool        mIncludeMetaData;
    287     int         mCompressionMethod;
    288     bool        mJunkPath;
    289     const char* mOutputAPKFile;
    290     const char* mManifestPackageNameOverride;
    291     const char* mInstrumentationPackageNameOverride;
    292     bool        mAutoAddOverlay;
    293     bool        mGenDependencies;
    294     const char* mCrunchedOutputDir;
    295     const char* mProguardFile;
    296     const char* mAndroidManifestFile;
    297     const char* mPublicOutputFile;
    298     const char* mRClassDir;
    299     const char* mResourceIntermediatesDir;
    300     android::String8 mConfigurations;
    301     android::String8 mPreferredDensity;
    302     android::Vector<android::String8> mPartialConfigurations;
    303     android::Vector<android::String8> mPackageIncludes;
    304     android::Vector<const char*> mJarFiles;
    305     android::Vector<const char*> mNoCompressExtensions;
    306     android::Vector<const char*> mAssetSourceDirs;
    307     android::Vector<const char*> mResourceSourceDirs;
    308 
    309     android::String8 mFeatureOfPackage;
    310     android::String8 mFeatureAfterPackage;
    311     const char* mManifestMinSdkVersion;
    312     const char* mMinSdkVersion;
    313     const char* mTargetSdkVersion;
    314     const char* mMaxSdkVersion;
    315     const char* mVersionCode;
    316     const char* mVersionName;
    317     bool        mReplaceVersion;
    318     const char* mCustomPackage;
    319     const char* mExtraPackages;
    320     const char* mMaxResVersion;
    321     bool        mDebugMode;
    322     bool        mNonConstantId;
    323     const char* mProduct;
    324     bool        mUseCrunchCache;
    325     bool        mErrorOnFailedInsert;
    326     bool        mErrorOnMissingConfigEntry;
    327     const char* mOutputTextSymbols;
    328     const char* mSingleCrunchInputFile;
    329     const char* mSingleCrunchOutputFile;
    330     bool        mBuildSharedLibrary;
    331     android::String8 mPlatformVersionCode;
    332     android::String8 mPlatformVersionName;
    333 
    334     /* file specification */
    335     int         mArgc;
    336     char* const* mArgv;
    337 
    338 #if 0
    339     /* misc stuff */
    340     int         mPackageCount;
    341 #endif
    342 
    343 };
    344 
    345 #endif // __BUNDLE_H
    346