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:net.grinder.util.AbstractGrinderClassPathProcessor.java

/**
 * Construct the patch classPath from current classLoader.
 *
 * @param logger logger/*from   w ww.ja v a  2 s  .c o m*/
 * @return classpath optimized for grinder.
 */
public String buildPatchClasspathBasedOnCurrentClassLoader(Logger logger) {
    URL[] urLs = ((URLClassLoader) AbstractGrinderClassPathProcessor.class.getClassLoader()).getURLs();
    StringBuilder builder = new StringBuilder();
    for (URL each : urLs) {
        builder.append(each.getFile()).append(File.pathSeparator);
    }
    return filterPatchClassPath(builder.toString(), logger);
}

From source file:com.qspin.qtaste.kernel.engine.TestEngine.java

private static boolean startOrStopSUT(boolean start, TestResult tr) {
    needToRestartSUT = !start;// www  .  j a  v  a  2s  . co  m
    String startOrStop = start ? "start" : "stop";
    TestBedConfiguration config = TestBedConfiguration.getInstance();
    if (hasControlScript()) {
        if (isStartStopSUTCancelled || (start && isAbortedByUser())) {
            if (tr != null) {
                tr.setStatus(Status.FAIL);
                tr.setExtraResultDetails("SUT " + startOrStop + " command cancelled");
            }
            return false;
        }

        // build the engine script command as a list to avoid mistakes with spaces (see ticket #7)
        String scriptFilename = config.getControlScriptFileName();
        List<String> scriptEngineCommand = new ArrayList<>();

        if (scriptFilename.endsWith(".py")) {
            final String qtasteJar = StaticConfiguration.QTASTE_ROOT
                    + "/kernel/target/qtaste-kernel-deploy.jar";
            final String jythonLib = StaticConfiguration.JYTHON_LIB;
            final String additionalJythonLib = StaticConfiguration.ADDITIONAL_JYTHON_LIB.trim();
            final String classPath = System.getProperties().getProperty("java.class.path", "").trim();

            scriptEngineCommand.add("java");
            scriptEngineCommand.add("-Dpython.path=" + qtasteJar + File.pathSeparator + jythonLib
                    + (additionalJythonLib.isEmpty() ? "" : File.pathSeparator + additionalJythonLib));
            scriptEngineCommand.add("-cp");
            scriptEngineCommand.add(qtasteJar + File.pathSeparator + classPath);
            scriptEngineCommand.add("org.python.util.jython");
        }

        // then, build the 'start or stop' command as a list
        List<String> startOrStopCommand = new ArrayList<>();

        startOrStopCommand.add(scriptFilename);
        startOrStopCommand.add(startOrStop);

        String scriptArguments = config.getControlScriptArguments();
        if (scriptArguments != null) {
            startOrStopCommand.add(scriptArguments);
        }

        if (isRestartingSUT) {
            startOrStopCommand.add("-restart true");
        }

        logger.info((start ? "Starting" : "Stopping") + " SUT using command '"
                + StringUtils.join(startOrStopCommand, " ") + "'");

        // report the control script
        try {
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            Map<String, String> env = new HashMap<>(System.getenv());
            env.put("TESTBED", config.getFileName());

            // build the full command to execute
            List<String> startOrStopFullCommand = new ArrayList<>();
            startOrStopFullCommand.addAll(scriptEngineCommand);
            startOrStopFullCommand.addAll(startOrStopCommand);

            logger.trace("FULL COMMAND : '" + StringUtils.join(startOrStopFullCommand, " ") + "'");

            // execute the full command
            int exitCode = sutStartStopExec.exec(
                    startOrStopFullCommand.toArray(new String[startOrStopFullCommand.size()]), env, output);

            if (isStartStopSUTCancelled || (start && isAbortedByUser())) {
                String errMsg = "SUT " + startOrStop + " command cancelled";
                logger.info(errMsg);
                if (tr != null) {
                    tr.setStatus(Status.FAIL);
                    tr.setExtraResultDetails(errMsg);
                }
                return false;
            } else if (exitCode == 0) {
                logger.info("SUT " + (start ? "started" : "stopped"));
                return true;
            } else {
                String errMsg = "SUT " + startOrStop + " command '" + startOrStopCommand
                        + "' exited with error code " + exitCode + ". Output:\n" + output.toString();
                logger.error(errMsg);
                if (tr != null) {
                    tr.setExtraResultDetails(errMsg);
                }
            }
        } catch (IOException e) {
            String errMsg = "Couldn't execute SUT " + startOrStop + " command '" + startOrStopCommand + "': "
                    + e.getMessage();
            logger.error(errMsg);
            if (tr != null) {
                tr.setExtraResultDetails(errMsg);
            }
        } catch (InterruptedException e) {
            String errMsg = "Interrupted while executing SUT " + startOrStop + " command '" + startOrStopCommand
                    + "': " + e.getMessage();
            logger.error(errMsg);
            if (tr != null) {
                tr.setExtraResultDetails(errMsg);
            }
        }
        logger.error("Couldn't " + startOrStop + " SUT");
        if (tr != null) {
            tr.setStatus(Status.FAIL);
        }
    } else {
        logger.info("No SUT control script available for this testbed!");
    }
    return false;
}

From source file:com.obergner.hzserver.ServerInfo.java

private void logClassPath() {
    logStringEntries("BootClassPath", getClassPath(), File.pathSeparator);
}

From source file:eu.udig.omsbox.OmsBoxPlugin.java

public String getClasspathJars() throws Exception {
    try {//from  w w  w .j  av  a  2s.  c  om
        StringBuilder sb = new StringBuilder();
        sb.append(".");
        sb.append(File.pathSeparator);

        String sysClassPath = System.getProperty("java.class.path");
        if (sysClassPath != null && sysClassPath.length() > 0 && !sysClassPath.equals("null")) {
            addPath(sysClassPath, sb);
            sb.append(File.pathSeparator);
        }

        // add this plugins classes
        Bundle omsBundle = Platform.getBundle(OmsBoxPlugin.PLUGIN_ID);
        String pluginPath = getPath(omsBundle, "/");
        if (pluginPath != null) {
            addPath(pluginPath, sb);
            sb.append(File.pathSeparator);
            addPath(pluginPath + File.separator + "bin", sb);
        }
        // add udig libs
        Bundle udigLibsBundle = Platform.getBundle("net.refractions.udig.libs");
        String udigLibsFolderPath = getPath(udigLibsBundle, "lib");
        if (udigLibsFolderPath != null) {
            sb.append(File.pathSeparator);
            addPath(udigLibsFolderPath + File.separator + "*", sb);

            File libsPluginPath = new File(udigLibsFolderPath).getParentFile();
            File[] toolsJararray = libsPluginPath.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.startsWith("tools_") && name.endsWith(".jar");
                }
            });
            if (toolsJararray.length == 1) {
                sb.append(File.pathSeparator);
                addPath(toolsJararray[0].getAbsolutePath(), sb);
            }
        }

        // add custom libs from plugins
        addCustomLibs(sb);

        // add jars in the default folder
        File extraSpatialtoolboxLibsFolder = getExtraSpatialtoolboxLibsFolder();
        if (extraSpatialtoolboxLibsFolder != null) {
            File[] extraJars = extraSpatialtoolboxLibsFolder.listFiles(new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.endsWith(".jar");
                }
            });
            for (File extraJar : extraJars) {
                sb.append(File.pathSeparator);
                addPath(extraJar.getAbsolutePath(), sb);
            }
        }

        // add loaded jars
        String[] retrieveSavedJars = retrieveSavedJars();
        for (String file : retrieveSavedJars) {
            sb.append(File.pathSeparator);
            addPath(file, sb);
        }

        return sb.toString();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:org.eclipse.tycho.extras.docbundle.JavadocRunner.java

private void addPath(final StringBuilder sb, final Collection<?> path) {
    boolean first = true;
    for (final Object ele : path) {
        if (ele == null) {
            continue;
        }/*from  w  w w. j  a  va2 s . c o m*/
        // convert black slashes to forward slashes for javadoc
        final String pathEle = ele.toString().replace('\\', '/');
        if (!first) {
            sb.append(File.pathSeparator);
        } else {
            first = false;
        }
        sb.append(pathEle);
    }
}

From source file:edu.harvard.mcz.imagecapture.TemplatePickerDialog.java

protected boolean setupForImage(ICImage image) throws UnreadableFileException {
    boolean result = false;
    imageToTemplate = image;//  w  ww. j  ava 2 s.  c o  m

    StringBuffer heading = new StringBuffer();
    heading.append("Current Template:");
    heading.append(" ").append(image.getTemplateId());

    StringBuffer filename = new StringBuffer();
    filename.append(image.getPath()).append(File.pathSeparator).append(image.getFilename());
    this.lblFileName.setText(filename.toString());
    lblTemplate.setText(heading.toString());
    comboBoxTemplatePicker.addItem(image.getTemplateId());
    File imageFile = new File(
            ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename()));

    BufferedImage bufImage = null;
    int imageWidth = 0;
    try {
        bufImage = ImageIO.read(imageFile);
        imageWidth = bufImage.getWidth();
    } catch (IOException e) {
        throw new UnreadableFileException("IOException trying to read " + imageFile.getName());
    }

    if (imageFile.exists()) {
        List<PositionTemplate> templates = PositionTemplate.getTemplates();
        ListIterator<PositionTemplate> i = templates.listIterator();
        while (i.hasNext()) {
            PositionTemplate template = i.next();
            if (!template.getTemplateId().equals(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS)) {
                int templateWidth = -1;
                try {
                    templateWidth = (int) template.getImageSize().getWidth();
                } catch (NullPointerException e) {
                    log.debug(e.getMessage());
                }
                if (imageWidth == templateWidth) {
                    comboBoxTemplatePicker.addItem(template.getTemplateId());
                }
            }
        }
    }

    return result;
}

From source file:com.opengamma.web.WebAbout.java

private static Set<URL> forJavaClassPath() {
    Set<URL> urls = Sets.newLinkedHashSet();
    String javaClassPath = System.getProperty("java.class.path");
    if (javaClassPath != null) {
        for (String path : javaClassPath.split(File.pathSeparator)) {
            try {
                urls.add(new File(path).toURI().toURL());
            } catch (Exception e) {
                e.printStackTrace();/*  www.ja va2 s. c  om*/
            }
        }
    }
    return urls;
}

From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java

/**
 * Run a command and wait/* ww w  .  j a va2 s  .  c o  m*/
 *
 * @param cmd The command to run
 * @param workingDir The folder where the command is run
 * @param executeFrom For logging message to the center of where to execute the command.
 * @return
 */
public static Process executeCommandAndForget(String cmd, String workingDir, String executeFrom) {
    logger.debug("Execute command: " + cmd);
    if (workingDir == null) {
        workingDir = "/tmp";
    }

    String[] splitStr = cmd.split("\\s+");
    ProcessBuilder pb = new ProcessBuilder(splitStr);
    pb.directory(new File(workingDir));
    pb = pb.redirectErrorStream(true); // this is important to redirect the error stream to output stream, prevent blocking with long output
    pb.redirectOutput(new File("/tmp/salsa.conductor.log"));
    Map<String, String> env = pb.environment();
    String path = env.get("PATH");
    path = path + File.pathSeparator + "/usr/bin:/usr/sbin";
    logger.debug("PATH to execute command: " + pb.environment().get("PATH"));
    env.put("PATH", path);
    Process p;
    try {
        p = pb.start();
        return p;
    } catch (IOException ex) {
        logger.debug("Cannot run the command: " + cmd);
        return null;
    }

}

From source file:org.eclipse.ecr.testlib.NXRuntimeTestCase.java

protected void initUrls() throws Exception {
    ClassLoader classLoader = NXRuntimeTestCase.class.getClassLoader();
    if (classLoader instanceof URLClassLoader) {
        urls = ((URLClassLoader) classLoader).getURLs();
    } else if (classLoader.getClass().getName().equals("org.apache.tools.ant.AntClassLoader")) {
        Method method = classLoader.getClass().getMethod("getClasspath");
        String cp = (String) method.invoke(classLoader);
        String[] paths = cp.split(File.pathSeparator);
        urls = new URL[paths.length];
        for (int i = 0; i < paths.length; i++) {
            urls[i] = new URL("file:" + paths[i]);
        }/*ww w .j av a  2 s . c  o m*/
    } else {
        log.warn("Unknow classloader type: " + classLoader.getClass().getName()
                + "\nWon't be able to load OSGI bundles");
        return;
    }
    // special case for maven surefire with useManifestOnlyJar
    if (urls.length == 1) {
        try {
            URI uri = urls[0].toURI();
            if (uri.getScheme().equals("file") && uri.getPath().contains("surefirebooter")) {
                JarFile jar = new JarFile(new File(uri));
                try {
                    String cp = jar.getManifest().getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
                    if (cp != null) {
                        String[] cpe = cp.split(" ");
                        URL[] newUrls = new URL[cpe.length];
                        for (int i = 0; i < cpe.length; i++) {
                            // Don't need to add 'file:' with maven surefire
                            // >= 2.4.2
                            String newUrl = cpe[i].startsWith("file:") ? cpe[i] : "file:" + cpe[i];
                            newUrls[i] = new URL(newUrl);
                        }
                        urls = newUrls;
                    }
                } finally {
                    jar.close();
                }
            }
        } catch (Exception e) {
            // skip
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("URLs on the classpath: ");
    for (URL url : urls) {
        sb.append(url.toString());
        sb.append('\n');
    }
    log.debug(sb.toString());
    readUris = new HashSet<URI>();
    bundles = new HashMap<String, BundleFile>();
}

From source file:org.asciidoctor.ant.AsciidoctorAntTask.java

private Asciidoctor getAsciidoctorInstance(String gemPath) {
    Asciidoctor asciidoctor;//from   www  .  j av  a  2s  . c o  m
    if (gemPath == null) {
        asciidoctor = Asciidoctor.Factory.create();
    } else {
        // Replace Windows path separator to avoid paths with mixed \ and /.
        // This happens for instance when setting: <gemPath>${project.build.directory}/gems-provided</gemPath>
        // because the project's path is converted to string.
        String normalizedGemPath = (File.separatorChar == '\\') ? gemPath.replaceAll("\\\\", "/") : gemPath;
        asciidoctor = Asciidoctor.Factory.create(normalizedGemPath);
    }

    String gemHome = JRubyRuntimeContext.get().evalScriptlet("ENV['GEM_HOME']").toString();
    String gemHomeExpected = (gemPath == null || "".equals(gemPath)) ? ""
            : gemPath.split(java.io.File.pathSeparator)[0];

    if (!"".equals(gemHome) && !gemHomeExpected.equals(gemHome)) {
        log("Using inherited external environment to resolve gems (" + gemHome
                + "), i.e. build is platform dependent!");
    }

    return asciidoctor;
}