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:Main.java

public static void main(String[] args) {

    File f = new File("test.txt");

    // set executable()
    boolean bool = f.setExecutable(true, true);

    System.out.println("setExecutable() succeeded?: " + bool);

    // can execute
    bool = f.canExecute();//from   ww  w  .j  ava  2 s . c o  m

    System.out.print("Can execute?: " + bool);

}

From source file:Main.java

/**
 * Create a script file to run one command
 * @param cmmd Command for the script to run
 * @param fileName The file name/*from w w w  .j a  v  a 2s.  c  o  m*/
 * @return The file
 * @throws IOException
 */
public static File createScriptFile(String cmmd, String fileName) throws IOException {
    String f = fileName == null ? "script_" + System.currentTimeMillis() : fileName;
    FileWriter w = new FileWriter(f);
    w.write(cmmd + "\n");
    w.close();
    File file = new File(f);
    file.setExecutable(true, false);
    return file;
}

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

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

From source file:brooklyn.util.io.FileUtil.java

public static void setFilePermissionsTo600(File file) throws IOException {
    file.createNewFile();//from www  . java2  s  .  com
    file.setExecutable(false, false);
    file.setReadable(false, false);
    file.setWritable(false, false);
    file.setReadable(true, true);
    file.setWritable(true, true);

    boolean setRead = file.setReadable(false, false) & file.setReadable(true, true);
    boolean setWrite = file.setWritable(false, false) & file.setWritable(true, true);
    boolean setExec = file.setExecutable(false, false);

    if (setRead && setWrite && setExec) {
        if (LOG.isTraceEnabled())
            LOG.trace("Set permissions to 600 for file {}", file.getAbsolutePath());
    } else {
        if (loggedSetFilePermissionsWarning) {
            if (LOG.isTraceEnabled())
                LOG.trace(
                        "Failed to set permissions to 600 for file {}: setRead={}, setWrite={}, setExecutable={}",
                        new Object[] { file.getAbsolutePath(), setRead, setWrite, setExec });
        } else {
            if (Os.isMicrosoftWindows()) {
                if (LOG.isDebugEnabled())
                    LOG.debug(
                            "Failed to set permissions to 600 for file {}; expected behaviour on Windows; setRead={}, setWrite={}, setExecutable={}; subsequent failures (on any file) will be logged at trace",
                            new Object[] { file.getAbsolutePath(), setRead, setWrite, setExec });
            } else {
                LOG.warn(
                        "Failed to set permissions to 600 for file {}: setRead={}, setWrite={}, setExecutable={}; subsequent failures (on any file) will be logged at trace",
                        new Object[] { file.getAbsolutePath(), setRead, setWrite, setExec });
            }
            loggedSetFilePermissionsWarning = true;
        }
    }
}

From source file:org.arquillian.cube.kubernetes.impl.utils.ProcessUtil.java

public static int runCommand(final Logger log, URL scriptUrl, Map<String, String> env) throws IOException {
    File scriptFile = File.createTempFile("arquillian-cube-script", getSuffix());
    FileUtils.copyURLToFile(scriptUrl, scriptFile);
    scriptFile.setExecutable(true, false);
    return runCommand(log, getCommand(), Arrays.asList(new String[] { scriptFile.getAbsolutePath() }), env,
            true);/*from  w w w  .ja v  a2s  .c  o m*/
}

From source file:io.github.blindio.prospero.core.browserdrivers.phantomjs.PhantomJSInstaller.java

public static String getPhantomJS() {
    File phantomJS = getPhantomJSExecutableFile();
    if (!phantomJS.exists()) {
        installPhantomJS();/*w  w w.  j ava2 s.c om*/
    }

    if (!phantomJS.canExecute()) {
        phantomJS.setExecutable(true, false);
    }

    return phantomJS.getAbsolutePath();
}

From source file:org.jboss.as.forge.util.Files.java

/**
 * Sets the permissions on the file./*from w  w  w. ja v a  2s  .  c  om*/
 *
 * @param file        the file
 * @param permissions the permissions to set
 */
public static void setPermissions(final File file, final FilePermissions permissions) {
    file.setExecutable(permissions.owner().canExecute(),
            !(permissions.group().canExecute() && permissions.pub().canExecute()));
    file.setReadable(permissions.owner().canWrite(),
            !(permissions.group().canWrite() && permissions.pub().canWrite()));
    file.setWritable(permissions.owner().canWrite(),
            !(permissions.group().canWrite() && permissions.pub().canWrite()));
}

From source file:ezbake.deployer.impl.Files.java

@SuppressWarnings("ResultOfMethodCallIgnored")
public static void setPosixFilePermissions(File file, Set<PosixFilePermission> filePermissions) {
    if (filePermissions.contains(PosixFilePermission.OWNER_EXECUTE))
        file.setExecutable(true, filePermissions.contains(PosixFilePermission.GROUP_EXECUTE)
                || filePermissions.contains(PosixFilePermission.OTHERS_EXECUTE));
    if (filePermissions.contains(PosixFilePermission.OWNER_READ))
        file.setReadable(true, filePermissions.contains(PosixFilePermission.GROUP_READ)
                || filePermissions.contains(PosixFilePermission.OTHERS_READ));
    if (filePermissions.contains(PosixFilePermission.OWNER_WRITE))
        file.setWritable(true, filePermissions.contains(PosixFilePermission.GROUP_WRITE)
                || filePermissions.contains(PosixFilePermission.OTHERS_WRITE));
}

From source file:com.dubture.symfony.core.util.UncompressUtils.java

/**
 * Add the executable bit to a file. The file must not be a directory otherwise
 * false is returned. If the executable bit has been applied successfully, the
 * method returns true. If the permissions specify
 *
 * @param file The file to add executable bit to
 * @param permissions The permissions associated with the file
 *
 * @return True if the application succeeded, false otherwise
 *//*from  w w  w .  ja va 2  s  .  c  o  m*/
private static boolean addExecutableBit(File file, Permissions permissions) {
    if (file.isDirectory() || !permissions.hasExecutableBit()) {
        return false;
    }

    return file.setExecutable(true, permissions.hasOnlyOwnerExecutableBit());
}

From source file:cz.cuni.amis.planning4j.validation.external.ValValidator.java

public static void extractAndPrepareValidator(File targetDirectory) {
    String folderName = getValidatorFolderName();
    try {/*from w w  w.  ja  va  2s . co m*/
        for (String fileToExtractName : getAuxiliaryFiles()) {
            File binaryFile = new File(targetDirectory, folderName + File.separatorChar + fileToExtractName);

            ItSimpleUtils.extractFileIfNotExists(binaryFile, "/" + folderName + "/" + fileToExtractName);
        }
        String validatorExecutableName = getValidatorExecutableName();
        File mainExecutable = new File(targetDirectory,
                folderName + File.separatorChar + validatorExecutableName);
        ItSimpleUtils.extractFileIfNotExists(mainExecutable, "/" + folderName + "/" + validatorExecutableName);
        mainExecutable.setExecutable(true, false);
    } catch (Exception ex) {
        throw new ValidationException("Could not extract VAL binaries.", ex);
    }
}