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:org.jboss.qa.jenkins.test.executor.utils.unpack.GUnZipper.java

@Override
public void unpack(File archive, File destination) throws IOException {
    try (FileInputStream in = new FileInputStream(archive);
            GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
            TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn)) {
        final Set<TarArchiveEntry> entries = getEntries(tarIn);

        if (ignoreRootFolders) {
            pathSegmentsToTrim = countRootFolders(entries);
        }// w  w  w . jav a2  s .com

        for (TarArchiveEntry entry : entries) {
            if (entry.isDirectory()) {
                continue;
            }

            final File file = new File(destination, trimPathSegments(entry.getName(), pathSegmentsToTrim));
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }

            try (FileOutputStream fos = new FileOutputStream(file)) {
                IOUtils.copy(tarIn, fos);

                // check for user-executable bit on entry and apply to file
                if ((entry.getMode() & 0100) != 0) {
                    file.setExecutable(true);
                }
            }
        }
    }
}

From source file:ddf.content.plugin.video.VideoThumbnailPlugin.java

private void copyFFmpegBinary(final InputStream inputStream) throws IOException {
    final File ffmpegBinary = new File(ffmpegPath);

    if (!ffmpegBinary.exists()) {
        FileUtils.copyInputStreamToFile(inputStream, ffmpegBinary);
        if (!ffmpegBinary.setExecutable(true)) {
            LOGGER.warn(/*from  w  w  w. jav a 2 s  . co  m*/
                    "Couldn't make FFmpeg binary at {} executable. It must be executable by its owner for the plugin to work.",
                    ffmpegPath);
        }
    }
}

From source file:org.apache.stratos.cartridge.agent.test.JavaCartridgeAgentTest.java

/**
 * Setup the JCA test path, copy test configurations
 *
 * @return//www . j a v  a2 s .co  m
 */
private String setupJavaAgent() {
    try {
        log.info("Setting up Java cartridge agent test setup");
        String jcaZipSource = getResourcesFolderPath()
                + "/../../../../products/cartridge-agent/modules/distribution/target/" + AGENT_NAME + ".zip";
        String testHome = getResourcesFolderPath() + "/../" + UUID.randomUUID() + "/";
        File agentHome = new File(testHome + AGENT_NAME);
        log.info("Extracting Java Cartridge Agent to test folder");
        ZipFile agentZip = new ZipFile(jcaZipSource);
        ProgressMonitor zipProgresMonitor = agentZip.getProgressMonitor();
        agentZip.extractAll(testHome);
        while (zipProgresMonitor.getPercentDone() < 100) {
            log.info("Extracting: " + zipProgresMonitor.getPercentDone());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        log.info("Copying agent jar");
        String agentJar = "org.apache.stratos.cartridge.agent-4.2.0-SNAPSHOT.jar";
        String agentJarSource = getResourcesFolderPath() + "/../" + agentJar;
        String agentJarDest = agentHome.getCanonicalPath() + "/lib/" + agentJar;
        FileUtils.copyFile(new File(agentJarSource), new File(agentJarDest));

        log.info("Copying test payload file");
        String srcPayloadPath = getResourcesFolderPath() + "/../../src/test/resources/payload";
        String destPayloadPath = agentHome + "/payload";
        FileUtils.copyDirectory(new File(srcPayloadPath), new File(destPayloadPath));

        log.info("Copying test conf files");
        String srcConf = getResourcesFolderPath() + "/../../src/test/resources/conf";
        String destConf = agentHome + "/conf";
        FileUtils.copyDirectory(new File(srcConf), new File(destConf));

        log.info("Copying test stratos.sh script");
        String srcBin = getResourcesFolderPath() + "/../../src/test/resources/bin";
        String destBin = agentHome + "/bin";
        FileUtils.copyDirectory(new File(srcBin), new File(destBin));

        log.info("Changing stratos.sh permissions");
        new File(agentHome.getCanonicalPath() + "/bin/stratos.sh").setExecutable(true);
        log.info("Changed permissions for stratos.sh");

        log.info("Changing extension scripts permissions");
        File extensionsPath = new File(agentHome.getCanonicalPath() + "/extensions/");
        File[] extensions = extensionsPath.listFiles();
        for (File extension : extensions) {
            extension.setExecutable(true);
        }
        log.info("Changed permissions for extensions : " + outputStream);

        log.info("Java cartridge agent setup complete.");

        return agentHome.getCanonicalPath();
    } catch (IOException e) {
        String message = "Could not copy cartridge agent distribution";
        log.error(message, e);
        throw new RuntimeException(message, e);
    } catch (ZipException e) {
        String message = "Could not unzip cartridge agent distribution. Please make sure to build <STRATOS_HOME>/products/cartridge-agent first.";
        log.error(message, e);
        throw new RuntimeException(message, e);
    }
}

From source file:org.jboss.qa.jenkins.test.executor.utils.unpack.UnZipper.java

@Override
public void unpack(File archive, File destination) throws IOException {
    try (ZipFile zip = new ZipFile(archive)) {
        final Set<ZipArchiveEntry> entries = new HashSet<>(Collections.list(zip.getEntries()));

        if (ignoreRootFolders) {
            pathSegmentsToTrim = countRootFolders(entries);
        }//from ww  w .j  ava2  s .c  o  m

        for (ZipArchiveEntry entry : entries) {
            if (entry.isDirectory()) {
                continue;
            }
            final String zipPath = trimPathSegments(entry.getName(), pathSegmentsToTrim);
            final File file = new File(destination, zipPath);
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs(); // Create parent folders if not exist
            }

            try (InputStream is = zip.getInputStream(entry); OutputStream fos = new FileOutputStream(file)) {
                IOUtils.copy(is, fos);
                // check for user-executable bit on entry and apply to file
                if ((entry.getUnixMode() & 0100) != 0) {
                    file.setExecutable(true);
                }
            }
            file.setLastModified(entry.getTime());
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.RuntimeProvider.java

public void install() throws IOException {
    if (installed) {
        return;/*from  ww  w .  j a  v a2  s .  com*/
    }

    Properties manifest = getManifest();
    for (String filename : manifest.stringPropertyNames()) {
        URL source = resolveLocation(baseLocation + platform + "/" + filename, this, null);
        File target = new File(getWorkspace(), filename);
        InputStream is = null;
        OutputStream os = null;
        try {
            is = source.openStream();
            os = new FileOutputStream(target);
            IOUtils.copyLarge(is, os);
        } finally {
            closeQuietly(is);
            closeQuietly(os);
        }

        if (MODE_EXECUTABLE.equals(manifest.getProperty(filename))) {
            target.setExecutable(true);
        }

        target.deleteOnExit();
    }

    installed = true;
}

From source file:edu.isi.wings.portal.controllers.ComponentController.java

public boolean initializeComponentFiles(String cid, String lang) {
    try {/*from w  w  w .j a  va 2 s.  c o m*/
        Component c = cc.getComponent(cid, true);
        String loc = c.getLocation();
        if (loc == null) {
            loc = cc.getDefaultComponentLocation(cid);
            c.setLocation(loc);
            cc.setComponentLocation(cid, loc);
            cc.save();
        }

        // Copy io.sh from resources
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        FileUtils.copyInputStreamToFile(classloader.getResourceAsStream("io.sh"), new File(loc + "/io.sh"));

        int numi = 0, nump = 0, numo = c.getOutputs().size();
        for (ComponentRole r : c.getInputs()) {
            if (r.isParam())
                nump++;
            else
                numi++;
        }

        String suffix = "";
        for (int i = 1; i <= numi; i++)
            suffix += " $INPUTS" + i;
        for (int i = 1; i <= nump; i++)
            suffix += " $PARAMS" + i;
        for (int i = 1; i <= numo; i++)
            suffix += " $OUTPUTS" + i;

        String runscript = "";
        String filename = null;
        for (String line : IOUtils.readLines(classloader.getResourceAsStream("run"))) {
            if (line.matches(".*io\\.sh.*")) {
                // Number of inputs and outputs
                line = ". $BASEDIR/io.sh " + numi + " " + nump + " " + numo + " \"$@\"";
            } else if (line.matches(".*generic_code.*")) {
                // Code invocation
                if (lang.equals("R")) {
                    filename = c.getName() + ".R";
                    line = "Rscript --no-save --no-restore $BASEDIR/" + filename;
                } else if (lang.equals("PHP")) {
                    filename = c.getName() + ".php";
                    line = "php $BASEDIR/" + filename;
                } else if (lang.equals("Python")) {
                    filename = c.getName() + ".py";
                    line = "python $BASEDIR/" + filename;
                } else if (lang.equals("Perl")) {
                    filename = c.getName() + ".pl";
                    line = "perl $BASEDIR/" + filename;
                } else if (lang.equals("Java")) {
                    line = "# Relies on existence of " + c.getName() + ".class file in this directory\n";
                    line += "java -classpath $BASEDIR " + c.getName();
                }
                // Add inputs, outputs as suffixes
                line += suffix;
            }
            runscript += line + "\n";
        }
        File runFile = new File(loc + "/run");
        FileUtils.writeStringToFile(runFile, runscript);
        runFile.setExecutable(true);

        if (filename != null)
            new File(loc + "/" + filename).createNewFile();

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        cc.end();
        dc.end();
        prov.end();
    }
    return false;
}

From source file:com.sap.prd.mobile.ios.mios.XCodeCopySourcesMojo.java

private void copy(final File source, final File targetDirectory, final FileFilter excludes) throws IOException {

    for (final File sourceFile : source.listFiles()) {
        final File destFile = new File(targetDirectory, sourceFile.getName());
        if (sourceFile.isDirectory()) {

            if (excludes.accept(sourceFile)) {
                copy(sourceFile, destFile, excludes);
            } else {
                getLog().info("File '" + sourceFile + "' ommited.");
            }/* w w w.ja  v  a2s . com*/
        } else {
            FileUtils.copyFile(sourceFile, destFile);
            if (sourceFile.canExecute()) {
                destFile.setExecutable(true);
            }
            getLog().debug((destFile.canExecute() ? "Executable" : "File '") + sourceFile + "' copied to '"
                    + destFile + "'.");
        }
    }
}

From source file:it.drwolf.ridire.index.cwb.CWBFrequencyList.java

private String getFrequencyList(boolean deleteFLFile, List<String> semDescription, List<String> funDescription,
        int quantityP, String type, Integer threshold, boolean sorted) {
    CommandLine commandLine = CommandLine.parse(this.cwbscanExecutable);
    commandLine.addArgument("-q");
    if (threshold != null && threshold > 0) {
        commandLine.addArgument("-f");
        commandLine.addArgument(threshold + "");
    }//from  ww w. j a  va 2s  . c  o m
    commandLine.addArgument("-r").addArgument(this.cqpRegistry);
    commandLine.addArgument("-C");
    commandLine.addArgument(this.cqpCorpusName);
    if (type.equals("forma")) {
        commandLine.addArgument("word+0");
    } else if (type.equals("PoS")) {
        commandLine.addArgument("pos+0");
    } else if (type.equals("easypos")) {
        commandLine.addArgument("easypos+0");
    } else if (type.equals("lemma")) {
        commandLine.addArgument("lemma+0");
    } else if (type.equals("PoS-forma")) {
        commandLine.addArgument("pos+0");
        commandLine.addArgument("word+0");
    } else if (type.equals("PoS-lemma")) {
        commandLine.addArgument("pos+0");
        commandLine.addArgument("lemma+0");
    }
    String semFuncParam = "";
    if (funDescription != null && funDescription.size() > 0 && funDescription.get(0) != null
            && funDescription.get(0).trim().length() > 0
            || semDescription != null && semDescription.size() > 0 && semDescription.get(0) != null
                    && semDescription.get(0).trim().length() > 0) {
        semFuncParam = "?";
        if (funDescription != null && funDescription.size() > 0 && funDescription.get(0) != null
                && funDescription.get(0).trim().length() > 0) {
            String fd = StringUtils.join(funDescription, "\\|");
            semFuncParam += "text_functional=/\\(" + fd + "\\)/ ";
        }
        if (semDescription != null && semDescription.size() > 0 && semDescription.get(0) != null
                && semDescription.get(0).trim().length() > 0) {
            String sd = StringUtils.join(semDescription, "\\|");
            semFuncParam += "text_semantic=/\\(" + sd + "\\)/ ";

        }
        commandLine.addArgument(semFuncParam);
    }
    if (sorted) {
        commandLine.addArgument("|");
        commandLine.addArgument("sort");
        commandLine.addArgument("-nr");
        commandLine.addArgument("-k");
        commandLine.addArgument("1");
    }
    if (quantityP > 0) {
        commandLine.addArgument("|");
        commandLine.addArgument("head");
        commandLine.addArgument("-" + quantityP);
    }
    File flTempFile = null;
    try {
        flTempFile = File.createTempFile("ridireFL", null);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    commandLine.addArgument(" > ");
    commandLine.addArgument(flTempFile.getAbsolutePath());
    String c = commandLine.toString();
    try {
        File tempSh = File.createTempFile("ridireSH", ".sh");
        FileUtils.writeStringToFile(tempSh, c);
        tempSh.setExecutable(true);
        commandLine = CommandLine.parse(tempSh.getAbsolutePath());
        DefaultExecutor executor = new DefaultExecutor();
        executor.setExitValue(0);
        ExecuteWatchdog watchdog = new ExecuteWatchdog(CWBFrequencyList.TIMEOUT);
        executor.setWatchdog(watchdog);
        ByteArrayOutputStream baosStdOut = new ByteArrayOutputStream(1024);
        ByteArrayOutputStream baosStdErr = new ByteArrayOutputStream(1024);
        ExecuteStreamHandler executeStreamHandler = new PumpStreamHandler(baosStdOut, baosStdErr, null);
        executor.setStreamHandler(executeStreamHandler);
        int exitValue = 0;
        exitValue = executor.execute(commandLine);
        FileUtils.deleteQuietly(tempSh);
        if (exitValue == 0) {
            StrTokenizer strTokenizer = new StrTokenizer();
            this.frequencyList = new ArrayList<FrequencyItem>();
            List<String> lines = FileUtils.readLines(flTempFile);
            for (String line : lines) {
                strTokenizer.reset(line);
                String[] tokens = strTokenizer.getTokenArray();
                if (tokens.length == 2) {
                    FrequencyItem frequencyItem = new FrequencyItem(tokens[1],
                            Integer.parseInt(tokens[0].trim()));
                    this.frequencyList.add(frequencyItem);
                } else if (tokens.length == 3) {
                    FrequencyItem frequencyItem = new FrequencyItem(tokens[2], tokens[1],
                            Integer.parseInt(tokens[0].trim()));
                    this.frequencyList.add(frequencyItem);
                }
            }
            if (deleteFLFile) {
                FileUtils.deleteQuietly(flTempFile);
            }
        }
    } catch (ExecuteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return flTempFile.getAbsolutePath();
}

From source file:org.apache.hadoop.hdfs.server.datanode.TestDataNodeVolumeFailureReporting.java

@After
public void tearDown() throws Exception {
    IOUtils.cleanup(LOG, fs);//w ww . j av a2 s. c  o m
    if (cluster != null) {
        for (File dir : cluster.getAllInstanceStorageDirs()) {
            dir.setExecutable(true);
        }
        IOUtils.cleanup(LOG, fs);
        cluster.shutdown();
    }
}

From source file:org.kalypso.kalypsomodel1d2d.sim.TelemacKalypsoSimulation.java

private File findTelemacBatch(final String exeVersionName, File tmpdir) throws CoreException {
    final File batchFile = new File(tmpdir, "runTelemacKalypso.bat"); //$NON-NLS-1$

    OutputStream batchOutStream = null;
    try {//from   w  w  w. j a v a 2s  .  c om
        batchOutStream = new BufferedOutputStream(new FileOutputStream(batchFile));

        Formatter formatter = new Formatter(batchOutStream);
        formatter.format("%s", exeVersionName);
        batchFile.setExecutable(true);
        formatter.close();
        batchOutStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (batchFile.exists())
        return batchFile;
    // final Location installLocation = Platform.getInstallLocation();
    // final File installDir = FileUtils.toFile( installLocation.getURL() );
    //    final File exeDir = new File( installDir, "bin" ); //$NON-NLS-1$
    // final File exeFile = new File( exeDir, exeName );
    // return exeFile;

    final String exeMissingMsg = String.format(
            Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.26"), //$NON-NLS-1$
            batchFile.getAbsolutePath());
    throw new CoreException(StatusUtilities.createErrorStatus(exeMissingMsg));
}