Search in sources :

Example 1 with Chmod

use of org.apache.tools.ant.taskdefs.Chmod in project hudson-2.x by hudson.

the class Util method makeWritable.

/**
     * Makes the given file writable by any means possible.
     */
@IgnoreJRERequirement
private static void makeWritable(File f) {
    // try chmod. this becomes no-op if this is not Unix.
    try {
        Chmod chmod = new Chmod();
        chmod.setProject(new Project());
        chmod.setFile(f);
        chmod.setPerm("u+w");
        chmod.execute();
    } catch (BuildException e) {
        LOGGER.log(Level.INFO, "Failed to chmod " + f, e);
    }
    // also try JDK6-way of doing it.
    try {
        f.setWritable(true);
    } catch (NoSuchMethodError e) {
    // not JDK6
    }
    try {
        // try libc chmod
        POSIX posix = PosixAPI.get();
        String path = f.getAbsolutePath();
        FileStat stat = posix.stat(path);
        // u+w
        posix.chmod(path, stat.mode() | 0200);
    } catch (Throwable t) {
        LOGGER.log(Level.FINE, "Failed to chmod(2) " + f, t);
    }
}
Also used : Project(org.apache.tools.ant.Project) FileStat(org.jruby.ext.posix.FileStat) BuildException(org.apache.tools.ant.BuildException) Chmod(org.apache.tools.ant.taskdefs.Chmod) POSIX(org.jruby.ext.posix.POSIX) IgnoreJRERequirement(org.jvnet.animal_sniffer.IgnoreJRERequirement)

Example 2 with Chmod

use of org.apache.tools.ant.taskdefs.Chmod in project hudson-2.x by hudson.

the class FilePath method _chmodAnt.

private static void _chmodAnt(File f, int mask) {
    if (!CHMOD_WARNED) {
        // only warn this once to avoid flooding the log
        CHMOD_WARNED = true;
        LOGGER.warning("GNU C Library not available: Using Ant's chmod task instead.");
    }
    Chmod chmodTask = new Chmod();
    chmodTask.setProject(new Project());
    chmodTask.setFile(f);
    chmodTask.setPerm(Integer.toOctalString(mask));
    chmodTask.execute();
}
Also used : Project(org.apache.tools.ant.Project) AbstractProject(hudson.model.AbstractProject) Chmod(org.apache.tools.ant.taskdefs.Chmod)

Aggregations

Project (org.apache.tools.ant.Project)2 Chmod (org.apache.tools.ant.taskdefs.Chmod)2 AbstractProject (hudson.model.AbstractProject)1 BuildException (org.apache.tools.ant.BuildException)1 FileStat (org.jruby.ext.posix.FileStat)1 POSIX (org.jruby.ext.posix.POSIX)1 IgnoreJRERequirement (org.jvnet.animal_sniffer.IgnoreJRERequirement)1