Example usage for java.io File canExecute

List of usage examples for java.io File canExecute

Introduction

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

Prototype

public boolean canExecute() 

Source Link

Document

Tests whether the application can execute the file denoted by this abstract pathname.

Usage

From source file:org.asqatasun.sebuilder.tools.ProfileFactory.java

/**
 * /*from w w  w . ja  va2  s  .c o m*/
 * @return 
 *      a set-up Firefox profile
 */
private FirefoxProfile getProfile(boolean loadImage) {
    if (StringUtils.isNotBlank(pathToPreSetProfile)) {
        File presetProfileDir = new File(pathToPreSetProfile);
        if (presetProfileDir.exists() && presetProfileDir.canRead() && presetProfileDir.canExecute()
                && presetProfileDir.canWrite()) {
            Logger.getLogger(this.getClass())
                    .debug("Start firefox profile with path " + presetProfileDir.getAbsolutePath());
            return new FirefoxProfile(presetProfileDir);
        } else {
            Logger.getLogger(this.getClass()).debug("The profile with path "
                    + presetProfileDir.getAbsolutePath() + " doesn't exist or don't have permissions");
        }
    }
    Logger.getLogger(this.getClass()).debug("Start firefox with fresh new profile");
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    setUpPreferences(firefoxProfile, loadImage);
    //        setUpExtensions(firefoxProfile);
    setUpProxy(firefoxProfile);
    return firefoxProfile;
}

From source file:com.thoughtworks.go.server.service.lookups.CommandRepositoryDirectoryWalker.java

public CommandSnippets getAllCommandSnippets(String repositoryDirectory) {
    serverHealthService/*  w  ww  .ja v a  2  s  . c  o  m*/
            .update(ServerHealthState.success(HealthStateType.commandRepositoryAccessibilityIssue()));

    try {
        File commandRepositoryDirectory = new File(repositoryDirectory);

        //adding the exists check till packaging command repository with Go story is played.
        if (commandRepositoryDirectory.isDirectory() && commandRepositoryDirectory.canRead()
                && commandRepositoryDirectory.canExecute()) {
            return new CommandSnippets(walk(commandRepositoryDirectory));
        } else {
            throw new IOException("Failed to access command repository located in Go Server Directory at "
                    + repositoryDirectory
                    + ". The directory does not exist or Go does not have sufficient permissions to access it.");
        }
    } catch (IOException e) {
        ServerHealthState serverHealthState = ServerHealthState.warning("Command Repository", e.getMessage(),
                HealthStateType.commandRepositoryAccessibilityIssue(),
                systemEnvironment.getCommandRepoWarningTimeout());
        serverHealthService.update(serverHealthState);
        LOGGER.warn(e.getMessage());
    }
    return new CommandSnippets(new ArrayList<>());
}

From source file:org.apache.sis.internal.maven.Assembler.java

/**
 * Adds the given file in the ZIP file. If the given file is a directory, then this method
 * recursively adds all files contained in this directory. This method is invoked for zipping
 * the "application/sis-console/src/main/artifact" directory and sub-directories before to zip
 * the Pack200 file.//from   w w  w.  j  a v a 2 s  . com
 */
private void appendRecursively(final File file, String relativeFile, final ZipArchiveOutputStream out,
        final byte[] buffer) throws IOException {
    if (file.isDirectory()) {
        relativeFile += '/';
    }
    final ZipArchiveEntry entry = new ZipArchiveEntry(file, relativeFile);
    if (file.canExecute()) {
        entry.setUnixMode(0744);
    }
    out.putArchiveEntry(entry);
    if (!entry.isDirectory()) {
        final FileInputStream in = new FileInputStream(file);
        try {
            int n;
            while ((n = in.read(buffer)) >= 0) {
                out.write(buffer, 0, n);
            }
        } finally {
            in.close();
        }
    }
    out.closeArchiveEntry();
    if (entry.isDirectory()) {
        for (final String filename : file.list(this)) {
            appendRecursively(new File(file, filename), relativeFile.concat(filename), out, buffer);
        }
    }
}

From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java

private void install(File targetDirectory, String filename, InputStream input) throws Throwable {
    final File file = new File(targetDirectory, filename);
    FileOutputStream output = null;
    try {/*ww  w  .ja v a  2  s .co  m*/
        output = new FileOutputStream(file);
        IOUtils.copy(input, output);
        if (!file.isFile() || (!file.canExecute() && !file.setExecutable(true))) {
            throw new Exception("Cannot set file permissions: " + file.getAbsolutePath());
        }
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:com.ubershy.streamsis.actions.RunProgramAction.java

@Override
public void init() {
    elementInfo.setAsReadyAndHealthy();/*from   www  .j  ava  2 s.c o m*/
    if (getPath().isEmpty()) {
        elementInfo.setAsBroken("The path to the program is empty");
        return;
    }
    // TODO: improve algorithms below. I was in hurry. =/
    String absolutePath = null;
    if (checkIfPathIsAbsoluteAndFileExists(getPath())) { // the path provided is absolute
        absolutePath = getPath();
    }
    // Too hard to implement ability to support non-absolute paths of executables.
    // TODO: implement someday. Now I'm in hurry. =/
    // else { // the path provided is not absolute
    // if ("cmd.exe".equals(getPath())) {
    // absolutePath = "C:\\Windows\\system32\\" + getPath();
    // return;
    // }
    // // lets search in environment variable "PATH"
    // String[] envDirs = environmentPATH.split(";");
    // for (String envDir : envDirs) {
    // File possibleFile = new File(envDir, getPath());
    // String possibleAbsolutePath = possibleFile.getAbsolutePath();
    // if (Util.checkifSingleFileExists(possibleAbsolutePath)) {
    // absolutePath = possibleAbsolutePath;
    // return;
    // }
    // }
    // }
    if (absolutePath == null) {
        elementInfo.setAsBroken("The path to the program seems invalid. "
                + "Please check if the program really exists on this path");
        return;
    }
    File pathFile = new File(absolutePath);
    try {
        if (!pathFile.canExecute()) {
            elementInfo.setAsBroken("The path to the program seems invalid. "
                    + "Please check if the program really exists on this path");
            return;
        }
    } catch (SecurityException e) {
        elementInfo.setAsBroken("You don't have enough rights to run this program");
        return;
    }

    if (getWorkingDir().isEmpty()) { // if it's empty, lets initialize workingDir by the
        // program directory
        File parentToPathFile = pathFile.getAbsoluteFile().getParentFile();
        if (parentToPathFile != null) {
            setWorkingDir(parentToPathFile.getAbsolutePath());
        } else {
            throw new RuntimeException("Can't find parent directory of the program");
        }
    } else { // Means the user has specified the working directory
        if (!Util.checkDirectory(getWorkingDir())) {
            elementInfo.setAsBroken("The working directory you have specified does not exist");
        }
    }
}

From source file:org.jajuk.util.UtilSystem.java

/**
 * Gets the mplayer OSX path.//w  w  w . j a  va2s. c  om
 * It is mainly based upon Windows getWindowsPath() path method, see comments over there
 * 
 * @return MPLayer binary MAC full path
 */
public static File getMPlayerOSXPath() {
    if (UtilSystem.mplayerPath != null) {
        return UtilSystem.mplayerPath;
    }
    // Search in /Applications first
    File file = new File("/Applications/Jajuk.app/Contents/MacOS/" + Const.FILE_MPLAYER_OSX_EXE);
    if (file.canExecute() && file.length() == Const.MPLAYER_OSX_EXE_SIZE) {
        UtilSystem.mplayerPath = file;
        return UtilSystem.mplayerPath;
    }
    // Search in collection path
    file = SessionService.getConfFileByPath(Const.FILE_MPLAYER_OSX_EXE);
    if (file.exists() && file.length() == Const.MPLAYER_OSX_EXE_SIZE) {
        UtilSystem.mplayerPath = file;
        return UtilSystem.mplayerPath;
    } else if (!UtilSystem.isUnderJNLP()) {
        // Search in jajuk installation directory, do not work under JNLP
        String sPATH = null;
        try {
            if (SessionService.isIdeMode()) {
                // If under dev, take mplayer exe file from /Applications (the mplayer osx binary is not
                // in SCM)
                sPATH = "/Applications";
            } else {
                sPATH = new File(getJarLocation(Main.class).toURI()).getParentFile().getParentFile()
                        .getAbsolutePath();
            }
            file = new File(sPATH + '/' + Const.FILE_MPLAYER_OSX_EXE);
            if (file.exists() && file.length() == Const.MPLAYER_OSX_EXE_SIZE) {
                UtilSystem.mplayerPath = file;
            }
        } catch (Exception e) {
            Log.error(e);
        }
    }
    return UtilSystem.mplayerPath; // can be null if none suitable file found
}

From source file:com.buaa.cfs.utils.FileUtil.java

/**
 * Platform independent implementation for {@link File#canExecute()}
 *
 * @param f input file// w  w w  .  j  a va  2 s.  c o  m
 *
 * @return On Unix, same as {@link File#canExecute()} On Windows, true if process has execute access on the path
 */
public static boolean canExecute(File f) {
    if (Shell.WINDOWS) {
        try {
            return NativeIO.Windows.access(f.getCanonicalPath(), NativeIO.Windows.AccessRight.ACCESS_EXECUTE);
        } catch (IOException e) {
            return false;
        }
    } else {
        return f.canExecute();
    }
}

From source file:com.devbury.mkremote.server.QuickLaunchServiceImpl.java

protected void open(final File file) {
    if (logger.isDebugEnabled()) {
        logger.debug("File name {} exists {}, read {}, write {}, execute {}", new Object[] {
                file.getAbsolutePath(), file.exists(), file.canRead(), file.canWrite(), file.canExecute() });
    }/*from  ww  w . j  a v a 2 s. c  o  m*/
    try {
        Desktop.getDesktop().open(file);
    } catch (Throwable t) {
        if (isMac()) {
            File file_app = newFile(file.getAbsolutePath() + ".app");
            try {
                Desktop.getDesktop().open(file_app);
            } catch (Throwable tt) {
                handleOpenError(file, t);
            }
        } else {
            handleOpenError(file, t);
        }
    }
}

From source file:com.vilt.minium.prefs.WebConsolePreferences.java

@Override
public void validate() {
    super.validate();

    File chromeBin = getChromeBin();
    checkState(chromeBin != null && chromeBin.exists(),
            "Chrome binary path %s does not exist, please ensure you edit "
                    + "minium-prefs.json and set webconsole.chromeBin to point to chrome binary",
            chromeBin);/*from w w w .  ja v a 2s  .  co m*/

    checkState(chromeBin.isFile(), "Chrome binary path %s is not a file", chromeBin);
    checkState(chromeBin.canExecute(), "Chrome binary path %s cannot execute", chromeBin);
}

From source file:org.hawkular.metrics.clients.ptrans.fullstack.CollectdITest.java

@Test
public void shouldFindCollectdMetricsOnServer() throws Exception {
    ptransProcessBuilder.command().addAll(ImmutableList.of("-c", ptransConfFile.getAbsolutePath()));
    ptransProcess = ptransProcessBuilder.start();
    assertPtransHasStarted(ptransProcess, ptransOut);

    File stdbuf = new File("/usr/bin/stdbuf");
    ImmutableList.Builder<String> collectdCmd = ImmutableList.builder();
    if (stdbuf.exists() && stdbuf.canExecute()) {
        collectdCmd.add(stdbuf.getAbsolutePath(), "-o0", "-e0");
    }/*from   ww  w.  j  a  v  a  2s.co  m*/
    collectdCmd.add(COLLECTD_PATH, "-C", collectdConfFile.getAbsolutePath(), "-f");
    collectdProcessBuilder.command(collectdCmd.build());
    collectdProcess = collectdProcessBuilder.start();

    waitForCollectdValues();

    kill(collectdProcess, Signal.SIGUSR1); // Flush data
    kill(collectdProcess, Signal.SIGTERM);
    collectdProcess.waitFor();

    Thread.sleep(MILLISECONDS.convert(1, SECONDS)); // Wait to make sure pTrans can send everything

    kill(ptransProcess, Signal.SIGTERM);
    ptransProcess.waitFor();

    List<Point> expectedData = getExpectedData();
    List<Point> serverData = getServerData();

    String failureMsg = String.format(Locale.ROOT, "Expected:%n%s%nActual:%n%s%n", pointsToString(expectedData),
            pointsToString(serverData));

    assertEquals(failureMsg, expectedData.size(), serverData.size());

    for (int i = 0; i < expectedData.size(); i++) {
        Point expectedPoint = expectedData.get(i);
        Point serverPoint = serverData.get(i);

        long timeDiff = expectedPoint.getTimestamp() - serverPoint.getTimestamp();
        assertTrue(failureMsg, Math.abs(timeDiff) < 2);

        assertEquals(failureMsg, expectedPoint.getType(), serverPoint.getType());
        assertEquals(failureMsg, expectedPoint.getValue(), serverPoint.getValue(), 0.1);
    }
}