Java Code Examples for java.io.File#pathSeparator()

The following examples show how to use java.io.File#pathSeparator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoEnvironmentTest.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
public void test_GoPath$() throws Exception {
	GoPath goPath = new GoPath(WS_FOO + File.pathSeparator + WS_BAR);
	
	assertAreEqual(goPath.findGoPathEntry(WS_FOO.resolve_valid("xxx")), new GoWorkspaceLocation(WS_FOO));
	assertAreEqual(goPath.findGoPathEntry(WS_BAR.resolve_valid("xxx")), new GoWorkspaceLocation(WS_BAR));
	assertAreEqual(goPath.findGoPathEntry(TESTS_WORKDIR.resolve_valid("xxx")), null);
	
	assertAreEqual(goPath.findGoPackageForLocation(WS_FOO.resolve_valid("xxx/")), null);
	assertAreEqual(goPath.findGoPackageForLocation(WS_FOO.resolve_valid("src/xxx/")), goPkg("xxx"));
	assertAreEqual(goPath.findGoPackageForLocation(WS_FOO.resolve_valid("src/xxx/zzz")), goPkg("xxx/zzz"));
	assertAreEqual(goPath.findGoPackageForLocation(WS_FOO.resolve_valid("src")), null);
	assertAreEqual(goPath.findGoPackageForLocation(WS_BAR.resolve_valid("src/xxx")), goPkg("xxx"));
	assertAreEqual(goPath.findGoPackageForLocation(WS_BAR.resolve_valid("src/src/src")), goPkg("src/src"));
	assertAreEqual(goPath.findGoPackageForLocation(TESTS_WORKDIR.resolve_valid("src/xxx")), null);
	
	// Test empty case
	goPath = new GoPath("");
	assertTrue(goPath.isEmpty());
	assertTrue(goPath.getGoPathEntries().size() == 0);
	assertEquals(goPath.getGoPathString(), "");
	
	verifyThrows(() -> new GoPath("").validate(), CommonException.class, "empty");
}
 
Example 2
Source File: ResourceTaskProviderParser.java    From workspacemechanic with Eclipse Public License 1.0 6 votes vote down vote up
public final String[] parse(String text) {
  if (!text.startsWith("[")) {
    // I would use Splitter, but I won't use split.
    StringTokenizer st = new StringTokenizer(text, File.pathSeparator);
    List<String> list = Lists.newArrayList();
    while (st.hasMoreElements()) {
      String elem = (String) st.nextElement();
      // Historically paths named "null" somehow got added to default prefs
      if (elem == null) {
        continue;
      }
      String substituted = variableParser.apply(elem);
      list.add(substituted);
    }
    return list.toArray(new String[0]);
  } else {
    return gson.fromJson(text, String[].class);
  }
}
 
Example 3
Source File: ClassPath.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public ClassPath(String classPath, boolean isCP) {
    this.isCP = isCP;
    List vec = new ArrayList();
    zipFileNameToFile = new JarLRUCache();

    for (StringTokenizer tok = new StringTokenizer(classPath, File.pathSeparator); tok.hasMoreTokens();) {
        String path = tok.nextToken();

        if (!path.equals("")) { // NOI18N
            File file = new File(path);

            if (file.exists()) {
                if (file.isDirectory()) {
                    vec.add(new Dir(file));
                } else {
                    vec.add(new Zip(file.getPath()));
                }
            }
        }
    }

    paths = (PathEntry[])vec.toArray(new PathEntry[0]);
}
 
Example 4
Source File: PathList.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Utility method for converting a search path string to an array
 * of directory and JAR file URLs.
 *
 * @param path the search path string
 * @return the resulting array of directory and JAR file URLs
 */
public static URL[] pathToURLs(String path) {
    StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
    URL[] urls = new URL[st.countTokens()];
    int count = 0;
    while (st.hasMoreTokens()) {
        URL url = fileToURL(new File(st.nextToken()));
        if (url != null) {
            urls[count++] = url;
        }
    }
    if (urls.length != count) {
        URL[] tmp = new URL[count];
        System.arraycopy(urls, 0, tmp, 0, count);
        urls = tmp;
    }
    return urls;
}
 
Example 5
Source File: Launcher.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static File[] getExtDirs() {
    String s = System.getProperty("java.ext.dirs");
    File[] dirs;
    if (s != null) {
        StringTokenizer st =
            new StringTokenizer(s, File.pathSeparator);
        int count = st.countTokens();
        dirs = new File[count];
        for (int i = 0; i < count; i++) {
            dirs[i] = new File(st.nextToken());
        }
    } else {
        dirs = new File[0];
    }
    return dirs;
}
 
Example 6
Source File: ClasspathUtil.java    From desktop with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Determine every URL location defined by the current classpath, and
 * it's associated package name.
 */
private static Map<URL, String> getClasspathLocations(ListType type) {
    Map<URL, String> map = new TreeMap<URL, String>(URL_COMPARATOR);

    String classpath = System.getProperty("java.class.path");
    //System.out.println ("classpath=" + classpath);
    
    StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator);
    while (st.hasMoreTokens()) {
        String path = st.nextToken();
        //System.out.println("PATH =" +path);
        include(null, new File(path), type, map);
    }

    return map;
}
 
Example 7
Source File: LauncherLifecycleCommands.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Deprecated
protected String getClasspath(final String userClasspath) {
  String classpath = getDefaultClasspath();

  if (!StringUtils.isBlank(userClasspath)) {
    classpath += (File.pathSeparator + userClasspath);
  }

  return classpath;
}
 
Example 8
Source File: SunFontManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void registerFontsOnPath(String pathName,
                                 boolean useJavaRasterizer, int fontRank,
                                 boolean defer, boolean resolveSymLinks) {

    StringTokenizer parser = new StringTokenizer(pathName,
            File.pathSeparator);
    try {
        while (parser.hasMoreTokens()) {
            registerFontsInDir(parser.nextToken(),
                    useJavaRasterizer, fontRank,
                    defer, resolveSymLinks);
        }
    } catch (NoSuchElementException e) {
    }
}
 
Example 9
Source File: ModularTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct class path string.
 */
public String buildClassPath(MODULE_TYPE cModuleType,
        Path cJarPath, MODULE_TYPE sModuletype,
        Path sJarPath) throws IOException {
    StringJoiner classPath = new StringJoiner(File.pathSeparator);
    classPath.add((cModuleType == MODULE_TYPE.UNNAMED)
            ? cJarPath.toFile().getCanonicalPath() : "");
    classPath.add((sModuletype == MODULE_TYPE.UNNAMED)
            ? sJarPath.toFile().getCanonicalPath() : "");
    return classPath.toString();
}
 
Example 10
Source File: Main.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the -src options.
 */
private static void checkSrcOption(String[] args)
    throws ProblemException {
    Set<File> dirs = new HashSet<File>();
    for (int i = 0; i<args.length; ++i) {
        if (args[i].equals("-src")) {
            if (i+1 >= args.length) {
                throw new ProblemException("You have to specify a directory following -src.");
            }
            StringTokenizer st = new StringTokenizer(args[i+1], File.pathSeparator);
            while (st.hasMoreElements()) {
                File dir = new File(st.nextToken());
                if (!dir.exists()) {
                    throw new ProblemException("This directory does not exist: "+dir.getPath());
                }
                if (!dir.isDirectory()) {
                    throw new ProblemException("\""+dir.getPath()+"\" is not a directory.");
                }
                if (dirs.contains(dir)) {
                    throw new ProblemException("The src directory \""+dir.getPath()+"\" is specified more than once!");
                }
                dirs.add(dir);
            }
        }
    }
    if (dirs.isEmpty()) {
        throw new ProblemException("You have to specify -src.");
    }
}
 
Example 11
Source File: Config.java    From jason with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getJarFromClassPath(String file, String fileInsideJar) {
    StringTokenizer st = new StringTokenizer(System.getProperty("java.class.path"), File.pathSeparator);
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        File f = new File(token);
        if (f.getName().startsWith(file) &&
                f.getName().endsWith(".jar") &&
                checkJarHasFile(f.getAbsolutePath(), fileInsideJar)) {
            return f.getAbsolutePath();
        }
    }
    return null;
}
 
Example 12
Source File: Storage.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
/**
 * Open database.
 *
 * @param db
 *            The name of the database
 * @param version
 *            The version
 * @param display_name
 *            The display name
 * @param size
 *            The size in bytes
 */
public void openDatabase(String db, String version, String display_name,
        long size) {

    // If database is open, then close it
    if (this.myDb != null) {
        this.myDb.close();
    }

    // If no database path, generate from application package
    if (this.path == null) {
        this.path = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    }

    this.dbName = this.path + File.separator + db + ".db";

    /*
     * What is all this nonsense? Well the separator was incorrect so the db was showing up in the wrong 
     * directory. This bit of code fixes that issue and moves the db to the correct directory.
     */
    File oldDbFile = new File(this.path + File.pathSeparator + db + ".db");
    if (oldDbFile.exists()) {
        File dbPath = new File(this.path);
        File dbFile = new File(dbName);
        dbPath.mkdirs();
        oldDbFile.renameTo(dbFile);
    }
    
    this.myDb = SQLiteDatabase.openOrCreateDatabase(this.dbName, null);
}
 
Example 13
Source File: WsCompileExample.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected String createClasspathString() {
    if (userClasspath == null) {
        userClasspath = "";
    }
                      String jcp = userClasspath + File.pathSeparator + System.getProperty("java.class.path");
              return jcp;
}
 
Example 14
Source File: AndroidProjectFolder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public String getSourcePath() {
    String sourcePath = super.getSourcePath();
    File generatedSource = new File(dirGenerated, "source");
    sourcePath += File.pathSeparator + generatedSource.getPath();
    return sourcePath;
}
 
Example 15
Source File: Win32FontManager.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void registerFontFile(String fontFileName, String[] nativeNames,
                                int fontRank, boolean defer) {

    // REMIND: case compare depends on platform
    if (registeredFontFiles.contains(fontFileName)) {
        return;
    }
    registeredFontFiles.add(fontFileName);

    int fontFormat;
    if (getTrueTypeFilter().accept(null, fontFileName)) {
        fontFormat = SunFontManager.FONTFORMAT_TRUETYPE;
    } else if (getType1Filter().accept(null, fontFileName)) {
        fontFormat = SunFontManager.FONTFORMAT_TYPE1;
    } else {
        /* on windows we don't use/register native fonts */
        return;
    }

    if (fontPath == null) {
        fontPath = getPlatformFontPath(noType1Font);
    }

    /* Look in the JRE font directory first.
     * This is playing it safe as we would want to find fonts in the
     * JRE font directory ahead of those in the system directory
     */
    String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
    StringTokenizer parser = new StringTokenizer(tmpFontPath,
                                                 File.pathSeparator);

    boolean found = false;
    try {
        while (!found && parser.hasMoreTokens()) {
            String newPath = parser.nextToken();
            boolean isJREFont = newPath.equals(jreFontDirName);
            File theFile = new File(newPath, fontFileName);
            if (theFile.canRead()) {
                found = true;
                String path = theFile.getAbsolutePath();
                if (defer) {
                    registerDeferredFont(fontFileName, path,
                                         nativeNames,
                                         fontFormat, isJREFont,
                                         fontRank);
                } else {
                    registerFontFile(path, nativeNames,
                                     fontFormat, isJREFont,
                                     fontRank);
                }
                break;
            }
        }
    } catch (NoSuchElementException e) {
        System.err.println(e);
    }
    if (!found) {
        addToMissingFontFileList(fontFileName);
    }
}
 
Example 16
Source File: Start.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Init the doclet invoker.
 * The doclet class may be given explicitly, or via the -doclet option in
 * argv.
 * If the doclet class is not given explicitly, it will be loaded from
 * the file manager's DOCLET_PATH location, if available, or via the
 * -doclet path option in argv.
 * @param docletClass The doclet class. May be null.
 * @param fileManager The file manager used to get the class loader to load
 * the doclet class if required. May be null.
 * @param argv Args containing -doclet and -docletpath, in case they are required.
 */
private void setDocletInvoker(Class<?> docletClass, JavaFileManager fileManager, String[] argv) {
    if (docletClass != null) {
        docletInvoker = new DocletInvoker(messager, docletClass, apiMode);
        // TODO, check no -doclet, -docletpath
        return;
    }

    String docletClassName = null;
    String docletPath = null;

    // Parse doclet specifying arguments
    for (int i = 0 ; i < argv.length ; i++) {
        String arg = argv[i];
        if (arg.equals(ToolOption.DOCLET.opt)) {
            oneArg(argv, i++);
            if (docletClassName != null) {
                usageError("main.more_than_one_doclet_specified_0_and_1",
                           docletClassName, argv[i]);
            }
            docletClassName = argv[i];
        } else if (arg.equals(ToolOption.DOCLETPATH.opt)) {
            oneArg(argv, i++);
            if (docletPath == null) {
                docletPath = argv[i];
            } else {
                docletPath += File.pathSeparator + argv[i];
            }
        }
    }

    if (docletClassName == null) {
        docletClassName = defaultDocletClassName;
    }

    // attempt to find doclet
    docletInvoker = new DocletInvoker(messager, fileManager,
            docletClassName, docletPath,
            docletParentClassLoader,
            apiMode);
}
 
Example 17
Source File: MutationSupporter.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void buildSpoonModel(ProjectRepairFacade projectFacade) throws Exception {
	String codeLocation = "";
	if (ConfigurationProperties.getPropertyBool("parsesourcefromoriginal")) {
		List<String> codeLocations = projectFacade.getProperties().getOriginalDirSrc();

		if (ConfigurationProperties.getPropertyBool("includeTestInSusp")
				&& projectFacade.getProperties().getTestDirSrc().size() > 0) {
			codeLocations.addAll(projectFacade.getProperties().getTestDirSrc());
		}

		for (String source : codeLocations) {
			codeLocation += source + File.pathSeparator;
		}
		if (codeLocation.length() > 0) {
			codeLocation = codeLocation.substring(0, codeLocation.length() - 1);
		}
	} else {
		codeLocation = projectFacade.getInDirWithPrefix(ProgramVariant.DEFAULT_ORIGINAL_VARIANT);
	}

	String bytecodeLocation = projectFacade.getOutDirWithPrefix(ProgramVariant.DEFAULT_ORIGINAL_VARIANT);
	String classpath = projectFacade.getProperties().getDependenciesString();
	String[] cpArray = (classpath != null && !classpath.trim().isEmpty()) ? classpath.split(File.pathSeparator)
			: null;

	logger.info("Creating model,  Code location from working folder: " + codeLocation);

	try {

		this.buildModel(codeLocation, bytecodeLocation, cpArray);
		logger.debug("Spoon Model built from location: " + codeLocation);
	} catch (Exception e) {
		logger.error("Problem compiling the model with compliance level "
				+ ConfigurationProperties.getPropertyInt("javacompliancelevel"));
		logger.error(e.getMessage());
		e.printStackTrace();
		try {
			this.cleanFactory();
			logger.info("Recompiling with compliance level "
					+ ConfigurationProperties.getPropertyInt("alternativecompliancelevel"));
			this.getFactory().getEnvironment()
					.setComplianceLevel(ConfigurationProperties.getPropertyInt("alternativecompliancelevel"));
			this.buildModel(codeLocation, bytecodeLocation, cpArray);

		} catch (Exception e2) {
			e2.printStackTrace();
			logger.error("Error compiling: " + e2.getMessage());
			if (!ConfigurationProperties.getPropertyBool("continuewhenmodelfail")) {
				logger.error("Astor does not continue when model build fails");
				throw e2;
			} else {

				logger.error("Astor continues when model build fails. Classes created: "
						+ this.getFactory().Type().getAll().size());

			}

		}

	}
}
 
Example 18
Source File: Win32FontManager.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
protected void registerFontFile(String fontFileName, String[] nativeNames,
                                int fontRank, boolean defer) {

    // REMIND: case compare depends on platform
    if (registeredFontFiles.contains(fontFileName)) {
        return;
    }
    registeredFontFiles.add(fontFileName);

    int fontFormat;
    if (getTrueTypeFilter().accept(null, fontFileName)) {
        fontFormat = SunFontManager.FONTFORMAT_TRUETYPE;
    } else if (getType1Filter().accept(null, fontFileName)) {
        fontFormat = SunFontManager.FONTFORMAT_TYPE1;
    } else {
        /* on windows we don't use/register native fonts */
        return;
    }

    if (fontPath == null) {
        fontPath = getPlatformFontPath(noType1Font);
    }

    /* Look in the JRE font directory first.
     * This is playing it safe as we would want to find fonts in the
     * JRE font directory ahead of those in the system directory
     */
    String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
    StringTokenizer parser = new StringTokenizer(tmpFontPath,
                                                 File.pathSeparator);

    boolean found = false;
    try {
        while (!found && parser.hasMoreTokens()) {
            String newPath = parser.nextToken();
            boolean isJREFont = newPath.equals(jreFontDirName);
            File theFile = new File(newPath, fontFileName);
            if (theFile.canRead()) {
                found = true;
                String path = theFile.getAbsolutePath();
                if (defer) {
                    registerDeferredFont(fontFileName, path,
                                         nativeNames,
                                         fontFormat, isJREFont,
                                         fontRank);
                } else {
                    registerFontFile(path, nativeNames,
                                     fontFormat, isJREFont,
                                     fontRank);
                }
                break;
            }
        }
    } catch (NoSuchElementException e) {
        System.err.println(e);
    }
    if (!found) {
        addToMissingFontFileList(fontFileName);
    }
}
 
Example 19
Source File: TestMiniMRChildTask.java    From big-c with Apache License 2.0 4 votes vote down vote up
public void configure(JobConf job) {
  boolean oldConfigs = job.getBoolean(OLD_CONFIGS, false);
  if (oldConfigs) {
    String javaOpts = job.get(JobConf.MAPRED_TASK_JAVA_OPTS);
    assertNotNull(JobConf.MAPRED_TASK_JAVA_OPTS + " is null!", 
                  javaOpts);
    assertEquals(JobConf.MAPRED_TASK_JAVA_OPTS + " has value of: " + 
                 javaOpts, 
                 javaOpts, TASK_OPTS_VAL);
  } else {
    String mapJavaOpts = job.get(JobConf.MAPRED_MAP_TASK_JAVA_OPTS);
    assertNotNull(JobConf.MAPRED_MAP_TASK_JAVA_OPTS + " is null!", 
                  mapJavaOpts);
    assertEquals(JobConf.MAPRED_MAP_TASK_JAVA_OPTS + " has value of: " + 
                 mapJavaOpts, 
                 mapJavaOpts, MAP_OPTS_VAL);
  }

  String path = job.get("path");
  
  // check if the pwd is there in LD_LIBRARY_PATH
  String pwd = System.getenv("PWD");
  
  assertTrue("LD doesnt contain pwd", 
             System.getenv("LD_LIBRARY_PATH").contains(pwd));
  
  // check if X=$X:/abc works for LD_LIBRARY_PATH
  checkEnv("LD_LIBRARY_PATH", "/tmp", "append");
  // check if X=y works for an already existing parameter
  checkEnv("LANG", "en_us_8859_1", "noappend");
  // check if X=/tmp for a new env variable
  checkEnv("MY_PATH", "/tmp", "noappend");
  // check if X=$X:/tmp works for a new env var and results into :/tmp
  checkEnv("NEW_PATH", File.pathSeparator + "/tmp", "noappend");
  // check if X=$(tt's X var):/tmp for an old env variable inherited from 
  // the tt
  if (Shell.WINDOWS) {
    // On Windows, PATH is replaced one more time as part of default config
    // of "mapreduce.admin.user.env", i.e. on Windows,
    // "mapreduce.admin.user.env" is set to
    // "PATH=%PATH%;%HADOOP_COMMON_HOME%\\bin"
    String hadoopHome = System.getenv("HADOOP_COMMON_HOME");
    if (hadoopHome == null) {
      hadoopHome = "";
    }
    String hadoopLibLocation = hadoopHome + "\\bin";
    path += File.pathSeparator + hadoopLibLocation;
    path += File.pathSeparator + path;
  }
  checkEnv("PATH",  path + File.pathSeparator + "/tmp", "noappend");

  String jobLocalDir = job.get(MRJobConfig.JOB_LOCAL_DIR);
  assertNotNull(MRJobConfig.JOB_LOCAL_DIR + " is null",
                jobLocalDir);
}
 
Example 20
Source File: Project.java    From meghanada-server with GNU General Public License v3.0 4 votes vote down vote up
public InputStream execMainClass(String mainClazz, boolean debug) throws IOException {
  log.debug("exec file:{}", mainClazz);

  final Config config = Config.load();
  final List<String> cmd = new ArrayList<>(16);
  final List<String> execArgs = config.getJavaExecArgs();
  final String binJava =
      SEP_COMPILE.matcher("/bin/java").replaceAll(Matcher.quoteReplacement(File.separator));

  final String javaCmd = new File(config.getJavaHomeDir(), binJava).getCanonicalPath();
  cmd.add(javaCmd);

  String cp = this.allClasspath();

  final String jarPath = Config.getInstalledPath().getCanonicalPath();

  cp += File.pathSeparator + jarPath;
  cmd.addAll(execArgs);
  cmd.add("-ea");
  cmd.add("-XX:+TieredCompilation");
  cmd.add("-XX:+UseConcMarkSweepGC");
  cmd.add("-XX:SoftRefLRUPolicyMSPerMB=50");
  cmd.add("-XX:ReservedCodeCacheSize=240m");
  cmd.add("-Dsun.io.useCanonCaches=false");
  cmd.add("-Xms128m");
  cmd.add("-Xmx750m");
  if (debug) {
    cmd.add("-Xdebug");
    cmd.add(
        "-Xrunjdwp:transport=dt_socket,address="
            + config.getDebuggerPort()
            + ",server=y,suspend=y");
  }
  cmd.add("-cp");
  cmd.add(cp);
  cmd.add(String.format("-Dproject.root=%s", this.projectRootPath));
  cmd.add(String.format("-Dmeghanada.output=%s", output.getCanonicalPath()));
  cmd.add(String.format("-Dmeghanada.test-output=%s", testOutput.getCanonicalPath()));
  cmd.add(mainClazz);

  log.debug("run cmd {}", Joiner.on(" ").join(cmd));
  return this.runProcess(cmd);
}