List of usage examples for java.io File pathSeparatorChar
char pathSeparatorChar
To view the source code for java.io File pathSeparatorChar.
Click Source Link
From source file:io.takari.maven.testing.executor.ForkedLauncher.java
private static String toPath(List<String> strings) { StringBuilder sb = new StringBuilder(); for (String string : strings) { if (sb.length() > 0) { sb.append(File.pathSeparatorChar); }//ww w . jav a 2 s .com sb.append(string); } return sb.toString(); }
From source file:gedi.util.FileUtils.java
public static String getExtension(String path) { int dotIndex = path.lastIndexOf('.'); int slashIndex = path.lastIndexOf(File.pathSeparatorChar); if (dotIndex > slashIndex) return path.substring(dotIndex + 1); else//from w w w . j a v a2 s . c o m return ""; }
From source file:org.orbeon.oxf.util.SystemUtils.java
/** * Walks class loader hierarchy of clazz looking for instances of URLClassLoader. * For each found gets file urls and adds, converted, elements to the path. * Note that the more junior a class loader is the later in the path it's * contribution is. <br/>//from ww w .j ava 2s . com * Also, tries to deal with fact that urls may or may not be encoded. * Converts the urls to java.io.File and checks for existence. If it * exists file name is used as is. If not name is URLDecoded. If the * decoded form exists that that is used. If neither exists then the * undecoded for is used. * * @param clazz Class to try and build a classpath from. * @return java.io.File.pathSeparator delimited path. */ public static String pathFromLoaders(final Class clazz) throws java.io.UnsupportedEncodingException { final TreeSet sysPths = new TreeSet(); gatherSystemPaths(sysPths); final StringBuilder sbuf = new StringBuilder(); final LinkedList urlLst = new LinkedList(); for (ClassLoader cl = clazz.getClassLoader(); cl != null; cl = cl.getParent()) { if (!(cl instanceof java.net.URLClassLoader)) { continue; } final java.net.URLClassLoader ucl = (java.net.URLClassLoader) cl; final java.net.URL[] urls = ucl.getURLs(); if (urls == null) continue; for (int i = urls.length - 1; i > -1; i--) { final java.net.URL url = urls[i]; final String prot = url.getProtocol(); if (!"file".equalsIgnoreCase(prot)) continue; urlLst.addFirst(url); } } for (final Iterator itr = urlLst.iterator(); itr.hasNext();) { final java.net.URL url = (java.net.URL) itr.next(); final String fnam = url.getFile(); final File fil = new File(fnam); if (sysPths.contains(fil)) continue; // 11/14/2004 d : Odd test attempts to deal with fact that // a.) The URLs passed to a URLClassLoader don't have to be encoded // in general. // b.) The app class loader and the extensions class loader, the // jdk class loaders responsible for loading classes from classpath // and the extensions dir respectively, do encode their urls. // c.) java.io.File.toURL doesn't produce encoded urls. ( Perhaps // a sun bug... ) // As you can see given (a) and (c) odds are pretty good that // should anyone use something other than jdk class loaders we // will end up unencoded urls. if (!fil.exists()) { final String unEncNam = URLDecoder.decode(fnam, "utf-8"); final File unEncFil = new File(unEncNam); if (unEncFil.exists()) sbuf.append(unEncNam); } else { sbuf.append(fnam); } sbuf.append(File.pathSeparatorChar); } final String ret = sbuf.toString(); return ret; }
From source file:org.apache.ranger.plugin.contextenricher.RangerTagEnricher.java
@Override public void init() { if (LOG.isDebugEnabled()) { LOG.debug("==> RangerTagEnricher.init()"); }/*from ww w . ja va 2 s. co m*/ super.init(); String tagRetrieverClassName = getOption(TAG_RETRIEVER_CLASSNAME_OPTION); long pollingIntervalMs = getLongOption(TAG_REFRESHER_POLLINGINTERVAL_OPTION, 60 * 1000); disableTrieLookupPrefilter = getBooleanOption(TAG_DISABLE_TRIE_PREFILTER_OPTION, false); if (StringUtils.isNotBlank(tagRetrieverClassName)) { try { @SuppressWarnings("unchecked") Class<RangerTagRetriever> tagRetriverClass = (Class<RangerTagRetriever>) Class .forName(tagRetrieverClassName); tagRetriever = tagRetriverClass.newInstance(); } catch (ClassNotFoundException exception) { LOG.error("Class " + tagRetrieverClassName + " not found, exception=" + exception); } catch (ClassCastException exception) { LOG.error("Class " + tagRetrieverClassName + " is not a type of RangerTagRetriever, exception=" + exception); } catch (IllegalAccessException exception) { LOG.error("Class " + tagRetrieverClassName + " illegally accessed, exception=" + exception); } catch (InstantiationException exception) { LOG.error("Class " + tagRetrieverClassName + " could not be instantiated, exception=" + exception); } if (tagRetriever != null) { String propertyPrefix = "ranger.plugin." + serviceDef.getName(); String cacheDir = RangerConfiguration.getInstance().get(propertyPrefix + ".policy.cache.dir"); String cacheFilename = String.format("%s_%s_tag.json", appId, serviceName); cacheFilename = cacheFilename.replace(File.separatorChar, '_'); cacheFilename = cacheFilename.replace(File.pathSeparatorChar, '_'); String cacheFile = cacheDir == null ? null : (cacheDir + File.separator + cacheFilename); tagRetriever.setServiceName(serviceName); tagRetriever.setServiceDef(serviceDef); tagRetriever.setAppId(appId); tagRetriever.init(enricherDef.getEnricherOptions()); tagRefresher = new RangerTagRefresher(tagRetriever, this, -1L, cacheFile, pollingIntervalMs); try { tagRefresher.populateTags(); } catch (Throwable exception) { LOG.error("Exception when retrieving tag for the first time for this enricher", exception); } tagRefresher.setDaemon(true); tagRefresher.startRefresher(); } } else { LOG.error("No value specified for " + TAG_RETRIEVER_CLASSNAME_OPTION + " in the RangerTagEnricher options"); } if (LOG.isDebugEnabled()) { LOG.debug("<== RangerTagEnricher.init()"); } }
From source file:org.sonar.plugins.ideainspections.IdeaExecutor.java
private String buildClassPath() { StringBuilder result = new StringBuilder(); result.append(new File(jdkHome, "lib/tools.jar").getPath()); //In OSX this is a no-op for (String jar : jars) { result.append(File.pathSeparatorChar); result.append(new File(libDir, jar).getPath()); }/*w ww . ja va 2 s .c o m*/ return result.toString(); }
From source file:hudson.EnvVars.java
/** * Overrides the current entry by the given entry. * * <p>/*from w w w. ja v a2 s . c o m*/ * Handles <tt>PATH+XYZ</tt> notation. */ public void override(String key, String value) { if (value == null || value.length() == 0) { remove(key); return; } int idx = key.indexOf('+'); if (idx > 0) { String realKey = key.substring(0, idx); String v = get(realKey); if (v == null) v = value; else { // we might be handling environment variables for a slave that can have different path separator // than the master, so the following is an attempt to get it right. // it's still more error prone that I'd like. char ch = platform == null ? File.pathSeparatorChar : platform.pathSeparator; v = value + ch + v; } put(realKey, v); return; } put(key, value); }
From source file:com.twosigma.beaker.javash.utils.JavaEvaluator.java
public void setShellOptions(String cp, String in, String od) throws IOException { if (od == null || od.isEmpty()) { od = FileSystems.getDefault().getPath(System.getenv("beaker_tmp_dir"), "dynclasses", sessionId) .toString();/*from ww w. jav a2s .c om*/ } else { od = od.replace("$BEAKERDIR", System.getenv("beaker_tmp_dir")); } // check if we are not changing anything if (currentClassPath.equals(cp) && currentImports.equals(in) && outDir.equals(od)) return; currentClassPath = cp; currentImports = in; outDir = od; if (cp.isEmpty()) classPath = new ArrayList<String>(); else classPath = Arrays.asList(cp.split("[\\s" + File.pathSeparatorChar + "]+")); if (in.isEmpty()) imports = new ArrayList<String>(); else imports = Arrays.asList(in.split("\\s+")); try { (new File(outDir)).mkdirs(); } catch (Exception e) { } resetEnvironment(); }
From source file:processing.app.windows.Platform.java
/** * Remove extra quotes, slashes, and garbage from the Windows PATH. */// ww w . j ava2s . c o m protected void checkPath() { String path = System.getProperty("java.library.path"); String[] pieces = PApplet.split(path, File.pathSeparatorChar); String[] legit = new String[pieces.length]; int legitCount = 0; for (String item : pieces) { if (item.startsWith("\"")) { item = item.substring(1); } if (item.endsWith("\"")) { item = item.substring(0, item.length() - 1); } if (item.endsWith(File.separator)) { item = item.substring(0, item.length() - File.separator.length()); } File directory = new File(item); if (!directory.exists()) { continue; } if (item.trim().length() == 0) { continue; } legit[legitCount++] = item; } legit = PApplet.subset(legit, 0, legitCount); String newPath = PApplet.join(legit, File.pathSeparator); if (!newPath.equals(path)) { System.setProperty("java.library.path", newPath); } }
From source file:com.expedia.tesla.compiler.Util.java
/** * Parse a Java {@code classpath} string to URLs. The {@code classpath} is represented with the same format of the * {@code CLASSPATH} variable or {@code -cp} java option. It supports the {@code *} wildcard. * /*w ww .j av a 2 s . co m*/ * @param classpath * the classpath string. * @return * URLs. * * @throws IOException * on IO errors. */ public static URL[] parseClassPath(String classpath) throws IOException { final String splitPattern = Character.toString(File.pathSeparatorChar); final String wildcardPattern = ".+\\*"; String[] paths = classpath.split(splitPattern); List<URL> urls = new ArrayList<URL>(); for (String path : paths) { path = path.trim(); if (path.matches(wildcardPattern)) { File folder = new File(path.replace("\\*", "")); if (folder.exists()) { File[] files = folder.listFiles(); for (File f : files) { urls.add(f.toURI().toURL()); } } } else { urls.add(new File(path).toURI().toURL()); } } URL[] result = new URL[urls.size()]; return urls.toArray(result); }
From source file:com.twosigma.beaker.javash.evaluator.JavaEvaluator.java
@Override public void setShellOptions(final KernelParameters kernelParameters) throws IOException { Map<String, Object> params = kernelParameters.getParams(); Collection<String> listOfImports = (Collection<String>) params.get(IMPORTS); Collection<String> listOfClassPath = (Collection<String>) params.get(CLASSPATH); String cp = getAsString(listOfClassPath); String in = getAsString(listOfImports); // check if we are not changing anything if (currentClassPath.equals(cp) && currentImports.equals(in)) return;/*from ww w . jav a2s.c om*/ currentClassPath = cp; currentImports = in; if (cp.isEmpty()) classPath = new ArrayList<>(); else classPath = Arrays.asList(cp.split("[\\s" + File.pathSeparatorChar + "]+")); if (in.isEmpty()) imports = new ArrayList<>(); else imports = Arrays.asList(in.split("\\s+")); resetEnvironment(); }