@Test public void buildPluginLoader() throws Exception { File cp1 = folder.newFolder("cp1"); File cp2 = folder.newFolder("cp2"); new File(cp1, "a").createNewFile(); new File(cp2, "b").createNewFile(); ClassLoader cl = CommandLineUtil.buildPluginLoader(getClass().getClassLoader(), Arrays.asList(cp1, cp2)); assertThat(cl.getResource("a"), is(not(nullValue()))); assertThat(cl.getResource("b"), is(not(nullValue()))); assertThat(cl.getResource("c"), is(nullValue())); }
public static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files) { if (files == null) { throw new IllegalArgumentException("files must not be null"); } List<URL> pluginLocations = new ArrayList<>(); for (File file : files) { try { if (file.exists() == false) { throw new FileNotFoundException(MessageFormat.format( "Failed to load plugin \"{0}\"", file.getAbsolutePath())); } URL url = file.toURI().toURL(); pluginLocations.add(url); } catch (IOException e) { WGLOG.warn(e, "W99001", file.getAbsolutePath()); } } ClassLoader serviceLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { URLClassLoader loader = new URLClassLoader( pluginLocations.toArray(new URL[pluginLocations.size()]), parent); return loader; }); return serviceLoader; }
CommandLineUtil { public static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files) { if (files == null) { throw new IllegalArgumentException("files must not be null"); } List<URL> pluginLocations = new ArrayList<>(); for (File file : files) { try { if (file.exists() == false) { throw new FileNotFoundException(MessageFormat.format( "Failed to load plugin \"{0}\"", file.getAbsolutePath())); } URL url = file.toURI().toURL(); pluginLocations.add(url); } catch (IOException e) { WGLOG.warn(e, "W99001", file.getAbsolutePath()); } } ClassLoader serviceLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { URLClassLoader loader = new URLClassLoader( pluginLocations.toArray(new URL[pluginLocations.size()]), parent); return loader; }); return serviceLoader; } }
CommandLineUtil { public static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files) { if (files == null) { throw new IllegalArgumentException("files must not be null"); } List<URL> pluginLocations = new ArrayList<>(); for (File file : files) { try { if (file.exists() == false) { throw new FileNotFoundException(MessageFormat.format( "Failed to load plugin \"{0}\"", file.getAbsolutePath())); } URL url = file.toURI().toURL(); pluginLocations.add(url); } catch (IOException e) { WGLOG.warn(e, "W99001", file.getAbsolutePath()); } } ClassLoader serviceLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { URLClassLoader loader = new URLClassLoader( pluginLocations.toArray(new URL[pluginLocations.size()]), parent); return loader; }); return serviceLoader; } private  CommandLineUtil(); }
CommandLineUtil { public static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files) { if (files == null) { throw new IllegalArgumentException("files must not be null"); } List<URL> pluginLocations = new ArrayList<>(); for (File file : files) { try { if (file.exists() == false) { throw new FileNotFoundException(MessageFormat.format( "Failed to load plugin \"{0}\"", file.getAbsolutePath())); } URL url = file.toURI().toURL(); pluginLocations.add(url); } catch (IOException e) { WGLOG.warn(e, "W99001", file.getAbsolutePath()); } } ClassLoader serviceLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { URLClassLoader loader = new URLClassLoader( pluginLocations.toArray(new URL[pluginLocations.size()]), parent); return loader; }); return serviceLoader; } private  CommandLineUtil(); static void prepareRuntimeContext(); static void prepareLogContext(); static String toName(URI uri); static URI toUri(String path); static Properties loadProperties(URI path, ClassLoader loader); static List<File> parseFileList(String fileListOrNull); static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files); static ParameterList parseArguments(String arguments); }
CommandLineUtil { public static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files) { if (files == null) { throw new IllegalArgumentException("files must not be null"); } List<URL> pluginLocations = new ArrayList<>(); for (File file : files) { try { if (file.exists() == false) { throw new FileNotFoundException(MessageFormat.format( "Failed to load plugin \"{0}\"", file.getAbsolutePath())); } URL url = file.toURI().toURL(); pluginLocations.add(url); } catch (IOException e) { WGLOG.warn(e, "W99001", file.getAbsolutePath()); } } ClassLoader serviceLoader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { URLClassLoader loader = new URLClassLoader( pluginLocations.toArray(new URL[pluginLocations.size()]), parent); return loader; }); return serviceLoader; } private  CommandLineUtil(); static void prepareRuntimeContext(); static void prepareLogContext(); static String toName(URI uri); static URI toUri(String path); static Properties loadProperties(URI path, ClassLoader loader); static List<File> parseFileList(String fileListOrNull); static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files); static ParameterList parseArguments(String arguments); static final String LOG_CONTEXT_PREFIX; static final String SCHEME_CLASSPATH; }