-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Baseline for a Java generator from CRD
- Loading branch information
Showing
46 changed files
with
22,514 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Java generator (early preview release) | ||
|
||
## Disclaimer | ||
|
||
This is an early preview of a Java generator from CRD and | ||
there might still be issues in the generated sources. | ||
Please give it a try and report any issue you might find. | ||
|
||
### Usage | ||
|
||
The `java-generator` is distributed as a tiny CLI application, you can obtain it by running: | ||
|
||
``` | ||
mvn clean package -f cli/pom.xml | ||
``` | ||
|
||
The produced executable will be `cli/target/java-gen` and it provides basic configuration options: | ||
|
||
```bash | ||
Usage: java-gen [-hV] -crd=<crdFile> -dest=<destFolder> | ||
-crd, --custom-resource-definition=<crdFile> | ||
The file with the CustomResourceDefinition to use | ||
-dest, --destination-folder=<destFolder> | ||
The folder to write the generated sources | ||
-h, --help Show this help message and exit. | ||
-V, --version Print version information and exit. | ||
``` | ||
|
||
### Formatting code | ||
|
||
Code formatting is automated but remember to fix the headers before committing: | ||
|
||
```bash | ||
mvn license:format -f java-generator/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,138 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2015 Red Hat, Inc. | ||
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"> | ||
<parent> | ||
<artifactId>java-generator-parent</artifactId> | ||
<groupId>io.fabric8</groupId> | ||
<version>6.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>java-generator-cli</artifactId> | ||
<name>Fabric8 :: Java generator :: CLI</name> | ||
|
||
<properties> | ||
<picocli.version>4.6.2</picocli.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>java-generator-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>info.picocli</groupId> | ||
<artifactId>picocli</artifactId> | ||
<version>${picocli.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>kubernetes-client</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>kubernetes-model-common</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>info.picocli</groupId> | ||
<artifactId>picocli-codegen</artifactId> | ||
<version>${picocli.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
<compilerArgs> | ||
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>io.fabric8.java.generator.cli.GenerateJavaSources</mainClass> | ||
</transformer> | ||
</transformers> | ||
<createDependencyReducedPom>false</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- now make the jar chmod +x style executable --> | ||
<plugin> | ||
<groupId>org.skife.maven</groupId> | ||
<artifactId>really-executable-jar-maven-plugin</artifactId> | ||
<version>1.4.1</version> | ||
<configuration> | ||
<flags>-Xmx1G</flags> | ||
<programFile>java-gen</programFile> | ||
</configuration> | ||
|
||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>really-executable-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
53 changes: 53 additions & 0 deletions
53
java-generator/cli/src/main/java/io/fabric8/java/generator/cli/GenerateJavaSources.java
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,53 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.java.generator.cli; | ||
|
||
import io.fabric8.java.generator.CRGeneratorRunner; | ||
import java.io.File; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command( | ||
name = "java-gen", | ||
mixinStandardHelpOptions = true, | ||
helpCommand = true, | ||
versionProvider = KubernetesClientVersionProvider.class) | ||
public class GenerateJavaSources implements Runnable { | ||
|
||
@Option( | ||
names = {"-crd", "--custom-resource-definition"}, | ||
description = "The file with the CustomResourceDefinition to use", | ||
required = true) | ||
File crdFile; | ||
|
||
@Option( | ||
names = {"-dest", "--destination-folder"}, | ||
description = "The folder to write the generated sources", | ||
required = true) | ||
File destFolder; | ||
|
||
@Override | ||
public void run() { | ||
CRGeneratorRunner runner = new CRGeneratorRunner(); | ||
runner.run(crdFile, destFolder); | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new GenerateJavaSources()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ator/cli/src/main/java/io/fabric8/java/generator/cli/KubernetesClientVersionProvider.java
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 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package io.fabric8.java.generator.cli; | ||
|
||
import io.fabric8.kubernetes.client.Version; | ||
import picocli.CommandLine; | ||
|
||
public class KubernetesClientVersionProvider implements CommandLine.IVersionProvider { | ||
@Override | ||
public String[] getVersion() throws Exception { | ||
return new String[] {Version.clientVersion()}; | ||
} | ||
} |
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 @@ | ||
*.received.txt |
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,116 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (C) 2015 Red Hat, Inc. | ||
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"> | ||
<parent> | ||
<artifactId>java-generator-parent</artifactId> | ||
<groupId>io.fabric8</groupId> | ||
<version>6.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>java-generator-core</artifactId> | ||
<name>Fabric8 :: Java generator :: Core</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>kubernetes-client</artifactId> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>kubernetes-model-common</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.javaparser</groupId> | ||
<artifactId>javaparser-core</artifactId> | ||
<version>3.23.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.sundr</groupId> | ||
<artifactId>sundr-adapter-reflect</artifactId> | ||
<version>${sundrio.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.sundr</groupId> | ||
<artifactId>builder-annotations</artifactId> | ||
<version>${sundrio.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.validation</groupId> | ||
<artifactId>validation-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Testing --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${slf4j.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.testing.compile</groupId> | ||
<artifactId>compile-testing</artifactId> | ||
<version>0.19</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.approvaltests</groupId> | ||
<artifactId>approvaltests</artifactId> | ||
<version>12.3.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<compilerArgument>-proc:none</compilerArgument> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.