FileDocCategorySizeDatePackage
AaptExecLoopTask.javaAPI DocAndroid 1.5 API7090Wed May 06 22:41:08 BST 2009com.android.ant

AaptExecLoopTask

public final class AaptExecLoopTask extends org.apache.tools.ant.Task
Task able to run an Exec task on aapt several times. It does not follow the exec task format, instead it has its own parameters, which maps directly to aapt.

Fields Summary
private String
mExecutable
private String
mCommand
private String
mManifest
private String
mResources
private String
mAssets
private String
mAndroidJar
private String
mOutFolder
private String
mBaseName
Constructors Summary
Methods Summary
private voidcreatePackage(java.lang.String configName, java.lang.String resourceFilter)
Creates a resource package.

param
configName the name of the filter config. Can be null in which case a full resource package will be generated.
param
resourceFilter the resource configuration filter to pass to aapt (if configName is non null)

        Project taskProject = getProject();

        if (configName == null || resourceFilter == null) {
            System.out.println("Creating full resource package...");
        } else {
            System.out.println(String.format(
                    "Creating resource package for config '%1$s' (%2$s)...",
                    configName, resourceFilter));
        }

        // create a task for the default apk.
        ExecTask task = new ExecTask();
        task.setExecutable(mExecutable);
        task.setFailonerror(true);
        
        // aapt command. Only "package" is supported at this time really.
        task.createArg().setValue(mCommand);
        
        // filters if needed
        if (configName != null && resourceFilter != null) {
            task.createArg().setValue("-c");
            task.createArg().setValue(resourceFilter);
        }
        
        // force flag
        task.createArg().setValue("-f");
        
        // manifest location
        task.createArg().setValue("-M");
        task.createArg().setValue(mManifest);

        // resources location. This may not exists, and aapt doesn't like it, so we check first.
        File res = new File(mResources);
        if (res.isDirectory()) {
            task.createArg().setValue("-S");
            task.createArg().setValue(mResources);
        }
        
        // assets location. This may not exists, and aapt doesn't like it, so we check first.
        File assets = new File(mAssets);
        if (assets.isDirectory()) {
            task.createArg().setValue("-A");
            task.createArg().setValue(mAssets);
        }
        
        // android.jar
        task.createArg().setValue("-I");
        task.createArg().setValue(mAndroidJar);
        
        // out file. This is based on the outFolder, baseName, and the configName (if applicable)
        String filename;
        if (configName != null && resourceFilter != null) {
            filename = mBaseName + "-" + configName + ".ap_";
        } else {
            filename = mBaseName + ".ap_";
        }
        
        File file = new File(mOutFolder, filename);
        task.createArg().setValue("-F");
        task.createArg().setValue(file.getAbsolutePath());
        
        // final setup of the task
        task.setProject(taskProject);
        task.setOwningTarget(getOwningTarget());
        
        // execute it.
        task.execute();
    
public voidexecute()

        Project taskProject = getProject();
        
        // first do a full resource package
        createPackage(null /*configName*/, null /*resourceFilter*/);

        // now see if we need to create file with filtered resources.
        // Get the project base directory.
        File baseDir = taskProject.getBaseDir();
        ProjectProperties properties = ProjectProperties.load(baseDir.getAbsolutePath(),
                PropertyType.DEFAULT);
        
        Map<String, String> apkConfigs = ApkConfigurationHelper.getConfigs(properties);
        if (apkConfigs.size() > 0) {
            Set<Entry<String, String>> entrySet = apkConfigs.entrySet();
            for (Entry<String, String> entry : entrySet) {
                createPackage(entry.getKey(), entry.getValue());
            }
        }
    
public voidsetAndroidjar(org.apache.tools.ant.types.Path androidJar)
Sets the value of the "androidjar" attribute.

param
androidJar the value.

        mAndroidJar = androidJar.toString();
    
public voidsetAssets(org.apache.tools.ant.types.Path assets)
Sets the value of the "assets" attribute.

param
assets the value.

        mAssets = assets.toString();
    
public voidsetBasename(java.lang.String baseName)
Sets the value of the "basename" attribute.

param
baseName the value.

        mBaseName = baseName;
    
public voidsetCommand(java.lang.String command)
Sets the value of the "command" attribute.

param
command the value.

        mCommand = command;
    
public voidsetExecutable(java.lang.String executable)
Sets the value of the "executable" attribute.

param
executable the value.

        mExecutable = executable;
    
public voidsetManifest(org.apache.tools.ant.types.Path manifest)
Sets the value of the "manifest" attribute.

param
manifest the value.

        mManifest = manifest.toString();
    
public voidsetOutfolder(org.apache.tools.ant.types.Path outFolder)
Sets the value of the "outfolder" attribute.

param
outFolder the value.

        mOutFolder = outFolder.toString();
    
public voidsetResources(org.apache.tools.ant.types.Path resources)
Sets the value of the "resources" attribute.

param
resources the value.

        mResources = resources.toString();