needs testing
This commit is contained in:
parent
e0922d5639
commit
46da5c5019
16 changed files with 406 additions and 36 deletions
8
endgen-maven-plugin/README.md
Normal file
8
endgen-maven-plugin/README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# References
|
||||
## Maven
|
||||
|
||||
https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#generatedsourcesdirectory
|
||||
|
||||
### For executing the plugin several times
|
||||
See executions
|
||||
https://maven.apache.org/guides/mini/guide-configuring-plugins.html
|
69
endgen-maven-plugin/pom.xml
Normal file
69
endgen-maven-plugin/pom.xml
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?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.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>endgen-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<properties>
|
||||
<maven-plugin-tools.version>3.15.1</maven-plugin-tools.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>3.9.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- dependency on annotations -->
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>${maven-plugin-tools.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nu.zoom.dsl</groupId>
|
||||
<artifactId>parser</artifactId>
|
||||
<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>
|
|
@ -0,0 +1,64 @@
|
|||
package nu.zoom.dsl.maven;
|
||||
|
||||
import nu.zoom.dsl.run.Runner;
|
||||
import nu.zoom.dsl.run.ValidationException;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mojo(
|
||||
name = "endgen",
|
||||
defaultPhase = LifecyclePhase.GENERATE_SOURCES
|
||||
)
|
||||
public class EndgenMojo extends AbstractMojo {
|
||||
@Parameter(defaultValue = "${project.build.sourceDirectory}/main/endgen-templates")
|
||||
File templates;
|
||||
|
||||
@Parameter(defaultValue = "${project.build.outputDirectory}/generated-sources/endgen")
|
||||
File output;
|
||||
|
||||
@Parameter
|
||||
File dsl;
|
||||
|
||||
@Parameter
|
||||
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(),
|
||||
optional(templates).map(File::toPath),
|
||||
optional(output).map(File::toPath),
|
||||
getParserType(parser),
|
||||
new MavenLogger(getLog())
|
||||
);
|
||||
} catch (Exception e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Runner.ParserType> getParserType(final String type) throws ValidationException {
|
||||
if (type == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try {
|
||||
return Optional.of(Runner.ParserType.valueOf(type));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ValidationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> Optional<T> optional(T arg) {
|
||||
return arg == null ? Optional.empty() : Optional.of(arg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package nu.zoom.dsl.maven;
|
||||
|
||||
import nu.zoom.dsl.run.Logger;
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
|
||||
public class MavenLogger implements Logger {
|
||||
private final Log delegate;
|
||||
|
||||
public MavenLogger(Log delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String message) {
|
||||
this.delegate.debug(message);
|
||||
}
|
||||
}
|
52
endgen-maven-plugin/src/main/java/nu/zoom/dsl/maven/Run.java
Normal file
52
endgen-maven-plugin/src/main/java/nu/zoom/dsl/maven/Run.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package nu.zoom.dsl.maven;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Run {
|
||||
private File templates;
|
||||
private File output;
|
||||
private File dsl;
|
||||
private String parser;
|
||||
|
||||
public File getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
public void setTemplates(File templates) {
|
||||
this.templates = templates;
|
||||
}
|
||||
|
||||
public File getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setOutput(File output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public File getDsl() {
|
||||
return dsl;
|
||||
}
|
||||
|
||||
public void setDsl(File dsl) {
|
||||
this.dsl = dsl;
|
||||
}
|
||||
|
||||
public String getParser() {
|
||||
return parser;
|
||||
}
|
||||
|
||||
public void setParser(String parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Run{" +
|
||||
"templates=" + templates +
|
||||
", output=" + output +
|
||||
", dsl=" + dsl +
|
||||
", parser='" + parser + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue