List of usage examples for java.io File setExecutable
public boolean setExecutable(boolean executable)
From source file:com.github.os72.protocjar.maven.ProtocJarMojo.java
private File resolveArtifact(String artifactSpec) throws MojoExecutionException { try {/* ww w. j a v a 2 s . c o m*/ Properties detectorProps = new Properties(); new PlatformDetector().detect(detectorProps, null); String platform = detectorProps.getProperty("os.detected.classifier"); getLog().info("Resolving artifact: " + artifactSpec + ", platform: " + platform); String[] as = artifactSpec.split(":"); Artifact artifact = artifactFactory.createDependencyArtifact(as[0], as[1], VersionRange.createFromVersionSpec(as[2]), "exe", platform, Artifact.SCOPE_RUNTIME); artifactResolver.resolve(artifact, remoteRepositories, localRepository); File tempFile = File.createTempFile(as[1], ".exe"); copyFile(artifact.getFile(), tempFile); tempFile.setExecutable(true); tempFile.deleteOnExit(); return tempFile; } catch (Exception e) { throw new MojoExecutionException("Error resolving artifact: " + artifactSpec, e); } }
From source file:org.apache.karaf.tooling.exam.container.internal.KarafTestContainer.java
private void makeScriptsInBinExec(File karafBin) { if (!karafBin.exists()) { return;/*from ww w . j a v a 2 s.c om*/ } File[] files = karafBin.listFiles(); for (File file : files) { file.setExecutable(true); } }
From source file:org.apache.whirr.service.hbase.HBaseMasterClusterActionHandler.java
private void createProxyScript(ClusterSpec clusterSpec, Cluster cluster) { File configDir = getConfigDir(clusterSpec); File hbaseProxyFile = new File(configDir, "hbase-proxy.sh"); try {/*from w w w . ja v a2 s. c o m*/ HadoopProxy proxy = new HadoopProxy(clusterSpec, cluster); InetAddress master = HBaseCluster.getMasterPublicAddress(cluster); String script = String.format("echo 'Running proxy to HBase cluster at %s. " + "Use Ctrl-c to quit.'\n", master.getHostName()) + Joiner.on(" ").join(proxy.getProxyCommand()); Files.write(script, hbaseProxyFile, Charsets.UTF_8); hbaseProxyFile.setExecutable(true); LOG.info("Wrote HBase proxy script {}", hbaseProxyFile); } catch (IOException e) { LOG.error("Problem writing HBase proxy script {}", hbaseProxyFile, e); } }
From source file:sce.ProcessExecutor.java
/** * File Permissions using File and PosixFilePermission * * @throws IOException// ww w.j av a2s . c o m */ public void setFilePermissions() throws IOException { File file = new File("/Users/temp.txt"); //set application user permissions to 455 file.setExecutable(false); file.setReadable(false); file.setWritable(true); //change permission to 777 for all the users //no option for group and others file.setExecutable(true, false); file.setReadable(true, false); file.setWritable(true, false); //using PosixFilePermission to set file permissions 777 Set<PosixFilePermission> perms = new HashSet<>(); //add owners permission perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); //add group permissions perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.GROUP_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); //add others permissions perms.add(PosixFilePermission.OTHERS_READ); perms.add(PosixFilePermission.OTHERS_WRITE); perms.add(PosixFilePermission.OTHERS_EXECUTE); Files.setPosixFilePermissions(Paths.get("/Users/pankaj/run.sh"), perms); }
From source file:org.apache.hadoop.mapred.TestJvmManager.java
private File writeScript(String fileName, String cmd, File pidFile) throws IOException { File script = new File(TEST_DIR, fileName); FileOutputStream out = new FileOutputStream(script); // write pid into a file out.write(("echo $$ >" + pidFile.toString() + ";").getBytes()); // ignore SIGTERM out.write(("trap '' 15\n").getBytes()); // write the actual command it self. out.write(cmd.getBytes());/* w w w .j a v a 2 s.c o m*/ out.close(); script.setExecutable(true); return script; }
From source file:org.apache.stratos.python.cartridge.agent.integration.tests.PythonAgentIntegrationTest.java
/** * Copy python agent distribution to a new folder, extract it and copy sample configuration files * * @return Python cartridge agent home directory *///from www . ja va2 s.co m protected String setupPythonAgent() { try { log.info("Setting up python cartridge agent..."); String srcAgentPath = PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + ".." + PATH_SEP + "distribution" + PATH_SEP + "target" + PATH_SEP + distributionName + ".zip"; String unzipDestPath = PythonAgentIntegrationTest.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 = PythonAgentIntegrationTest.class.getResource(PATH_SEP).getPath() + PATH_SEP + ".." + PATH_SEP + PYTHON_AGENT_DIR_NAME + PATH_SEP + distributionName; String srcAgentConfPath = getTestCaseResourcesPath() + PATH_SEP + "agent.conf"; String destAgentConfPath = destAgentPath + PATH_SEP + "agent.conf"; FileUtils.copyFile(new File(srcAgentConfPath), new File(destAgentConfPath)); String srcLoggingIniPath = getTestCaseResourcesPath() + PATH_SEP + "logging.ini"; String destLoggingIniPath = destAgentPath + PATH_SEP + "logging.ini"; FileUtils.copyFile(new File(srcLoggingIniPath), new File(destLoggingIniPath)); String srcPayloadPath = getTestCaseResourcesPath() + PATH_SEP + "payload"; String destPayloadPath = destAgentPath + PATH_SEP + "payload"; FileUtils.copyDirectory(new File(srcPayloadPath), new File(destPayloadPath)); // copy extensions directory if it exists String srcExtensionPath = getTestCaseResourcesPath() + PATH_SEP + "extensions" + PATH_SEP + "bash"; File extensionsDirFile = new File(srcExtensionPath); if (extensionsDirFile.exists()) { FileUtils.copyDirectory(extensionsDirFile, new File(destAgentPath + PATH_SEP + "extensions" + PATH_SEP + "bash")); } // copy plugins directory if it exists String srcPluginPath = getTestCaseResourcesPath() + PATH_SEP + "extensions" + PATH_SEP + "py"; File pluginsDirFile = new File(srcPluginPath); if (pluginsDirFile.exists()) { FileUtils.copyDirectory(pluginsDirFile, new File(destAgentPath + PATH_SEP + "plugins")); } File extensionsPath = new File(destAgentPath + PATH_SEP + "extensions" + PATH_SEP + "bash"); File[] extensions = extensionsPath.listFiles(); log.info("Changing extension scripts permissions in: " + extensionsPath.getAbsolutePath()); assert extensions != null; 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.openmeetings.app.data.flvrecord.converter.FlvInterviewConverter.java
public HashMap<String, String> processImageWindows(String file1, String file2, String file3) { HashMap<String, String> returnMap = new HashMap<String, String>(); returnMap.put("process", "processImageWindows"); try {//www .j a va 2s . com // Init variables String[] cmd; String executable_fileName = ""; String pathToIMagick = this.getPathToImageMagick(); Date tnow = new Date(); String runtimeFile = "interviewMerge" + tnow.getTime() + ".bat"; // String runtimeFile = "interviewMerge.bat"; executable_fileName = ScopeApplicationAdapter.batchFileDir + runtimeFile; cmd = new String[1]; cmd[0] = executable_fileName; // Create the Content of the Converter Script (.bat or .sh File) String fileContent = pathToIMagick + " " + file1 + " " + file2 + " " + "+append" + " " + file3 + ScopeApplicationAdapter.lineSeperator + ""; File previous = new File(executable_fileName); if (previous.exists()) { previous.delete(); } // execute the Script FileOutputStream fos = new FileOutputStream(executable_fileName); fos.write(fileContent.getBytes()); fos.close(); File now = new File(executable_fileName); now.setExecutable(true); Runtime rt = Runtime.getRuntime(); returnMap.put("command", cmd.toString()); Process proc = rt.exec(cmd); InputStream stderr = proc.getErrorStream(); BufferedReader br = new BufferedReader(new InputStreamReader(stderr)); String line = null; String error = ""; while ((line = br.readLine()) != null) { error += line; } br.close(); returnMap.put("error", error); int exitVal = proc.waitFor(); returnMap.put("exitValue", "" + exitVal); if (now.exists()) { now.delete(); } return returnMap; } catch (Throwable t) { t.printStackTrace(); returnMap.put("error", t.getMessage()); returnMap.put("exitValue", "-1"); return returnMap; } }
From source file:edu.stanford.epad.epadws.Main.java
private static void copyFiles(String macDir, String dicomProxyDir, String resourceDir, String[] scripts) { try {//from ww w.j a v a 2s .co m // Copy start/stop scripts over (mainly for docker) File binDir = new File(macDir); if (!binDir.exists()) binDir = new File(dicomProxyDir); for (String scriptFile : scripts) { File file = new File(binDir, scriptFile); if (!file.exists()) { InputStream in = null; OutputStream out = null; try { in = new Dcm4CheeOperations().getClass().getClassLoader() .getResourceAsStream(resourceDir + scriptFile); out = new FileOutputStream(file); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } catch (Exception x) { } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } if (file.exists()) file.setExecutable(true); } } catch (Exception x) { log.warning("Exception in docker script copy", x); } }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProviderTest.java
private File create(String path) { File file = new File(folder.getRoot(), path); assertThat(file.getParentFile().isDirectory() || file.getParentFile().mkdirs(), is(true)); try {/*from w w w . j a v a 2 s. com*/ assertThat(file.createNewFile(), is(true)); } catch (IOException e) { throw new AssertionError(e); } file.setExecutable(false); return file; }
From source file:it.drwolf.ridire.index.cwb.CWBCollocatesExtractor.java
private File tabulate() throws IOException { EnvironmentUtils.addVariableToEnvironment(EnvironmentUtils.getProcEnvironment(), "LC_ALL=C"); File tmpAwk = File.createTempFile("ridireAWK", ".awk"); String awk = this.createAWKString(); FileUtils.writeStringToFile(tmpAwk, awk); File tmpTabulate = File.createTempFile("ridireTAB", ".tab"); String tabulate = this.createTabulateString(tmpAwk, tmpTabulate); File tempSh = File.createTempFile("ridireSH", ".sh"); FileUtils.writeStringToFile(tempSh, tabulate); tempSh.setExecutable(true); Executor executor = new DefaultExecutor(); executor.setExitValue(0);/* w ww .j a va2s . c o m*/ ExecuteWatchdog watchdog = new ExecuteWatchdog(CWBCollocatesExtractor.CWB_COLLOCATES_EXTRACTOR_TIMEOUT); executor.setWatchdog(watchdog); CommandLine commandLine = new CommandLine(this.cqpExecutable); commandLine.addArgument("-f").addArgument(tempSh.getAbsolutePath()).addArgument("-D") .addArgument(this.cqpCorpusName).addArgument("-r").addArgument(this.cqpRegistry); executor.execute(commandLine); FileUtils.deleteQuietly(tmpAwk); FileUtils.deleteQuietly(tempSh); return tmpTabulate; }