All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.threerings.getdown.classpath.ClassPath Maven / Gradle / Ivy

There is a newer version: 1.8.7
Show newest version
package com.threerings.getdown.classpath;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * Represents the class path and it's elements of the application to be launched. The class path can
 * either be represented as an {@link #asArgumentString() argument string} for the java command line
 * or as an {@link #asUrls() array of URLs} to be used by a {@link URLClassLoader}.
 */
public class ClassPath
{
    public ClassPath (LinkedHashSet classPathEntries)
    {
        _classPathEntries = Collections.unmodifiableSet(classPathEntries);
    }

    /**
     * Returns the class path as an java command line argument string, e.g.
     *
     * 
     *   /path/to/a.jar:/path/to/b.jar
     * 
*/ public String asArgumentString () { StringBuilder builder = new StringBuilder(); String delimiter = ""; for (File entry: _classPathEntries) { builder.append(delimiter).append(entry.getAbsolutePath()); delimiter = File.pathSeparator; } return builder.toString(); } /** * Returns the class path entries as an array of URLs to be used for example by an * {@link URLClassLoader}. */ public URL[] asUrls () { URL[] urls = new URL[_classPathEntries.size()]; int i = 0; for (File entry : _classPathEntries) { urls[i++] = getURL(entry); } return urls; } public Set getClassPathEntries () { return _classPathEntries; } private static URL getURL (File file) { try { return file.toURI().toURL(); } catch (MalformedURLException e) { throw new IllegalStateException("URL of file is illegal: " + file.getAbsolutePath(), e); } } private final Set _classPathEntries; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy