Example usage for java.io File pathSeparator

List of usage examples for java.io File pathSeparator

Introduction

In this page you can find the example usage for java.io File pathSeparator.

Prototype

String pathSeparator

To view the source code for java.io File pathSeparator.

Click Source Link

Document

The system-dependent path-separator character, represented as a string for convenience.

Usage

From source file:org.apache.geode.management.internal.cli.commands.StartMemberUtils.java

static String getGemFireJarPath() {
    String classpath = getSystemClasspath();
    String gemfireJarPath = GEODE_JAR_PATHNAME;
    for (String classpathElement : classpath.split(File.pathSeparator)) {
        if (classpathElement.endsWith("gemfire-core-8.2.0.0-SNAPSHOT.jar")) {
            gemfireJarPath = classpathElement;
            break;
        }//from  ww w  .  jav  a  2 s .  com
    }
    return gemfireJarPath;
}

From source file:hudson.util.FormValidation.java

/**
 * Makes sure that the given string points to an executable file.
 *
 * @param exeValidator If the validation process discovers a valid
 * executable program on the given path, the specified {@link FileValidator}
 * can perform additional checks (such as making sure that it has the right
 * version, etc.)/*from   w  w  w . j a va2 s  .  c  om*/
 */
public static FormValidation validateExecutable(String exe, FileValidator exeValidator) {
    // insufficient permission to perform validation?
    if (!Hudson.getInstance().hasPermission(Hudson.ADMINISTER)) {
        return ok();
    }

    exe = fixEmpty(exe);
    if (exe == null) {
        return ok();
    }

    if (exe.indexOf(File.separatorChar) >= 0) {
        // this is full path
        File f = new File(exe);
        if (f.exists()) {
            return exeValidator.validate(f);
        }

        File fexe = new File(exe + ".exe");
        if (fexe.exists()) {
            return exeValidator.validate(fexe);
        }

        return error("There's no such file: " + exe);
    }

    // look in PATH
    String path = EnvVars.masterEnvVars.get("PATH");
    String tokenizedPath = "";
    String delimiter = null;
    if (path != null) {
        for (String _dir : Util.tokenize(path.replace("\\", "\\\\"), File.pathSeparator)) {
            if (delimiter == null) {
                delimiter = ", ";
            } else {
                tokenizedPath += delimiter;
            }

            tokenizedPath += _dir.replace('\\', '/');

            File dir = new File(_dir);

            File f = new File(dir, exe);
            if (f.exists()) {
                return exeValidator.validate(f);
            }

            File fexe = new File(dir, exe + ".exe");
            if (fexe.exists()) {
                return exeValidator.validate(fexe);
            }
        }

        tokenizedPath += ".";
    } else {
        tokenizedPath = "unavailable.";
    }

    // didn't find it
    return error("There's no such executable " + exe + " in PATH: " + tokenizedPath);
}

From source file:org.dawnsci.python.rpc.AnalysisRpcPythonPyDevService.java

private static Map<String, String> getEnv(IInterpreterInfo interpreter, IProject project) {
    IPythonNature pythonNature = null;//from   ww  w  . j a va  2  s.c  om
    if (project != null) {
        pythonNature = PythonNature.getPythonNature(project);
    }

    IInterpreterManager manager = PydevPlugin.getPythonInterpreterManager();

    String[] envp = null;
    try {
        waitForPythonNaturesToLoad();
        envp = SimpleRunner.getEnvironment(pythonNature, interpreter, manager);
    } catch (CoreException e) {
        // Should be unreachable
        logger.error("exception occurred while setting environemt", e);
    }

    final Map<String, String> env = new HashMap<String, String>(System.getenv());
    for (String s : envp) {
        String kv[] = s.split("=", 2);
        env.put(kv[0], kv[1]);
    }

    // To support this flow, we need both Diamond and PyDev's python
    // paths in the PYTHONPATH. We add the expected ones here.
    // NOTE: This can be problematic in cases where the user really
    // wanted a different Diamond or PyDev python path. Therefore we
    // force the paths in here.
    // TODO consider if scisoftpath should be added
    // in AnalysisRpcPythonService instead
    String path = env.get("PYTHONPATH");
    if (path == null) {
        path = "";
    }
    StringBuilder pythonpath = new StringBuilder(path);
    if (pythonpath.length() > 0) {
        pythonpath.append(File.pathSeparator);
    }

    String pyDevPySrc = getPyDevPySrc();
    if (pyDevPySrc != null) {
        pythonpath.append(pyDevPySrc).append(File.pathSeparator);
    }

    String scisoftpath = getScisoftPath();
    if (scisoftpath != null) {
        pythonpath.append(scisoftpath).append(File.pathSeparator);
        pythonpath.append(scisoftpath + "/src").append(File.pathSeparator);
    }

    env.put("PYTHONPATH", pythonpath.toString());

    return env;
}

From source file:org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl.java

private void append(StringBuilder classpathBuilder, URL url) throws URISyntaxException {
    File file = new File(url.toURI());
    // do not include dirs containing hadoop or accumulo site files
    if (!containsSiteFile(file))
        classpathBuilder.append(File.pathSeparator).append(file.getAbsolutePath());
}

From source file:com.mmnaseri.dragonfly.entity.impl.DefaultEntityContext.java

/**
 * This method will determine the classpath argument passed to the JavaC compiler used by this
 * implementation/*from   w w w .  j  a v  a  2s .  c o  m*/
 *
 * @return the classpath
 */
protected String getClassPath(ClassLoader classLoader) {
    final Set<File> classPathElements = new HashSet<File>();
    //Adding runtime dependencies available to the project
    final URL[] urls;
    if (classLoader instanceof URLClassLoader) {
        urls = ((URLClassLoader) classLoader).getURLs();
    } else if (classLoader instanceof ConfigurableClassLoader) {
        urls = ((ConfigurableClassLoader) classLoader).getUrls();
    } else {
        urls = new URL[0];
    }
    for (URL url : urls) {
        try {
            final File file = new File(url.toURI());
            if (file.exists()) {
                classPathElements.add(file);
            }
        } catch (Throwable ignored) {
        }
    }
    return with(classPathElements).transform(new Transformer<File, String>() {
        @Override
        public String map(File input) {
            return input.getAbsolutePath();
        }
    }).join(File.pathSeparator);
}

From source file:com.sangupta.jerry.util.FileUtils.java

/**
 * List the files in the given path string with wild cards.
 * /*  w w w . j a v  a  2 s . c o  m*/
 * @param baseDir
 *            the base directory to search for files in
 * 
 * @param filePathWithWildCards
 *            the file path to search in - can be absolute
 * 
 * @param recursive
 *            whether to look in sub-directories or not
 * 
 * @param additionalFilters
 *            additional file filters that need to be used when scanning for
 *            files
 * 
 * @return the list of files and directories that match the criteria
 */
public static List<File> listFiles(File baseDir, String filePathWithWildCards, boolean recursive,
        List<IOFileFilter> additionalFilters) {
    if (filePathWithWildCards == null) {
        throw new IllegalArgumentException("Filepath cannot be null");
    }

    // change *.* to *
    filePathWithWildCards = filePathWithWildCards.replace("*.*", "*");

    // normalize
    filePathWithWildCards = FilenameUtils.normalize(filePathWithWildCards);

    if (filePathWithWildCards.endsWith(File.pathSeparator)) {
        filePathWithWildCards += "*";
    }

    // check if this is an absolute path or not
    String prefix = FilenameUtils.getPrefix(filePathWithWildCards);
    final boolean isAbsolute = !prefix.isEmpty();

    // change the base dir if absolute directory
    if (isAbsolute) {
        baseDir = new File(filePathWithWildCards);
        if (!baseDir.isDirectory()) {
            // not a directory - get the base directory
            filePathWithWildCards = baseDir.getName();
            if (filePathWithWildCards.equals("~")) {
                filePathWithWildCards = "*";
            }

            if (AssertUtils.isEmpty(filePathWithWildCards)) {
                filePathWithWildCards = "*";
            }

            baseDir = baseDir.getParentFile();
            if (baseDir == null) {
                baseDir = getUsersHomeDirectory();
            }
        }
    }

    // check if the provided argument is a directory
    File dir = new File(filePathWithWildCards);
    if (dir.isDirectory()) {
        baseDir = dir.getAbsoluteFile();
        filePathWithWildCards = "*";
    } else {
        // let's check for base directory
        File parent = dir.getParentFile();
        if (parent != null) {
            baseDir = parent.getAbsoluteFile();
            filePathWithWildCards = dir.getName();
        }
    }

    // check for user home
    String basePath = baseDir.getPath();
    if (basePath.startsWith("~")) {
        basePath = getUsersHomeDirectory().getAbsolutePath() + File.separator + basePath.substring(1);
        basePath = FilenameUtils.normalize(basePath);
        baseDir = new File(basePath);
    }

    // now read the files
    WildcardFileFilter wildcardFileFilter = new WildcardFileFilter(filePathWithWildCards, IOCase.SYSTEM);
    IOFileFilter finalFilter = wildcardFileFilter;
    if (AssertUtils.isNotEmpty(additionalFilters)) {
        additionalFilters.add(0, wildcardFileFilter);
        finalFilter = new AndFileFilter(additionalFilters);
    }

    Collection<File> files = org.apache.commons.io.FileUtils.listFiles(baseDir, finalFilter,
            recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE);

    return (List<File>) files;
}

From source file:jeplus.RadianceWinTools.java

/**
 * Call Rpict to run the simulation/*from   w  w  w .  jav a2s .  c om*/
 * @param config Radiance Configuration
 * @param WorkDir The working directory where the input files are stored and the output files to be generated
 * @param args
 * @param model
 * @param in
 * @param out
 * @param err
 * @param png Switch for converting scene to jpg or not
 * @param process
 * @return the result code represents the state of execution steps. >=0 means successful
 */
public static int runRpict(RadianceConfig config, String WorkDir, String args, String model, String in,
        String out, String err, boolean png, ProcessWrapper process) {

    int ExitValue = -99;

    // Call rpict
    StringBuilder buf = new StringBuilder(config.getResolvedRadianceBinDir());
    buf.append(File.separator).append("rpict");

    List<String> command = new ArrayList<>();
    command.add(buf.toString());
    String[] arglist = args.split("\\s+");
    command.addAll(Arrays.asList(arglist));
    command.add(model);
    try {
        ProcessBuilder builder = new ProcessBuilder(command);
        builder.directory(new File(WorkDir));
        builder.environment().put("RAYPATH", "." + File.pathSeparator + config.getResolvedRadianceLibDir());
        builder.redirectError(new File(WorkDir + File.separator + err));
        builder.redirectOutput(new File(WorkDir + File.separator + out));
        if (in != null) {
            builder.redirectInput(new File(WorkDir + File.separator + in));
        }
        Process proc = builder.start();
        if (process != null) {
            process.setWrappedProc(proc);
        }
        ExitValue = proc.waitFor();
    } catch (IOException | InterruptedException ex) {
        logger.error("Error occoured when executing Rpict", ex);
    }

    if (png) {
        // Sweep everything with the same extension as out. This is for handling
        // -o option in rpict
        String ext = FilenameUtils.getExtension(out);
        File[] files = new File(WorkDir).listFiles((FileFilter) new WildcardFileFilter("*." + ext));
        for (File file : files) {
            String outname = file.getName();

            // Filter scene
            try {
                buf = new StringBuilder(config.getResolvedRadianceBinDir());
                buf.append(File.separator).append("pfilt");

                command = new ArrayList<>();
                command.add(buf.toString());
                // String [] arglist = "-1 -e -3".split("\\s+");
                // command.addAll(Arrays.asList(arglist));
                command.add(outname);
                ProcessBuilder builder = new ProcessBuilder(command);
                builder.directory(new File(WorkDir));
                builder.environment().put("RAYPATH",
                        "." + File.pathSeparator + config.getResolvedRadianceLibDir());
                builder.redirectError(new File(WorkDir + File.separator + err));
                builder.redirectOutput(new File(WorkDir + File.separator + outname + ".flt"));
                Process proc = builder.start();
                ExitValue = proc.waitFor();
            } catch (IOException | InterruptedException ex) {
                logger.error("Error occoured when executing pfilt", ex);
            }

            // Convert to bmp
            try {
                buf = new StringBuilder(config.getResolvedRadianceBinDir());
                buf.append(File.separator).append("ra_bmp");

                command = new ArrayList<>();
                command.add(buf.toString());
                //String [] arglist = "-g 1.0".split("\\s+");
                //command.addAll(Arrays.asList(arglist));
                command.add(outname + ".flt");
                command.add(outname + ".bmp");
                ProcessBuilder builder = new ProcessBuilder(command);
                builder.directory(new File(WorkDir));
                builder.environment().put("RAYPATH",
                        "." + File.pathSeparator + config.getResolvedRadianceLibDir());
                builder.redirectError(
                        ProcessBuilder.Redirect.appendTo(new File(WorkDir + File.separator + err)));
                Process proc = builder.start();
                ExitValue = proc.waitFor();
            } catch (IOException | InterruptedException ex) {
                logger.error("Error occoured when executing ra_bmp", ex);
            }

            // Convert to png
            BufferedImage input_image = null;
            try {
                input_image = ImageIO.read(new File(WorkDir + File.separator + outname + ".bmp")); //read bmp into input_image object
                File outputfile = new File(WorkDir + File.separator + outname + ".png"); //create new outputfile object
                ImageIO.write(input_image, "png", outputfile); //write PNG output to file 
            } catch (Exception ex) {
                logger.error("Error converting bmp to png.", ex);
            }

            // Remove flt and bmp
            new File(WorkDir + File.separator + outname + ".flt").delete();
            new File(WorkDir + File.separator + outname + ".bmp").delete();
        }
    }
    // Return Radiance exit value
    return ExitValue;
}

From source file:org.apache.james.mailbox.maildir.MaildirStore.java

/**
 * Get the absolute name of the folder for a specific mailbox
 * @param namespace The namespace of the mailbox
 * @param user The user of the mailbox/*from w ww.  j a v a 2  s .  c  om*/
 * @param name The name of the mailbox
 * @return absolute name
 */
public String getFolderName(String namespace, String user, String name) {
    String root = userRoot(user);
    // if INBOX => location == maildirLocation
    if (name.equals(MailboxConstants.INBOX))
        return root;
    StringBuilder folder = new StringBuilder(root);
    if (!root.endsWith(File.pathSeparator))
        folder.append(File.separator);
    folder.append(".");
    folder.append(name);
    return folder.toString();
}

From source file:com.atlassian.jira.startup.JiraSystemInfo.java

public void obtainSystemPathProperties() {
    final Properties sysProps = jiraSystemProperties.getProperties();
    logMsg.outputHeader("Java Class Paths");
    for (final String key : PATH_RELATED_KEYS) {
        final String value = sysProps.getProperty(key, null);
        if (value != null) {
            logMsg.outputProperty(key, value, File.pathSeparator);
            logMsg.add("");
        }//from  w  w w  . j a  v  a  2  s  .c  o  m
    }
}

From source file:org.apache.flink.yarn.Utils.java

/**
 * Copied method from org.apache.hadoop.yarn.util.Apps
 * It was broken by YARN-1824 (2.4.0) and fixed for 2.4.1
 * by https://issues.apache.org/jira/browse/YARN-1931
 *///from   w w  w  .  jav  a  2  s  .  c o m
public static void addToEnvironment(Map<String, String> environment, String variable, String value) {
    String val = environment.get(variable);
    if (val == null) {
        val = value;
    } else {
        val = val + File.pathSeparator + value;
    }
    environment.put(StringInterner.weakIntern(variable), StringInterner.weakIntern(val));
}