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:com.frostwire.gui.updates.PortableUpdater.java

private void fixExecutablePermissions(File file, String[] exePaths) {
    if (file.isDirectory()) {
        for (File child : file.listFiles()) {
            fixExecutablePermissions(child, exePaths);
        }/*w  w w .  ja  v  a 2  s  .  c  o m*/
    } else {
        for (String path : exePaths) {
            if (file.getPath().contains(path)) {
                file.setExecutable(true);
            }
        }
    }
}

From source file:com.isomorphic.maven.mojo.AbstractPackagerMojo.java

/**
 * Provides some initialization and validation steps around the collection and transformation of an Isomorphic SDK. 
 * // w ww  . j  av  a2s.  c o  m
 * @throws MojoExecutionException When any fatal error occurs.
 * @throws MojoFailureException When any non-fatal error occurs. 
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(false);
    if (buildDate == null) {
        buildDate = dateFormat.format(new Date());
    }
    try {
        dateFormat.parse(buildDate);
    } catch (ParseException e) {
        throw new MojoExecutionException(
                String.format("buildDate '%s' must take the form yyyy-MM-dd.", buildDate));
    }

    LOGGER.debug("buildDate set to '{}'", buildDate);

    String buildNumberFormat = "\\d.*\\.\\d.*[d|p]";
    if (!buildNumber.matches(buildNumberFormat)) {
        throw new MojoExecutionException(
                String.format("buildNumber '%s' must take the form [major].[minor].[d|p].  e.g., 4.1d",
                        buildNumber, buildNumberFormat));
    }

    File basedir = FileUtils.getFile(workdir, product.toString(), license.toString(), buildNumber, buildDate);

    //add optional modules to the list of downloads
    List<License> licenses = new ArrayList<License>();
    licenses.add(license);
    if (license == POWER || license == ENTERPRISE) {
        if (includeAnalytics) {
            licenses.add(ANALYTICS_MODULE);
        }
        if (includeMessaging) {
            licenses.add(MESSAGING_MODULE);
        }
    }

    //collect the maven artifacts and send them along to the abstract method
    Set<Module> artifacts = collect(licenses, basedir);

    File bookmarkable = new File(basedir.getParent(), "latest");
    LOGGER.info("Copying distribution to '{}'", bookmarkable.getAbsolutePath());
    try {
        FileUtils.forceMkdir(bookmarkable);
        FileUtils.cleanDirectory(bookmarkable);
        FileUtils.copyDirectory(basedir, bookmarkable,
                FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("zip")));
    } catch (IOException e) {
        throw new MojoFailureException("Unable to copy distribution contents", e);
    }

    String[] executables = { "bat", "sh", "command" };
    Collection<File> scripts = FileUtils.listFiles(basedir, executables, true);
    scripts.addAll(FileUtils.listFiles(bookmarkable, executables, true));
    for (File script : scripts) {
        script.setExecutable(true);
        LOGGER.debug("Enabled execute permissions on file '{}'", script.getAbsolutePath());
    }
    doExecute(artifacts);

}

From source file:org.dataone.proto.trove.mn.service.v1.impl.MNStorageImpl.java

@Override
public Identifier create(Identifier pid, InputStream object, SystemMetadata sysmeta)
        throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType,
        InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest {
    try {/* w  w  w.j  a  v  a  2  s. c o  m*/
        File systemMetadata = new File(dataoneCacheDirectory + File.separator + "meta" + File.separator
                + EncodingUtilities.encodeUrlPathSegment(pid.getValue()));
        TypeMarshaller.marshalTypeToFile(sysmeta, systemMetadata.getAbsolutePath());

        if (systemMetadata.exists()) {
            systemMetadata.setLastModified(sysmeta.getDateSysMetadataModified().getTime());
        } else {
            throw new ServiceFailure("1190", "SystemMetadata not found on FileSystem after create");
        }
        File objectFile = new File(dataoneCacheDirectory + File.separator + "object" + File.separator
                + EncodingUtilities.encodeUrlPathSegment(pid.getValue()));
        if (!objectFile.exists() && objectFile.createNewFile()) {
            objectFile.setReadable(true);
            objectFile.setWritable(true);
            objectFile.setExecutable(false);
        }

        if (object != null) {
            FileOutputStream objectFileOutputStream = new FileOutputStream(objectFile);
            BufferedInputStream inputStream = new BufferedInputStream(object);
            byte[] barray = new byte[SIZE];
            int nRead = 0;

            while ((nRead = inputStream.read(barray, 0, SIZE)) != -1) {
                objectFileOutputStream.write(barray, 0, nRead);
            }
            objectFileOutputStream.flush();
            objectFileOutputStream.close();
            inputStream.close();
        }
    } catch (FileNotFoundException ex) {
        throw new ServiceFailure("1190", ex.getCause().toString() + ":" + ex.getMessage());
    } catch (IOException ex) {
        throw new ServiceFailure("1190", ex.getMessage());
    } catch (JiBXException ex) {
        throw new InvalidSystemMetadata("1180", ex.getMessage());
    }
    return pid;
}

From source file:com.blackducksoftware.integration.hub.cli.CLILocation.java

public File getProvidedJavaExec() throws IOException, InterruptedException {
    final File cliHomeFile = getCLIHome();
    if (cliHomeFile == null) {
        return null;
    }/*  www.j  a  v  a 2s  .  com*/

    final File[] files = cliHomeFile.listFiles();
    final File jreFolder = findFileByName(files, "jre");
    if (jreFolder == null) {
        return null;
    }

    final File jreContents = getJreContentsDirectory(jreFolder);
    File javaExec = new File(jreContents, "bin");
    if (SystemUtils.IS_OS_WINDOWS) {
        javaExec = new File(javaExec, "java.exe");
    } else {
        javaExec = new File(javaExec, "java");
    }
    if (!javaExec.exists()) {
        return null;
    }

    javaExec.setExecutable(true);
    return javaExec;
}

From source file:edu.stanford.epad.epadws.processing.pipeline.task.DicomHeadersTask.java

@Override
public void run() {
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // Let interactive thread run sooner
    FileWriter tagFileWriter = null;
    InputStream is = null;/* ww  w  .ja  v  a  2s .com*/
    InputStreamReader isr = null;
    BufferedReader br = null;
    Process process = null;

    try {
        String[] command = { "./dcm2txt", "-w", "250", "-l", "250", dicomInputFile.getAbsolutePath() };
        ProcessBuilder processBuilder = new ProcessBuilder(command);
        String dicomBinDir = EPADConfig.getEPADWebServerDICOMScriptsDir() + "bin/";
        File script = new File(dicomBinDir, "dcm2txt");
        if (!script.exists())
            dicomBinDir = EPADConfig.getEPADWebServerDICOMBinDir();
        script = new File(dicomBinDir, "dcm2txt");
        // Java 6 - Runtime.getRuntime().exec("chmod u+x "+script.getAbsolutePath());
        script.setExecutable(true);

        processBuilder.directory(new File(dicomBinDir));
        process = processBuilder.start();
        process.getOutputStream();

        is = process.getInputStream();
        isr = new InputStreamReader(is);
        br = new BufferedReader(isr);

        String line;
        StringBuilder sb = new StringBuilder();
        StringBuilder log = new StringBuilder();
        while ((line = br.readLine()) != null) {
            sb.append(line).append("\n");
            log.append("./dcm2txt: " + line).append("\n");
        }

        try {
            process.waitFor();
        } catch (InterruptedException e) {
            logger.info(log.toString());
            logger.warning("Couldn't get tags for series " + seriesUID + "; dicom="
                    + dicomInputFile.getAbsolutePath() + " tagFile:" + outputFile.getAbsolutePath(), e);
        }

        EPADFileUtils.createDirsAndFile(outputFile);
        File tagFile = outputFile;
        tagFileWriter = new FileWriter(tagFile);
        tagFileWriter.write(sb.toString());
    } catch (Exception e) {
        logger.warning("DicomHeadersTask failed to create DICOM tags for series " + seriesUID + " dicom FIle:"
                + dicomInputFile.getAbsolutePath() + " : " + outputFile.getAbsolutePath(), e);
    } catch (OutOfMemoryError oome) {
        logger.warning("DicomHeadersTask for series " + seriesUID + " out of memory: ", oome);
    } finally {
        IOUtils.closeQuietly(tagFileWriter);
        IOUtils.closeQuietly(br);

        if (process != null)
            process.destroy();
    }
}

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

/**
 * Copy python agent distribution to a new folder, extract it and copy sample configuration files
 *
 * @return/*from  w  ww.  ja va 2 s. co m*/
 */
protected String setupPythonAgent(String resourcesPath) {
    try {
        log.info("Setting up python cartridge agent...");

        String srcAgentPath = PythonAgentTestManager.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".."
                + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + "distribution" + PATH_SEP + "target" + PATH_SEP
                + distributionName + ".zip";
        String unzipDestPath = PythonAgentTestManager.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".."
                + PATH_SEP + PYTHON_AGENT_DIR_NAME + PATH_SEP;
        //FileUtils.copyFile(new File(srcAgentPath), new File(destAgentPath));
        unzip(srcAgentPath, unzipDestPath);
        String destAgentPath = PythonAgentTestManager.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".."
                + PATH_SEP + PYTHON_AGENT_DIR_NAME + PATH_SEP + distributionName;

        String srcAgentConfPath = getResourcesPath(resourcesPath) + PATH_SEP + "agent.conf";
        String destAgentConfPath = destAgentPath + PATH_SEP + "agent.conf";
        FileUtils.copyFile(new File(srcAgentConfPath), new File(destAgentConfPath));

        String srcLoggingIniPath = getResourcesPath(resourcesPath) + PATH_SEP + "logging.ini";
        String destLoggingIniPath = destAgentPath + PATH_SEP + "logging.ini";
        FileUtils.copyFile(new File(srcLoggingIniPath), new File(destLoggingIniPath));

        String srcPayloadPath = getResourcesPath(resourcesPath) + PATH_SEP + "payload";
        String destPayloadPath = destAgentPath + PATH_SEP + "payload";
        FileUtils.copyDirectory(new File(srcPayloadPath), new File(destPayloadPath));

        log.info("Changing extension scripts permissions");
        File extensionsPath = new File(destAgentPath + PATH_SEP + "extensions" + PATH_SEP + "bash");
        File[] extensions = extensionsPath.listFiles();
        for (File extension : extensions) {
            extension.setExecutable(true);
        }

        log.info("Python cartridge agent setup completed");

        return destAgentPath;
    } catch (Exception e) {
        String message = "Could not copy cartridge agent distribution";
        log.error(message, e);
        throw new RuntimeException(message, e);
    }
}

From source file:org.eclipse.che.git.impl.nativegit.ssh.GitSshScript.java

/**
 * Stores ssh script that will be executed with all commands that need ssh.
 *
 * @param keyPath//from ww  w . j av a2 s  .c o  m
 *         path to ssh key
 * @return file that contains script for ssh commands
 * @throws GitException
 *         when any error with ssh script storing occurs
 */
private File storeSshScript(String keyPath) throws GitException {
    File sshScriptFile = new File(rootFolder, getSshKeyFileName());
    try (FileOutputStream fos = new FileOutputStream(sshScriptFile)) {
        fos.write(getSshScriptTemplate().replace("$ssh_key", keyPath).getBytes());
    } catch (IOException e) {
        LOG.error("It is not possible to store {} ssh key", keyPath);
        throw new GitException("Can't store SSH key");
    }
    if (!sshScriptFile.setExecutable(true)) {
        LOG.error("Can't make {} executable", sshScriptFile);
        throw new GitException("Can't set permissions to SSH key");
    }
    return sshScriptFile;
}

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

/**
 * Copy python agent distribution to a new folder, extract it and copy sample configuration files
 *
 * @return//from  ww w .  j  a v a2 s. com
 */
private String setupPythonAgent() {
    try {
        log.info("Setting up python cartridge agent...");
        String srcAgentPath = getResourcesFolderPath()
                + "/../../src/main/python/cartridge.agent/cartridge.agent";
        String destAgentPath = getResourcesFolderPath() + "/../" + UUID.randomUUID() + "/cartridge.agent";
        FileUtils.copyDirectory(new File(srcAgentPath), new File(destAgentPath));

        String srcAgentConfPath = getResourcesFolderPath() + "/agent.conf";
        String destAgentConfPath = destAgentPath + "/agent.conf";
        FileUtils.copyFile(new File(srcAgentConfPath), new File(destAgentConfPath));

        String srcLoggingIniPath = getResourcesFolderPath() + "/logging.ini";
        String destLoggingIniPath = destAgentPath + "/logging.ini";
        FileUtils.copyFile(new File(srcLoggingIniPath), new File(destLoggingIniPath));

        String srcPayloadPath = getResourcesFolderPath() + "/payload";
        String destPayloadPath = destAgentPath + "/payload";
        FileUtils.copyDirectory(new File(srcPayloadPath), new File(destPayloadPath));

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

        log.info("Python cartridge agent setup completed");

        return destAgentPath;
    } catch (Exception e) {
        String message = "Could not copy cartridge agent distribution";
        log.error(message, e);
        throw new RuntimeException(message, e);
    }
}

From source file:org.eclipse.che.plugin.ssh.key.script.SshScript.java

/**
 * Stores ssh script that will be executed with all commands that need ssh.
 *
 * @param keyPath/*from  w ww .j a v  a  2  s.co m*/
 *         path to ssh key
 * @return file that contains script for ssh commands
 * @throws ServerException
 *         when any error with ssh script storing occurs
 */
private File storeSshScript(String keyPath) throws ServerException {
    File sshScriptFile = new File(rootFolder, getSshKeyFileName());
    try (FileOutputStream fos = new FileOutputStream(sshScriptFile)) {
        fos.write(getSshScriptTemplate().replace("$ssh_key", keyPath).getBytes());
    } catch (IOException e) {
        LOG.error("It is not possible to store {} ssh key", keyPath);
        throw new ServerException("Can't store SSH key");
    }
    if (!sshScriptFile.setExecutable(true)) {
        LOG.error("Can't make {} executable", sshScriptFile);
        throw new ServerException("Can't set permissions to SSH key");
    }
    return sshScriptFile;
}

From source file:com.liferay.blade.cli.command.CreateCommand.java

protected void execute(ProjectTemplatesArgs projectTemplatesArgs) throws Exception {
    File dir = projectTemplatesArgs.getDestinationDir();
    String name = projectTemplatesArgs.getName();

    new ProjectTemplates(projectTemplatesArgs);

    File gradlew = new File(dir, name + "/gradlew");

    if (gradlew.exists()) {
        gradlew.setExecutable(true);
    }//  ww w  .j ava 2 s  . co  m
}