LPhy Extension Mechanism
The LPhy extension mechanism is implemented using the Service Provider Interface (SPI)
and the Java Platform Module System (JPMS).
An LPhy extension has to be a Java module, which also needs to implement the interface
LPhyExtension.java
to provide a list of the required classes to extend the functionality of LPhy.
Project structure
The LPhy repository contains two modules
separated in two subfolder, where lphy
contains core classes, such as parser, distributions, functions and data types,
and lphy-studio
are GUI. The project folder structure looks like:
linguaPhylo
├── build.gradle.kts
├── examples
├── lphy
│ ├── build.gradle.kts
│ ├── doc
│ └── src
│ ├── main
│ │ ├── java
│ │ │ ├── lphy
│ │ │ └── module-info.java
│ │ └── resources
│ └── test
│
├──lphy-studio
│ ├── build.gradle.kts
│ └── src
│ ├── main
│ │ ├── java
│ │ │ ├── lphystudio
│ │ │ └── module-info.java
│ │ └── resources
│ └── test
├──settings.gradle.kts
└──tutorials
SPI and the extension’s container provider class
The module lphy
declares the package dependencies and SPI LPhyExtension
using the following code.
Because we consider the core itself as an extension, the Container Provider class LPhyExtImpl
is also required to declare in this module using the following one-line code.
Here is the source code of SPI in LPhy :
Then the Container Provider class LPhyExtImpl
lists all classes required to be extended:
GenerativeDistribution, Func, and SequenceType.
These two classes can be seen from the package lphy.spi.
In the next sub-project lphy-studio
, even though it is not going to extend anything from lphy
,
we still create an empty class LPhyStudioImpl as a flag to make it recognised by the extension mechanism.
Setting up
The project is migrated to a Gradle project from version 1.1.0. How to set up the project is available in the developer note.