< prev index next >

src/java.base/share/classes/jdk/internal/module/Modules.java

Print this page




  65      * The URI is for information purposes only.
  66      */
  67     public static Module defineModule(ClassLoader loader,
  68                                       ModuleDescriptor descriptor,
  69                                       URI uri)
  70     {
  71         return JLRMA.defineModule(loader, descriptor, uri);
  72     }
  73 
  74     /**
  75      * Define a new module to the VM. The module has the given set of
  76      * packages and is defined to the given class loader.
  77      *
  78      * The resulting Module is in a larval state in that it does not not read
  79      * any other module and does not have any exports.
  80      */
  81     public static Module defineModule(ClassLoader loader,
  82                                       String name,
  83                                       Set<String> packages)
  84     {
  85         ModuleDescriptor descriptor = ModuleDescriptor.module(name)
  86                 .contains(packages)
  87                 .build();
  88 
  89         return JLRMA.defineModule(loader, descriptor, null);
  90     }
  91 
  92     /**
  93      * Adds a read-edge so that module {@code m1} reads module {@code m1}.
  94      * Same as m1.addReads(m2) but without a caller check.
  95      */
  96     public static void addReads(Module m1, Module m2) {
  97         JLRMA.addReads(m1, m2);
  98     }
  99 
 100     /**
 101      * Update module {@code m} to read all unnamed modules.
 102      */
 103     public static void addReadsAllUnnamed(Module m) {
 104         JLRMA.addReadsAllUnnamed(m);
 105     }
 106 


 168             ServicesCatalog catalog;
 169             if (loader == null) {
 170                 catalog = BootLoader.getServicesCatalog();
 171             } else {
 172                 catalog = ServicesCatalog.getServicesCatalog(loader);
 173             }
 174             catalog.addProvider(m, service, impl);
 175         }
 176 
 177         if (layer != null) {
 178             // update Layer catalog
 179             SharedSecrets.getJavaLangReflectModuleAccess()
 180                     .getServicesCatalog(layer)
 181                     .addProvider(m, service, impl);
 182         }
 183     }
 184 
 185     /**
 186      * Adds a package to a module's content.
 187      *
 188      * This method is a no-op if the module already contains the package.

 189      */
 190     public static void addPackage(Module m, String pn) {
 191         JLRMA.addPackage(m, pn);
 192     }
 193 
 194     /**
 195      * Called by the VM when code in the given Module has been transformed by
 196      * an agent and so may have been instrumented to call into supporting
 197      * classes on the boot class path or application class path.
 198      */
 199     public static void transformedByAgent(Module m) {
 200         addReads(m, BootLoader.getUnnamedModule());
 201         addReads(m, ClassLoaders.appClassLoader().getUnnamedModule());
 202     }
 203 }


  65      * The URI is for information purposes only.
  66      */
  67     public static Module defineModule(ClassLoader loader,
  68                                       ModuleDescriptor descriptor,
  69                                       URI uri)
  70     {
  71         return JLRMA.defineModule(loader, descriptor, uri);
  72     }
  73 
  74     /**
  75      * Define a new module to the VM. The module has the given set of
  76      * packages and is defined to the given class loader.
  77      *
  78      * The resulting Module is in a larval state in that it does not not read
  79      * any other module and does not have any exports.
  80      */
  81     public static Module defineModule(ClassLoader loader,
  82                                       String name,
  83                                       Set<String> packages)
  84     {
  85         ModuleDescriptor descriptor = ModuleDescriptor.newModule(name)
  86                 .packages(packages)
  87                 .build();
  88 
  89         return JLRMA.defineModule(loader, descriptor, null);
  90     }
  91 
  92     /**
  93      * Adds a read-edge so that module {@code m1} reads module {@code m1}.
  94      * Same as m1.addReads(m2) but without a caller check.
  95      */
  96     public static void addReads(Module m1, Module m2) {
  97         JLRMA.addReads(m1, m2);
  98     }
  99 
 100     /**
 101      * Update module {@code m} to read all unnamed modules.
 102      */
 103     public static void addReadsAllUnnamed(Module m) {
 104         JLRMA.addReadsAllUnnamed(m);
 105     }
 106 


 168             ServicesCatalog catalog;
 169             if (loader == null) {
 170                 catalog = BootLoader.getServicesCatalog();
 171             } else {
 172                 catalog = ServicesCatalog.getServicesCatalog(loader);
 173             }
 174             catalog.addProvider(m, service, impl);
 175         }
 176 
 177         if (layer != null) {
 178             // update Layer catalog
 179             SharedSecrets.getJavaLangReflectModuleAccess()
 180                     .getServicesCatalog(layer)
 181                     .addProvider(m, service, impl);
 182         }
 183     }
 184 
 185     /**
 186      * Adds a package to a module's content.
 187      *
 188      * This method is a no-op if the module already contains the package or the
 189      * module is an unnamed module.
 190      */
 191     public static void addPackage(Module m, String pn) {
 192         JLRMA.addPackage(m, pn);
 193     }
 194 
 195     /**
 196      * Called by the VM when code in the given Module has been transformed by
 197      * an agent and so may have been instrumented to call into supporting
 198      * classes on the boot class path or application class path.
 199      */
 200     public static void transformedByAgent(Module m) {
 201         addReads(m, BootLoader.getUnnamedModule());
 202         addReads(m, ClassLoaders.appClassLoader().getUnnamedModule());
 203     }
 204 }
< prev index next >