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:net.sourceforge.pmd.cache.AbstractAnalysisCache.java
private URL[] getClassPathEntries() { final String classpath = System.getProperty("java.class.path"); final String[] classpathEntries = classpath.split(File.pathSeparator); final List<URL> entries = new ArrayList<>(); final SimpleFileVisitor<Path> fileVisitor = new SimpleFileVisitor<Path>() { @Override//from w w w .j av a 2 s . co m public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (!attrs.isSymbolicLink()) { // Broken link that can't be followed entries.add(file.toUri().toURL()); } return FileVisitResult.CONTINUE; } }; final SimpleFileVisitor<Path> jarFileVisitor = new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { String extension = FilenameUtils.getExtension(file.toString()); if ("jar".equalsIgnoreCase(extension)) { fileVisitor.visitFile(file, attrs); } return FileVisitResult.CONTINUE; } }; try { for (final String entry : classpathEntries) { final File f = new File(entry); if (isClassPathWildcard(entry)) { Files.walkFileTree(new File(entry.substring(0, entry.length() - 1)).toPath(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), 1, jarFileVisitor); } else if (f.isFile()) { entries.add(f.toURI().toURL()); } else { Files.walkFileTree(f.toPath(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, fileVisitor); } } } catch (final IOException e) { LOG.log(Level.SEVERE, "Incremental analysis can't check execution classpath contents", e); throw new RuntimeException(e); } return entries.toArray(new URL[0]); }
From source file:Which4J.java
/** * Iterate over the system classpath defined by "java.class.path" searching * for all occurrances of the given class name. * //from ww w . j a v a2 s . c o m * @param classname the fully qualified class name to search for */ private static void findIt(String classname) { try { // get the system classpath String classpath = System.getProperty("java.class.path", ""); if (classpath.equals("")) { System.err.println("error: classpath is not set"); } if (debug) { System.out.println("classname: " + classname); System.out.println("system classpath = " + classpath); } if (isPrimitiveOrVoid(classname)) { System.out.println("'" + classname + "' primitive"); return; } StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); while (st.hasMoreTokens()) { String token = st.nextToken(); File classpathElement = new File(token); if (debug) System.out.println(classpathElement.isDirectory() ? "dir: " + token : "jar: " + token); URL[] url = { classpathElement.toURL() }; URLClassLoader cl = URLClassLoader.newInstance(url, null); String classnameAsResource = classname.replace('.', '/') + ".class"; URL it = cl.findResource(classnameAsResource); if (it != null) { System.out.println("found in: " + token); System.out.println(" url: " + it.toString()); System.out.println(""); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:de.monticore.codegen.GeneratorTest.java
/** * Instantiates all the parameters required for a CompilationTask and returns * the finished task./*from ww w . j ava2 s .c o m*/ * * @param sourceCodePath the source directory to be compiled * @param diagnostics a bin for any error messages that may be generated by * the compiler * @return the compilationtask that will compile any entries in the given * directory */ protected Optional<CompilationTask> setupCompilation(Path sourceCodePath, DiagnosticCollector<JavaFileObject> diagnostics) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (compiler != null) { StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); // set compiler's classpath to be same as the runtime's String sPath = Paths.get("target/generated-sources/monticore/codetocompile").toAbsolutePath() .toString(); List<String> optionList = Lists.newArrayList("-classpath", System.getProperty("java.class.path") + File.pathSeparator + sPath, "-sourcepath", sPath); // System.out.println("Options" + optionList); Iterable<? extends JavaFileObject> javaFileObjects = getJavaFileObjects(sourceCodePath, fileManager); // System.out.println("Java files" + javaFileObjects); return Optional.of(compiler.getTask(null, fileManager, diagnostics, optionList, null, javaFileObjects)); } return Optional.empty(); }
From source file:org.codehaus.mojo.AbstractLaunchMojo.java
/** * The current build session instance./* w ww. j a v a2 s .c o m*/ * * @parameter expression="${session}" * @required * @readonly */ //private MavenSession session; CommandLine getExecutablePath(Map enviro, File dir) { File execFile = new File(getExecutable()); String exec = null; if (execFile.exists()) { getLog().debug("Toolchains are ignored, 'executable' parameter is set to " + getExecutable()); exec = execFile.getAbsolutePath(); } else { if (OS.isFamilyWindows()) { String ex = getExecutable().indexOf(".") < 0 ? getExecutable() + ".bat" : getExecutable(); File f = new File(dir, ex); if (f.exists()) { exec = ex; } else { // now try to figure the path from PATH, PATHEXT env vars // if bat file, wrap in cmd /c String path = (String) enviro.get("PATH"); if (path != null) { String[] elems = StringUtils.split(path, File.pathSeparator); for (int i = 0; i < elems.length; i++) { f = new File(new File(elems[i]), ex); if (f.exists()) { exec = ex; break; } } } } } } if (exec == null) { exec = getExecutable(); } CommandLine toRet; if (OS.isFamilyWindows() && exec.toLowerCase(Locale.getDefault()).endsWith(".bat")) { toRet = new CommandLine("cmd"); toRet.addArgument("/c"); toRet.addArgument(exec); } else { toRet = new CommandLine(exec); } return toRet; }
From source file:com.yunrang.hadoop.app.utils.CustomizedUtil.java
/** * Returns a classpath string built from the content of the "tmpjars" value * in {@code conf}. Also exposed to shell scripts via `bin/hbase mapredcp`. *///from w ww . j a v a 2s . c om public static String buildDependencyClasspath(Configuration conf) { if (conf == null) { throw new IllegalArgumentException("Must provide a configuration object."); } Set<String> paths = new HashSet<String>(conf.getStringCollection("tmpjars")); if (paths.size() == 0) { throw new IllegalArgumentException("Configuration contains no tmpjars."); } StringBuilder sb = new StringBuilder(); for (String s : paths) { // entries can take the form 'file:/path/to/file.jar'. int idx = s.indexOf(":"); if (idx != -1) s = s.substring(idx + 1); if (sb.length() > 0) sb.append(File.pathSeparator); sb.append(s); } return sb.toString(); }
From source file:net.grinder.util.GrinderClassPathUtils.java
/** * Construct classPath from current classLoader. * // w w w . ja v a 2s .c o m * @param logger * logger * @return classpath optimized for grinder. */ public static String buildClasspathBasedOnCurrentClassLoader(Logger logger) { URL[] urLs = ((URLClassLoader) GrinderClassPathUtils.class.getClassLoader()).getURLs(); StringBuilder builder = new StringBuilder(); for (URL each : urLs) { builder.append(each.getFile()).append(File.pathSeparator); } return GrinderClassPathUtils.filterClassPath(builder.toString(), logger); }
From source file:org.apache.hive.hcatalog.templeton.tool.LaunchMapper.java
/** * Ensures that {@code paths} are prepended to {@code pathVarName} and made available to forked child * process./* ww w.ja va2s . c o m*/ * @param paths properly separated list of paths */ private static void prependPathToVariable(String pathVarName, Map<String, String> env, String paths) { if (!TempletonUtils.isset(pathVarName) || !TempletonUtils.isset(paths) || env == null) { return; } if (TempletonUtils.isset(env.get(pathVarName))) { env.put(pathVarName, paths + File.pathSeparator + env.get(pathVarName)); } else if (TempletonUtils.isset(System.getenv(pathVarName))) { env.put(pathVarName, paths + File.pathSeparator + System.getenv(pathVarName)); } else { env.put(pathVarName, paths); } }
From source file:info.magnolia.freemarker.FreemarkerServletContextWrapper.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Set getResourcePaths(String path) { if (StringUtils.equals(path, "/WEB-INF/lib")) { log.debug("returning resources from classpath"); // Just when asking libraries, pass the classpath ones. final Set<String> resources = new HashSet<String>(); final ClassLoader cl = Thread.currentThread().getContextClassLoader(); // if the classloader is an URLClassloader we have a better method for discovering resources // whis will also fetch files from jars outside WEB-INF/lib, useful during development if (cl instanceof URLClassLoader) { final URLClassLoader urlClassLoader = (URLClassLoader) cl; final URL[] urls = urlClassLoader.getURLs(); for (int j = 0; j < urls.length; j++) { final File tofile = sanitizeToFile(urls[j]); if (tofile.isDirectory()) { for (File file : ((List<File>) FileUtils.listFiles(tofile, null, true))) { resources.add(file.getAbsolutePath()); }/* w w w . j a va 2 s . c o m*/ } else { resources.add(tofile.getAbsolutePath()); } } return resources; } try { // be friendly to WAS developers too... // in development mode under RAD 7.5 here we have an instance of com.ibm.ws.classloader.WsClassLoader // and jars are NOT deployed to WEB-INF/lib by default, so they can't be found without this explicit // check // // but since we don't want to depend on WAS stuff we just check if the cl exposes a "classPath" property PropertyDescriptor pd = new PropertyDescriptor("classPath", cl.getClass()); if (pd != null && pd.getReadMethod() != null) { String classpath = (String) pd.getReadMethod().invoke(cl, new Object[] {}); if (StringUtils.isNotBlank(classpath)) { String[] paths = StringUtils.split(classpath, File.pathSeparator); for (int j = 0; j < paths.length; j++) { final File tofile = new File(paths[j]); // there can be several missing (optional?) paths here... if (tofile.exists()) { if (tofile.isDirectory()) { for (File file : ((List<File>) FileUtils.listFiles(tofile, null, true))) { resources.add(file.getAbsolutePath()); } } else { resources.add(tofile.getAbsolutePath()); } } } return resources; } } } catch (Throwable e) { // no, it's not a classloader we can handle in a special way } // no way, we have to assume a standard war structure and look in the WEB-INF/lib and WEB-INF/classes dirs // read the jars in the lib dir } return parentContext.getResourcePaths(path); }
From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.launcher.ContainerLaunch.java
@VisibleForTesting public static String expandEnvironment(String var, Path containerLogDir) { var = var.replace(ApplicationConstants.LOG_DIR_EXPANSION_VAR, containerLogDir.toString()); var = var.replace(ApplicationConstants.CLASS_PATH_SEPARATOR, File.pathSeparator); // replace parameter expansion marker. e.g. {{VAR}} on Windows is replaced // as %VAR% and on Linux replaced as "$VAR" if (Shell.WINDOWS) { var = var.replaceAll("(\\{\\{)|(\\}\\})", "%"); } else {//from www .j a v a2 s. co m var = var.replace(ApplicationConstants.PARAMETER_EXPANSION_LEFT, "$"); var = var.replace(ApplicationConstants.PARAMETER_EXPANSION_RIGHT, ""); } return var; }
From source file:org.esa.s2tbx.dataio.gdal.GDALInstaller.java
private void processInstalledDistribution(Path gdalFolderPath, Path gdalBinFolderPath, OSCategory osCategory, String mapLibraryName) throws IOException { Path pathItem = gdalBinFolderPath.resolve(mapLibraryName); if (Files.exists(pathItem)) { // the library file exists on the local disk String libraryFileName = System.mapLibraryName("environment-variables"); Path libraryFilePath = gdalFolderPath.resolve(libraryFileName); if (!Files.exists(libraryFilePath)) { String libraryFilePathFromSources = SRC_PATH + "/" + libraryFileName; URL libraryFileURLFromSources = getClass().getClassLoader().getResource(libraryFilePathFromSources); FileHelper.copyFile(libraryFileURLFromSources, libraryFilePath); }/*from www . j av a2 s. c o m*/ NativeLibraryUtils.registerNativePaths(libraryFilePath.getParent()); if (registerNativePaths(gdalBinFolderPath, osCategory)) { Path gdalAppsFolderPath = gdalBinFolderPath.resolve(APPS_PATH); String pathEnvironment = EnvironmentVariables.getEnvironmentVariable("PATH"); boolean foundBinFolderInPath = findFolderInPathEnvironment(gdalBinFolderPath, pathEnvironment); if (!foundBinFolderInPath) { StringBuilder newPathValue = new StringBuilder(); newPathValue.append("PATH").append("=").append(gdalBinFolderPath.toString()) .append(File.pathSeparator).append(gdalAppsFolderPath.toString()) .append(File.pathSeparator).append(pathEnvironment); EnvironmentVariables.setEnvironmentVariable(newPathValue.toString()); } Path gdalDataFolderPath = gdalBinFolderPath.resolve(DATA_PATH); StringBuilder gdalDataValue = new StringBuilder(); gdalDataValue.append("GDAL_DATA").append("=").append(gdalDataFolderPath.toString()); EnvironmentVariables.setEnvironmentVariable(gdalDataValue.toString()); Path gdalDriverFolderPath = gdalBinFolderPath.resolve(PLUGINS_PATH); StringBuilder gdalDriverValue = new StringBuilder(); gdalDriverValue.append("GDAL_DRIVER_PATH").append("=").append(gdalDriverFolderPath.toString()); EnvironmentVariables.setEnvironmentVariable(gdalDriverValue.toString()); GdalInstallInfo gdalInstallInfo = GdalInstallInfo.INSTANCE; gdalInstallInfo.setLocations(gdalBinFolderPath, gdalAppsFolderPath, gdalDriverFolderPath, gdalDataFolderPath); } } else { logger.log(Level.SEVERE, "The GDAL bin folder '" + gdalBinFolderPath.toString() + "' does not contain the library '" + mapLibraryName + "'."); } }