Proposed enhancement to Layer API

Remi Forax forax at univ-mlv.fr
Tue Jan 3 23:33:11 UTC 2017


I agree with all the proposed methods but the one that add a package, in my opinion, a package is part of what structurally define a module, it should not be possible to add it after the resolution algorithm.

Rémi

----- Mail original -----
> De: "David M. Lloyd" <david.lloyd at redhat.com>
> À: "jigsaw-dev" <jigsaw-dev at openjdk.java.net>
> Envoyé: Mardi 3 Janvier 2017 21:45:04
> Objet: Proposed enhancement to Layer API

> This is a proposed enhancement to the Layer API, a sibling to the
> discussion around #NonHierarchicalLayers going on in the JPMS spec list.
>  While discussion is ongoing, I want to ensure that there is a "real"
> patch somewhere out in the public that can be referenced and discussed.
> 
> Essentially this patch allows our module system to achieve a basic level
> of functionality in conjunction with Jigsaw, by giving the Layer's
> Controller more control over the content and behavior of its modules.
> 
> I hereby (on behalf of myself and of my employer) submit the code in the
> patch in this email message under the terms of the MIT license, which
> (among other things) should allow the OpenJDK project to appropriate and
> modify these code changes at will without copyright assignment issues.
> 
> Here's the patch:
> 
> diff --git
> a/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
> b/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
> index 4b4588c..be013e9 100644
> --- a/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
> +++ b/jdk/src/java.base/share/classes/java/lang/reflect/Layer.java
> @@ -196,6 +196,28 @@ public final class Layer {
> 
> 
>          /**
> +         * Updates module {@code source} in the layer to contain a new
> package.
> +         * This method is a no-op if {@code source} already contains
> package {@code pn}.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name to add
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer
> +         */
> +        public Controller addPackage(Module source, String pn) {
> +            Objects.requireNonNull(source);
> +            Objects.requireNonNull(pn);
> +            ensureInLayer(source);
> +            Modules.addPackage(source, pn);
> +            return this;
> +        }
> +
> +        /**
>           * Updates module {@code source} in the layer to read module
>           * {@code target}. This method is a no-op if {@code source}
> already
>           * reads {@code target}.
> @@ -251,6 +273,160 @@ public final class Layer {
>              Modules.addOpens(source, pn, target);
>              return this;
>          }
> +
> +        /**
> +         * Updates module {@code source} in the layer to open a package to
> +         * all modules.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer or the package
> is not
> +         *         in the source module
> +         *
> +         * @see Module#addOpens
> +         */
> +        public Controller addOpensToAll(Module source, String pn) {
> +            Objects.requireNonNull(source);
> +            ensureInLayer(source);
> +            Modules.addOpensToAll(source, pn);
> +            return this;
> +        }
> +
> +        /**
> +         * Updates module {@code source} in the layer to open a package to
> +         * to all unnamed modules.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer or the package
> is not
> +         *         in the source module
> +         *
> +         * @see ModuleDescriptor.Builder#opens(String)
> +         */
> +        public Controller addOpensToAllUnnamed(Module source, String pn) {
> +            Objects.requireNonNull(source);
> +            ensureInLayer(source);
> +            Modules.addOpensToAllUnnamed(source, pn);
> +            return this;
> +        }
> +
> +        /**
> +         * Updates module {@code source} in the layer to export a
> package to
> +         * module {@code target}. This method is a no-op if {@code source}
> +         * already exports the package to at least {@code target}.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name
> +         * @param  target
> +         *         The target module to read
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer or the package
> is not
> +         *         in the source module
> +         *
> +         * @see Module#addExports
> +         */
> +        public Controller addExports(Module source, String pn, Module
> target) {
> +            Objects.requireNonNull(source);
> +            Objects.requireNonNull(target);
> +            ensureInLayer(source);
> +            Modules.addExports(source, pn, target);
> +            return this;
> +        }
> +
> +        /**
> +         * Updates module {@code source} in the layer to export a
> package to
> +         * module {@code target}. This method is a no-op if {@code source}
> +         * already exports the package to at least {@code target}.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer or the package
> is not
> +         *         in the source module
> +         *
> +         * @see Module#addExports
> +         */
> +        public Controller addExportsToAll(Module source, String pn) {
> +            Objects.requireNonNull(source);
> +            ensureInLayer(source);
> +            Modules.addExportsToAll(source, pn);
> +            return this;
> +        }
> +
> +        /**
> +         * Updates module {@code source} in the layer to export a
> package to
> +         * all unnamed modules.
> +         *
> +         * @param  source
> +         *         The source module
> +         * @param  pn
> +         *         The package name
> +         *
> +         * @return This controller
> +         *
> +         * @throws IllegalArgumentException
> +         *         If {@code source} is not in the layer or the package
> is not
> +         *         in the source module
> +         *
> +         * @see Module#addExports
> +         */
> +        public Controller addExportsToAllUnnamed(Module source, String
> pn) {
> +            Objects.requireNonNull(source);
> +            ensureInLayer(source);
> +            Modules.addExportsToAllUnnamed(source, pn);
> +            return this;
> +        }
> +
> +        /**
> +         * Updates module {@code source} in the layer to add a
> +         * service dependence on the given service type. This method is
> +         * a no-op when invoked on an unnamed module or an automatic
> module.
> +         *
> +         * <p> This method does not cause {@link
> +         * Configuration#resolveRequiresAndUses resolveRequiresAndUses}
> to be
> +         * re-run. </p>
> +         *
> +         * @param  service
> +         *         The service type
> +         *
> +         * @return this module
> +         *
> +         * @throws IllegalStateException
> +         *         If this is a named module and the caller is not this
> module
> +         *
> +         * @see Module#addUses(Class)
> +         * @see ModuleDescriptor#uses()
> +         */
> +        public Controller addUses(Module source, Class<?> service) {
> +            Objects.requireNonNull(source);
> +            Objects.requireNonNull(service);
> +            ensureInLayer(source);
> +            Modules.addUses(source, service);
> +            return this;
> +        }
> +
>      }
> 
> 
> --
> - DML


More information about the jigsaw-dev mailing list