Add "source of module name" to ModuleDescriptor API

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Add "source of module name" to ModuleDescriptor API

Christian Stein
Hi,

at the moment, class `java.lang.module.ModuleDescriptor` only
provides an `isAutomatic()` getter -- which doesn't allow to
determine from where the module name actually came from.

Program `PresentModule.java` [1] creates a `JarFile` instance
to determine the source of an automatic module.

As the module name is resolved by the runtime from a
specific source, it could be stored as a constant in the
`ModuleDescriptor` instance at resolution time.

I propose to extend the `ModuleDescriptor` class with a

  public enum NameSource {
    FILENAME, MANIFEST, DESCRIPTOR
  }

and an accessor:

  public NameSource nameSource { return ... }

Cheers,
Christian

[1] https://github.com/sormuras/modules/blob/master/src/PresentModule.java
Reply | Threaded
Open this post in threaded view
|

Re: Add "source of module name" to ModuleDescriptor API

Alan Bateman
On 02/07/2019 09:47, Christian Stein wrote:

> Hi,
>
> at the moment, class `java.lang.module.ModuleDescriptor` only
> provides an `isAutomatic()` getter -- which doesn't allow to
> determine from where the module name actually came from.
>
> Program `PresentModule.java` [1] creates a `JarFile` instance
> to determine the source of an automatic module.
>
> As the module name is resolved by the runtime from a
> specific source, it could be stored as a constant in the
> `ModuleDescriptor` instance at resolution time.
>
> I propose to extend the `ModuleDescriptor` class with a
>
>    public enum NameSource {
>      FILENAME, MANIFEST, DESCRIPTOR
>    }
>
> and an accessor:
>
>    public NameSource nameSource { return ... }
>
ModuleDescriptor just describes a named module and doesn't care how the
module name came about when creating an automatic module. Anything
working with module locations should use a ModuleReference as it defines
the "location" method to get a URI to the module content (if possible).
So probably better if tools like this used a ModuleReference and special
cased the JAR case  when they want to know if the module name was
derived from the JAR file name or came from the value of the
Automatic-Module-Name attribute.

-Alan
Reply | Threaded
Open this post in threaded view
|

Re: Add "source of module name" to ModuleDescriptor API

Christian Stein
On Tue, Jul 2, 2019 at 1:14 PM Alan Bateman <[hidden email]> wrote:

> On 02/07/2019 09:47, Christian Stein wrote:
> > Hi,
> >
> > at the moment, class `java.lang.module.ModuleDescriptor` only
> > provides an `isAutomatic()` getter -- which doesn't allow to
> > determine from where the module name actually came from.
> >
> > Program `PresentModule.java` [1] creates a `JarFile` instance
> > to determine the source of an automatic module.
> >
> > As the module name is resolved by the runtime from a
> > specific source, it could be stored as a constant in the
> > `ModuleDescriptor` instance at resolution time.
> >
> > I propose to extend the `ModuleDescriptor` class with a
> >
> >    public enum NameSource {
> >      FILENAME, MANIFEST, DESCRIPTOR
> >    }
> >
> > and an accessor:
> >
> >    public NameSource nameSource { return ... }
> >
> ModuleDescriptor just describes a named module and doesn't care how the
> module name came about when creating an automatic module. Anything
> working with module locations should use a ModuleReference as it defines
> the "location" method to get a URI to the module content (if possible).
> So probably better if tools like this used a ModuleReference and special
> cased the JAR case  when they want to know if the module name was
> derived from the JAR file name or came from the value of the
> Automatic-Module-Name attribute.
>
> -Alan
>

 Thank you for the clarification, Alan.

Wondering why `isAutomatic()` is part of the API then. Its underlying
value is also not declared by the author of the module, but rather
determined at/by the runtime.
Reply | Threaded
Open this post in threaded view
|

Re: Add "source of module name" to ModuleDescriptor API

Alan Bateman
On 04/07/2019 07:40, Christian Stein wrote:
> :
>
>  Thank you for the clarification, Alan.
>
> Wondering why `isAutomatic()` is part of the API then. Its underlying
> value is also not declared by the author of the module, but rather
> determined at/by the runtime.
>
Automatic modules require special treatment so it's very important that
the runtime or other programs using the ModuleDescriptor API know if the
module is an automatic module or not. This isn't the same thing as
knowing how the name was generated as most programs shouldn't care about
that, e.g. modules generated at run-time will be named by whatever
system generates them.

-Alan