Add sample project to test the maven plugin

This commit is contained in:
Johan Maasing 2025-05-04 15:04:47 +02:00
parent 46da5c5019
commit 790be88cd7
7 changed files with 186 additions and 46 deletions

View file

@ -1,8 +1,35 @@
# References
## Maven
# Configure
https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#generatedsourcesdirectory
Add the following to your `pom.xml`
### For executing the plugin several times
See executions
https://maven.apache.org/guides/mini/guide-configuring-plugins.html
```xml
<build>
<plugins>
<plugin>
<groupId>nu.zoom.dsl</groupId>
<artifactId>endgen-maven-plugin</artifactId>
<version>1.2-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>endgen</goal>
</goals>
<configuration>
<templates>${project.basedir}/src/main/endpoint-templates</templates>
<dsl>${project.basedir}/src/main/endgen/test01.endpoints</dsl>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
Replace the `<version>` with the latest published version of the endgen plugin.
* `templates` should point to the template directory to use.
* `dsl` should be the file to generate code from.
* `output` can be used to specify the directory where the generated files are written. Default is `${project.build.directory}/generated-sources/endgen`.
* `parser` can be used to force the use of either the `Endpoints` or the `States` parser. Default is to determined by looking at the file ending of the dsl-file.
If you have several DSL-files that you wish to generate from you can repeat the `<execution>` block with other configurations.

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -33,37 +34,4 @@
<version>${project.parent.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${maven-plugin-tools.version}</version>
<executions>
<execution>
<id>help-mojo</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>nu.zoom.dsl</groupId>
<artifactId>endgen-maven-plugin</artifactId>
<version>1.2-SNAPSHOT</version>
<executions>
<execution>
<configuration>
<templates>${project.build.sourceDirectory}/main/endgen-templates</templates>
<output>${project.build.sourceDirectory}/generated-sources/endgen endpoints-output</output>
<dsl>${project.basedir}/../test01.endpoints</dsl>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View file

@ -17,23 +17,27 @@ import java.util.Optional;
defaultPhase = LifecyclePhase.GENERATE_SOURCES
)
public class EndgenMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.sourceDirectory}/main/endgen-templates")
@Parameter(
name = "templates",
defaultValue = "${project.build.sourceDirectory}/main/endgen-templates"
)
File templates;
@Parameter(defaultValue = "${project.build.outputDirectory}/generated-sources/endgen")
@Parameter(
name = "output",
defaultValue = "${project.build.directory}/generated-sources/endgen"
)
File output;
@Parameter
@Parameter(name = "dsl", required = true)
File dsl;
@Parameter
@Parameter(name = "parser")
String parser;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Running endgen");
getLog().info("Using dsl: " + dsl);
try {
Runner.run(
optional(dsl).map(File::toPath).orElseThrow(),