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

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

The newest version!
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE

package com.threerings.getdown.data;

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
     * 
* * The paths are relativized to dir. * * @param dir the working directory of the process */ public String asArgumentString (File dir) { StringBuilder builder = new StringBuilder(); String delimiter = ""; for (File entry: _classPathEntries) { builder.append(delimiter).append(dir.toPath().relativize(entry.toPath())); 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 - 2025 Weber Informatics LLC | Privacy Policy