@Test public void testGetPlanClassLoader_empty() throws Exception { final File cacheDir = new File("target/test-output/OpearFileTest/testGetPlanClassLoader_empty/cache"); if (cacheDir.exists()) { FileUtils.deleteDirectory(cacheDir); } OpearFile opearFile = new OpearFile(cacheDir, new OpearFile.OpearMetadata(new String[0], new String[0], true)); final ClassLoader parent = new URLClassLoader(new URL[0], null); assertSame("same classloader with empty classpath", parent, opearFile.getPlanClassLoader(parent)); }
@Override public ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent) { final URL[] urls = Stream.of(metadata.getPlanClassPath()) .map(name -> new File(cacheDir, name)).flatMap(file -> { if (file.isDirectory() || file.getName().endsWith(".jar")) { return compose1(File::toURI, result1(URI::toURL)).apply(file).stream(); } else { return Stream.empty(); } }) .toArray(URL[]::new); if (urls.length > 0) { return new URLClassLoader(urls, parent); } else { return parent; } }
OpearFile implements Opear { @Override public ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent) { final URL[] urls = Stream.of(metadata.getPlanClassPath()) .map(name -> new File(cacheDir, name)).flatMap(file -> { if (file.isDirectory() || file.getName().endsWith(".jar")) { return compose1(File::toURI, result1(URI::toURL)).apply(file).stream(); } else { return Stream.empty(); } }) .toArray(URL[]::new); if (urls.length > 0) { return new URLClassLoader(urls, parent); } else { return parent; } } }
OpearFile implements Opear { @Override public ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent) { final URL[] urls = Stream.of(metadata.getPlanClassPath()) .map(name -> new File(cacheDir, name)).flatMap(file -> { if (file.isDirectory() || file.getName().endsWith(".jar")) { return compose1(File::toURI, result1(URI::toURL)).apply(file).stream(); } else { return Stream.empty(); } }) .toArray(URL[]::new); if (urls.length > 0) { return new URLClassLoader(urls, parent); } else { return parent; } } OpearFile(final File cacheDir, final OpearMetadata metadata); }
OpearFile implements Opear { @Override public ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent) { final URL[] urls = Stream.of(metadata.getPlanClassPath()) .map(name -> new File(cacheDir, name)).flatMap(file -> { if (file.isDirectory() || file.getName().endsWith(".jar")) { return compose1(File::toURI, result1(URI::toURL)).apply(file).stream(); } else { return Stream.empty(); } }) .toArray(URL[]::new); if (urls.length > 0) { return new URLClassLoader(urls, parent); } else { return parent; } } OpearFile(final File cacheDir, final OpearMetadata metadata); @Override URL getDefaultPlan(); @Override Result<URL> getSpecificPlan(final @NotNull String planName); @Override ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent); static Result<OpearFile> fromDirectory(final @NotNull File directory); static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir); }
OpearFile implements Opear { @Override public ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent) { final URL[] urls = Stream.of(metadata.getPlanClassPath()) .map(name -> new File(cacheDir, name)).flatMap(file -> { if (file.isDirectory() || file.getName().endsWith(".jar")) { return compose1(File::toURI, result1(URI::toURL)).apply(file).stream(); } else { return Stream.empty(); } }) .toArray(URL[]::new); if (urls.length > 0) { return new URLClassLoader(urls, parent); } else { return parent; } } OpearFile(final File cacheDir, final OpearMetadata metadata); @Override URL getDefaultPlan(); @Override Result<URL> getSpecificPlan(final @NotNull String planName); @Override ClassLoader getPlanClassLoader(final @NotNull ClassLoader parent); static Result<OpearFile> fromDirectory(final @NotNull File directory); static Result<OpearFile> fromJar(final @NotNull JarFile jarFile, final @NotNull File cacheBaseDir); static final Attributes.Name NAME_BUNDLE_SYMBOLICNAME; static final Attributes.Name NAME_BUNDLE_VERSION; static final Attributes.Name NAME_CLASS_PATH; static final Attributes.Name NAME_OAKPAL_VERSION; static final Attributes.Name NAME_OAKPAL_PLAN; }