2 // Getdown - application installer, patcher and launcher
3 // Copyright (C) 2004-2018 Getdown authors
4 // https://github.com/threerings/getdown/blob/master/LICENSE
6 package com.threerings.getdown.data;
9 import java.net.MalformedURLException;
11 import java.net.URLClassLoader;
12 import java.util.Collections;
13 import java.util.LinkedHashSet;
17 * Represents the class path and it's elements of the application to be launched. The class path
18 * can either be represented as an {@link #asArgumentString() argument string} for the java command
19 * line or as an {@link #asUrls() array of URLs} to be used by a {@link URLClassLoader}.
21 public class ClassPath
23 public ClassPath (LinkedHashSet<File> classPathEntries)
25 _classPathEntries = Collections.unmodifiableSet(classPathEntries);
29 * Returns the class path as an java command line argument string, e.g.
32 * /path/to/a.jar:/path/to/b.jar
35 public String asArgumentString ()
37 StringBuilder builder = new StringBuilder();
38 String delimiter = "";
39 for (File entry: _classPathEntries) {
40 builder.append(delimiter).append(entry.getAbsolutePath());
41 delimiter = File.pathSeparator;
43 return builder.toString();
47 * Returns the class path entries as an array of URLs to be used for example by an
48 * {@link URLClassLoader}.
50 public URL[] asUrls ()
52 URL[] urls = new URL[_classPathEntries.size()];
54 for (File entry : _classPathEntries) {
55 urls[i++] = getURL(entry);
60 public Set<File> getClassPathEntries ()
62 return _classPathEntries;
66 private static URL getURL (File file)
69 return file.toURI().toURL();
70 } catch (MalformedURLException e) {
71 throw new IllegalStateException("URL of file is illegal: " + file.getAbsolutePath(), e);
75 private final Set<File> _classPathEntries;