lbownik commented on code in PR #3860:
URL: https://github.com/apache/netbeans/pull/3860#discussion_r922626727
##########
platform/o.n.bootstrap/test/unit/src/org/netbeans/JarClassLoaderTest.java:
##########
@@ -414,4 +425,65 @@ public static void initialize(String path, Semaphore sync)
{
public @Override void checkPermission(Permission perm, Object ctx) {}
}
+
+ public void testMultiReleaseJar() throws Exception {
+ clearWorkDir();
+ File classes = new File(getWorkDir(), "classes");
+ classes.mkdirs();
+ ToolProvider.getSystemJavaCompiler()
+ .getTask(null, null, d -> { throw new
IllegalStateException(d.toString()); }, Arrays.asList("-d",
classes.getAbsolutePath()), null,
+ Arrays.asList(new
SourceFileObject("test/Impl.java", "package test; public class Impl { public
static String get() { return \"base\"; } }"),
+ new
SourceFileObject("api/API.java", "package api; public class API { public static
String run() { return test.Impl.get(); } }")))
+ .call();
+ File classes9 = new File(new File(new File(classes, "META-INF"),
"versions"), "9");
+ classes9.mkdirs();
+ ToolProvider.getSystemJavaCompiler()
+ .getTask(null, null, d -> { throw new
IllegalStateException(d.toString()); }, Arrays.asList("-d",
classes9.getAbsolutePath(), "-classpath", classes.getAbsolutePath()), null,
+ Arrays.asList(new
SourceFileObject("test/Impl.java", "package test; public class Impl { public
static String get() { return \"9\"; } }")))
+ .call();
+ Map<String, byte[]> jarContent = new LinkedHashMap<>();
+ jarContent.put("META-INF/MANIFEST.MF", "Manifest-Version:
1.0\nMulti-Release: true\n\n".getBytes());
+ Path classesPath = classes.toPath();
+ Files.walk(classesPath)
+ .filter(p -> Files.isRegularFile(p))
+ .forEach(p -> {
+ try {
+ jarContent.put(classesPath.relativize(p).toString(),
TestFileUtils.readFileBin(p.toFile()));
+ } catch (IOException ex) {
+ throw new IllegalStateException(ex);
+ }
+ });
+ File jar = new File(getWorkDir(), "multi-release.jar");
+ try (OutputStream out = new FileOutputStream(jar)) {
+ TestFileUtils.writeZipFile(out, jarContent);
+ }
+ JarClassLoader jcl = new JarClassLoader(Arrays.asList(jar), new
ProxyClassLoader[0]);
+ Class<?> api = jcl.loadClass("api.API");
+ Method run = api.getDeclaredMethod("run");
+ String output = (String) run.invoke(null);
+ String expected;
+ try {
Review Comment:
How about estracting this try-catch into a private method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists