Example usage for java.io File setExecutable

List of usage examples for java.io File setExecutable

Introduction

In this page you can find the example usage for java.io File setExecutable.

Prototype

public boolean setExecutable(boolean executable, boolean ownerOnly) 

Source Link

Document

Sets the owner's or everybody's execute permission for this abstract pathname.

Usage

From source file:com.vmware.photon.controller.deployer.helpers.TestHelper.java

public static void createScriptFile(DeployerContext deployerContext, String scriptContents,
        String scriptFileName) throws IOException {
    File scriptFile = new File(deployerContext.getScriptDirectory(), scriptFileName);
    scriptFile.createNewFile();/*from ww  w. jav a  2 s.c  o m*/
    scriptFile.setExecutable(true, true);
    FileUtils.writeStringToFile(scriptFile, scriptContents);
}

From source file:org.robovm.maven.resolver.Archiver.java

public static void unarchive(Logger logger, File archive, File destDir) throws IOException {
    TarArchiveInputStream in = null;/*from   w  w  w. ja  v a2  s  . c o m*/
    try {
        in = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(archive)));
        ArchiveEntry entry = null;
        while ((entry = in.getNextEntry()) != null) {
            File f = new File(destDir, entry.getName());
            if (entry.isDirectory()) {
                f.mkdirs();
            } else {
                logger.debug(f.getAbsolutePath());
                f.getParentFile().mkdirs();
                OutputStream out = null;
                try {
                    out = new FileOutputStream(f);
                    IOUtils.copy(in, out);
                } finally {
                    IOUtils.closeQuietly(out);
                }
            }
            f.setLastModified(entry.getLastModifiedDate().getTime());
            if (entry instanceof TarArchiveEntry) {
                int mode = ((TarArchiveEntry) entry).getMode();
                if ((mode & 00100) > 0) {
                    // Preserve execute permissions
                    f.setExecutable(true, (mode & 00001) == 0);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.android.tradefed.util.FileUtil.java

public static boolean chmodRWXRecursively(File file) {
    boolean success = true;
    if (!file.setExecutable(true, false)) {
        CLog.w("Failed to set %s executable.", file.getAbsolutePath());
        success = false;/*from  ww w  .  ja  va  2  s . c  o m*/
    }
    if (!file.setWritable(true, false)) {
        CLog.w("Failed to set %s writable.", file.getAbsolutePath());
        success = false;
    }
    if (!file.setReadable(true, false)) {
        CLog.w("Failed to set %s readable", file.getAbsolutePath());
        success = false;
    }

    if (file.isDirectory()) {
        File[] childs = file.listFiles();
        for (File child : childs) {
            if (!chmodRWXRecursively(child)) {
                success = false;
            }
        }

    }
    return success;
}

From source file:com.wuba.utils.FileUtil.java

public static boolean chmodRWXRecursively(File file) {
    boolean success = true;
    if (!file.setExecutable(true, false)) {
        LOG.warn(String.format("Failed to set %s executable.", file.getAbsolutePath()));
        success = false;// w w  w  . j  a  v  a  2  s  .c  o  m
    }
    if (!file.setWritable(true, false)) {
        LOG.warn(String.format("Failed to set %s writable.", file.getAbsolutePath()));
        success = false;
    }
    if (!file.setReadable(true, false)) {
        LOG.warn(String.format("Failed to set %s readable", file.getAbsolutePath()));
        success = false;
    }

    if (file.isDirectory()) {
        File[] childs = file.listFiles();
        for (File child : childs) {
            if (!chmodRWXRecursively(child)) {
                success = false;
            }
        }

    }
    return success;
}

From source file:org.mule.test.infrastructure.process.rules.MuleInstallation.java

private void chmodRwx(File destFile) {
    destFile.setExecutable(true, false);
    destFile.setWritable(true, false);
    destFile.setReadable(true, false);
}

From source file:ca.unbsj.cbakerlab.sqltemplate.schematicanswers.ExecutionEngine.java

public ExecutionEngine(CommandLineArgsBuilder cBuilder, ResultHandler resultHandler, long exeTimeout,
        String binPath, String... resources) {
    ClassLoader loader = this.getClass().getClassLoader();
    if (loader == null)
        System.out.println("class not loaded");
    File binFile = extractFromResource(loader, binPath);
    binFile.setExecutable(true, true);
    m_binPath = binFile.getPath();/*from w w  w.j  a  va 2  s  .co  m*/
    m_resourcePaths = new String[resources.length];

    for (int i = 0; i < resources.length; i++) {
        m_resourcePaths[i] = extractFromResource(loader, resources[i]).getPath();
        System.out.println("resource path " + (i) + " " + m_resourcePaths[i].toString());
    }

    m_commBuilder = cBuilder;
    m_exeTimeout = exeTimeout;
    m_resultHandler = resultHandler;
}

From source file:edu.ucsd.crbs.cws.io.ResourceToExecutableScriptWriterImpl.java

/**
 * Writes a given resource to an executable script file.  The result is written to
 * <b>destinationScript</b> and this script is made executable via File setExecutable
 * method.//from   www.j av a 2s .com
 * 
 * @param resourcePath Path that can be loaded via {@link Class.class.getResourceAsStream} 
 * @param destinationScript File to write script to
 * @param replacer Optional object that lets caller alter script on a line by line basis before it is written
 * @throws Exception if there is an io error
 * @throws IllegalArgumentException if either <b>resourcePath</b> or <b>destinationScript</b> are null
 */
@Override
public void writeResourceToScript(final String resourcePath, final String destinationScript,
        StringReplacer replacer) throws Exception {
    if (resourcePath == null) {
        throw new IllegalArgumentException("resourcePath method parameter cannot be null");
    }

    if (destinationScript == null) {
        throw new IllegalArgumentException("destinationScript method parameter cannot be null");
    }

    //load script
    List<String> scriptLines = IOUtils.readLines(Class.class.getResourceAsStream(resourcePath));

    BufferedWriter bw = new BufferedWriter(new FileWriter(destinationScript));

    for (String line : scriptLines) {
        if (replacer != null) {
            bw.write(replacer.replace(line));
        } else {
            bw.write(line);
        }
        bw.newLine();
    }
    bw.flush();
    bw.close();

    //make script executable
    File script = new File(destinationScript);
    script.setExecutable(true, false);

}

From source file:org.eclipse.cdt.internal.p2.touchpoint.natives.actions.UnpackAction.java

private void chmod(File file, int mode) {
    file.setExecutable((mode & 0111) != 0, (mode & 0110) == 0);
    file.setWritable((mode & 0222) != 0, (mode & 0220) == 0);
    file.setReadable((mode & 0444) != 0, (mode & 0440) == 0);
}

From source file:org.geoserver.importer.rest.PostScriptTransformTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    dd = new GeoServerDataDirectory(FileUtils.getTempDirectory());
    GeoServerExtensionsHelper.singleton("dataDirectory", dd, GeoServerDataDirectory.class);

    // write out a simple shell script in the data dir and make it executable
    File scripts = dd.findOrCreateDir("importer", "scripts");
    File script = new File(scripts, "test.sh");
    FileUtils.writeStringToFile(script, "touch test.properties\n");
    script.setExecutable(true, true);
}

From source file:com.theaetetuslabs.android_apkmaker.AndroidApkMaker.java

private static File unpackAapt(Context context, File aapt) throws IOException {
    if (!aapt.exists()) {
        String aaptToUse = null;//from w w  w. j a  va 2s  .  co m
        boolean usePie = VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN;
        String abi;
        if (VERSION.SDK_INT > VERSION_CODES.LOLLIPOP) {
            String[] abis = Build.SUPPORTED_32_BIT_ABIS;
            for (String mAbi : abis) {
                aaptToUse = getAaptFlavor(mAbi, usePie);
                if (aaptToUse != null) {
                    break;
                }
            }
        } else {
            aaptToUse = getAaptFlavor(Build.CPU_ABI, usePie);
        }
        if (aaptToUse == null) {
            aaptToUse = "aapt-arm";
        }
        if (usePie) {
            aaptToUse += "-pie";
        }
        unpackAsset(context, aaptToUse, aapt);
    }
    if (!aapt.canExecute()) {
        aapt.setExecutable(true, true);
    }
    if (!aapt.canExecute()) {
        Runtime.getRuntime().exec("chmod 777 " + aapt.getAbsolutePath());
    }
    return aapt;
}