Fix packaging

This commit is contained in:
Johan Maasing 2025-04-12 19:59:44 +02:00
parent 19e2d46dd0
commit 1abc1a3164
8 changed files with 144 additions and 25 deletions

View file

@ -19,6 +19,41 @@ separate files (for endpoint-definitions, circe serializer support etc).
So I wrote a [DSL](https://en.wikipedia.org/wiki/Domain-specific_language) parsed by an [ANTLR4](https://www.antlr.org)
parser and a code generator using [freemarker](https://freemarker.apache.org).
```
| Endgen |
-------------------------------------------------
----------- ||--------| |-----------| |------------||
| endpoint | || Parser | | In-Memory | | Freemarker || ---------------
| file | --> || | --> | AST | --> | engine || --> | Output file |
\__________\ ||--------| |-----------| |------------|| \_____________\
------------------------------------------------- -
^
|
----------------
| Template.ftl |
\_______________\
```
## How to Run
You need a Java 24 runtime and java in the path. A very convenient way to install a java runtime is [SdkMan](https://sdkman.io).
Unpack the archive, run the provided shellscript file.
### Usage
```
Usage: EndpointsCLI [-hvV] [-o=<outputDir>] [-t=<templateDir>] <file>
Generate source code from an endpoints specification file.
<file> The source endpoints DSL file.
-h, --help Show this help message and exit.
-o, --output=<outputDir> The directory to write the generated code to.
Default is ~/endpoints-output
-t, --template=<templateDir>
The template directory. Default is
~/endpoints-templates
-v, --verbose Print verbose debug messages.
-V, --version Print version information and exit.
```
## DSL example
In the simplest form the DSL looks like this

View file

@ -1,23 +0,0 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nu.zoom.dsl</groupId>
<artifactId>endgen</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>assembly</artifactId>
<dependencies>
<dependency>
<groupId>nu.zoom.dsl</groupId>
<artifactId>parser</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

46
endgen-dist/pom.xml Normal file
View file

@ -0,0 +1,46 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>nu.zoom.dsl</groupId>
<artifactId>endgen</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>endgen-dist</artifactId>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>nu.zoom.dsl</groupId>
<artifactId>parser</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,44 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
<id>bin</id>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>endgen-${project.version}</baseDirectory>
<formats>
<format>dir</format>
<format>zip</format>
</formats>
<files>
<file>
<source>src/main/resources/run.sh</source>
<outputDirectory></outputDirectory>
<filtered>true</filtered>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory>libs</outputDirectory>
<excludes>
<exclude>nu.zoom.dsl:parser:*</exclude>
</excludes>
<useStrictFiltering>true</useStrictFiltering>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
<dependencySet>
<outputDirectory></outputDirectory>
<includes>
<include>nu.zoom.dsl:parser:*</include>
</includes>
<useStrictFiltering>true</useStrictFiltering>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>

View file

@ -0,0 +1,4 @@
#! /bin/sh
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "${SCRIPT_DIR}"
java -jar parser-${artifact.baseVersion}.jar

View file

@ -56,6 +56,19 @@
<target>24</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<classpathPrefix>libs/</classpathPrefix>
<addClasspath>true</addClasspath>
<mainClass>nu.zoom.dsl.cli.EndpointsCLI</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Plugin to compile the g4 files ahead of the java files
See https://github.com/antlr/antlr4/blob/master/antlr4-maven-plugin/src/site/apt/examples/simple.apt.vm
Except that the grammar does not need to contain the package declaration as stated in the documentation (I do not know why)

View file

@ -29,7 +29,7 @@ import java.util.List;
import java.util.concurrent.Callable;
@Command(
name = "EndpointsCLI",
name = "run.sh",
mixinStandardHelpOptions = true,
description = "Generate source code from an endpoints specification file."
)

View file

@ -32,7 +32,7 @@
<modules>
<module>parser</module>
<module>assembly</module>
<module>endgen-dist</module>
</modules>
</project>