List of usage examples for java.io File canExecute
public boolean canExecute()
From source file:com.ikon.servlet.admin.ConfigServlet.java
/** * File existence and if can be executed *///from w w w. j av a 2 s.c om private void checkExecutable(PrintWriter out, String cmd) { if (cmd.equals("")) { warn(out, "Not configured"); } else { int idx = cmd.indexOf(" "); String exec = null; if (idx > -1) { exec = cmd.substring(0, idx); } else { exec = cmd; } File prg = new File(exec); if (prg.exists() && prg.canRead() && prg.canExecute()) { ok(out, "OK - " + prg.getPath()); } else { warn(out, "Can't read or execute: " + prg.getPath()); } } }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProviderTest.java
/** * search for hadoop command from PATH.//from www . j a v a2 s . co m */ @Test public void findHadoopCommand_manypath() { putExec("path1/java"); putExec("path2/hadoop"); putExec("path3/ant"); StringBuilder buf = new StringBuilder(); buf.append(File.pathSeparator); buf.append(new File(folder.getRoot(), "path1").getAbsolutePath()); buf.append(File.pathSeparator); buf.append(new File(folder.getRoot(), "path2").getAbsolutePath()); buf.append(File.pathSeparator); buf.append(new File(folder.getRoot(), "path3").getAbsolutePath()); buf.append(File.pathSeparator); Map<String, String> envp = new HashMap<>(); envp.put("PATH", buf.toString()); File file = ConfigurationProvider.findHadoopCommand(envp); assertThat(file, is(notNullValue())); assertThat(file.toString(), file.canExecute(), is(true)); assertThat(file.toString(), file.getParentFile().getName(), is("path2")); }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProviderTest.java
/** * search for confdir from PATH using symlink. * @throws IOException IOException//from ww w . ja v a2 s . co m */ @Test public void symlink() throws IOException { Assume.assumeThat(SystemUtils.IS_OS_WINDOWS, is(false)); File cmd = putExec("hadoop/bin/hadoop"); putConf("hadoop/etc/hadoop/core-site.xml"); File path = folder.newFolder("path"); try { Process proc = new ProcessBuilder("ln", "-s", cmd.getAbsolutePath(), new File(path, "hadoop").getAbsolutePath()).start(); try { int exitCode = proc.waitFor(); Assume.assumeThat(exitCode, is(0)); } finally { proc.destroy(); } } catch (Exception e) { System.out.println("Failed to create symlink"); e.printStackTrace(System.out); Assume.assumeNoException(e); } Map<String, String> envp = new HashMap<>(); envp.put("PATH", path.getAbsolutePath()); Configuration conf = new ConfigurationProvider(envp).newInstance(); assertThat(isLoaded(conf), is(true)); File file = ConfigurationProvider.findHadoopCommand(envp); assertThat(file, is(notNullValue())); assertThat(file.toString(), file.canExecute(), is(true)); assertThat(file.toString(), file.getParentFile().getName(), is("path")); }
From source file:com.fizzed.stork.assembly.CopyFile.java
public void copyFile(File inputFile, File outputDir) throws IOException { if (inputFile.isDirectory()) { File[] files = inputFile.listFiles(); File newOutputDir = new File(outputDir, inputFile.getName()); for (File f : files) { copyFile(f, newOutputDir);//from w w w . j a v a 2 s. co m } } else { File outputFile = new File(outputDir, inputFile.getName()); outputDir.mkdirs(); logger.info(" copying " + inputFile + " to " + outputFile); FileUtils.copyFile(inputFile, outputFile); if (inputFile.canExecute()) { outputFile.setExecutable(true); } } }
From source file:com.ikon.servlet.admin.ConfigServlet.java
/** * File existence and if can be executed *//* w ww. j a va 2 s .c o m*/ private void checkOpenOffice(PrintWriter out, String path) { if (path.equals("")) { warn(out, "Not configured"); } else { File prg = new File(path); if (prg.exists() && prg.canRead()) { File offExec = OfficeUtils.getOfficeExecutable(prg); if (offExec.exists() && offExec.canRead() && offExec.canExecute()) { ok(out, "OK - " + offExec.getPath()); } else { warn(out, "Can't read or execute: " + offExec.getPath()); } } else { warn(out, "Can't read: " + prg.getPath()); } } }
From source file:org.jboss.tools.openshift.internal.ui.preferences.OpenShiftPreferencePage.java
private boolean validateLocation(String location) { if (StringUtils.isBlank(location)) { return true; }//from w w w .j a va 2 s . c om File file = new File(location); if (!ocBinary.getName().equals(file.getName())) { setErrorMessage(NLS.bind("{0} is not the OpenShift Client ''{1}'' executable.", file.getName(), ocBinary.getName())); return false; } if (!file.exists()) { setErrorMessage(NLS.bind("{0} was not found.", file)); return false; } if (!file.canExecute()) { setErrorMessage(NLS.bind("{0} does not have execute permissions.", file)); return false; } return true; }
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 ww .j ava 2 s . co m*/ } else { FileUtils.copyFile(sourceFile, destFile); if (sourceFile.canExecute()) { destFile.setExecutable(true); } getLog().debug((destFile.canExecute() ? "Executable" : "File '") + sourceFile + "' copied to '" + destFile + "'."); } } }
From source file:org.elasticsearch.plugins.PluginManagerTests.java
@Test public void testLocalPluginInstallWithBinAndConfig() throws Exception { String pluginName = "plugin-test"; Tuple<Settings, Environment> initialSettings = InternalSettingsPreparer .prepareSettings(ImmutableSettings.settingsBuilder().build(), false); Environment env = initialSettings.v2(); File binDir = new File(env.homeFile(), "bin"); if (!binDir.exists() && !FileSystemUtils.mkdirs(binDir)) { throw new IOException("Could not create bin directory [" + binDir.getAbsolutePath() + "]"); }/*from www . j av a 2 s . c om*/ File pluginBinDir = new File(binDir, pluginName); File configDir = env.configFile(); if (!configDir.exists() && !FileSystemUtils.mkdirs(configDir)) { throw new IOException("Could not create config directory [" + configDir.getAbsolutePath() + "]"); } File pluginConfigDir = new File(configDir, pluginName); try { PluginManager pluginManager = pluginManager(getPluginUrlForResource("plugin_with_bin_and_config.zip"), initialSettings); pluginManager.downloadAndExtract(pluginName); File[] plugins = pluginManager.getListInstalledPlugins(); assertThat(plugins, arrayWithSize(1)); assertDirectoryExists(pluginBinDir); assertDirectoryExists(pluginConfigDir); File toolFile = new File(pluginBinDir, "tool"); assertFileExists(toolFile); assertThat(toolFile.canExecute(), is(true)); } finally { // we need to clean up the copied dirs FileSystemUtils.deleteRecursively(pluginBinDir); FileSystemUtils.deleteRecursively(pluginConfigDir); } }
From source file:com.facebook.buck.util.unarchive.UntarTest.java
private void assertExecutable(Path path, boolean shouldBeExecutable, boolean allowFilesToBeWrong) { Path fullPath = tmpFolder.getRoot().resolve(path); File file = fullPath.toFile(); boolean isExecutable = file.canExecute(); // Bit of a hack around windows writing normal files as exectuable by default if (!file.isDirectory() && isExecutable && allowFilesToBeWrong && !shouldBeExecutable) { return;/* ww w. j a v a 2 s . co m*/ } Assert.assertEquals(String.format("Expected execute on %s to be %s, got %s", fullPath, shouldBeExecutable, isExecutable), shouldBeExecutable, isExecutable); }
From source file:be.deadba.ampd.SettingsActivity.java
/** * A preference value change listener that updates the preference's summary * to reflect its new value.//from w w w .j ava 2 s . c o m */ @Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); String key = preference.getKey(); Log.d(TAG, "onPreferenceChange: key: " + key + " / value: " + stringValue); if (preference.isPersistent()) { Editor editor = MPDConf.getSharedPreferences(this).edit(); if (value instanceof Boolean) editor.putBoolean(key, (Boolean) value); else editor.putString(key, (String) value); editor.commit(); } if (key.equals("run")) { mRunPreference = (TwoStatePreference) preference; mRun = stringValue.equals("true"); onMPDStatePreferenceChange(false); return true; } if (key.equals("run_on_boot")) { mRunOnBootPreference = (TwoStatePreference) preference; mRunOnBoot = stringValue.equals("true"); if (mRunOnBoot) mRun = true; onMPDStatePreferenceChange(false); return true; } else if (key.equals("wakelock")) { onMPDStatePreferenceChange(true); return true; } else if (key.equals("mpd_music_directory")) { File file = new File(stringValue); mDirValid = file.exists() && file.isDirectory() && file.canRead() && file.canExecute(); onMPDStatePreferenceChange(true); } else if (key.equals("mpd_port")) { int port = 0; try { port = Integer.parseInt(stringValue); } catch (NumberFormatException e) { } mPortValid = port >= 1024 && port <= 65535; if (mPortValid) mPort = String.valueOf(port); onMPDStatePreferenceChange(true); } else if (key.equals("mpd_mixer")) { onMPDStatePreferenceChange(true); return true; } else if (key.equals("mpd_output")) { onMPDStatePreferenceChange(true); } if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. ListPreference listPreference = (ListPreference) preference; int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }