FileDocCategorySizeDatePackage
Chmod.javaAPI DocApache Ant 1.708114Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

Chmod

public class Chmod extends ExecuteOn
Chmod equivalent for unix-like environments.
since
Ant 1.1
ant.task
category="filesystem"
todo
Refactor so it does not extend from ExecuteOn and then turn around and unsupport several attributes.

Fields Summary
private org.apache.tools.ant.types.FileSet
defaultSet
private boolean
defaultSetDefined
private boolean
havePerm
Constructors Summary
public Chmod()
Chmod task for setting file and directory permissions.


                 
      
        super.setExecutable("chmod");
        super.setParallel(true);
        super.setSkipEmptyFilesets(true);
    
Methods Summary
protected voidcheckConfiguration()
Check the attributes and nested elements.

        if (!havePerm) {
            throw new BuildException("Required attribute perm not set in chmod",
                                     getLocation());
        }

        if (defaultSetDefined && defaultSet.getDir(getProject()) != null) {
            addFileset(defaultSet);
        }
        super.checkConfiguration();
    
public PatternSet.NameEntrycreateExclude()
Add a name entry on the exclude list.

return
a nameentry to be configured.

        defaultSetDefined = true;
        return defaultSet.createExclude();
    
public PatternSet.NameEntrycreateInclude()
Add a name entry on the include list.

return
a NameEntry to be configured.

        defaultSetDefined = true;
        return defaultSet.createInclude();
    
public org.apache.tools.ant.types.PatternSetcreatePatternSet()
Add a set of patterns.

return
a patternset to be configured.

        defaultSetDefined = true;
        return defaultSet.createPatternSet();
    
public voidexecute()
Carry out the chmoding.

throws
BuildException on error.

        /*
         * In Ant 1.1, <chmod dir="foo" /> means, change the permissions
         * of directory foo, not anything inside of it.  This is the case the
         * second branch of the if statement below catches for backwards
         * compatibility.
         */
        if (defaultSetDefined || defaultSet.getDir(getProject()) == null) {
            try {
                super.execute();
            } finally {
                if (defaultSetDefined && defaultSet.getDir(getProject()) != null) {
                    filesets.removeElement(defaultSet);
                }
            }
        } else if (isValidOs()) {
            // we are chmodding the given directory
            Execute execute = prepareExec();
            Commandline cloned = (Commandline) cmdl.clone();
            cloned.createArgument().setValue(defaultSet.getDir(getProject())
                                             .getPath());
            try {
                execute.setCommandline(cloned.getCommandline());
                runExecute(execute);
            } catch (IOException e) {
                throw new BuildException("Execute failed: " + e, e, getLocation());
            } finally {
                // close the output file if required
                logFlush();
            }
        }
    
protected booleanisValidOs()
Check if the os is valid. Always include unix.

return
true if the os is valid.

        return Os.isFamily(Os.FAMILY_UNIX) && super.isValidOs();
    
public voidsetAddsourcefile(boolean b)
This is not allowed for Chmod.

param
b ignored.
throws
BuildException always.
ant.attribute
ignore="true"

        throw new BuildException(getTaskType()
            + " doesn\'t support the addsourcefile attribute", getLocation());
    
public voidsetCommand(org.apache.tools.ant.types.Commandline cmdl)
Set the command. This is not allowed for Chmod.

param
cmdl ignored.
throws
BuildException always.
ant.attribute
ignore="true"

        throw new BuildException(getTaskType()
            + " doesn\'t support the command attribute", getLocation());
    
public voidsetDefaultexcludes(boolean useDefaultExcludes)
Sets whether default exclusions should be used or not.

param
useDefaultExcludes "true"|"on"|"yes" when default exclusions should be used, "false"|"off"|"no" when they shouldn't be used.

        defaultSetDefined = true;
        defaultSet.setDefaultexcludes(useDefaultExcludes);
    
public voidsetDir(java.io.File src)
The directory which holds the files whose permissions must be changed.

param
src the directory.

        defaultSet.setDir(src);
    
public voidsetExcludes(java.lang.String excludes)
Sets the set of exclude patterns. Patterns may be separated by a comma or a space.

param
excludes the string containing the exclude patterns.

        defaultSetDefined = true;
        defaultSet.setExcludes(excludes);
    
public voidsetExecutable(java.lang.String e)
Set the executable. This is not allowed for Chmod.

param
e ignored.
throws
BuildException always.
ant.attribute
ignore="true"

        throw new BuildException(getTaskType()
            + " doesn\'t support the executable attribute", getLocation());
    
public voidsetFile(java.io.File src)
The file or single directory of which the permissions must be changed.

param
src the source file or directory.

        FileSet fs = new FileSet();
        fs.setFile(src);
        addFileset(fs);
    
public voidsetIncludes(java.lang.String includes)
Sets the set of include patterns. Patterns may be separated by a comma or a space.

param
includes the string containing the include patterns.

        defaultSetDefined = true;
        defaultSet.setIncludes(includes);
    
public voidsetPerm(java.lang.String perm)
Set the new permissions.

param
perm the new permissions.

        createArg().setValue(perm);
        havePerm = true;
    
public voidsetProject(org.apache.tools.ant.Project project)
Set the project of this task. Calls the super class and sets the project on dhe default FileSet.

param
project the project for this task.
see
org.apache.tools.ant.ProjectComponent#setProject

        super.setProject(project);
        defaultSet.setProject(project);
    
public voidsetSkipEmptyFilesets(boolean skip)
This is not allowed for Chmod.

param
skip ignored.
throws
BuildException always.
ant.attribute
ignore="true"

        throw new BuildException(getTaskType()
            + " doesn\'t support the skipemptyfileset attribute", getLocation());