Skip to content

Commit 79e2829

Browse files
committed
Split build into seperate Maven modules
1 parent e865d59 commit 79e2829

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+683
-566
lines changed

generator/pom.xml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>dev.cdevents</groupId>
9+
<artifactId>cdevents-sdk-java-parent</artifactId>
10+
<version>0.1.2-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>cdevents-sdk-java-generator</artifactId>
14+
15+
<name>cdevents-sdk-java-generator</name>
16+
<description>Source code generator for CDEvents Java SDK</description>
17+
<url>https://github.com/cdevents</url>
18+
19+
<properties>
20+
<maven.javadoc.skip>true</maven.javadoc.skip>
21+
<maven.source.skip>true</maven.source.skip>
22+
<maven.deploy.skip>true</maven.deploy.skip>
23+
<maven.compiler.source>11</maven.compiler.source>
24+
<maven.compiler.target>11</maven.compiler.target>
25+
<sdk.project.dir>${project.basedir}/../sdk</sdk.project.dir>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>com.fasterxml.jackson.core</groupId>
31+
<artifactId>jackson-databind</artifactId>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>com.fasterxml.jackson.datatype</groupId>
36+
<artifactId>jackson-datatype-jsr310</artifactId>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.slf4j</groupId>
41+
<artifactId>slf4j-api</artifactId>
42+
<version>${slf4j.version}</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.apache.commons</groupId>
47+
<artifactId>commons-lang3</artifactId>
48+
<version>3.12.0</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>com.github.spullara.mustache.java</groupId>
53+
<artifactId>compiler</artifactId>
54+
<version>0.9.6</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.slf4j</groupId>
59+
<artifactId>slf4j-simple</artifactId>
60+
<version>${slf4j.version}</version>
61+
<scope>runtime</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.jsonschema2pojo</groupId>
69+
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
70+
<version>1.2.1</version>
71+
<configuration>
72+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
73+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
74+
<includeToString>false</includeToString>
75+
<addCompileSourceRoot>false</addCompileSourceRoot>
76+
</configuration>
77+
<executions>
78+
<execution>
79+
<id>generate-artifact-packaged-from-schema</id>
80+
<phase>generate-sources</phase>
81+
<goals>
82+
<goal>generate</goal>
83+
</goals>
84+
<configuration>
85+
<sourcePaths>
86+
<sourcePath>${sdk.project.dir}/src/main/resources/schema/artifact-packaged-event.json
87+
</sourcePath>
88+
</sourcePaths>
89+
<targetPackage>dev.cdevents.models.artifact.packaged</targetPackage>
90+
<outputDirectory>${sdk.project.dir}/src/main/java</outputDirectory>
91+
<includeHashcodeAndEquals>false</includeHashcodeAndEquals>
92+
<includeToString>false</includeToString>
93+
</configuration>
94+
</execution>
95+
<execution>
96+
<id>generate-artifact-published-from-schema</id>
97+
<phase>generate-sources</phase>
98+
<goals>
99+
<goal>generate</goal>
100+
</goals>
101+
<configuration>
102+
<sourcePaths>
103+
<sourcePath>${sdk.project.dir}/src/main/resources/schema/artifact-published-event.json
104+
</sourcePath>
105+
</sourcePaths>
106+
<targetPackage>dev.cdevents.models.artifact.published</targetPackage>
107+
</configuration>
108+
</execution>
109+
<execution>
110+
<id>generate-pipeline-run-finished-from-schema</id>
111+
<phase>generate-sources</phase>
112+
<goals>
113+
<goal>generate</goal>
114+
</goals>
115+
<configuration>
116+
<sourcePaths>
117+
<sourcePath>
118+
${sdk.project.dir}/src/main/resources/schema/pipeline-run-finished-event.json
119+
</sourcePath>
120+
</sourcePaths>
121+
<targetPackage>dev.cdevents.models.pipelinerun.finished</targetPackage>
122+
</configuration>
123+
</execution>
124+
</executions>
125+
</plugin>
126+
<plugin>
127+
<groupId>org.codehaus.mojo</groupId>
128+
<artifactId>exec-maven-plugin</artifactId>
129+
<version>3.1.0</version>
130+
<executions>
131+
<execution>
132+
<id>run-CDEventsGenerator-main-class</id>
133+
<phase>process-classes</phase>
134+
<goals>
135+
<goal>java</goal>
136+
</goals>
137+
<configuration>
138+
<mainClass>dev.cdevents.generator.CDEventsGenerator</mainClass>
139+
<arguments>
140+
<argument>${project.basedir}</argument>
141+
<argument>${sdk.project.dir}</argument>
142+
</arguments>
143+
</configuration>
144+
</execution>
145+
</executions>
146+
</plugin>
147+
</plugins>
148+
</build>
149+
</project>

src/main/java/dev/cdevents/CDEventsGenerator.java renamed to generator/src/main/java/dev/cdevents/generator/CDEventsGenerator.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package dev.cdevents;
1+
package dev.cdevents.generator;
22

33
import com.fasterxml.jackson.databind.JsonNode;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.github.mustachejava.DefaultMustacheFactory;
66
import com.github.mustachejava.Mustache;
77
import com.github.mustachejava.MustacheFactory;
8-
import dev.cdevents.constants.CDEventConstants;
9-
import dev.cdevents.exception.CDEventsException;
10-
import org.apache.commons.lang.StringUtils;
8+
import org.apache.commons.lang3.StringUtils;
119
import org.slf4j.Logger;
1210
import org.slf4j.LoggerFactory;
1311
import java.io.BufferedWriter;
@@ -21,6 +19,15 @@
2119

2220
public final class CDEventsGenerator {
2321

22+
/**
23+
* Event JsonSchema files location.
24+
*/
25+
private static final String RESOURCES_DIR = "src/main/resources/";
26+
/**
27+
* Mustache generic event template file.
28+
*/
29+
private static final String EVENT_TEMPLATE_MUSTACHE = RESOURCES_DIR + "template/event-template.mustache";
30+
2431
private CDEventsGenerator() {
2532
}
2633

@@ -32,25 +39,29 @@ private CDEventsGenerator() {
3239
private static final int VERSION_INDEX = 4;
3340
private static final int SUBSTRING_PIPELINE_INDEX = 8;
3441

35-
private static final String TARGET_PACKAGE = "src/main/java/dev/cdevents/events";
36-
3742
/**
3843
* Main method to generate CDEvents from Json schema files.
39-
* @param args
44+
* @param args [0] - base directory for the cdevents-java-sdk-generator module
45+
* [1] - base directory for the cdevents-java-sdk module
4046
*/
4147
public static void main(String[] args) {
42-
File folder = new File(CDEventConstants.SCHEMA_FOLDER);
48+
String generatorBasedir = args[0];
49+
String sdkBasedir = args[1];
50+
51+
File folder = new File(sdkBasedir + File.separator + RESOURCES_DIR + "schema");
52+
System.out.println(folder.toPath().toAbsolutePath());
4353
if (folder.isDirectory()) {
4454
File[] files = folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".json"));
4555
if (files != null) {
4656
//Create Mustache factory and compile event-template.mustache template
4757
MustacheFactory mf = new DefaultMustacheFactory();
48-
Mustache mustache = mf.compile(CDEventConstants.EVENT_TEMPLATE_MUSTACHE);
58+
Mustache mustache = mf.compile(generatorBasedir + File.separator + EVENT_TEMPLATE_MUSTACHE);
4959

5060
//Generate a class file for each Json schema file using a mustache template
61+
String targetDirectory = sdkBasedir + File.separator + "src/main/java/dev/cdevents/events";
5162
for (File file : files) {
5263
SchemaData schemaData = buildCDEventDataFromJsonSchema(file);
53-
generateClassFileFromSchemaData(mustache, schemaData, TARGET_PACKAGE);
64+
generateClassFileFromSchemaData(mustache, schemaData, targetDirectory);
5465
}
5566
}
5667
}
@@ -66,7 +77,7 @@ private static void generateClassFileFromSchemaData(Mustache mustache, SchemaDat
6677
fileWriter.close();
6778
} catch (IOException e) {
6879
log.error("Exception occurred while generating class file from Json schema {}", e.getMessage());
69-
throw new CDEventsException("Exception occurred while generating class file from Json schema ", e);
80+
throw new IllegalStateException("Exception occurred while generating class file from Json schema ", e);
7081
}
7182
log.info("Rendered event-template has been written to file - {}", classFile.getAbsolutePath());
7283
}
@@ -106,7 +117,7 @@ private static SchemaData buildCDEventDataFromJsonSchema(File file) {
106117
updateSubjectContentProperties(schemaData, subjectContentNode);
107118
} catch (IOException e) {
108119
log.error("Exception occurred while building schema data from Json schema {}", e.getMessage());
109-
throw new CDEventsException("Exception occurred while building schema data from Json schema ", e);
120+
throw new IllegalStateException("Exception occurred while building schema data from Json schema ", e);
110121
}
111122
return schemaData;
112123
}

src/main/java/dev/cdevents/SchemaData.java renamed to generator/src/main/java/dev/cdevents/generator/SchemaData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package dev.cdevents;
1+
package dev.cdevents.generator;
22

33
import java.util.List;
44

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright 2022-Present https://cdevents.dev/
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*
14+
*
15+
*/
16+
17+
package dev.cdevents.generator;

src/main/resources/template/event-template.mustache renamed to generator/src/main/resources/template/event-template.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Code generated by dev.cdevents.CDEventsGenerator. DO NOT EDIT.
1+
// Code generated by dev.cdevents.generator.CDEventsGenerator. DO NOT EDIT.
22

33
/*
44
Copyright 2023 The CDEvents Authors

0 commit comments

Comments
 (0)