List of usage examples for java.io File setExecutable
public boolean setExecutable(boolean executable)
From source file:com.opentable.db.postgres.embedded.BundledPostgresBinaryResolver.java
/** * Unpack archive compressed by tar with bzip2 compression. By default system tar is used * (faster). If not found, then the java implementation takes place. * * @param tbzPath// w w w. j a v a 2 s . co m * The archive path. * @param targetDir * The directory to extract the content to. */ private static void extractTxz(String tbzPath, String targetDir) throws IOException { try (InputStream in = Files.newInputStream(Paths.get(tbzPath)); XZInputStream xzIn = new XZInputStream(in); TarArchiveInputStream tarIn = new TarArchiveInputStream(xzIn)) { TarArchiveEntry entry; while ((entry = tarIn.getNextTarEntry()) != null) { final String individualFile = entry.getName(); final File fsObject = new File(targetDir + "/" + individualFile); if (entry.isSymbolicLink() || entry.isLink()) { Path target = FileSystems.getDefault().getPath(entry.getLinkName()); Files.createSymbolicLink(fsObject.toPath(), target); } else if (entry.isFile()) { byte[] content = new byte[(int) entry.getSize()]; int read = tarIn.read(content, 0, content.length); Verify.verify(read != -1, "could not read %s", individualFile); mkdirs(fsObject.getParentFile()); try (OutputStream outputFile = new FileOutputStream(fsObject)) { IOUtils.write(content, outputFile); } } else if (entry.isDirectory()) { mkdirs(fsObject); } else { throw new UnsupportedOperationException( String.format("Unsupported entry found: %s", individualFile)); } if (individualFile.startsWith("bin/") || individualFile.startsWith("./bin/")) { fsObject.setExecutable(true); } } } }
From source file:com.comcast.magicwand.spells.web.iexplore.IePhoenixDriver.java
/** * {@inheritDoc}/*w w w. j a v a 2s. c om*/ */ public boolean verify(PhoenixDriverIngredients i) { boolean rv = false; Map<String, Object> configs = i.getDriverConfigs(); LOGGER.debug("[version_property, arch_property] = [{}, {}]", (String) configs.get(IE_DRIVER_VERSION_KEY), (String) configs.get(IE_DRIVER_ARCH_KEY)); IePlatformSpecifics ips = this.createIePlatformSpecifics((String) configs.get(IE_DRIVER_VERSION_KEY), (String) configs.get(IE_DRIVER_ARCH_KEY)); if (!ips.isValid()) { LOGGER.error("The IePlatformSpecifics retrieved are not valid."); return false; } try { XPath xpath = XPathFactory.newInstance().newXPath(); String pwd = System.getProperty("user.dir"); String version = ips.getVersion(); String arch = ips.getArch(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(IE_XML_DRIVER_LISTING_URL); NodeList nodes = (NodeList) xpath.evaluate(IE_XML_DRIVER_LISTING_XPATH, doc, XPathConstants.NODESET); String highestVersion = null; String needle = version + "/IEDriverServer_" + arch + "_"; for (int idx = 0; idx < nodes.getLength(); idx++) { Node n = nodes.item(idx); String text = n.getTextContent(); if (text.startsWith(needle)) { text = text.substring(needle.length(), text.length()); if (IePhoenixDriver.versionGreater(highestVersion, text)) { highestVersion = text; } } } if (null != highestVersion) { highestVersion = FilenameUtils.removeExtension(highestVersion); URL url = new URL(String.format(IE_HTTP_DRIVER_PATH_FORMAT, version, arch, highestVersion)); String zipName = String.format(IE_ZIP_FILE_FORMAT, arch, highestVersion); File ieSaveDir = new File(Paths.get(pwd, "target", "drivers", "iexplore", version).toString()); LOGGER.debug("Will read from \"{}\"", url); File zipFile = new File( Paths.get(pwd, "target", "drivers", "iexplore", version, zipName).toString()); FileUtils.copyURLToFile(url, zipFile); extract(zipFile, ieSaveDir.getAbsolutePath()); File exe = Paths.get(pwd, "target", "drivers", "iexplore", version, IE_EXE_FILE_NAME).toFile(); if (exe.exists()) { exe.setExecutable(true); systemSetProperty("webdriver.ie.driver", exe.getAbsolutePath()); this.webDriver = this.createDriver(i.getDriverCapabilities()); rv = true; } else { LOGGER.error("Extracted zip archive did nto contain \"{}\".", IE_EXE_FILE_NAME); } } else { LOGGER.error("Unable to find any IE Drivers from [{}]", IE_XML_DRIVER_LISTING_XPATH); } } catch (ParserConfigurationException | SAXException | XPathExpressionException err) { throw new RuntimeException(err); } catch (IOException ioe) { LOGGER.error("IO failure: {}", ioe); } return rv; }
From source file:com.thoughtworks.go.util.command.CommandLineTest.java
@Test @DisabledOnOs(OS.WINDOWS)/*from w w w.j a v a2s . co m*/ void shouldBeAbleToRunCommandsInSubdirectories() throws IOException { File shellScript = createScript("hello-world.sh", "echo ${PWD}"); assertThat(shellScript.setExecutable(true), is(true)); CommandLine line = CommandLine.createCommandLine("./hello-world.sh").withWorkingDir(subFolder) .withEncoding("utf-8"); InMemoryStreamConsumer out = new InMemoryStreamConsumer(); line.execute(out, new EnvironmentVariableContext(), null).waitForExit(); assertThat(out.getAllOutput().trim(), endsWith("subFolder")); }
From source file:com.bhb27.isu.Main.java
public void extractAssets(String executableFilePath, String filename) { AssetManager assetManager = getAssets(); InputStream inStream = null;/*from www . j a va2s. co m*/ OutputStream outStream = null; try { inStream = assetManager.open(filename); outStream = new FileOutputStream(executableFilePath); // for override file content //outStream = new FileOutputStream(out,true); // for append file content byte[] buffer = new byte[1024]; int length; while ((length = inStream.read(buffer)) > 0) { outStream.write(buffer, 0, length); } if (inStream != null) inStream.close(); if (outStream != null) outStream.close(); } catch (IOException e) { Log.e(TAG, "Failed to copy asset file: " + filename, e); } File execFile = new File(executableFilePath); execFile.setExecutable(true); Log.e(TAG, "Copy success: " + filename); }
From source file:com.thoughtworks.go.util.command.CommandLineTest.java
@Test @DisabledOnOs(OS.WINDOWS)//from w ww.ja v a2 s . c o m void shouldBeAbleToRunCommandsInSubdirectoriesWithNoWorkingDir() throws IOException { File shellScript = createScript("hello-world.sh", "echo 'Hello World!'"); assertThat(shellScript.setExecutable(true), is(true)); CommandLine line = CommandLine.createCommandLine("subFolder/hello-world.sh") .withWorkingDir(temporaryFolder.getRoot()).withEncoding("utf-8"); InMemoryStreamConsumer out = new InMemoryStreamConsumer(); line.execute(out, new EnvironmentVariableContext(), null).waitForExit(); assertThat(out.getAllOutput(), containsString("Hello World!")); }
From source file:io.specto.hoverfly.junit.HoverflyRule.java
private Path extractBinary(final String binaryName) throws IOException, URISyntaxException { final URI sourceHoverflyUrl = findResourceOnClasspath(binaryName); final Path temporaryHoverflyPath = Files.createTempFile(binaryName, ""); LOGGER.info("Storing binary in temporary directory " + temporaryHoverflyPath); final File temporaryHoverflyFile = temporaryHoverflyPath.toFile(); FileUtils.copyURLToFile(sourceHoverflyUrl.toURL(), temporaryHoverflyFile); if (SystemUtils.IS_OS_WINDOWS) { temporaryHoverflyFile.setExecutable(true); temporaryHoverflyFile.setReadable(true); temporaryHoverflyFile.setWritable(true); } else {// w ww. ja v a2 s . c om Files.setPosixFilePermissions(temporaryHoverflyPath, new HashSet<>(asList(OWNER_EXECUTE, OWNER_READ))); } return temporaryHoverflyPath; }
From source file:com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScannerZipInstaller.java
private void downloadIfModified(File scannerExpansionDirectory, File versionFile, String downloadUrl) throws IOException, IntegrationException, ArchiveException { long lastTimeDownloaded = versionFile.lastModified(); logger.debug(String.format("last time downloaded: %d", lastTimeDownloaded)); Request downloadRequest = new Request.Builder(downloadUrl).build(); Optional<Response> optionalResponse = intHttpClient.executeGetRequestIfModifiedSince(downloadRequest, lastTimeDownloaded);/* www . j av a 2s . c o m*/ if (optionalResponse.isPresent()) { Response response = optionalResponse.get(); try { logger.info("Downloading the Black Duck Signature Scanner."); try (InputStream responseStream = response.getContent()) { logger.info(String.format( "If your Black Duck server has changed, the contents of %s may change which could involve deleting files - please do not place items in the expansion directory as this directory is assumed to be under blackduck-common control.", scannerExpansionDirectory.getAbsolutePath())); cleanupZipExpander.expand(responseStream, scannerExpansionDirectory); } long lastModifiedOnServer = response.getLastModified(); versionFile.setLastModified(lastModifiedOnServer); ScanPaths scanPaths = scanPathsUtility .determineSignatureScannerPaths(scannerExpansionDirectory.getParentFile()); File javaExecutable = new File(scanPaths.getPathToJavaExecutable()); File oneJar = new File(scanPaths.getPathToOneJar()); File scanExecutable = new File(scanPaths.getPathToScanExecutable()); javaExecutable.setExecutable(true); oneJar.setExecutable(true); scanExecutable.setExecutable(true); logger.info(String.format("Black Duck Signature Scanner downloaded successfully.")); } finally { response.close(); } } else { logger.debug( "The Black Duck Signature Scanner has not been modified since it was last downloaded - skipping download."); } }
From source file:com.asakusafw.runtime.util.hadoop.ConfigurationProviderTest.java
private File putExec(String path) { File file = create(path); file.setExecutable(true); return file; }
From source file:com.aurel.track.dbase.HandleHome.java
private static void copyExportTemplates(ServletContext context, String templateBaseDir) { String tpHome = getTrackplus_Home(); File templatesDir = new File(tpHome + File.separator + templateBaseDir); URL rootTillFolder = null;/*from w w w.j a v a 2 s . c om*/ String rootPathTillFolder = null; String templatePath = templateBaseDir.replace("\\", "/"); try { if (context.getResource("/WEB-INF/classes/resources/" + templatePath) != null) { rootTillFolder = context.getResource("/WEB-INF/classes/resources/" + templatePath); } else if (context.getResource("/WEB-INF/classes/" + templatePath) != null) { rootTillFolder = context.getResource("/WEB-INF/classes/" + templatePath); } else { rootTillFolder = new URL(context.getRealPath("../.")); } } catch (IOException ioEx) { LOGGER.error(ExceptionUtils.getStackTrace(ioEx)); } if (rootTillFolder != null) { rootPathTillFolder = rootTillFolder.getPath(); if (rootPathTillFolder.contains("/WEB-INF")) { rootPathTillFolder = rootPathTillFolder.substring(rootPathTillFolder.indexOf("/WEB-INF"), rootPathTillFolder.length()); } Set<String> folderContent = context.getResourcePaths(rootPathTillFolder); if (folderContent != null) { for (String fileNameWithPath : folderContent) { String fileName = fileNameWithPath.replace("/WEB-INF/classes/resources/" + templatePath + "/", ""); if (fileName.endsWith(".docx") || fileName.endsWith(".tex") || fileName.endsWith(".jpg") || fileName.endsWith(".png") || fileName.endsWith(".tlx") || fileName.endsWith(".sh") || fileName.endsWith(".cmd") || fileName.endsWith(".pdf")) { try { copyObject(context, "resources/" + templatePath, fileName, templateBaseDir); } catch (ServletException servEx) { LOGGER.error(ExceptionUtils.getStackTrace(servEx)); } } if (fileName.endsWith(".sh") || fileName.endsWith(".cmd")) { File fileToCopyInHome = new File( tpHome + File.separator + templateBaseDir + File.separator + fileName); fileToCopyInHome.setExecutable(true); } if (fileName.endsWith(".zip") || fileName.endsWith(".tlx")) { try { File fileToCopyInHome = new File( tpHome + File.separator + templateBaseDir + File.separator + fileName); copyObject(context, "resources/" + templatePath, fileName, templateBaseDir); File fileToUnzip = new File( tpHome + File.separator + templateBaseDir + File.separator + fileName); PluginUtils.unzipFileIntoDirectory(fileToUnzip, templatesDir); } catch (ServletException servEx) { LOGGER.error(ExceptionUtils.getStackTrace(servEx)); } } } } } }
From source file:com.blackducksoftware.integration.hub.cli.CLILocation.java
public File getCLI(final IntLogger logger) throws IOException, InterruptedException { final File cliHomeFile = getCLIHome(); if (cliHomeFile == null) { return null; }//w w w . j a v a2 s .c o m // find the lib folder in the iScan directory logger.debug("BlackDuck scan directory: " + cliHomeFile.getCanonicalPath()); final File[] files = cliHomeFile.listFiles(); if (files == null || files.length <= 0) { logger.error("No files found in the BlackDuck scan directory."); return null; } logger.debug("directories in the BlackDuck scan directory: " + files.length); final File libFolder = findFileByName(files, "lib"); if (libFolder == null) { logger.error("Could not find the lib directory of the CLI."); return null; } logger.debug("BlackDuck scan lib directory: " + libFolder.getCanonicalPath()); File hubScanJar = null; for (final File file : libFolder.listFiles()) { if (file.getName().startsWith("scan.cli") && file.getName().endsWith(".jar")) { hubScanJar = file; hubScanJar.setExecutable(true); break; } } return hubScanJar; }