-
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add Integrate with maven example (#1579)
- Loading branch information
1 parent
2a29267
commit 69dd4e4
Showing
16 changed files
with
606 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Integrate Modelina into Maven | ||
|
||
This example show how you can integrate Modelina into Maven with a custom build script. [Please have a look at the Maven project README file for further information](./maven-project/README.md). |
25 changes: 25 additions & 0 deletions
25
examples/integrate-modelina-into-maven/maven-project/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
target/ | ||
pom.xml.tag | ||
pom.xml.releaseBackup | ||
pom.xml.versionsBackup | ||
pom.xml.next | ||
release.properties | ||
dependency-reduced-pom.xml | ||
buildNumber.properties | ||
.mvn/timing.properties | ||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar | ||
.mvn/wrapper/maven-wrapper.jar | ||
|
||
# Eclipse m2e generated files | ||
# Eclipse Core | ||
.project | ||
# JDT-specific (Eclipse Java Development Tools) | ||
.classpath | ||
|
||
bin | ||
.settings | ||
|
||
# Ignore Modelina generation node modules | ||
scripts/modelina/java_runtime_node | ||
scripts/modelina/node_modules |
10 changes: 10 additions & 0 deletions
10
examples/integrate-modelina-into-maven/maven-project/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Integrate Modelina into Maven | ||
|
||
This Java Maven project shows an example how to integrate Modelina and AsyncAPI into your build process. | ||
|
||
Here is how it works: | ||
- The script `./scripts/modelina/generate.ts` is what generates all the models, and what Maven uses to generate the models. This can also be executed manually through `npm run generate`. | ||
- The input, in this case, is an AsyncAPI document located in the root of the project `./asyncapi.json`. The input can be anything, just alter the generator script. | ||
- The Maven project file `./pom.xml` then utilizes the [frontend-maven-plugin](https://github.com/eirslett/frontend-maven-plugin) to execute the generate script on build so you will always have the up to date models from your AsyncAPI document. | ||
|
||
> NOTICE: The only thing you manually have to change for this to work in your project is the dependency entry for `"@asyncapi/modelina": "file:../../../../../",` in the `./scripts/modelina/package.json` file to use the latest Modelina version (we only use a local one for testing purposes). |
26 changes: 26 additions & 0 deletions
26
examples/integrate-modelina-into-maven/maven-project/asyncapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"asyncapi": "2.2.0", | ||
"info": { | ||
"title": "example", | ||
"version": "0.1.0" | ||
}, | ||
"channels": { | ||
"/test": { | ||
"subscribe": { | ||
"message": { | ||
"payload": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"email": { | ||
"type": "string", | ||
"format": "email" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
examples/integrate-modelina-into-maven/maven-project/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?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> | ||
|
||
<groupId>com.mycompany.app</groupId> | ||
<artifactId>maven-project</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>maven-project</name> | ||
<url>http://www.example.com</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations --> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.15.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.15.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-all --> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<version>1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.eirslett</groupId> | ||
<artifactId>frontend-maven-plugin</artifactId> | ||
<version>1.12.1</version> | ||
<configuration> | ||
<workingDirectory>./scripts/modelina</workingDirectory> | ||
<installDirectory>java_runtime_node</installDirectory> | ||
</configuration> | ||
<executions> | ||
<!-- It will install nodejs and npm --> | ||
<execution> | ||
<id>install node and npm</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>install-node-and-npm</goal> | ||
</goals> | ||
<configuration> | ||
<nodeVersion>v18.15.0</nodeVersion> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>Generate sources</id> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>npm</goal> | ||
</goals> | ||
<configuration> | ||
<arguments>run generate</arguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
examples/integrate-modelina-into-maven/maven-project/scripts/modelina/generate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { JAVA_JACKSON_PRESET, JavaFileGenerator } from '@asyncapi/modelina'; | ||
import path from 'path'; | ||
|
||
// Where should the models be placed relative to root maven project? | ||
const PACKAGE_NAME = 'java/com/mycompany/app'; | ||
const MODEL_DIR = `src/main/${PACKAGE_NAME}`; | ||
|
||
const FINAL_OUTPUT_PATH = path.resolve(__dirname, '../../', MODEL_DIR); | ||
// Setup the generator and all it's configurations | ||
const generator = new JavaFileGenerator({ | ||
presets: [JAVA_JACKSON_PRESET] | ||
}); | ||
|
||
// Load the input from file, memory, or remotely. | ||
// Here we just use a local AsyncAPI file | ||
import INPUT from '../../asyncapi.json'; | ||
const input = INPUT; | ||
|
||
// Generate all the files | ||
generator.generateToFiles(input, FINAL_OUTPUT_PATH, { | ||
packageName: 'com.mycompany.app' | ||
}); |
Oops, something went wrong.