maven #1
7 changed files with 186 additions and 46 deletions
|
@ -1,8 +1,35 @@
|
||||||
# References
|
# Configure
|
||||||
## Maven
|
|
||||||
|
|
||||||
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
|
```xml
|
||||||
See executions
|
<build>
|
||||||
https://maven.apache.org/guides/mini/guide-configuring-plugins.html
|
<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.
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
@ -33,37 +34,4 @@
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</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>
|
</project>
|
|
@ -17,23 +17,27 @@ import java.util.Optional;
|
||||||
defaultPhase = LifecyclePhase.GENERATE_SOURCES
|
defaultPhase = LifecyclePhase.GENERATE_SOURCES
|
||||||
)
|
)
|
||||||
public class EndgenMojo extends AbstractMojo {
|
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;
|
File templates;
|
||||||
|
|
||||||
@Parameter(defaultValue = "${project.build.outputDirectory}/generated-sources/endgen")
|
@Parameter(
|
||||||
|
name = "output",
|
||||||
|
defaultValue = "${project.build.directory}/generated-sources/endgen"
|
||||||
|
)
|
||||||
File output;
|
File output;
|
||||||
|
|
||||||
@Parameter
|
@Parameter(name = "dsl", required = true)
|
||||||
File dsl;
|
File dsl;
|
||||||
|
|
||||||
@Parameter
|
@Parameter(name = "parser")
|
||||||
String parser;
|
String parser;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
getLog().info("Running endgen");
|
|
||||||
getLog().info("Using dsl: " + dsl);
|
|
||||||
try {
|
try {
|
||||||
Runner.run(
|
Runner.run(
|
||||||
optional(dsl).map(File::toPath).orElseThrow(),
|
optional(dsl).map(File::toPath).orElseThrow(),
|
||||||
|
|
70
sample-maven/pom.xml
Normal file
70
sample-maven/pom.xml
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
// Copyright 2025 "Johan Maasing" <johan@zoom.nu>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
-->
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>sample-maven</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>ASF 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<name>Johan Maasing</name>
|
||||||
|
<email>johan@zoom.nu</email>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
</project>
|
28
sample-maven/src/main/endgen/test01.endpoints
Normal file
28
sample-maven/src/main/endgen/test01.endpoints
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
Copyright 2025 "Johan Maasing" <johan@zoom.nu>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
some: configvalue,
|
||||||
|
someother: value,
|
||||||
|
package: se.rutdev.senash
|
||||||
|
}
|
||||||
|
|
||||||
|
/some/endpoint <- SomeType(foo:String)
|
||||||
|
Embedded(foo:Bar)
|
||||||
|
/some/other/endpoint <- (bar:Seq[Embedded])
|
||||||
|
/yet/other/endpoint2 <- (bar2:Seq[AType]) -> NamedResponse(foo:Bar)
|
||||||
|
AType(data: java.util.List<String>)
|
||||||
|
/yet/other/endpoint3 <- (bar2:Seq[AType]) -> (foo:Bar)
|
21
sample-maven/src/main/endgen/test01.states
Normal file
21
sample-maven/src/main/endgen/test01.states
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
Copyright 2025 "Johan Maasing" <johan@zoom.nu>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{ title: SomeNodes, package: nu.zoom.dsl.states }
|
||||||
|
|
||||||
|
start(s:S) -> message(foo:foo) -> middle(foo:foo) ,
|
||||||
|
middle -> selfmessage(bar:bar) -> middle(bar:bar),
|
||||||
|
middle -> message(bar:baz) -> end
|
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2025 "Johan Maasing" <johan@zoom.nu>
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
<#list meta.templateDirectories>package<#items as dir>${dir}<#sep>.</#items>;</#list>
|
||||||
|
|
||||||
|
class Endpoints() {
|
||||||
|
<#list endpoints as endpoint>
|
||||||
|
/* <#list endpoint.paths.paths><#items as segment>/${segment}</#items></#list> */
|
||||||
|
public void handle${endpoint.inputType?cap_first}
|
||||||
|
|
||||||
|
</#list>
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue