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:ninja.build.RunClassInSeparateJvmMachine.java
public RunClassInSeparateJvmMachine(String name, String classNameWithMainToRun, List<String> classpath, List<String> jvmArguments, File mavenBaseDir) { this(name, classNameWithMainToRun, StringUtils.join(classpath, File.pathSeparator), jvmArguments, mavenBaseDir);//from ww w . ja v a2 s . c o m }
From source file:org.evosuite.executionmode.PrintStats.java
private static void printStats(String targetClass, List<String> args) { if (!BytecodeInstrumentation.checkIfCanInstrument(targetClass)) { throw new IllegalArgumentException("Cannot consider " + targetClass + " because it belongs to one of the packages EvoSuite cannot currently handle"); }/*from w w w . jav a 2s. c om*/ String classPath = ClassPathHandler.getInstance().getEvoSuiteClassPath(); String cp = ClassPathHandler.getInstance().getTargetProjectClasspath(); classPath += File.pathSeparator + cp; ExternalProcessHandler handler = new ExternalProcessHandler(); int port = handler.openServer(); List<String> cmdLine = new ArrayList<String>(); cmdLine.add(EvoSuite.JAVA_CMD); cmdLine.add("-cp"); cmdLine.add(classPath); cmdLine.add("-Dprocess_communication_port=" + port); cmdLine.add("-Djava.awt.headless=true"); cmdLine.add("-Dlogback.configurationFile=" + LoggingUtils.getLogbackFileName()); cmdLine.add("-Djava.library.path=lib"); cmdLine.add("-DCP=" + cp); // cmdLine.add("-Dminimize_values=true"); for (String arg : args) { if (!arg.startsWith("-DCP=")) { cmdLine.add(arg); } } cmdLine.add("-DTARGET_CLASS=" + targetClass); if (Properties.PROJECT_PREFIX != null) { cmdLine.add("-DPROJECT_PREFIX=" + Properties.PROJECT_PREFIX); } cmdLine.add("-Dclassloader=true"); cmdLine.add(ClientProcess.class.getName()); /* * TODO: here we start the client with several properties that are set through -D. These properties are not visible to the master process (ie * this process), when we access the Properties file. At the moment, we only need few parameters, so we can hack them */ Properties.getInstance();// should force the load, just to be sure Properties.TARGET_CLASS = targetClass; Properties.PROCESS_COMMUNICATION_PORT = port; LoggingUtils logUtils = new LoggingUtils(); if (!Properties.CLIENT_ON_THREAD) { /* * We want to completely mute the SUT. So, we block all outputs from client, and use a remote logging */ boolean logServerStarted = logUtils.startLogServer(); if (!logServerStarted) { logger.error("Cannot start the log server"); return; } int logPort = logUtils.getLogServerPort(); // cmdLine.add(1, "-Dmaster_log_port=" + logPort); cmdLine.add(1, "-Devosuite.log.appender=CLIENT"); } String[] newArgs = cmdLine.toArray(new String[cmdLine.size()]); for (String entry : ClassPathHandler.getInstance().getClassPathElementsForTargetProject()) { try { ClassPathHacker.addFile(entry); } catch (IOException e) { LoggingUtils.getEvoLogger().info("* Error while adding classpath entry: " + entry); } } handler.setBaseDir(EvoSuite.base_dir_path); if (handler.startProcess(newArgs)) { Set<ClientNodeRemote> clients = null; try { clients = MasterServices.getInstance().getMasterNode().getClientsOnceAllConnected(10000); } catch (InterruptedException e) { } if (clients == null) { logger.error("Not possible to access to clients"); } else { /* * The clients have started, and connected back to Master. * So now we just need to tell them to start a search */ for (ClientNodeRemote client : clients) { try { client.printClassStatistics(); } catch (RemoteException e) { logger.error("Error in starting clients", e); } } handler.waitForResult( (Properties.GLOBAL_TIMEOUT + Properties.MINIMIZATION_TIMEOUT + Properties.EXTRA_TIMEOUT) * 1000); // FIXXME: search } // timeout plus // 100 seconds? try { Thread.sleep(100); } catch (InterruptedException e) { } handler.killProcess(); } else { LoggingUtils.getEvoLogger().info("* Could not connect to client process"); } handler.closeServer(); if (!Properties.CLIENT_ON_THREAD) { try { Thread.sleep(100); } catch (InterruptedException e) { } logUtils.closeLogServer(); } }
From source file:org.jsweet.util.ProcessUtil.java
public static void runCmd(File directory, Consumer<String> stdoutConsumer, String... cmd) { System.out.println("run command: " + StringUtils.join(cmd, " ")); String[] args;//from ww w. j a v a2s .co m if (System.getProperty("os.name").startsWith("Windows")) { args = new String[] { "cmd", "/c" }; } else { args = new String[0]; } args = ArrayUtils.addAll(args, cmd); System.out.println("run command: '" + StringUtils.join(args, " ") + "' in directory " + directory); // logger.fine("run command: " + StringUtils.join(args, " ")); int code = -1; try { ProcessBuilder processBuilder = new ProcessBuilder(args); 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 process = processBuilder.start(); try (BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()))) { String line; while ((line = in.readLine()) != null) { if (stdoutConsumer != null) { stdoutConsumer.accept(line); } else { logger.info("OUT:" + line); } } } code = process.waitFor(); if (code != 0) { throw new RuntimeException( "error while exectuting: " + StringUtils.join(args, " ") + ", error code: " + code); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.cloudata.core.parallel.hadoop.CloudataMapReduceUtil.java
/** * Configure classpath to run MapReduce job which uses Cloudata<BR> * 1. Uploads cloudata library to HDFS: cloudata-xxx-core.jar<BR> * 2. make cloudata-configure.jar includes cloudata-site.xml and uploads to HDFS<BR> * 3. run DistributedCache.addArchiveToClassPath() for each file<BR> * Must call clearMapReduce() after running job. * @param jobConf/*from www. j av a 2 s. c o m*/ * @param cloudataHomeDir * @return temporary directory for linrary in HDFS. When calling clearMapReduce(), use this value. * @throws IOException */ public static String initMapReduce(JobConf jobConf) throws IOException { String jarPath = "Cloudata_Lib_" + System.currentTimeMillis(); FileSystem fs = FileSystem.get(conf); Path parentPath = fs.makeQualified(new Path(jarPath)); //upload jar to dfs fs.mkdirs(parentPath); String[] classpaths = System.getProperty("java.class.path", "").split(File.pathSeparator); if (classpaths == null || classpaths.length == 0) { throw new IOException("No classpath"); } List<String> uploadedFiles = new ArrayList<String>(); for (String eachPath : classpaths) { if (eachPath.indexOf("cloudata") >= 0 || eachPath.indexOf("lib") >= 0 || eachPath.indexOf("conf") >= 0) { uploadFile(fs, parentPath, new File(eachPath), uploadedFiles); } } if (uploadedFiles.size() == 0) { throw new IOException("No lib files[cloudata-xxx-core.jar, zookeeper-xxx.jar] in classpath"); } Path rootPath = new Path("/"); String rootUri = fs.makeQualified(rootPath).toString(); for (String eachPath : uploadedFiles) { Path path = fs.makeQualified(new Path(eachPath)); String pathStr = path.toUri().toString(); if (pathStr.indexOf(rootUri) >= 0) { pathStr = pathStr.substring(pathStr.indexOf(rootUri) + rootUri.length()); } if (!pathStr.startsWith("/")) { pathStr = "/" + pathStr; } LOG.debug("DistributedCache.addArchiveToClassPath: " + pathStr); DistributedCache.addArchiveToClassPath(new Path(pathStr), jobConf); } return jarPath; }
From source file:com.thoughtworks.gauge.util.GaugeUtil.java
private static GaugeSettingsModel getSettingsFromPATH(GaugeSettingsModel model) throws GaugeNotFoundException { String path = EnvironmentUtil.getValue("PATH"); LOG.info("PATH => " + path); if (!StringUtils.isEmpty(path)) { for (String entry : path.split(File.pathSeparator)) { File file = new File(entry, gaugeExecutable()); if (isValidGaugeExec(file)) { LOG.info("executable path from `PATH`: " + file.getAbsolutePath()); return new GaugeSettingsModel(file.getAbsolutePath(), model.getHomePath(), model.useIntelliJTestRunner()); }/*from ww w . j a va 2 s. c o m*/ } } String msg = "Could not find executable in `PATH`. Please make sure Gauge is installed." + "\nIf Gauge is installed then set the Gauge executable path in settings -> tools -> gauge."; throw new GaugeNotFoundException(msg); }
From source file:org.evosuite.executionmode.WriteDependencies.java
private static void writeDependencies(String targetFile, String targetClass, List<String> args) { if (!BytecodeInstrumentation.checkIfCanInstrument(targetClass)) { throw new IllegalArgumentException("Cannot consider " + targetClass + " because it belongs to one of the packages EvoSuite cannot currently handle"); }/*ww w .ja va 2s .c o m*/ String classPath = ClassPathHandler.getInstance().getEvoSuiteClassPath(); String cp = ClassPathHandler.getInstance().getTargetProjectClasspath(); classPath += File.pathSeparator + cp; ExternalProcessHandler handler = new ExternalProcessHandler(); int port = handler.openServer(); List<String> cmdLine = new ArrayList<String>(); cmdLine.add(EvoSuite.JAVA_CMD); cmdLine.add("-cp"); cmdLine.add(classPath); cmdLine.add("-Dprocess_communication_port=" + port); cmdLine.add("-Djava.awt.headless=true"); cmdLine.add("-Dlogback.configurationFile=" + LoggingUtils.getLogbackFileName()); cmdLine.add("-Djava.library.path=lib"); cmdLine.add("-DCP=" + cp); // cmdLine.add("-Dminimize_values=true"); for (String arg : args) { if (!arg.startsWith("-DCP=")) { cmdLine.add(arg); } } cmdLine.add("-DTARGET_CLASS=" + targetClass); if (Properties.PROJECT_PREFIX != null) { cmdLine.add("-DPROJECT_PREFIX=" + Properties.PROJECT_PREFIX); } cmdLine.add("-Dclassloader=true"); cmdLine.add(ClientProcess.class.getName()); /* * TODO: here we start the client with several properties that are set through -D. These properties are not visible to the master process (ie * this process), when we access the Properties file. At the moment, we only need few parameters, so we can hack them */ Properties.getInstance();// should force the load, just to be sure Properties.TARGET_CLASS = targetClass; Properties.PROCESS_COMMUNICATION_PORT = port; LoggingUtils logUtils = new LoggingUtils(); if (!Properties.CLIENT_ON_THREAD) { /* * We want to completely mute the SUT. So, we block all outputs from client, and use a remote logging */ boolean logServerStarted = logUtils.startLogServer(); if (!logServerStarted) { logger.error("Cannot start the log server"); return; } int logPort = logUtils.getLogServerPort(); // cmdLine.add(1, "-Dmaster_log_port=" + logPort); cmdLine.add(1, "-Devosuite.log.appender=CLIENT"); } String[] newArgs = cmdLine.toArray(new String[cmdLine.size()]); for (String entry : ClassPathHandler.getInstance().getClassPathElementsForTargetProject()) { try { ClassPathHacker.addFile(entry); } catch (IOException e) { LoggingUtils.getEvoLogger().info("* Error while adding classpath entry: " + entry); } } handler.setBaseDir(EvoSuite.base_dir_path); if (handler.startProcess(newArgs)) { Set<ClientNodeRemote> clients = null; try { clients = MasterServices.getInstance().getMasterNode().getClientsOnceAllConnected(10000); } catch (InterruptedException e) { } if (clients == null) { logger.error("Not possible to access to clients"); } else { /* * The clients have started, and connected back to Master. * So now we just need to tell them to start a search */ for (ClientNodeRemote client : clients) { try { client.doDependencyAnalysis(targetFile); } catch (RemoteException e) { logger.error("Error in starting clients", e); } } handler.waitForResult( (Properties.GLOBAL_TIMEOUT + Properties.MINIMIZATION_TIMEOUT + Properties.EXTRA_TIMEOUT) * 1000); // FIXXME: search } // timeout plus // 100 seconds? try { Thread.sleep(100); } catch (InterruptedException e) { } handler.killProcess(); } else { LoggingUtils.getEvoLogger().info("* Could not connect to client process"); } handler.closeServer(); if (!Properties.CLIENT_ON_THREAD) { try { Thread.sleep(100); } catch (InterruptedException e) { } logUtils.closeLogServer(); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectClinicalRawFileListener.java
@Override public void handleEvent(Event event) { this.selectRawFilesUI.openLoadingShell(); new Thread() { public void run() { String[] paths = selectRawFilesUI.getPath().split(File.pathSeparator, -1); for (int i = 0; i < paths.length; i++) { String path = paths[i]; if (path == null) { selectRawFilesUI.setIsLoading(false); return; }//from w w w . ja v a 2 s .c om File rawFile = new File(path); if (rawFile.exists()) { if (rawFile.isFile()) { if (path.contains("%")) { selectRawFilesUI.setMessage("File name can not contain percent ('%') symbol."); selectRawFilesUI.setIsLoading(false); return; } String newPath = dataType.getPath().getAbsolutePath() + File.separator + rawFile.getName(); if (selectRawFilesUI.getFormat().compareTo("Tab delimited raw file") != 0 && selectRawFilesUI.getFormat().compareTo("SOFT") != 0) { selectRawFilesUI.setMessage("File format does not exist"); selectRawFilesUI.setIsLoading(false); return; } if (selectRawFilesUI.getFormat().compareTo("SOFT") == 0) { File newFile = new File(newPath); if (newFile.exists()) { selectRawFilesUI.setMessage("File has already been added"); selectRawFilesUI.setIsLoading(false); return; } else { if (createTabFileFromSoft(rawFile, newFile)) { ((ClinicalData) dataType).addRawFile(newFile); selectRawFilesUI.setMessage("File has been added"); } } } else if (selectRawFilesUI.getFormat().compareTo("Tab delimited raw file") == 0) { if (!checkTabFormat(rawFile)) { selectRawFilesUI.setIsLoading(false); return; } File copiedRawFile = new File(newPath); if (!copiedRawFile.exists()) { try { FileUtils.copyFile(rawFile, copiedRawFile); ((ClinicalData) dataType).addRawFile(copiedRawFile); selectRawFilesUI.setMessage("File has been added"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage()); selectRawFilesUI.setIsLoading(false); return; } } else { selectRawFilesUI.setMessage("File has already been added"); selectRawFilesUI.setIsLoading(false); return; } } } else { selectRawFilesUI.setMessage("File is a directory"); selectRawFilesUI.setIsLoading(false); return; } } else { selectRawFilesUI.setMessage("Path does no exist"); selectRawFilesUI.setIsLoading(false); return; } } selectRawFilesUI.setIsLoading(false); } }.start(); this.selectRawFilesUI.waitForThread(); selectRawFilesUI.updateViewer(); WorkPart.updateSteps(); UsedFilesPart.sendFilesChanged(dataType); }
From source file:org.evosuite.EvoSuite.java
public static String generateInheritanceTree(String cp) throws IOException { LoggingUtils.getEvoLogger().info("* Analyzing classpath (generating inheritance tree)"); List<String> cpList = Arrays.asList(cp.split(File.pathSeparator)); // Clear current inheritance file to make sure a new one is generated Properties.INHERITANCE_FILE = ""; InheritanceTree tree = InheritanceTreeGenerator.createFromClassPath(cpList); File outputFile = File.createTempFile("ES_inheritancetree", ".xml.gz"); outputFile.deleteOnExit();/*from w w w.j a v a 2 s.c o m*/ InheritanceTreeGenerator.writeInheritanceTree(tree, outputFile); return outputFile.getAbsolutePath(); }
From source file:com.jstar.eclipse.preferences.PreferenceConstants.java
public static String getSootClassPath() { if (SystemUtils.IS_OS_MAC) { return getSootClassPathClasses() + File.pathSeparator + getSootClassPathUi(); } else {//from ww w .j a v a 2 s. c om return getSootClassPathRt(); } }
From source file:net.grinder.util.AbstractGrinderClassPathProcessor.java
/** * Construct classPath for grinder from given classpath string. * * @param classPath classpath string//from w w w . j a v a2 s . c o m * @param logger logger * @return classpath optimized for grinder. */ public String filterClassPath(String classPath, Logger logger) { List<String> classPathList = new ArrayList<String>(); for (String eachClassPath : checkNotNull(classPath).split(File.pathSeparator)) { String filename = FilenameUtils.getName(eachClassPath); if (isUsefulJar(filename) || isUsefulReferenceProject(eachClassPath)) { logger.trace("classpath :" + eachClassPath); classPathList.add(eachClassPath); } } return StringUtils.join(classPathList, File.pathSeparator); }