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:eu.stratosphere.nephele.io.compression.CompressionLoader.java
/** * Returns the path to the native libraries or <code>null</code> if an error occurred. * /* www . j a v a 2s . c om*/ * @param libraryClass * the name of this compression library's wrapper class including full package name * @return the path to the native libraries or <code>null</code> if an error occurred */ private static String getNativeLibraryPath(final String libraryClass) { final ClassLoader cl = ClassLoader.getSystemClassLoader(); if (cl == null) { LOG.error("Cannot find system class loader"); return null; } final String classLocation = libraryClass.replace('.', '/') + ".class"; if (LOG.isDebugEnabled()) { LOG.debug("Class location is " + classLocation); } final URL location = cl.getResource(classLocation); if (location == null) { LOG.error("Cannot determine location of CompressionLoader class"); return null; } final String locationString = location.toString(); if (locationString.contains(".jar!")) { // Class if inside of a deployed jar file // Create and return path to native library cache final String pathName = GlobalConfiguration .getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH) .split(File.pathSeparator)[0] + File.separator + NATIVELIBRARYCACHENAME; final File path = new File(pathName); if (!path.exists()) { if (!path.mkdir()) { LOG.error("Cannot create directory for native library cache."); return null; } } return pathName; } else { String result = ""; int pos = locationString.indexOf(classLocation); if (pos < 0) { LOG.error("Cannot find extract native path from class location"); return null; } result = locationString.substring(0, pos) + "META-INF/lib"; // Strip the file:/ scheme, it confuses the class loader if (result.startsWith("file:")) { result = result.substring(5); } return result; } }
From source file:net.minecraftforge.fml.relauncher.FMLLaunchHandler.java
private void setupHome() { FMLInjectionData.build(minecraftHome, classLoader); redirectStdOutputToLog();//w w w . j av a2 s . c om FMLLog.log.info("Forge Mod Loader version {}.{}.{}.{} for Minecraft {} loading", FMLInjectionData.major, FMLInjectionData.minor, FMLInjectionData.rev, FMLInjectionData.build, FMLInjectionData.mccversion); FMLLog.log.info("Java is {}, version {}, running on {}:{}:{}, installed at {}", System.getProperty("java.vm.name"), System.getProperty("java.version"), System.getProperty("os.name"), System.getProperty("os.arch"), System.getProperty("os.version"), System.getProperty("java.home")); FMLLog.log.debug("Java classpath at launch is:"); for (String path : System.getProperty("java.class.path").split(File.pathSeparator)) FMLLog.log.debug(" {}", path); FMLLog.log.debug("Java library path at launch is:"); for (String path : System.getProperty("java.library.path").split(File.pathSeparator)) FMLLog.log.debug(" {}", path); try { LibraryManager.setup(minecraftHome); CoreModManager.handleLaunch(minecraftHome, classLoader, tweaker); } catch (Throwable t) { throw new RuntimeException("An error occurred trying to configure the Minecraft home at " + minecraftHome.getAbsolutePath() + " for Forge Mod Loader", t); } }
From source file:org.apache.hadoop.yarn.applications.unmanagedamlauncher.TestUnmanagedAMLauncher.java
private static String getTestRuntimeClasspath() { LOG.info("Trying to generate classpath for app master from current thread's classpath"); String envClassPath = ""; String cp = System.getProperty("java.class.path"); if (cp != null) { envClassPath += cp.trim() + File.pathSeparator; }//from w w w . j a v a 2s. c om // yarn-site.xml at this location contains proper config for mini cluster ClassLoader thisClassLoader = Thread.currentThread().getContextClassLoader(); URL url = thisClassLoader.getResource("yarn-site.xml"); envClassPath += new File(url.getFile()).getParent(); return envClassPath; }
From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java
public static int executeCommandGetReturnCode(String cmd, String workingDir, String executeFrom) { if (workingDir == null) { workingDir = "/tmp"; }//www.j a v a2s.c o m logger.debug("Execute command: " + cmd + ". Working dir: " + workingDir); try { String[] splitStr = cmd.split("\\s+"); ProcessBuilder pb = new ProcessBuilder(splitStr); pb.directory(new File(workingDir)); pb = pb.redirectErrorStream(true); // this is important to redirect the error stream to output stream, prevent blocking with long output Map<String, String> env = pb.environment(); String path = env.get("PATH"); path = path + File.pathSeparator + "/usr/bin:/usr/sbin"; logger.debug("PATH to execute command: " + pb.environment().get("PATH")); env.put("PATH", path); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = reader.readLine()) != null) { logger.debug(line); } p.waitFor(); int returnCode = p.exitValue(); logger.debug("Execute command done: " + cmd + ". Get return code: " + returnCode); return returnCode; } catch (InterruptedException | IOException e1) { logger.error("Error when execute command. Error: " + e1); } return -1; }
From source file:org.datavyu.util.NativeLoader.java
/** * Unpacks a native application to a temporary location so that it can be * utilized from within java code./*from w ww.j av a 2 s .c o m*/ * * @param appJar The jar containing the native app that you want to unpack. * @return The path of the native app as unpacked to a temporary location. * * @throws Exception If unable to unpack the native app to a temporary * location. */ public static String unpackNativeApp(final String appJar) throws Exception { final String nativeLibraryPath; if (nativeLibFolder == null) { nativeLibraryPath = System.getProperty("java.io.tmpdir") + UUID.randomUUID().toString() + "nativelibs"; nativeLibFolder = new File(nativeLibraryPath); if (!nativeLibFolder.exists()) { nativeLibFolder.mkdir(); } } // Search the class path for the application jar. JarFile jar = null; // BugID: 26178921 -- We need to inspect the surefire test class path as // well as the regular class path property so that we can scan dependencies // during tests. String searchPath = System.getProperty("surefire.test.class.path") + File.pathSeparator + System.getProperty("java.class.path"); for (String s : searchPath.split(File.pathSeparator)) { // Success! We found a matching jar. if (s.endsWith(appJar + ".jar") || s.endsWith(appJar)) { jar = new JarFile(s); } } // If we found a jar - it should contain the desired application. // decompress as needed. if (jar != null) { Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry inFile = entries.nextElement(); File outFile = new File(nativeLibFolder, inFile.getName()); // If the file from the jar is a directory, create it. if (inFile.isDirectory()) { outFile.mkdir(); // The file from the jar is regular - decompress it. } else { InputStream in = jar.getInputStream(inFile); // Create a temporary output location for the library. FileOutputStream out = new FileOutputStream(outFile); BufferedOutputStream dest = new BufferedOutputStream(out, BUFFER); int count; byte[] data = new byte[BUFFER]; while ((count = in.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); out.close(); in.close(); } loadedLibs.add(outFile); } // Unable to find jar file - abort decompression. } else { System.err.println("Unable to find jar file for unpacking: " + appJar + ". Java classpath is:"); for (String s : System.getProperty("java.class.path").split(File.pathSeparator)) { System.err.println(" " + s); } throw new Exception("Unable to find '" + appJar + "' for unpacking."); } return nativeLibFolder.getAbsolutePath(); }
From source file:org.jsweet.transpiler.candy.CandyProcessor.java
/** * Create a candies processor.// www . jav a 2 s. c o m * * @param workingDir * the directory where the processor will save all cache and * temporary data for processing * @param classPath * the classpath where the processor will seek for JSweet candies * @param extractedCandiesJavascriptDir * see JSweetTranspiler.extractedCandyJavascriptDir */ public CandyProcessor(File workingDir, String classPath, File extractedCandiesJavascriptDir) { this.workingDir = workingDir; this.classPath = (classPath == null ? System.getProperty("java.class.path") : classPath); String[] cp = this.classPath.split(File.pathSeparator); int[] indices = new int[0]; for (int i = 0; i < cp.length; i++) { if (cp[i].replace('\\', '/').matches(".*org/jsweet/lib/.*-testbundle/.*/.*-testbundle-.*\\.jar")) { logger.warn("candies processor ignores classpath entry: " + cp[i]); indices = ArrayUtils.add(indices, i); } } cp = ArrayUtils.removeAll(cp, indices); this.classPath = StringUtils.join(cp, File.pathSeparator); logger.info("candies processor classpath: " + this.classPath); candiesSourceDir = new File(workingDir, CANDIES_SOURCES_DIR_NAME); candiesStoreFile = new File(workingDir, CANDIES_STORE_FILE_NAME); candiesTsdefsDir = new File(workingDir, CANDIES_TSDEFS_DIR_NAME); setCandiesJavascriptOutDir(extractedCandiesJavascriptDir); }
From source file:net.grinder.util.AbstractGrinderClassPathProcessor.java
/** * Construct the classpath of ngrinder which is very important and located in the head of * classpath.//w w w.j a v a 2 s . c o m * * @param classPath classpath string * @param logger logger * @return classpath optimized for grinder. */ public String filterPatchClassPath(String classPath, Logger logger) { List<String> classPathList = new ArrayList<String>(); for (String eachClassPath : checkNotNull(classPath).split(File.pathSeparator)) { String filename = FilenameUtils.getName(eachClassPath); if (isPatchJar(filename)) { logger.trace("classpath :" + eachClassPath); classPathList.add(eachClassPath); } } return StringUtils.join(classPathList, File.pathSeparator); }
From source file:org.jsweet.transpiler.candies.CandiesProcessor.java
/** * Create a candies processor./*from w ww . ja va 2 s . com*/ * * @param workingDir * the directory where the processor will save all cache and * temporary data for processing * @param classPath * the classpath where the processor will seek for JSweet candies * @param extractedCandiesJavascriptDir * see JSweetTranspiler.extractedCandyJavascriptDir */ public CandiesProcessor(File workingDir, String classPath, File extractedCandiesJavascriptDir) { this.workingDir = workingDir; this.classPath = (classPath == null ? System.getProperty("java.class.path") : classPath); String[] cp = this.classPath.split(File.pathSeparator); int[] indices = new int[0]; for (int i = 0; i < cp.length; i++) { if (cp[i].replace('\\', '/').matches(".*org/jsweet/lib/.*-testbundle/.*/.*-testbundle-.*\\.jar")) { logger.warn("candies processor ignores classpath entry: " + cp[i]); indices = ArrayUtils.add(indices, i); } } cp = ArrayUtils.removeAll(cp, indices); this.classPath = StringUtils.join(cp, File.pathSeparator); logger.info("candies processor classpath: " + this.classPath); candiesSourceDir = new File(workingDir, CANDIES_SOURCES_DIR_NAME); candiesStoreFile = new File(workingDir, CANDIES_STORE_FILE_NAME); candiesTsdefsDir = new File(workingDir, CANDIES_TSDEFS_DIR_NAME); setCandiesJavascriptOutDir(extractedCandiesJavascriptDir); }
From source file:com.github.jknack.handlebars.maven.I18nJsPlugin.java
@Override protected void doExecute() throws Exception { notNull(bundle, "The bundle's name parameter is required."); notNull(output, "The output parameter is required."); Handlebars handlebars = new Handlebars(); Context context = Context.newContext(null); URL[] classpath = projectClasspath(); new File(output).mkdirs(); getLog().info("Converting bundles..."); getLog().debug("Options:"); getLog().debug(" output: " + output); getLog().debug(" merge: " + merge); getLog().debug(" amd: " + amd); getLog().debug(" classpath: " + join(classpath, File.pathSeparator)); StringBuilder buffer = new StringBuilder(); // 1. find all the bundles List<File> bundles = bundles(this.bundle, classpath); // 2. hash for i18njs helper Map<String, Object> hash = new HashMap<String, Object>(); hash.put("wrap", false); if (classpath.length > 0) { hash.put("classLoader", new URLClassLoader(classpath, getClass().getClassLoader())); }/* ww w . j av a2 s .c o m*/ // 3. get the base name from the bundle String basename = FileUtils.removePath(this.bundle.replace(".", FileUtils.FS)); Collections.sort(bundles); for (File bundle : bundles) { // bundle name String bundleName = FileUtils.removeExtension(bundle.getName()); getLog().debug("converting: " + bundle.getName()); // extract locale from bundle name String locale = bundleName.substring(basename.length()); if (locale.startsWith("_")) { locale = locale.substring(1); } // set bundle name hash.put("bundle", this.bundle); Options options = new Options.Builder(handlebars, I18nHelper.i18nJs.name(), TagType.VAR, context, Template.EMPTY).setHash(hash).build(); // convert to JS buffer.append(I18nHelper.i18nJs.apply(locale, options)); if (!merge) { FileUtils.fileWrite(new File(output, bundleName + ".js"), encoding, wrap(bundleName, buffer, amd)); buffer.setLength(0); getLog().debug(" => " + bundleName + ".js"); } else { buffer.append("\n"); } } if (merge && buffer.length() > 0) { FileUtils.fileWrite(new File(output, basename + ".js"), wrap(basename, buffer, amd)); getLog().debug(" =>" + basename + ".js"); } }
From source file:ClassSearchUtils.java
/** * Search for the resource with the extension in the classpath. * @param extension Mandatory extension of the resource. If all resources * are required extension should be empty string. Null extension is not * allowed and will cause method to fail. * @return List of all resources with specified extension. *//*from www.jav a2s .c o m*/ private List<Class<?>> find(String extension) { this.extension = extension; this.list = new ArrayList(); this.classloader = this.getClass().getClassLoader(); String classpath = System.getProperty("java.class.path"); try { Method method = this.classloader.getClass().getMethod("getClassPath", (Class<?>) null); if (method != null) { classpath = (String) method.invoke(this.classloader, (Object) null); } } catch (Exception e) { // ignore } if (classpath == null) { classpath = System.getProperty("java.class.path"); } StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator); String token; File dir; String name; while (tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); dir = new File(token); if (dir.isDirectory()) { lookInDirectory("", dir); } if (dir.isFile()) { name = dir.getName().toLowerCase(); if (name.endsWith(".zip") || name.endsWith(".jar")) { this.lookInArchive(dir); } } } return this.list; }