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

The following are Jave code examples for showing how to use pathSeparator() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: OptionDecoding.java   View Source Code Vote up 6 votes
static void testSearchPaths() {
    List<String> i, x, iF, xF;
    i = x = iF = xF = new ArrayList<>();

    SourceLocation dir1 = new SourceLocation(Paths.get("dir1"), i, x);
    SourceLocation dir2 = new SourceLocation(Paths.get("dir2"), i, x);
    String dir1_PS_dir2 = "dir1" + File.pathSeparator + "dir2";

    Options options = Options.parseArgs("--source-path", dir1_PS_dir2);
    assertEquals(options.getSourceSearchPaths(), Arrays.asList(dir1, dir2));

    options = Options.parseArgs("--module-path", dir1_PS_dir2);
    assertEquals(options.getModuleSearchPaths(), Arrays.asList(dir1, dir2));

    options = Options.parseArgs("--class-path", dir1_PS_dir2);
    assertEquals(options.getClassSearchPath(), Arrays.asList(dir1, dir2));
}
 
Example 2
Project: openjdk-jdk10   File: UpgradeModulePathTest.java   View Source Code Vote up 6 votes
/**
 * Run the test with a non-existent file on the upgrade module path.
 * It should be silently ignored.
 */
public void testRunWithNonExistentEntry() throws Exception {

    String upgrademodulepath
        = "DoesNotExit" + File.pathSeparator + UPGRADEDMODS_DIR.toString();
    String mid = "test/jdk.test.Main";

    int exitValue
        = executeTestJava(
            "--upgrade-module-path", upgrademodulepath,
            "--module-path", MODS_DIR.toString(),
            "-m", mid)
        .outputTo(System.out)
        .errorTo(System.out)
        .getExitValue();

    assertTrue(exitValue == 0);

}
 
Example 3
Project: jdk8u-jdk   File: ExtensionDependency.java   View Source Code Vote up 6 votes
/**
 * <p>
 * @return the java.ext.dirs property as a list of directory
 * </p>
 */
private static File[] getExtDirs() {
    String s = java.security.AccessController.doPrivileged(
            new sun.security.action.GetPropertyAction("java.ext.dirs"));

    File[] dirs;
    if (s != null) {
        StringTokenizer st =
            new StringTokenizer(s, File.pathSeparator);
        int count = st.countTokens();
        debug("getExtDirs count " + count);
        dirs = new File[count];
        for (int i = 0; i < count; i++) {
            dirs[i] = new File(st.nextToken());
            debug("getExtDirs dirs["+i+"] "+ dirs[i]);
        }
    } else {
        dirs = new File[0];
        debug("getExtDirs dirs " + dirs);
    }
    debug("getExtDirs dirs.length " + dirs.length);
    return dirs;
}
 
Example 4
Project: incubator-netbeans   File: JavaAntLogger.java   View Source Code Vote up 6 votes
private static void addPath(
    @NullAllowed final String path,
    @NonNull Collection<? super FileObject> collector,
    final boolean modulepath) {
    if (path != null) {
        final StringTokenizer tok = new StringTokenizer(path, File.pathSeparator);
        while (tok.hasMoreTokens()) {
            final String binrootS = tok.nextToken();
            final File f = FileUtil.normalizeFile(new File(binrootS));
            final Collection<? extends File> toAdd = modulepath ?
                    collectModules(f) :
                    Collections.singleton(f);
            toAdd.forEach((e) -> {
                final URL binroot = FileUtil.urlForArchiveOrDir(f);
                if (binroot != null) {
                    final FileObject[] someRoots = SourceForBinaryQuery.findSourceRoots(binroot).getRoots();
                    Collections.addAll(collector, someRoots);
                }
            });
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: ExternalProcessBuilder.java   View Source Code Vote up 6 votes
Map<String, String> buildEnvironment(Map<String, String> original) {
    Map<String, String> ret = new HashMap<String, String>(original);
    ret.putAll(envVariables);

    // Find PATH environment variable - on Windows it can be some other
    // case and we should use whatever it has.
    String pathName = getPathName(original);

    // TODO use StringBuilder
    String currentPath = ret.get(pathName);

    if (currentPath == null) {
        currentPath = "";
    }

    for (File path : paths) {
        currentPath = path.getAbsolutePath().replace(" ", "\\ ") //NOI18N
                + File.pathSeparator + currentPath;
    }

    if (!"".equals(currentPath.trim())) {
        ret.put(pathName, currentPath);
    }
    return ret;
}
 
Example 6
Project: incubator-netbeans   File: ExternalProcessBuilder.java   View Source Code Vote up 6 votes
public static void putPath(File path, String pathName, boolean prepend, Map<String, String> current) {
    String currentPath = current.get(pathName);

    if (currentPath == null) {
        currentPath = "";
    }

    if (prepend) {
        currentPath = path.getAbsolutePath().replace(" ", "\\ ") //NOI18N
                + File.pathSeparator + currentPath;
    } else {
        currentPath = currentPath + File.pathSeparator
                + path.getAbsolutePath().replace(" ", "\\ "); //NOI18N
    }

    if (!"".equals(currentPath.trim())) {
        current.put(pathName, currentPath);
    }
}
 
Example 7
Project: openjdk-jdk10   File: PathsTest.java   View Source Code Vote up 6 votes
void run() throws Exception {
    String PS = File.pathSeparator;
    writeFile("src1/p/A.java",
            "package p; public class A { }");
    compile("-d", "classes1", "src1/p/A.java");

    writeFile("src2/q/B.java",
            "package q; public class B extends p.A { }");
    compile("-d", "classes2", "-classpath", "classes1", "src2/q/B.java");

    writeFile("src/Test.java",
            "/** &0; */ class Test extends q.B { }");

    test("src/Test.java", "-sourcepath", "src1" + PS + "src2");
    test("src/Test.java", "-classpath", "classes1" + PS + "classes2");

    File testJar = createJar();
    test("src/Test.java", "-bootclasspath",
            testJar + PS + "classes1" + PS + "classes2");

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example 8
Project: hadoop   File: TestEncryptedShuffle.java   View Source Code Vote up 5 votes
private void startCluster(Configuration  conf) throws Exception {
  if (System.getProperty("hadoop.log.dir") == null) {
    System.setProperty("hadoop.log.dir", "target/test-dir");
  }
  conf.set("dfs.block.access.token.enable", "false");
  conf.set("dfs.permissions", "true");
  conf.set("hadoop.security.authentication", "simple");
  String cp = conf.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
      StringUtils.join(",",
          YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH))
      + File.pathSeparator + classpathDir;
  conf.set(YarnConfiguration.YARN_APPLICATION_CLASSPATH, cp);
  dfsCluster = new MiniDFSCluster.Builder(conf).build();
  FileSystem fileSystem = dfsCluster.getFileSystem();
  fileSystem.mkdirs(new Path("/tmp"));
  fileSystem.mkdirs(new Path("/user"));
  fileSystem.mkdirs(new Path("/hadoop/mapred/system"));
  fileSystem.setPermission(
    new Path("/tmp"), FsPermission.valueOf("-rwxrwxrwx"));
  fileSystem.setPermission(
    new Path("/user"), FsPermission.valueOf("-rwxrwxrwx"));
  fileSystem.setPermission(
    new Path("/hadoop/mapred/system"), FsPermission.valueOf("-rwx------"));
  FileSystem.setDefaultUri(conf, fileSystem.getUri());
  mrCluster = MiniMRClientClusterFactory.create(this.getClass(), 1, conf);

  // so the minicluster conf is avail to the containers.
  Writer writer = new FileWriter(classpathDir + "/core-site.xml");
  mrCluster.getConfig().writeXml(writer);
  writer.close();
}
 
Example 9
Project: incubator-netbeans   File: FormatingTest.java   View Source Code Vote up 5 votes
private ClassPath createClassPath(String classpath) {
    StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
    List/*<PathResourceImplementation>*/ list = new ArrayList();
    while (tokenizer.hasMoreTokens()) {
        String item = tokenizer.nextToken();
        File f = FileUtil.normalizeFile(new File(item));
        URL url = getRootURL(f);
        if (url != null) {
            list.add(ClassPathSupport.createResource(url));
        }
    }
    return ClassPathSupport.createClassPath(list);
}
 
Example 10
Project: openjdk-jdk10   File: CompiledVersionTest.java   View Source Code Vote up 5 votes
private void createImage(Path outputDir, String... modules) throws Throwable {
    Path jlink = Paths.get(JAVA_HOME, "bin", "jlink");
    String mp = JMODS.toString() + File.pathSeparator + MODS_DIR.toString();
    assertTrue(executeProcess(jlink.toString(), "--output", outputDir.toString(),
                    "--add-modules", Arrays.stream(modules).collect(Collectors.joining(",")),
                    "--module-path", mp)
                    .outputTo(System.out)
                    .errorTo(System.out)
                    .getExitValue() == 0);
}
 
Example 11
Project: openjdk-jdk10   File: CheckSealedTest.java   View Source Code Vote up 5 votes
public static void main(String[] args)
        throws Throwable {

    String baseDir = System.getProperty("user.dir") + File.separator;
    String javac = JDKToolFinder.getTestJDKTool("javac");
    String java = JDKToolFinder.getTestJDKTool("java");

    setup(baseDir);
    String srcDir = System.getProperty("test.src");
    String cp = srcDir + File.separator + "a" + File.pathSeparator
            + srcDir + File.separator + "b.jar" + File.pathSeparator
            + ".";
    List<String[]> allCMDs = List.of(
            // Compile command
            new String[]{
                    javac, "-cp", cp, "-d", ".",
                    srcDir + File.separator + TEST_NAME + ".java"
            },
            // Run test the first time
            new String[]{
                    java, "-cp", cp, TEST_NAME, "1"
            },
            // Run test the second time
            new String[]{
                    java, "-cp", cp, TEST_NAME, "2"
            }
    );

    for (String[] cmd : allCMDs) {
        ProcessTools.executeCommand(cmd)
                    .outputTo(System.out)
                    .errorTo(System.out)
                    .shouldHaveExitValue(0);
    }
}
 
Example 12
Project: openjdk-jdk10   File: PatchTest.java   View Source Code Vote up 5 votes
/**
 * Run test with ---patch-module and exploded patches
 */
public void testWithExplodedPatches() throws Exception {

    // patches1/java.base:patches2/java.base
    String basePatches = PATCHES1_DIR.resolve("java.base")
            + File.pathSeparator + PATCHES2_DIR.resolve("java.base");

    String dnsPatches = PATCHES1_DIR.resolve("jdk.naming.dns")
            + File.pathSeparator + PATCHES2_DIR.resolve("jdk.naming.dns");

    String compilerPatches = PATCHES1_DIR.resolve("jdk.compiler")
            + File.pathSeparator + PATCHES2_DIR.resolve("jdk.compiler");

    runTest(basePatches, dnsPatches, compilerPatches);
}
 
Example 13
Project: marathonv5   File: ChooserHelper.java   View Source Code Vote up 5 votes
public static File[] decode(String text) {
    ArrayList<File> files = new ArrayList<File>();
    StringTokenizer tokenizer = new StringTokenizer(text, File.pathSeparator);
    while (tokenizer.hasMoreElements()) {
        File file = decodeFile((String) tokenizer.nextElement());
        files.add(file);
    }
    return files.toArray(new File[files.size()]);
}
 
Example 14
Project: parabuild-ci   File: RuntimeUtils.java   View Source Code Vote up 5 votes
/**
 * Accepts exact path to a given command. A command may be in
 * uneven quotes (both single and double).
 */
public static boolean commandIsAvailable(final String command) {
  try {
    final String quotedCommand = StringUtils.putIntoDoubleQuotes(command);
    final String[] parsed = new CommandLineParser().parse(quotedCommand);
    if (parsed.length != 1) return false; // not a single command
    final File commmandFile = new File(parsed[0]);
    // first try to find given executable file in path if command is not in path
    if (!commmandFile.isAbsolute()) {
      final String pathVariable = getEnvVariable(isWindows() ? "Path" : "PATH");
      final StringTokenizer stPath = new StringTokenizer(pathVariable, File.pathSeparator, false);
      while (stPath.hasMoreTokens()) {
        String commandToCheck = null;
        if (isWindows() && !command.endsWith(EXE_SUFFIX)) {
          commandToCheck = command + EXE_SUFFIX;
        } else {
          commandToCheck = command;
        }
        final String path = stPath.nextToken();
        final File fullPath = new File(path, commandToCheck);
        if (fullPath.exists() && fullPath.isFile()) return true;
      }
    }
    if (!commmandFile.exists()) return false;
    return commmandFile.isFile();
  } catch (CommandLineParserException e) {
    return false;
  }
}
 
Example 15
Project: openjdk-jdk10   File: LegalFilePluginTest.java   View Source Code Vote up 5 votes
@Test
public void errorIfNotSameContent() {
    if (Files.notExists(MODULE_PATH)) {
        // exploded image
        return;
    }

    String dir = "test";

    String mpath = MODULE_PATH.toString() + File.pathSeparator +
                   JMODS_DIR.toString();
    List<String> options = Stream.of("--dedup-legal-notices",
                                     "error-if-not-same-content",
                                     "--module-path", mpath,
                                     "--add-modules=m3,m4",
                                     "--output", imageDir(dir))
                                 .collect(Collectors.toList());

    StringWriter writer = new StringWriter();
    PrintWriter pw = new PrintWriter(writer);
    System.out.println("jlink " + options.stream().collect(Collectors.joining(" ")));
    int rc = JLINK_TOOL.run(pw, pw,
                            options.toArray(new String[0]));
    assertTrue(rc != 0);
    assertTrue(writer.toString().trim()
                     .matches("Error:.*/m4/legal/m4/test-license .*contain different content"));
}
 
Example 16
Project: openjdk-jdk10   File: BasicTest.java   View Source Code Vote up 5 votes
/**
 * Run the test with a non-existent file on the application module path.
 * It should be silently ignored.
 */
public void testRunWithNonExistentEntry() throws Exception {
    String mp = "DoesNotExist" + File.pathSeparator + MODS_DIR.toString();
    String mid = TEST_MODULE + "/" + MAIN_CLASS;

    // java --module-path mods --module $TESTMODULE/$MAINCLASS
    int exitValue = exec("--module-path", mp, "--module", mid);
    assertTrue(exitValue == 0);
}
 
Example 17
Project: incubator-netbeans   File: PathFileSetTest.java   View Source Code Vote up 5 votes
@Test
public void testPathAttribute() throws IOException {
    new ClusterRecord("cl3").create().addModule("org-m3", true, false, false);
    new ClusterRecord("cl4").create().addModule("org-m4", true, false, false);
    Path path = new Path(fakeproj, getWorkDir().getPath() + File.separator + "cl3"
            + File.pathSeparator
            + getWorkDir().getPath() + File.separator + "cl4");
    pfs.setPath(path);
    pfs.setInclude("**/*.jar");
    executeAndCheckResults(new String[] {
        "cl1/modules/org-m1.jar", "cl2/modules/org-m2.jar",
        "cl3/modules/org-m3.jar", "cl4/modules/org-m4.jar"
    });
}
 
Example 18
Project: monarch   File: SystemUtils.java   View Source Code Vote up 5 votes
/**
 * Returns true if the specified location is in the JVM classpath. This may ignore additions to
 * the classpath that are not reflected by the value in
 * <code>System.getProperty("java.class.path")</code>.
 * 
 * @param location the directory or jar URL to test for
 * @return true if location is in the JVM classpath
 * @throws MalformedURLException
 */
public static boolean isInClassPath(URL location) throws MalformedURLException {
  String classPath = System.getProperty("java.class.path");
  StringTokenizer st = new StringTokenizer(classPath, File.pathSeparator);
  while (st.hasMoreTokens()) {
    String path = st.nextToken();
    if (location.equals(new File(path).toURI().toURL())) {
      return true;
    }
  }
  return false;
}
 
Example 19
Project: incubator-netbeans   File: Util.java   View Source Code Vote up 4 votes
/**
 * Get JRE extension JARs/ZIPs.
 * @param extPath a native-format path for e.g. jre/lib/ext
 * @return a native-format classpath for extension JARs and ZIPs found in it
 */
public static String getExtensions (String extPath) {
    if (extPath == null) {
        return null;
    }
    final StringBuilder sb = new StringBuilder();
    final StringTokenizer tk = new StringTokenizer (extPath, File.pathSeparator);
    while (tk.hasMoreTokens()) {
        File extFolder = FileUtil.normalizeFile(new File(tk.nextToken()));
        File[] files = extFolder.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File f = files[i];
                if (!f.exists()) {
                    //May happen, eg. broken link, it is safe to ignore it
                    //since it is an extension directory, but log it.
                    LOG.log(
                            Level.WARNING,
                            NbBundle.getMessage(Util.class,"MSG_BrokenExtension"),
                            new Object[] {
                                f.getName(),
                                extFolder.getAbsolutePath()
                            });
                    continue;
                }
                if (Utilities.isMac() && "._.DS_Store".equals(f.getName())) {  //NOI18N
                    //Ignore Apple temporary ._.DS_Store files in the lib/ext folder
                    continue;
                }
                FileObject fo = FileUtil.toFileObject(f);
                if (fo == null) {
                    LOG.log(
                            Level.WARNING,
                            "Cannot create FileObject for file: {0} exists: {1}", //NOI18N
                            new Object[]{
                                f.getAbsolutePath(),
                                f.exists()
                            });
                    continue;
                }
                if (!FileUtil.isArchiveFile(fo)) {
                    // #42961: Mac OS X has e.g. libmlib_jai.jnilib.
                    continue;
                }
                sb.append(File.pathSeparator);
                sb.append(files[i].getAbsolutePath());
            }
        }
    }
    if (sb.length() == 0) {
        return null;
    }
    return sb.substring(File.pathSeparator.length());
}
 
Example 20
Project: monarch   File: LauncherLifecycleCommands.java   View Source Code Vote up 4 votes
String toClasspath(final boolean includeSystemClasspath, String[] jarFilePathnames,
    String... userClasspaths) {
  // gemfire jar must absolutely be the first JAR file on the CLASSPATH!!!
  String classpath = getGemFireJarPath();

  userClasspaths = (userClasspaths != null ? userClasspaths : StringUtils.EMPTY_STRING_ARRAY);

  // Then, include user-specified classes on CLASSPATH to enable the user to override GemFire JAR
  // dependencies
  // with application-specific versions; this logic/block corresponds to classes/jar-files
  // specified with the
  // --classpath option to the 'start locator' and 'start server commands'; also this will
  // override any
  // System CLASSPATH environment variable setting, which is consistent with the Java platform
  // behavior...
  for (String userClasspath : userClasspaths) {
    if (!StringUtils.isBlank(userClasspath)) {
      classpath += (classpath.isEmpty() ? StringUtils.EMPTY_STRING : File.pathSeparator);
      classpath += userClasspath;
    }
  }

  // Now, include any System-specified CLASSPATH environment variable setting...
  if (includeSystemClasspath) {
    classpath += File.pathSeparator;
    classpath += getSystemClasspath();
  }

  jarFilePathnames =
      (jarFilePathnames != null ? jarFilePathnames : StringUtils.EMPTY_STRING_ARRAY);

  // And finally, include all GemFire dependencies on the CLASSPATH...
  for (String jarFilePathname : jarFilePathnames) {
    if (!StringUtils.isBlank(jarFilePathname)) {
      classpath += (classpath.isEmpty() ? StringUtils.EMPTY_STRING : File.pathSeparator);
      classpath += jarFilePathname;
    }
  }

  return classpath;
}