From 790be88cd763f0324f57207a065124c9684022cb Mon Sep 17 00:00:00 2001 From: Johan Maasing Date: Sun, 4 May 2025 15:04:47 +0200 Subject: [PATCH] Add sample project to test the maven plugin --- endgen-maven-plugin/README.md | 39 +++++++++-- endgen-maven-plugin/pom.xml | 36 +--------- .../java/nu/zoom/dsl/maven/EndgenMojo.java | 16 +++-- sample-maven/pom.xml | 70 +++++++++++++++++++ sample-maven/src/main/endgen/test01.endpoints | 28 ++++++++ sample-maven/src/main/endgen/test01.states | 21 ++++++ .../nu/zoom/dsl/sample/Endpoints.java.ftl | 22 ++++++ 7 files changed, 186 insertions(+), 46 deletions(-) create mode 100644 sample-maven/pom.xml create mode 100644 sample-maven/src/main/endgen/test01.endpoints create mode 100644 sample-maven/src/main/endgen/test01.states create mode 100644 sample-maven/src/main/endpoint-templates/nu/zoom/dsl/sample/Endpoints.java.ftl diff --git a/endgen-maven-plugin/README.md b/endgen-maven-plugin/README.md index 1e02921..3df592d 100644 --- a/endgen-maven-plugin/README.md +++ b/endgen-maven-plugin/README.md @@ -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 \ No newline at end of file +```xml + + + + nu.zoom.dsl + endgen-maven-plugin + 1.2-SNAPSHOT + + + + endgen + + + ${project.basedir}/src/main/endpoint-templates + ${project.basedir}/src/main/endgen/test01.endpoints + + + + + + +``` + +Replace the `` 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 `` block with other configurations. \ No newline at end of file diff --git a/endgen-maven-plugin/pom.xml b/endgen-maven-plugin/pom.xml index e9f42c5..77bfe12 100644 --- a/endgen-maven-plugin/pom.xml +++ b/endgen-maven-plugin/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 @@ -33,37 +34,4 @@ ${project.parent.version} - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${maven-plugin-tools.version} - - - help-mojo - - helpmojo - - - - - - nu.zoom.dsl - endgen-maven-plugin - 1.2-SNAPSHOT - - - - ${project.build.sourceDirectory}/main/endgen-templates - ${project.build.sourceDirectory}/generated-sources/endgen endpoints-output - ${project.basedir}/../test01.endpoints - - - - - - - \ No newline at end of file diff --git a/endgen-maven-plugin/src/main/java/nu/zoom/dsl/maven/EndgenMojo.java b/endgen-maven-plugin/src/main/java/nu/zoom/dsl/maven/EndgenMojo.java index 8d204aa..757eee5 100644 --- a/endgen-maven-plugin/src/main/java/nu/zoom/dsl/maven/EndgenMojo.java +++ b/endgen-maven-plugin/src/main/java/nu/zoom/dsl/maven/EndgenMojo.java @@ -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(), diff --git a/sample-maven/pom.xml b/sample-maven/pom.xml new file mode 100644 index 0000000..99fdbab --- /dev/null +++ b/sample-maven/pom.xml @@ -0,0 +1,70 @@ + + + + 4.0.0 + + nu.zoom.dsl + sample-maven + 1.0-SNAPSHOT + jar + + + 21 + 21 + UTF-8 + + + + + ASF 2.0 + https://www.apache.org/licenses/LICENSE-2.0 + + + + + + Johan Maasing + johan@zoom.nu + + developer + + + + + + + + nu.zoom.dsl + endgen-maven-plugin + 1.2-SNAPSHOT + + + + endgen + + + ${project.basedir}/src/main/endpoint-templates + ${project.basedir}/src/main/endgen/test01.endpoints + + + + + + + + diff --git a/sample-maven/src/main/endgen/test01.endpoints b/sample-maven/src/main/endgen/test01.endpoints new file mode 100644 index 0000000..6f212ed --- /dev/null +++ b/sample-maven/src/main/endgen/test01.endpoints @@ -0,0 +1,28 @@ +/* + Copyright 2025 "Johan Maasing" + + 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) +/yet/other/endpoint3 <- (bar2:Seq[AType]) -> (foo:Bar) diff --git a/sample-maven/src/main/endgen/test01.states b/sample-maven/src/main/endgen/test01.states new file mode 100644 index 0000000..3b9a67a --- /dev/null +++ b/sample-maven/src/main/endgen/test01.states @@ -0,0 +1,21 @@ +/* + Copyright 2025 "Johan Maasing" + + 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 diff --git a/sample-maven/src/main/endpoint-templates/nu/zoom/dsl/sample/Endpoints.java.ftl b/sample-maven/src/main/endpoint-templates/nu/zoom/dsl/sample/Endpoints.java.ftl new file mode 100644 index 0000000..624c722 --- /dev/null +++ b/sample-maven/src/main/endpoint-templates/nu/zoom/dsl/sample/Endpoints.java.ftl @@ -0,0 +1,22 @@ +// Copyright 2025 "Johan Maasing" +// +// 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>.; + +class Endpoints() { +<#list endpoints as endpoint> + /* <#list endpoint.paths.paths><#items as segment>/${segment} */ + public void handle${endpoint.inputType?cap_first} + + +} \ No newline at end of file