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:net.erdfelt.android.sdkfido.local.LocalAndroidPlatforms.java

/**
 * Attempt to find the local java sdk using the most common environment variables.
 * //from  w  w w  . j a v a  2 s .co  m
 * @return the local android java sdk directory
 * @throws IOException
 *             if unable to load the default local java sdk
 */
public static File findLocalJavaSdk() throws IOException {
    StringBuilder err = new StringBuilder();
    err.append("Unable to find the Local Android Java SDK Folder.");

    // Check Environment Variables First
    String envKeys[] = { "ANDROID_HOME", "ANDROID_SDK_ROOT" };
    for (String envKey : envKeys) {
        File sdkHome = getEnvironmentVariableDir(err, envKey);
        if (sdkHome == null) {
            continue; // skip, not found on that key
        }
        LocalAndroidPlatforms platforms = new LocalAndroidPlatforms(sdkHome);
        if (platforms.valid()) {
            return sdkHome;
        }
    }

    // Check Path for possible android.exe (or similar)
    List<String> searchBins = new ArrayList<String>();
    if (SystemUtils.IS_OS_WINDOWS) {
        searchBins.add("adb.exe");
        searchBins.add("emulator.exe");
        searchBins.add("android.exe");
    } else {
        searchBins.add("adb");
        searchBins.add("emulator");
        searchBins.add("android");
    }

    String pathParts[] = StringUtils.split(System.getenv("PATH"), File.pathSeparatorChar);
    for (String searchBin : searchBins) {
        err.append("\nSearched PATH for ").append(searchBin);
        for (String pathPart : pathParts) {
            File pathDir = new File(pathPart);
            LOG.fine("Searching Path: " + pathDir);
            File bin = new File(pathDir, searchBin);
            if (bin.exists() && bin.isFile() && bin.canExecute()) {
                File homeDir = bin.getParentFile().getParentFile();
                LOG.fine("Possible Home Dir: " + homeDir);
                LocalAndroidPlatforms platforms = new LocalAndroidPlatforms(homeDir);
                if (platforms.valid) {
                    return homeDir;
                }
            }
        }
        err.append(", not found.");
    }

    throw new FileNotFoundException(err.toString());
}

From source file:org.kitodo.selenium.testframework.helper.WebDriverProvider.java

/**
 * Downloads Geckodriver, extracts archive file and set system property
 * "webdriver.gecko.driver". On Linux the method also sets executable
 * permission.//ww w  .j a  va2  s . c  om
 *
 * @param geckoDriverVersion
 *            The geckodriver version.
 * @param downloadFolder
 *            The folder in which the downloaded files will be put in.
 * @param extractFolder
 *            The folder in which the extracted files will be put in.
 */
public static void provideGeckoDriver(String geckoDriverVersion, String downloadFolder, String extractFolder)
        throws IOException {
    String geckoDriverUrl = "https://github.com/mozilla/geckodriver/releases/download/v" + geckoDriverVersion
            + "/";
    String geckoDriverFileName;
    if (SystemUtils.IS_OS_WINDOWS) {
        geckoDriverFileName = "geckodriver.exe";
        File geckoDriverZipFile = new File(downloadFolder + "geckodriver.zip");
        FileUtils.copyURLToFile(new URL(geckoDriverUrl + "geckodriver-v" + geckoDriverVersion + "-win64.zip"),
                geckoDriverZipFile);
        extractZipFileToFolder(geckoDriverZipFile, new File(extractFolder));
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        geckoDriverFileName = "geckodriver";
        File geckoDriverTarFile = new File(downloadFolder + "geckodriver.tar.gz");
        FileUtils.copyURLToFile(
                new URL(geckoDriverUrl + "geckodriver-v" + geckoDriverVersion + "-macos.tar.gz"),
                geckoDriverTarFile);
        File theDir = new File(extractFolder);
        if (!theDir.exists()) {
            theDir.mkdir();
        }
        extractTarFileToFolder(geckoDriverTarFile, theDir);
    } else {
        geckoDriverFileName = "geckodriver";
        File geckoDriverTarFile = new File(downloadFolder + "geckodriver.tar.gz");
        FileUtils.copyURLToFile(
                new URL(geckoDriverUrl + "geckodriver-v" + geckoDriverVersion + "-linux64.tar.gz"),
                geckoDriverTarFile);
        extractTarFileToFolder(geckoDriverTarFile, new File(extractFolder));
    }
    File geckoDriverFile = new File(extractFolder, geckoDriverFileName);

    if (geckoDriverFile.exists()) {
        if (!SystemUtils.IS_OS_WINDOWS) {
            ExecutionPermission.setExecutePermission(geckoDriverFile);
        }

        if (geckoDriverFile.canExecute()) {
            System.setProperty("webdriver.gecko.driver", geckoDriverFile.getPath());
        } else {
            logger.error("Geckodriver not executeable");
        }
    } else {
        logger.error("Geckodriver file not found");
    }
}

From source file:org.kitodo.selenium.testframework.helper.WebDriverProvider.java

/**
 * Downloads chrome driver, extracts archive file and set system property
 * "webdriver.chrome.driver". On Linux the method also sets executable
 * permission.//  w  ww  . j av a  2s. c o m
 *
 * @param chromeDriverVersion
 *            The chrome driver version.
 * @param downloadFolder
 *            The folder in which the downloaded files will be put in.
 * @param extractFolder
 *            The folder in which the extracted files will be put in.
 */
public static void provideChromeDriver(String chromeDriverVersion, String downloadFolder, String extractFolder)
        throws IOException {

    String chromeDriverUrl = "https://chromedriver.storage.googleapis.com/" + chromeDriverVersion + "/";
    String chromeDriverFileName;
    if (SystemUtils.IS_OS_WINDOWS) {
        chromeDriverFileName = "chromedriver.exe";
        File chromeDriverZipFile = new File(downloadFolder + "chromedriver.zip");
        FileUtils.copyURLToFile(new URL(chromeDriverUrl + "chromedriver_win32.zip"), chromeDriverZipFile);
        extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder));

    } else if (SystemUtils.IS_OS_MAC_OSX) {
        chromeDriverFileName = "chromedriver";
        File chromeDriverZipFile = new File(downloadFolder + "chromedriver.zip");
        FileUtils.copyURLToFile(new URL(chromeDriverUrl + "chromedriver_mac64.zip"), chromeDriverZipFile);
        File theDir = new File(extractFolder);
        if (!theDir.exists()) {
            theDir.mkdir();
        }
        extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder));

    } else {
        chromeDriverFileName = "chromedriver";
        File chromeDriverZipFile = new File(downloadFolder + "chromedriver.zip");
        FileUtils.copyURLToFile(new URL(chromeDriverUrl + "chromedriver_linux64.zip"), chromeDriverZipFile);
        extractZipFileToFolder(chromeDriverZipFile, new File(extractFolder));
    }
    File chromeDriverFile = new File(extractFolder, chromeDriverFileName);

    if (chromeDriverFile.exists()) {
        if (!SystemUtils.IS_OS_WINDOWS) {
            ExecutionPermission.setExecutePermission(chromeDriverFile);
        }

        if (chromeDriverFile.canExecute()) {
            System.setProperty("webdriver.chrome.driver", chromeDriverFile.getPath());
        } else {
            logger.error("Chromedriver not executeable");
        }
    } else {
        logger.error("Chromedriver file not found");
    }
}

From source file:com.microsoft.alm.plugin.idea.common.utils.IdeaHelper.java

/**
 * Check if a file is executable and if not sets it to be executable. When the plugin is unzipped,
 * the permissions of a file is not persisted so that is why a check is needed.
 *
 * @param executable executable file for application
 * @throws FileNotFoundException/*from  w w  w  . j ava2 s  . com*/
 */
public static void setExecutablePermissions(final File executable) throws FileNotFoundException {
    if (!executable.exists()) {
        throw new FileNotFoundException(executable.getPath() + " not found while trying to set permissions.");
    }

    // set the executable to execute for all users
    if (!executable.canExecute()) {
        executable.setExecutable(true, false);
    }
}

From source file:io.github.bonigarcia.wdm.Downloader.java

public static final synchronized void download(URL url, String version, String export, List<String> driverName)
        throws IOException {
    File targetFile = new File(getTarget(version, url));
    File binary = null;/*from  w  w w . jav a2 s . c  om*/

    // Check if binary exists
    boolean download = !targetFile.getParentFile().exists()
            || (targetFile.getParentFile().exists() && targetFile.getParentFile().list().length == 0)
            || WdmConfig.getBoolean("wdm.override");

    if (!download) {
        // Check if existing binary is valid
        Collection<File> listFiles = FileUtils.listFiles(targetFile.getParentFile(), null, true);
        for (File file : listFiles) {
            for (String s : driverName) {
                if (file.getName().startsWith(s) && file.canExecute()) {
                    binary = file;
                    log.debug("Using binary driver previously downloaded {}", binary);
                    download = false;
                    break;
                } else {
                    download = true;
                }
            }
            if (!download) {
                break;
            }
        }
    }

    if (download) {
        log.info("Downloading {} to {}", url, targetFile);
        HttpURLConnection conn = getConnection(url);
        int responseCode = conn.getResponseCode();
        log.debug("Response HTTP {}", responseCode);
        if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                || responseCode == HttpURLConnection.HTTP_MOVED_PERM
                || responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
            // HTTP Redirect
            URL newUrl = new URL(conn.getHeaderField("Location"));
            log.debug("Redirect to {}", newUrl);
            conn = getConnection(newUrl);
        }

        FileUtils.copyInputStreamToFile(conn.getInputStream(), targetFile);

        if (!export.contains("edge")) {
            binary = extract(targetFile, export);
            targetFile.delete();
        } else {
            binary = targetFile;
        }

    }
    if (export != null) {
        BrowserManager.exportDriver(export, binary.toString());
    }

}

From source file:com.amaze.carbonfilemanager.filesystem.RootHelper.java

public static String parseFilePermission(File f) {
    String per = "";
    if (f.canRead()) {
        per = per + "r";
    }/*  w ww  .  j a  va 2  s . com*/
    if (f.canWrite()) {
        per = per + "w";
    }
    if (f.canExecute()) {
        per = per + "x";
    }
    return per;
}

From source file:com.docd.purefm.test.JavaFileTest.java

private static void testAgainstJavaIoFile(final JavaFile genericFile, final File javaFile) throws Throwable {
    assertEquals(javaFile, genericFile.toFile());
    assertEquals(javaFile.getName(), genericFile.getName());
    assertEquals(javaFile.getAbsolutePath(), genericFile.getAbsolutePath());
    assertEquals(javaFile.canRead(), genericFile.canRead());
    assertEquals(javaFile.canWrite(), genericFile.canWrite());
    assertEquals(javaFile.canExecute(), genericFile.canExecute());
    assertEquals(javaFile.exists(), genericFile.exists());
    assertEquals(javaFile.getPath(), genericFile.getPath());
    assertEquals(javaFile.getParent(), genericFile.getParent());
    assertEquals(javaFile.length(), genericFile.length());
    final File parentFile;
    final GenericFile genericParentFile = genericFile.getParentFile();
    if (genericParentFile == null) {
        parentFile = null;/*from ww w.j  a  va 2 s.c  o  m*/
    } else {
        parentFile = genericParentFile.toFile();
    }
    assertEquals(javaFile.getParentFile(), parentFile);
    assertEquals(javaFile.length(), genericFile.length());
    try {
        assertEquals(FileUtils.isSymlink(javaFile), genericFile.isSymlink());
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        assertEquals(javaFile.getCanonicalPath(), genericFile.getCanonicalPath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    assertEquals(javaFile.length(), genericFile.length());
    assertEquals(javaFile.lastModified(), genericFile.lastModified());
    assertEquals(javaFile.isDirectory(), genericFile.isDirectory());
    assertTrue(Arrays.equals(javaFile.list(), genericFile.list()));
    assertTrue(Arrays.equals(javaFile.listFiles(), genericFile.listFiles()));
}

From source file:org.jboss.tools.openshift.common.core.utils.FileUtils.java

/**
 * Replicates the owner permissions from the source to the destination. Due
 * to limitation in java6 this is the best we can do (there's no way in
 * java6 to know if rights are due to owner or group)
 * //from  ww w  . j ava  2s.c o  m
 * @param source
 * @param destination
 * 
 * @see File#canRead()
 * @see File#setReadable(boolean)
 * @see File#canWrite()
 * @see File#setWritable(boolean)
 * @see File#canExecute()
 * @see File#setExecutable(boolean)
 */
private static void copyPermissions(File source, File destination) {
    Assert.isLegal(source != null);
    Assert.isLegal(destination != null);

    destination.setReadable(source.canRead());
    destination.setWritable(source.canWrite());
    destination.setExecutable(source.canExecute());
}

From source file:org.ut.biolab.medsavant.server.MedSavantServerEngine.java

private static boolean completelyPermissive(File d) {
    return d.canRead() && d.canWrite() && d.canExecute();
}

From source file:org.ut.biolab.medsavant.server.MedSavantServerEngine.java

private static String permissions(File d) {
    return (d.canRead() ? "r" : "-") + (d.canWrite() ? "w" : "-") + (d.canExecute() ? "x" : "-");
}