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.jruyi.launcher.Main.java
private static File[] getLibJars() throws Exception { // Home Dir/* ww w .j a v a 2s .com*/ File homeDir; String temp = System.getProperty(JRUYI_HOME_DIR); if (temp == null) { String classpath = System.getProperty("java.class.path"); int index = classpath.toLowerCase().indexOf("jruyi-launcher"); int start = classpath.lastIndexOf(File.pathSeparator, index) + 1; if (index >= start) { temp = classpath.substring(start, index); homeDir = new File(temp).getCanonicalFile().getParentFile(); } else // use current dir homeDir = new File(System.getProperty("user.dir")); } else homeDir = new File(temp); homeDir = homeDir.getCanonicalFile(); System.setProperty(JRUYI_HOME_DIR, homeDir.getCanonicalPath()); return new File(homeDir, "lib").listFiles(new JarFileFilter()); }
From source file:org.apache.uima.ruta.descriptor.RutaDescriptorBuilder.java
public TypeSystemDescription createTypeSystemDescription(RutaDescriptorInformation desc, String typeSystemOutput, RutaBuildOptions options, String[] enginePaths) throws InvalidXMLException, ResourceInitializationException, IOException, URISyntaxException { TypeSystemDescription typeSystemDescription = uimaFactory.createTypeSystemDescription(); ResourceManager rm = UIMAFramework.newDefaultResourceManager(); if (options.getClassLoader() != null) { rm = new ResourceManager_impl(options.getClassLoader()); }/* ww w. j a va 2 s . c o m*/ if (enginePaths != null) { String dataPath = ""; for (String string : enginePaths) { dataPath += string + File.pathSeparator; } rm.setDataPath(dataPath); } Map<String, String> typeNameMap = new HashMap<String, String>(); TypeSystemDescription initialTypeSystem = UIMAFramework.getXMLParser() .parseTypeSystemDescription(new XMLInputSource(defaultTypeSystem)); CAS cas = CasCreationUtils.createCas(initialTypeSystem, null, new FsIndexDescription[0]); fillTypeNameMap(typeNameMap, cas.getTypeSystem()); cas.release(); List<TypeSystemDescription> toInclude = new ArrayList<TypeSystemDescription>(); List<Import> importList = new ArrayList<Import>(); Import_impl import_impl = new Import_impl(); if (options.isImportByName()) { String name = initialTypeSystem.getName(); import_impl.setName(name); } else if (options.isResolveImports()) { String absoluteLocation = initialTypeSystem.getSourceUrlString(); import_impl.setLocation(absoluteLocation); } else { URI uri = null; try { uri = defaultTypeSystem.toURI(); } catch (URISyntaxException e) { // do nothing } if (uri != null) { String relativeLocation = getRelativeLocation(uri, typeSystemOutput); if (relativeLocation != null) { import_impl.setLocation(relativeLocation); } else { toInclude.add(initialTypeSystem); } } else { toInclude.add(initialTypeSystem); } } if (import_impl.getLocation() != null || import_impl.getName() != null) { importList.add(import_impl); } for (String eachName : desc.getImportedTypeSystems()) { String locate = RutaEngine.locate(eachName, enginePaths, ".xml"); URL url = null; boolean include = false; if (locate != null) { File file = new File(locate); url = file.toURI().toURL(); } if (url == null) { url = checkImportExistence(eachName, ".xml", options.getClassLoader()); include = true; if (url == null) { throw new FileNotFoundException( "Build process can't find " + eachName + " in " + desc.getScriptName()); } } TypeSystemDescription each = getTypeSystemDescriptor(url, options, rm); if (each != null) { fillTypeNameMap(typeNameMap, each); if (include) { // need to include the complete type system because an import is not possible each.resolveImports(rm); toInclude.add(each); } else { import_impl = new Import_impl(); if (options.isImportByName()) { import_impl.setName(eachName); } else if (options.isResolveImports()) { String absoluteLocation = each.getSourceUrlString(); import_impl.setLocation(absoluteLocation); } else { String relativeLocation = getRelativeLocation(url.toURI(), typeSystemOutput); File parentFile = new File(typeSystemOutput).getParentFile(); File targetFile = new File(parentFile, relativeLocation); boolean ableToFindFile = targetFile.exists(); if (!ableToFindFile) { // hotfix for different partitions making trouble for the relative path import_impl.setName(eachName); } else { import_impl.setLocation(relativeLocation); } } importList.add(import_impl); } } else { throw new FileNotFoundException( "Build process can't find " + eachName + " in " + desc.getScriptName()); } } for (String eachName : desc.getImportedScripts()) { String locate = RutaEngine.locate(eachName, enginePaths, options.getTypeSystemSuffix() + ".xml"); URL url = null; if (locate != null) { File file = new File(locate); url = file.toURI().toURL(); } if (url == null) { url = checkImportExistence(eachName, options.getTypeSystemSuffix() + ".xml", options.getClassLoader()); if (url == null) { throw new FileNotFoundException("Build process can't find " + eachName + options.getTypeSystemSuffix() + ".xml" + " in " + desc.getScriptName()); } } TypeSystemDescription each = getTypeSystemDescriptor(url, options, rm); if (each != null) { fillTypeNameMap(typeNameMap, each); import_impl = new Import_impl(); if (options.isImportByName()) { import_impl.setName(eachName + options.getTypeSystemSuffix()); } else if (options.isResolveImports()) { String absoluteLocation = each.getSourceUrlString(); import_impl.setLocation(absoluteLocation); } else { String relativeLocation = getRelativeLocation(url.toURI(), typeSystemOutput); import_impl.setLocation(relativeLocation); } importList.add(import_impl); } else { throw new FileNotFoundException( "Build process can't find " + eachName + " in " + desc.getScriptName()); } } typeSystemDescription = CasCreationUtils.mergeTypeSystems(toInclude, rm); if (!importList.isEmpty()) { Import[] newImports = importList.toArray(new Import[0]); typeSystemDescription.setImports(newImports); } if (options.isResolveImports()) { typeSystemDescription.resolveImports(rm); } // TODO hotfixes: where do I get the final types?? Set<String> finalTypes = new HashSet<String>(); finalTypes.addAll(Arrays.asList(new String[] { "uima.cas.Boolean", "uima.cas.Byte", "uima.cas.Short", "uima.cas.Integer", "uima.cas.Long", "uima.cas.Float", "uima.cas.Double", "uima.cas.BooleanArray", "uima.cas.ByteArray", "uima.cas.ShortArray", "uima.cas.IntegerArray", "uima.cas.LongArray", "uima.cas.FloatArray", "uima.cas.DoubleArray", "uima.cas.StringArray", "uima.cas.FSArray" })); int typeIndex = 0; for (String eachType : desc.getTypeShortNames()) { StringTriple typeTriple = desc.getTypeTriples().get(typeIndex); typeTriple = resolveType(typeTriple, typeNameMap, desc.getScriptName()); if (typeSystemDescription.getType(typeTriple.getName()) != null) { continue; } if (!finalTypes.contains(typeTriple.getParent())) { TypeDescription newType = typeSystemDescription.addType(typeTriple.getName(), typeTriple.getDescription(), typeTriple.getParent()); Collection<StringTriple> collection = desc.getFeatures().get(eachType); if (collection != null) { for (StringTriple eachFeature : collection) { eachFeature = resolveFeature(eachFeature, typeNameMap); newType.addFeature(eachFeature.getName(), eachFeature.getDescription(), eachFeature.getParent()); // capability.addInputFeature(eachFeature.getName()); // capability.addOutputFeature(eachFeature.getName()); } } } typeIndex++; } Set<String> names = new HashSet<String>(); Collection<TypeDescription> types = new HashSet<TypeDescription>(); for (TypeDescription each : typeSystemDescription.getTypes()) { String name = each.getName(); if (!names.contains(name)) { names.add(name); types.add(each); } } TypeDescription[] presentTypes = typeSystemDescription.getTypes(); types.addAll(Arrays.asList(presentTypes)); typeSystemDescription.setTypes(types.toArray(new TypeDescription[0])); typeSystemDescription .setName(desc.getPackageString() + "." + desc.getScriptName() + options.getTypeSystemSuffix()); if (typeSystemOutput != null) { File typeSystemFile = getFile(typeSystemOutput); typeSystemDescription.setSourceUrl(typeSystemFile.toURI().toURL()); } return typeSystemDescription; }
From source file:org.apache.hadoop.hive.conf.HiveConfUtil.java
public static void dumpConfig(Configuration originalConf, StringBuilder sb) { Set<String> hiddenSet = getHiddenSet(originalConf); sb.append("Values omitted for security reason if present: ").append(hiddenSet).append("\n"); Configuration conf = new Configuration(originalConf); stripConfigurations(conf, hiddenSet); Iterator<Map.Entry<String, String>> configIter = conf.iterator(); List<Map.Entry<String, String>> configVals = new ArrayList<>(); while (configIter.hasNext()) { configVals.add(configIter.next()); }/*ww w.j a v a 2 s . c o m*/ Collections.sort(configVals, new Comparator<Map.Entry<String, String>>() { @Override public int compare(Map.Entry<String, String> ent, Map.Entry<String, String> ent2) { return ent.getKey().compareTo(ent2.getKey()); } }); for (Map.Entry<String, String> entry : configVals) { //use get() to make sure variable substitution works if (entry.getKey().toLowerCase().contains("path")) { StringTokenizer st = new StringTokenizer(conf.get(entry.getKey()), File.pathSeparator); sb.append(entry.getKey()).append("=\n"); while (st.hasMoreTokens()) { sb.append(" ").append(st.nextToken()).append(File.pathSeparator).append('\n'); } } else { sb.append(entry.getKey()).append('=').append(conf.get(entry.getKey())).append('\n'); } } }
From source file:edu.unc.lib.dl.util.FileUtils.java
/** * Safely returns a File object for a "file:" URL. The base and root directories are both considered to be the dir. * URLs that point outside of that directory will throw an IOException. * * @param url/*from www.ja v a 2 s . co m*/ * the URL * @param dir * the directory within which to resolve the "file:" URL. * @return a File object * @throws IOException * when URL improperly formatted or points outside of the dir. */ public static File getFileForUrl(String url, File dir) throws IOException { File result = null; // remove any file: prefix and beginning slashes or backslashes Matcher m = filePathPattern.matcher(url); if (m.find()) { String path = m.group(3); // grab the path group path = path.replaceAll("\\\\", File.pathSeparator); result = new File(dir, path); if (result.getCanonicalPath().startsWith(dir.getCanonicalPath())) { return result; } else { throw new IOException("Bad locator for a file in SIP:" + url); } } else { throw new IOException("Bad locator for a file in SIP:" + url); } }
From source file:com.twosigma.beaker.javash.evaluator.JavaEvaluator.java
public void resetEnvironment() { executor.killAllThreads();//from www . ja v a2 s . c om String cpp = ""; for (String pt : classPath) { cpp += pt; cpp += File.pathSeparator; } cpp += File.pathSeparator; cpp += outDir; cpp += File.pathSeparator; cpp += System.getProperty("java.class.path"); cps = new ClasspathScanner(cpp); jac = createJavaAutocomplete(cps); for (String st : imports) jac.addImport(st); // signal thread to create loader updateLoader = true; syncObject.release(); }
From source file:averroes.options.AverroesOptions.java
/** * The list of the application JAR files separated by * {@link File#pathSeparator}./*from w w w .j a v a2 s. com*/ * * @return */ public static List<String> getApplicationJars() { return Arrays.asList(cmd.getOptionValue(applicationJars.getOpt()).split(File.pathSeparator)); }
From source file:hudson.remoting.Launcher.java
@Option(name = "-cp", aliases = "-classpath", metaVar = "PATH", usage = "add the given classpath elements to the system classloader.") public void addClasspath(String pathList) throws Exception { Method $addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); $addURL.setAccessible(true);//from w w w . ja v a2 s . co m for (String token : pathList.split(File.pathSeparator)) $addURL.invoke(ClassLoader.getSystemClassLoader(), new File(token).toURI().toURL()); // fix up the system.class.path to pretend that those jar files // are given through CLASSPATH or something. // some tools like JAX-WS RI and Hadoop relies on this. System.setProperty("java.class.path", System.getProperty("java.class.path") + File.pathSeparatorChar + pathList); }
From source file:com.twosigma.beakerx.kernel.magic.command.MavenJarResolver.java
public String findMvn() { if (mavenLocation == null) { if (System.getenv("M2_HOME") != null) { mavenLocation = System.getenv("M2_HOME") + "/bin/mvn"; return mavenLocation; }/* w ww . j av a 2s. c o m*/ for (String dirname : System.getenv("PATH").split(File.pathSeparator)) { File file = new File(dirname, "mvn"); if (file.isFile() && file.canExecute()) { mavenLocation = file.getAbsolutePath(); return mavenLocation; } } throw new RuntimeException( "No mvn found, please install mvn by 'conda install maven' or setup M2_HOME"); } return mavenLocation; }
From source file:com.bt.download.android.util.SystemUtils.java
/** * // w ww. j a v a 2 s. c om * Use this instead ContextCompat * * @param context * @return */ public static File[] getExternalFilesDirs(Context context) { if (hasKitKat()) { List<File> dirs = new LinkedList<File>(); for (File f : ContextCompat.getExternalFilesDirs(context, null)) { if (f != null) { dirs.add(f); } } return dirs.toArray(new File[0]); } else { List<File> dirs = new LinkedList<File>(); dirs.add(context.getExternalFilesDir(null)); try { String secondaryStorages = System.getenv("SECONDARY_STORAGE"); if (secondaryStorages != null) { String[] storages = secondaryStorages.split(File.pathSeparator); for (String s : storages) { dirs.add(new File(s)); } } } catch (Throwable e) { LOG.error("Unable to get secondary external storages", e); } return dirs.toArray(new File[0]); } }
From source file:com.blackducksoftware.integration.hub.detect.util.executable.ExecutableFinder.java
private File findExecutableFileFromPath(final String path, final String executableName) { final List<String> executables; final OperatingSystemType currentOs = detectInfo.getCurrentOs(); if (currentOs == OperatingSystemType.WINDOWS) { executables = Arrays.asList(executableName + ".cmd", executableName + ".bat", executableName + ".exe"); } else {// w w w. jav a 2 s . co m executables = Arrays.asList(executableName); } for (final String pathPiece : path.split(File.pathSeparator)) { for (final String possibleExecutable : executables) { final File foundFile = detectFileFinder.findFile(pathPiece, possibleExecutable); if (foundFile != null && foundFile.exists() && foundFile.canExecute()) { return foundFile; } } } logger.debug(String.format("Could not find the executable: %s while searching through: %s", executableName, path)); return null; }