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) 

Source Link

Document

A convenience method to set the owner's execute permission for this abstract pathname.

Usage

From source file:edu.wisc.doit.tcrypt.TokenEncryptDecryptIT.java

@Test
public void testJavaEncOpenSSLDec() throws Exception {
    //Encrypt with Java
    final String expected = "foobar";
    final String encrypted = this.tokenEncrypter.encrypt(expected);

    //Decrypt with OpenSSL
    final File decryptFileScript = setupTempFile("decryptToken.sh");
    decryptFileScript.setExecutable(true);

    final File privateKey = setupTempFile("my.wisc.edu-private.pem");

    final ProcessBuilder pb = new ProcessBuilder(decryptFileScript.getAbsolutePath(),
            privateKey.getAbsolutePath(), encrypted);

    final Process p = pb.start();
    final int ret = p.waitFor();
    if (ret != 0) {
        final String pOut = IOUtils.toString(p.getInputStream(), TokenEncrypter.CHARSET).trim();
        System.out.println(pOut);
        final String pErr = IOUtils.toString(p.getErrorStream(), TokenEncrypter.CHARSET).trim();
        System.out.println(pErr);
    }//from   w w  w .ja v  a2  s.  com
    assertEquals(0, ret);

    final String actual = IOUtils.toString(p.getInputStream(), TokenEncrypter.CHARSET).trim();

    //Verify
    assertEquals(expected, actual);
}

From source file:edu.wisc.doit.tcrypt.BouncyCastleFileEncrypterDecrypterIT.java

@Test
public void testOpenSSLEncJavaDec() throws Exception {
    //Encrypt with openssl
    final File encryptFileScript = setupTempFile("encryptFile.sh");
    encryptFileScript.setExecutable(true);

    final File publicKey = setupTempFile("my.wisc.edu-public.pem");
    final File testFile = setupTempFile("testFile.txt");

    final ProcessBuilder pb = new ProcessBuilder(encryptFileScript.getAbsolutePath(),
            publicKey.getAbsolutePath(), testFile.getAbsolutePath());

    final Process p = pb.start();
    final int ret = p.waitFor();
    if (ret != 0) {
        final String pOut = IOUtils.toString(p.getInputStream(), TokenEncrypter.CHARSET).trim();
        System.out.println(pOut);
        final String pErr = IOUtils.toString(p.getErrorStream(), TokenEncrypter.CHARSET).trim();
        System.out.println(pErr);
    }/*from w  ww.ja  v a2  s . com*/
    assertEquals(0, ret);

    //Decrypt with java
    final File encryptedFile = new File(testFile.getParentFile(), "testFile.txt.tar");

    final InputStream encTestFileInStream = new FileInputStream(encryptedFile);
    final ByteArrayOutputStream testFileOutStream = new ByteArrayOutputStream();
    fileDecrypter.decrypt(encTestFileInStream, testFileOutStream);
    final String actual = new String(testFileOutStream.toByteArray(), Charset.defaultCharset()).trim();

    //Verify
    final String expected = FileUtils.readFileToString(testFile);
    assertEquals(expected, actual);
}

From source file:edu.wisc.doit.tcrypt.BouncyCastleFileEncrypterDecrypterIT.java

@Test
public void testJavaEncOpenSSLDec() throws Exception {
    //Encrypt with Java
    final File testFile = setupTempFile("testFile.txt");

    InputStream testFileInStream = new FileInputStream(testFile);

    final File encFile = this.testFolder.newFile("testFile.txt.tar");
    this.fileEncrypter.encrypt("testFile.txt", (int) testFile.length(), testFileInStream,
            new FileOutputStream(encFile));

    //Decrypt with OpenSSL
    final File decryptFileScript = setupTempFile("decryptFile.sh");
    decryptFileScript.setExecutable(true);

    final File privateKey = setupTempFile("my.wisc.edu-private.pem");

    final ProcessBuilder pb = new ProcessBuilder(decryptFileScript.getAbsolutePath(),
            privateKey.getAbsolutePath(), encFile.getAbsolutePath());

    final Process p = pb.start();
    final int ret = p.waitFor();
    if (ret != 0) {
        final String pOut = IOUtils.toString(p.getInputStream(), TokenEncrypter.CHARSET).trim();
        System.out.println(pOut);
        final String pErr = IOUtils.toString(p.getErrorStream(), TokenEncrypter.CHARSET).trim();
        System.out.println(pErr);
    }/*  ww  w.  j a va 2s. c  om*/
    assertEquals(0, ret);

    final File decryptedFile = new File(encFile.getParentFile(), "testFile.txt");

    //Verify
    final String expected = FileUtils.readFileToString(testFile);
    final String actual = FileUtils.readFileToString(decryptedFile);
    assertEquals(expected, actual);
}

From source file:org.jenkinsci.test.acceptance.po.ToolInstallation.java

protected String fakeHome(String binary, String homeEnvName) {
    try {/* www.  j  ava  2  s  . c  o m*/
        final File home = File.createTempFile("toolhome", binary);

        home.delete();
        new File(home, "bin").mkdirs();
        home.deleteOnExit();

        final String path = new CommandBuilder("which", binary).popen().asText().trim();
        final String code = String.format("#!/bin/sh\nexport %s=\nexec %s \"$@\"\n", homeEnvName, path);

        final File command = new File(home, "bin/" + binary);
        FileUtils.writeStringToFile(command, code);
        command.setExecutable(true);

        return home.getAbsolutePath();
    } catch (IOException ex) {
        throw new Error(ex);
    } catch (InterruptedException ex) {
        throw new Error(ex);
    }
}

From source file:org.uberfire.java.nio.fs.jgit.util.commands.CreateRepository.java

public Optional<Git> execute() {
    try {/*from   w w  w . j av  a2 s . c  om*/
        final org.eclipse.jgit.api.Git _git = org.eclipse.jgit.api.Git.init().setBare(true)
                .setDirectory(repoDir).call();

        if (leaders != null) {
            new WriteConfiguration(_git.getRepository(), cfg -> {
                cfg.setInt("core", null, "repositoryformatversion", 1);
                cfg.setString("extensions", null, "refsStorage", "reftree");
            }).execute();
        }

        final Repository repo = new FileRepositoryBuilder().setGitDir(repoDir).build();

        final org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repo);

        if (hookDir != null) {
            final File repoHookDir = new File(repoDir, "hooks");

            try {
                FileUtils.copyDirectory(hookDir, repoHookDir);
            } catch (final Exception ex) {
                throw new RuntimeException(ex);
            }

            for (final File file : repoHookDir.listFiles()) {
                if (file != null && file.isFile()) {
                    file.setExecutable(true);
                }
            }
        }

        return Optional.of(new GitImpl(git, leaders));
    } catch (final Exception ex) {
        throw new IOException(ex);
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestNNStorageFailures.java

@Test
public void testAllImageDirsFailOnRoll() throws IOException {
    assertTrue(doAnEdit());//from w  w w .  ja  v a2  s  . c  o  m
    Collection<File> namedirs = cluster.getNameDirs();
    for (File f : namedirs) {
        LOG.info("Changing permissions for directory " + f);
        f.setExecutable(false);
    }
    try {
        cluster.getNameNode().getNamesystem().rollEditLog();
        fail("Should get an exception here");
    } catch (IOException e) {
        LOG.info(e);
        assertTrue(e.toString().contains("No image locations are available"));
        // image dirs are not writable
        assertEquals(2, NameNode.getNameNodeMetrics().imagesFailed.get());
        // journals are separate, and accessible
        assertEquals(0, NameNode.getNameNodeMetrics().journalsFailed.get());
    } finally {
        for (File f : namedirs) {
            LOG.info("Changing permissions for directory " + f);
            f.setExecutable(true);
        }
    }
}

From source file:org.openengsb.openengsbplugin.Provision.java

private void createExecutableCommand(CommandLineBuilder command, String executablePath) {
    File executable = new File(RUNNER + executablePath);
    executable.setExecutable(true);
    command.append(executable.getAbsolutePath());
}

From source file:com.comcast.dawg.selenium.ChromeDriverProvider.java

/**
 * Provides the appropriate chromedriver for the currently running os.
 *
 * @throws  IOException  if we're unable to determine the os
 *//*from  w w  w.  j  a  v  a  2s. co m*/
public File getDriverFile() throws IOException {
    String driver;
    String filename;
    String chromeDriverPath = System.getProperty(SYSTEM_PROP_KEY);
    chromeDriverPath = chromeDriverPath == null ? System.getenv(ENV_KEY) : chromeDriverPath;
    if (chromeDriverPath == null) {
        if (isWindows) {
            driver = WINDOWS;
            filename = WINDOWS_FILENAME;
        } else if (isLinux) {
            filename = LINUX_FILENAME;

            if (is32bit()) {
                driver = LINUX_32;
            } else {
                driver = LINUX_64;
            }
        } else if (isMac) {
            filename = MAC_FILENAME;
            driver = MAC_32;
        } else {
            System.out.println(this.toString());

            // We're on an unknown OS and the driver won't run.
            throw new IOException("A compatible executable could not be determined for this operating system");
        }

        System.out.println("Getting resource for: " + driver + " having filename: " + filename);
        System.out.println(ChromeDriverProvider.class.getResource(DRIVER_DIR + driver));

        InputStream srcFile = ChromeDriverProvider.class.getResourceAsStream(DRIVER_DIR + driver);
        File destFile = new File(USER_HOME + TEMP_DIR + filename);

        copyFile(srcFile, destFile);
        destFile.setExecutable(true);

        return destFile;
    } else {
        return new File(chromeDriverPath);
    }
}

From source file:org.rhq.cassandra.Deployer.java

public void updateFilePerms() {
    File deployDir = new File(deploymentOptions.getBasedir());
    File binDir = new File(deployDir, "bin");

    log.info("Updating file permissions in " + binDir);

    for (File f : binDir.listFiles()) {
        f.setExecutable(true);
    }/*from   w w  w  . jav  a2  s .c  om*/
}

From source file:com.dianping.phoenix.dev.core.tools.wms.AgentWorkspaceServiceImpl.java

@Override
protected void generateWorkspaceMisc(WorkspaceContext context) throws Exception {
    WorkspaceStartSHGenerator workspaceStartSHGenerator = new WorkspaceStartSHGenerator();
    File startSh = new File(context.getBaseDir(), "start.sh");
    workspaceStartSHGenerator.generate(startSh, new ArrayList<String>());
    startSh.setExecutable(true);

    WorkspaceStopSHGenerator workspaceStopSHGenerator = new WorkspaceStopSHGenerator();
    File stopSh = new File(context.getBaseDir(), "stop.sh");
    workspaceStopSHGenerator.generate(stopSh, new ArrayList<String>());
    stopSh.setExecutable(true);/*from ww w  .  ja v  a  2s.  c om*/
}