39 import jdk.tools.jlink.plugin.ResourcePool; 40 import jdk.tools.jlink.plugin.ResourcePoolBuilder; 41 import jdk.tools.jlink.plugin.ResourcePoolEntry; 42 import jdk.tools.jlink.plugin.ResourcePoolModule; 43 import jdk.tools.jlink.plugin.ResourcePoolModuleView; 44 import jdk.tools.jlink.plugin.PluginException; 45 46 /** 47 * A manager for pool of resources. 48 */ 49 public class ResourcePoolManager { 50 // utility to read ModuleDescriptor of the given ResourcePoolModule 51 static ModuleDescriptor readModuleDescriptor(ResourcePoolModule mod) { 52 String p = "/" + mod.name() + "/module-info.class"; 53 Optional<ResourcePoolEntry> content = mod.findEntry(p); 54 if (!content.isPresent()) { 55 throw new PluginException("No module-info for " + mod.name() 56 + " module"); 57 } 58 ByteBuffer bb = ByteBuffer.wrap(content.get().contentBytes()); 59 return ModuleDescriptor.read(bb); 60 } 61 62 /** 63 * Returns true if a resource has an effective package. 64 */ 65 public static boolean isNamedPackageResource(String path) { 66 return (path.endsWith(".class") && !path.endsWith("module-info.class")) || 67 !ResourceHelper.isSimpleResource(path); 68 } 69 70 class ResourcePoolModuleImpl implements ResourcePoolModule { 71 72 final Map<String, ResourcePoolEntry> moduleContent = new LinkedHashMap<>(); 73 // lazily initialized 74 private ModuleDescriptor descriptor; 75 final String name; 76 77 private ResourcePoolModuleImpl(String name) { 78 this.name = name; 79 } | 39 import jdk.tools.jlink.plugin.ResourcePool; 40 import jdk.tools.jlink.plugin.ResourcePoolBuilder; 41 import jdk.tools.jlink.plugin.ResourcePoolEntry; 42 import jdk.tools.jlink.plugin.ResourcePoolModule; 43 import jdk.tools.jlink.plugin.ResourcePoolModuleView; 44 import jdk.tools.jlink.plugin.PluginException; 45 46 /** 47 * A manager for pool of resources. 48 */ 49 public class ResourcePoolManager { 50 // utility to read ModuleDescriptor of the given ResourcePoolModule 51 static ModuleDescriptor readModuleDescriptor(ResourcePoolModule mod) { 52 String p = "/" + mod.name() + "/module-info.class"; 53 Optional<ResourcePoolEntry> content = mod.findEntry(p); 54 if (!content.isPresent()) { 55 throw new PluginException("No module-info for " + mod.name() 56 + " module"); 57 } 58 ByteBuffer bb = ByteBuffer.wrap(content.get().contentBytes()); 59 try { 60 return ModuleDescriptor.read(bb); 61 } catch (RuntimeException re) { 62 throw new RuntimeException("module descriptor cannot be read for " + mod.name(), re); 63 } 64 } 65 66 /** 67 * Returns true if a resource has an effective package. 68 */ 69 public static boolean isNamedPackageResource(String path) { 70 return (path.endsWith(".class") && !path.endsWith("module-info.class")) || 71 !ResourceHelper.isSimpleResource(path); 72 } 73 74 class ResourcePoolModuleImpl implements ResourcePoolModule { 75 76 final Map<String, ResourcePoolEntry> moduleContent = new LinkedHashMap<>(); 77 // lazily initialized 78 private ModuleDescriptor descriptor; 79 final String name; 80 81 private ResourcePoolModuleImpl(String name) { 82 this.name = name; 83 } |