List of usage examples for java.io File pathSeparator
String pathSeparator
To view the source code for java.io File pathSeparator.
Click Source Link
From source file:org.apache.cxf.maven_plugin.Java2WSMojo.java
public void execute() throws MojoExecutionException { System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true"); if (skip) {/*from ww w. j a v a2 s .co m*/ getLog().info("Skipping Java2WS execution"); return; } ClassLoaderSwitcher classLoaderSwitcher = new ClassLoaderSwitcher(getLog()); try { String cp = classLoaderSwitcher.switchClassLoader(project, false, classpath, classpathElements); if (fork) { List<String> artifactsPath = new ArrayList<>(pluginArtifacts.size()); for (Artifact a : pluginArtifacts) { File file = a.getFile(); if (file == null) { throw new MojoExecutionException("Unable to find file for artifact " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion()); } artifactsPath.add(file.getPath()); } cp = StringUtils.join(artifactsPath.iterator(), File.pathSeparator) + File.pathSeparator + cp; } List<String> args = initArgs(cp); processJavaClass(args); } finally { classLoaderSwitcher.restoreClassLoader(); } System.gc(); }
From source file:org.evosuite.executionmode.TestGeneration.java
private static List<List<TestGenerationResult>> generateTestsPrefix(Properties.Strategy strategy, String prefix, List<String> args) { List<List<TestGenerationResult>> results = new ArrayList<List<TestGenerationResult>>(); String cp = ClassPathHandler.getInstance().getTargetProjectClasspath(); Set<String> classes = new HashSet<String>(); for (String classPathElement : cp.split(File.pathSeparator)) { classes.addAll(ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .getAllClasses(classPathElement, prefix, false)); try {/* w w w . jav a2 s . c om*/ ClassPathHacker.addFile(classPathElement); } catch (IOException e) { // Ignore? } } try { if (Properties.INSTRUMENT_CONTEXT || Properties.INHERITANCE_FILE.isEmpty()) { String inheritanceFile = EvoSuite.generateInheritanceTree(cp); args.add("-Dinheritance_file=" + inheritanceFile); } } catch (IOException e) { LoggingUtils.getEvoLogger().info("* Error while traversing classpath: " + e); return results; } LoggingUtils.getEvoLogger().info("* Found " + classes.size() + " matching classes for prefix " + prefix); for (String sut : classes) { try { if (ResourceList.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()) .isClassAnInterface(sut)) { LoggingUtils.getEvoLogger().info("* Skipping interface: " + sut); continue; } } catch (IOException e) { LoggingUtils.getEvoLogger().info("Could not load class: " + sut); continue; } LoggingUtils.getEvoLogger().info("* Current class: " + sut); results.addAll(generateTests(Strategy.EVOSUITE, sut, args)); } return results; }
From source file:com.eucalyptus.blockstorage.HttpReader.java
private void getResponseToFile() { byte[] bytes = new byte[StorageProperties.TRANSFER_CHUNK_SIZE]; FileOutputStream fileOutputStream = null; BufferedOutputStream bufferedOut = null; try {//from ww w. ja v a2 s . c om File outFile = null; File outFileUncompressed = null; if (compressed) { String outFileNameUncompressed = tempPath + File.pathSeparator + file.getName() + Hashes.getRandom(16); outFileUncompressed = new File(outFileNameUncompressed); outFile = new File(outFileNameUncompressed + ".gz"); } else { outFile = file; } httpClient.executeMethod(method); // GZIPInputStream has a bug thats corrupting snapshot file system. Mounting the block device failed with unknown file system error /*InputStream httpIn = null; if(compressed) { httpIn = new GZIPInputStream(method.getResponseBodyAsStream()); } else { httpIn = method.getResponseBodyAsStream(); }*/ InputStream httpIn = method.getResponseBodyAsStream(); int bytesRead; fileOutputStream = new FileOutputStream(outFile); // fileOutputStream = new FileOutputStream(file); bufferedOut = new BufferedOutputStream(fileOutputStream); while ((bytesRead = httpIn.read(bytes)) > 0) { bufferedOut.write(bytes, 0, bytesRead); } bufferedOut.close(); if (compressed) { try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(new String[] { "/bin/gunzip", outFile.getAbsolutePath() }); StreamConsumer error = new StreamConsumer(proc.getErrorStream()); StreamConsumer output = new StreamConsumer(proc.getInputStream()); error.start(); output.start(); output.join(); error.join(); } catch (Exception t) { LOG.error(t); } if ((outFileUncompressed != null) && (!outFileUncompressed.renameTo(file))) { LOG.error("Unable to uncompress: " + outFile.getAbsolutePath()); return; } } } catch (Exception ex) { LOG.error(ex, ex); } finally { method.releaseConnection(); if (bufferedOut != null) { try { bufferedOut.close(); } catch (IOException e) { LOG.error(e); } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e) { LOG.error(e); } } } }
From source file:io.fabric8.maven.core.util.ProcessUtil.java
private static List<File> getPathDirectories() { List<File> pathDirectories = new ArrayList<>(); String pathText = System.getenv("PATH"); if (isWindows() && pathText == null) { // On windows, the PATH env var is case insensitive, force to upper case. for (Map.Entry<String, String> entry : System.getenv().entrySet()) { if (entry.getKey().equalsIgnoreCase("PATH")) { pathText = entry.getValue(); break; }//w w w.ja v a 2s . c om } } if (StringUtils.isNotBlank(pathText)) { String[] pathTexts = pathText.split(File.pathSeparator); for (String text : pathTexts) { File dir = new File(text); if (dir.exists() && dir.isDirectory()) { pathDirectories.add(dir); } } } return pathDirectories; }
From source file:org.jsweet.transpiler.util.ProcessUtil.java
/** * Runs the given command.//from www . ja v a 2 s . c o m * * @param command * the command name * @param directory * the working directory of the created process * @param async * tells if the command should be run asynchronously (in a * separate thread) * @param stdoutConsumer * consumes the standard output stream as lines of characters * @param endConsumer * called when the process actually ends * @param errorHandler * upcalled when the command does not terminate successfully * @param args * the command-line arguments * @return the process that was created to execute the command (can be still * running at this point if <code>async</code> is <code>true</code>) */ public static Process runCommand(String command, File directory, boolean async, Consumer<String> stdoutConsumer, Consumer<Process> endConsumer, Runnable errorHandler, String... args) { String[] cmd; if (System.getProperty("os.name").startsWith("Windows")) { if (nodeCommands.contains(command)) { cmd = new String[] { getNpmPath(command) }; } else { cmd = new String[] { "cmd", "/c", command }; } } else { if (nodeCommands.contains(command)) { cmd = new String[] { getNpmPath(command) }; } else { cmd = new String[] { command }; } } cmd = ArrayUtils.addAll(cmd, args); logger.debug("run command: " + StringUtils.join(cmd, " ")); Process[] process = { null }; try { ProcessBuilder processBuilder = new ProcessBuilder(cmd); processBuilder.redirectErrorStream(true); if (directory != null) { processBuilder.directory(directory); } if (!StringUtils.isBlank(EXTRA_PATH)) { processBuilder.environment().put("PATH", processBuilder.environment().get("PATH") + File.pathSeparator + EXTRA_PATH); } process[0] = processBuilder.start(); Runnable runnable = new Runnable() { @Override public void run() { try { try (BufferedReader in = new BufferedReader( new InputStreamReader(process[0].getInputStream()))) { String line; while ((line = in.readLine()) != null) { if (stdoutConsumer != null) { stdoutConsumer.accept(line); } else { logger.info(command + " - " + line); } } } process[0].waitFor(); if (endConsumer != null) { endConsumer.accept(process[0]); } if (process[0].exitValue() != 0) { if (errorHandler != null) { errorHandler.run(); } } } catch (Exception e) { logger.error(e.getMessage(), e); if (errorHandler != null) { errorHandler.run(); } } } }; if (async) { new Thread(runnable).start(); } else { runnable.run(); } } catch (Exception e) { logger.error(e.getMessage(), e); if (errorHandler != null) { errorHandler.run(); } return null; } return process[0]; }
From source file:com.axelor.studio.service.ModuleRecorderService.java
private String setPath(String path, String var) throws AxelorException { String home = ENV.get(var); if (home == null) { throw new AxelorException(I18n.get("Please set %s environment variable"), 1, var); }//from w ww . j a v a 2 s . c o m String binPath; if (home.endsWith(File.separator)) { binPath = home + "bin"; } else { binPath = home + File.separator + "bin"; } if (!path.contains(binPath)) { path += File.pathSeparator + binPath; } return path; }
From source file:org.apache.giraph.io.hcatalog.HCatGiraphRunner.java
/** * set hive configuration// w ww. j a v a2 s .com * @param conf Configuration argument */ private static void adjustConfigurationForHive(Configuration conf) { // when output partitions are used, workers register them to the // metastore at cleanup stage, and on HiveConf's initialization, it // looks for hive-site.xml from. addToStringCollection(conf, "tmpfiles", conf.getClassLoader().getResource("hive-site.xml").toString()); // Also, you need hive.aux.jars as well // addToStringCollection(conf, "tmpjars", // conf.getStringCollection("hive.aux.jars.path")); // Or, more effectively, we can provide all the jars client needed to // the workers as well String[] hadoopJars = System.getenv("HADOOP_CLASSPATH").split(File.pathSeparator); List<String> hadoopJarURLs = Lists.newArrayList(); for (String jarPath : hadoopJars) { File file = new File(jarPath); if (file.exists() && file.isFile()) { String jarURL = file.toURI().toString(); hadoopJarURLs.add(jarURL); } } addToStringCollection(conf, "tmpjars", hadoopJarURLs); }
From source file:net.morematerials.manager.HandlerManager.java
private void prepareCompiler(File binFolder) { //Search & add dependencies List<String> libs = new ArrayList<String>(); libs.add(System.getProperty("java.class.path")); // Add all plugins to allow using other plugins. for (File lib : (new File("plugins")).listFiles()) { if (lib.getName().endsWith(".jar")) { libs.add("plugins/" + lib.getName()); }//w ww . j av a2 s .c om } // Set the classpath. this.compilerOptions.addAll(Arrays.asList("-classpath", StringUtils.join(libs, File.pathSeparator), "-d", binFolder.getAbsolutePath())); }
From source file:com.dal.unity.Config.java
@SuppressWarnings("unchecked") void set(String[] args) { CommandLineParser parser;/* w ww . j a v a 2 s .co m*/ @SuppressWarnings("UnusedAssignment") CommandLine cmd = null; try { parser = new DefaultParser(); try { cmd = parser.parse(getOptions(), args); } catch (MissingOptionException x) { System.out.println(x.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("unity", getOptions()); System.exit(-20); } if (cmd.hasOption(FLAG_HELP)) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("unity", getOptions()); System.exit(0); } if (cmd.hasOption(FLAG_CLASSPATH_FILE)) { classPath = readClasspath(cmd.getOptionValue(FLAG_CLASSPATH_FILE)); } else { classPath = DEFAULT_CLASSPATH; } if (cmd.hasOption(FLAG_COMPILE)) { compile = true; } if (cmd.hasOption(FLAG_VALUES_MAX)) { maxTests = true; } if (cmd.hasOption(FLAG_VALUES_MIN)) { minTests = true; } if (cmd.hasOption(FLAG_TESTS_NULL)) { nullTests = true; } if (cmd.hasOption(FLAG_RECURSION)) { recursive = true; } if (cmd.hasOption(FLAG_REGRESSION)) { regression = true; } if (cmd.hasOption(FLAG_SOURCE)) { source = cmd.getOptionValue(FLAG_SOURCE); } else { source = DEFAULT_SOURCE; } sourceFile = new File(source); if (cmd.hasOption(FLAG_TARGET)) { target = cmd.getOptionValue(FLAG_TARGET); } targetFile = new File(target); classPath += File.pathSeparator + target + File.pathSeparator + DEFAULT_TARGET; if (cmd.hasOption(FLAG_SINK)) { sink = cmd.getOptionValue(FLAG_SINK); } else { sink = DEFAULT_SINK; } sinkFile = new File(sink); if (cmd.hasOption(FLAG_OPTIONS_COMPILER)) { Object result = cmd.getParsedOptionValue(FLAG_OPTIONS_COMPILER); if (result instanceof Map) { javaOptions = (Map<String, String>) result; } else { throw new ParseException("Java Options is not MAP, parsed to " + result.getClass().getName()); } } if (cmd.hasOption(FLAG_FILE_SUFFIX)) { testSuffix = cmd.getOptionValue(FLAG_FILE_SUFFIX); } else { testSuffix = DEFAULT_TEST_FILE_SUFFIX; } if (cmd.hasOption(FLAG_METHOD_SUFFIX)) { methodSuffix = cmd.getOptionValue(FLAG_METHOD_SUFFIX); } else { methodSuffix = DEFAULT_TEST_METHOD_SUFFIX; } } catch (ParseException x) { LOG.error("Parsing failed: {}", x, x); System.err.println("Parsing failed. Reason: " + x.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ant", getOptions()); System.exit(-1); } }