List of usage examples for java.io File setExecutable
public boolean setExecutable(boolean executable)
From source file:net.orpiske.sdm.lib.io.support.ShieldAwareCopier.java
@Override protected void handleFile(File file, int depth, Collection results) throws IOException { File destinationFile = new File(destination, file.getName()); if (!ShieldUtils.isShielded(destinationFile)) { FileUtils.copyFile(file, destinationFile); destinationFile.setExecutable(file.canExecute()); destinationFile.setReadable(file.canRead()); destinationFile.setWritable(file.canWrite()); } else {//from ww w . jav a 2 s . c o m System.out.println("Ignoring shielded file " + file.getPath()); } }
From source file:de.huberlin.wbi.hiway.common.Worker.java
private int exec() { File script = new File("./" + containerId); script.setExecutable(true); ProcessBuilder processBuilder = new ProcessBuilder(script.getPath()); processBuilder.directory(new File(".")); Process process;/* w ww . ja v a 2 s . c o m*/ int exitValue = -1; try { File stdOutFile = new File(Invocation.STDOUT_FILENAME); File stdErrFile = new File(Invocation.STDERR_FILENAME); processBuilder.redirectOutput(stdOutFile); processBuilder.redirectError(stdErrFile); process = processBuilder.start(); exitValue = process.waitFor(); } catch (IOException | InterruptedException e) { e.printStackTrace(); System.exit(-1); } return exitValue; }
From source file:de.uka.ilkd.key.dl.gui.initialdialog.gui.ToolInstaller.java
/** * @param tmp/*from w ww . j av a 2 s . co m*/ * @param dir * @throws IOException * @throws ArchiveException */ private static void untar(File file, File dir, FileType ft, PropertySetter ps, JProgressBar bar) throws IOException, ArchiveException { FileInputStream fis = new FileInputStream(file); InputStream is; switch (ft) { case TARGZ: is = new GZIPInputStream(fis); break; case TARBZ2: is = new BZip2CompressorInputStream(fis); break; default: throw new IllegalArgumentException("Don't know how to handle filetype: " + ft); } final TarArchiveInputStream debInputStream = (TarArchiveInputStream) new ArchiveStreamFactory() .createArchiveInputStream("tar", is); TarArchiveEntry entry = null; int value = 0; while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) { bar.setValue(value++); final File outputFile = new File(dir, entry.getName()); if (entry.isDirectory()) { if (!outputFile.exists()) { if (!outputFile.mkdirs()) { throw new IllegalStateException( String.format("Couldn't create directory %s.", outputFile.getAbsolutePath())); } } } else { final OutputStream outputFileStream = new FileOutputStream(outputFile); IOUtils.copy(debInputStream, outputFileStream); if (OSInfosDefault.INSTANCE.getOs() == OperatingSystem.OSX) { // FIXME: we need to make everything executable as somehow // the executable bit is not preserved in // OSX outputFile.setExecutable(true); } if (ps.filterFilename(outputFile)) { ps.setProperty(outputFile.getAbsolutePath()); } outputFileStream.flush(); outputFileStream.close(); } } debInputStream.close(); is.close(); file.delete(); }
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);// w w w. ja v a 2 s . c o 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.flysystem.core.adapter.local.Local.java
private boolean setVisibilityPublic(File file) { boolean readable = file.setReadable(true); boolean executable = file.setExecutable(true); boolean writable = file.setWritable(true); return readable && executable && writable; }
From source file:com.flysystem.core.adapter.local.Local.java
private boolean setVisibilityPrivate(File file) { boolean readable = file.setReadable(false); boolean executable = file.setExecutable(false); boolean writable = file.setWritable(false); return readable && executable && writable; }
From source file:org.kalypso.model.hydrology.internal.processing.KalypsoNaProcessor.java
private File copyExecutable() throws SimulationException { try {/*w ww.j av a2s . c o m*/ final File kalypsoNaExe = CalcCoreUtils.findExecutable(m_exeVersion, EXECUTABLES_FILE_TEMPLATE, EXECUTABLES_FILE_PATTERN, CalcCoreUtils.COMPATIBILITY_MODE.NA); if (kalypsoNaExe == null) throw new SimulationException(Messages.getString("KalypsoNaProcessor.0")); //$NON-NLS-1$ final File destFile = new File(m_asciiDirs.startDir, kalypsoNaExe.getName()); if (!destFile.exists()) FileUtils.copyFile(kalypsoNaExe, destFile); destFile.setExecutable(true); return destFile; } catch (final CoreException e) { final IStatus status = e.getStatus(); final String msg = status.getMessage(); throw new SimulationException(msg, e); } catch (final IOException e) { final String msg = String.format(Messages.getString("KalypsoNaProcessor.1"), e.getLocalizedMessage()); //$NON-NLS-1$ throw new SimulationException(msg, e); } }
From source file:de.akquinet.innovation.play.maven.Play2InstallPlayMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (StringUtils.isEmpty(play2version)) { throw new MojoExecutionException("play2version configuration parameter is not set"); }/* w w w .j a va2 s . c o m*/ String debugLogPrefix = "AutoInstall - Play! " + play2version + ' '; File play2basedirFile = new File(play2basedir); File play2home = new File(play2basedirFile, "play-" + play2version); File play2 = new File(play2home, AbstractPlay2Mojo.isWindows() ? "play.bat" : "play"); // Is the requested Play! version already installed? if (play2.isFile() && play2.canExecute()) { getLog().info(debugLogPrefix + "is already installed in " + play2home); return; } getLog().info("Play! " + play2version + " download and installation, please be patient ..."); File zipFile = new File(play2basedirFile, "play-" + play2version + ".zip"); try { URL zipUrl = new URL("http://download.playframework.org/releases/play-" + play2version + ".zip"); FileUtils.forceMkdir(play2basedirFile); // Download getLog().debug(debugLogPrefix + "is downloading to " + zipFile); FileUtils.copyURLToFile(zipUrl, zipFile); // Extract getLog().debug(debugLogPrefix + "is extracting to " + play2basedir); UnArchiver unarchiver = archiverManager.getUnArchiver(zipFile); unarchiver.setSourceFile(zipFile); unarchiver.setDestDirectory(play2basedirFile); unarchiver.extract(); // Prepare File framework = new File(play2home, "framework"); File build = new File(framework, AbstractPlay2Mojo.isWindows() ? "build.bat" : "build"); if (!build.canExecute() && !build.setExecutable(true)) { throw new MojoExecutionException("Can't set " + build + " execution bit"); } if (!play2.canExecute() && !play2.setExecutable(true)) { throw new MojoExecutionException("Can't set " + play2 + " execution bit"); } getLog().debug(debugLogPrefix + "is now installed in " + play2home); } catch (NoSuchArchiverException ex) { throw new MojoExecutionException("Can't auto install Play! " + play2version + " in " + play2basedir, ex); } catch (IOException ex) { try { if (play2home.exists()) { // Clean extracted data FileUtils.forceDelete(play2home); } } catch (IOException ignored) { getLog().warn("Unable to delete extracted Play! distribution after error: " + play2home); } throw new MojoExecutionException("Can't auto install Play! " + play2version + " in " + play2basedir, ex); } catch (ArchiverException e) { throw new MojoExecutionException("Cannot unzip Play " + play2version + " in " + play2basedir, e); } finally { try { if (zipFile.exists()) { // Clean downloaded data FileUtils.forceDelete(zipFile); } } catch (IOException ignored) { getLog().warn("Unable to delete downloaded Play! distribution: " + zipFile); } } }
From source file:com.anrisoftware.globalpom.exec.script.ScriptCommandLine.java
private File copyScript(String scriptString) throws CommandExecException { try {//from w w w. j a va2s . c om File file = createTempFile(SCRIPT, SCRIPT_POST); FileUtils.write(file, scriptString); file.setExecutable(true); return file; } catch (IOException e) { throw log.errorCopyScript(this, e); } }
From source file:com.github.nethad.clustermeister.provisioning.local.JPPFLocalNode.java
/** * Start the node in a new independent process. * //from w w w.j a v a 2s .c o m * @throws RuntimeException when there's an IOException. */ protected void startNode() throws RuntimeException { File startNodeScript = new File(targetDir, "jppf-node/startNode.sh"); startNodeScript.setExecutable(true); try { // String jppfNodePath = startNodeScript.getParentFile().getAbsolutePath(); String jvmOptions = nodeConfiguration.getJvmOptions().or("").replaceAll("\\s", "\\ "); System.out.println("jvmOptions = " + jvmOptions); final String command = String.format("%s %s %s %s %s", "./" + startNodeScript.getName(), nodeConfigFileName, "false", "false", jvmOptions); logger.info("Start node with {}", command); Runtime.getRuntime().exec(command, new String[] {}, startNodeScript.getParentFile()); } catch (IOException ex) { throw new RuntimeException(ex); } }