Search in sources :

Example 21 with ModuleDescriptor

use of java.lang.module.ModuleDescriptor in project openj9 by eclipse.

the class MyLoader method dumpModules.

private void dumpModules() {
    HashSet<Option> opts = new HashSet<>(Arrays.asList(new Option[] { Option.RETAIN_CLASS_REFERENCE, Option.SHOW_HIDDEN_FRAMES, Option.SHOW_REFLECT_FRAMES }));
    List<StackFrame> frameList = (StackWalker.getInstance(opts)).walk(s -> s.collect(Collectors.toList()));
    for (StackFrame f : frameList) {
        Module frameModule = f.getDeclaringClass().getModule();
        if ((null != frameModule)) {
            ModuleDescriptor d = frameModule.getDescriptor();
            if (null != d) {
                StackTraceElement e = f.toStackTraceElement();
                String modName = d.name();
                String expectedName = e.getModuleName();
                if (null != modName) {
                    assertEquals(modName, expectedName, "Wrong module name");
                }
                Optional<Version> modVersion = d.version();
                if (modVersion.isPresent()) {
                    String actualVersion = modVersion.get().toString();
                    String expectedVersion = e.getModuleVersion();
                    assertEquals(actualVersion, expectedVersion, "Wrong module version");
                }
                if (f.getDeclaringClass() == Thread.class) {
                    assertEquals("java.base", expectedName, "Wrong module name");
                }
            }
        }
    }
}
Also used : ModuleDescriptor(java.lang.module.ModuleDescriptor) Version(java.lang.module.ModuleDescriptor.Version) StackFrame(java.lang.StackWalker.StackFrame) Option(java.lang.StackWalker.Option) Module(java.lang.Module) HashSet(java.util.HashSet)

Aggregations

ModuleDescriptor (java.lang.module.ModuleDescriptor)21 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)12 ModuleReference (java.lang.module.ModuleReference)10 Set (java.util.Set)10 ResolvedModule (java.lang.module.ResolvedModule)9 Map (java.util.Map)9 URI (java.net.URI)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 IOException (java.io.IOException)6 Collections (java.util.Collections)6 List (java.util.List)6 Optional (java.util.Optional)6 JarFile (java.util.jar.JarFile)6 UncheckedIOException (java.io.UncheckedIOException)5 ModuleFinder (java.lang.module.ModuleFinder)5 Path (java.nio.file.Path)5 Paths (java.nio.file.Paths)5 Collectors (java.util.stream.Collectors)5