Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable running jsonCodGen under Java17 #41

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM mcr.microsoft.com/java/jdk:11u3-zulu-alpine as build
FROM azul/zulu-openjdk-alpine:17.0.4.1 as build

# replace '--strip-debug' with '--strip-java-debug-attributes' or install package binutils
# Avoid error 'Cannot run program "objcopy": error=2, No such file or directory'!
RUN apk add --no-cache binutils
RUN ["jlink", \
"--compress=2", \
"--strip-debug", \
"--no-header-files", \
"--no-man-pages", \
"--module-path", "/usr/lib/jvm/zulu-11-azure-jdk_11.31.11-11.0.3-linux_musl_x64/jmods", \
"--module-path", "/usr/lib/jvm/zulu17-ca/jmods", \
"--add-modules", "java.base,java.logging,java.desktop,java.naming,java.prefs,java.xml,java.scripting,java.sql", \
"--output", "/custom_jre"]

Expand Down
45 changes: 37 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
A simple Groovy based program to do generation tasks from a JSON schema.

## Requirements
* Java 8
* Gradle v5.4*
* Java 17
* Gradle v7.*

## Unsupported JSON schema features
* patternProperties - make no sense in model description
Expand Down Expand Up @@ -59,7 +59,7 @@ A simple Groovy based program to do generation tasks from a JSON schema.
gradle buildRelease

# builds release and copy artifacts to docker image dir as preparation for the image build
gradle copyReleaseToDockerImage
gradle buildDockerImage

# run program without any arguments from project
gradle myRun
Expand All @@ -69,13 +69,17 @@ gradle myRun -PmyArgs="-m,src/test/resources/schemas/ProcessDataEvent.json"

# complex example for debug mode run
gradle myRun -PDEBUG -PmyArgs="-o,/tmp/test_beans,-m,src/test/resources/test_schemas/multiType.json,\
-g,multifiles=src/main/resources/templates/java/java_bean.txt,\
-g,multifiles=src/main/resources/templates/java/bean.txt,\
-gp,destFileNameExt=java,-gp,packageName=de.sw.atlas.test"

# complex example without debug mode run
gradle myRun -PmyArgs="-o,/tmp/test_beans,-m,src/test/resources/test_schemas/multiType.json,\
-g,multifiles=src/main/resources/templates/java/java_bean.txt,\
-g,multifiles=src/main/resources/templates/java/bean.txt,\
-gp,destFileNameExt=java,-gp,packageName=de.sw.atlas.test"

# swagger example
gradle myRun -PmyArgs="-o,/tmp/swagger,-m,src/test/resources/test_schemas/ds/user.json\
,-g,swagger,-gp,removeEmptyLines=true,-gp,host=api.lisaplus.de"
```
### Usage of the release

Expand All @@ -89,26 +93,32 @@ Usage: de.lisaplus.atlas.DoCodeGen [options]
-b, --black-list
black listed type, multiple usage possible
Default: []
-cet, --create-enum-types
if set the model is built with enum types
Default: false
-g, --generator
generator that are used with the model. This parameter can be used
multiple times
Default: []
-gp, --generator-parameter
special parameter that are passed to template via maps
Default: []
-gs, --generator-scripts
additional script that should be passed to the used templates
-h, --help

-mta, --main-types-attrib
specify a needed attribute to be a maintype, used in addition to the
schema location
* -m, --model
Path to JSON schema to parse
Default: []
-o, --outputBase
Base directory for the output
-pmt, --print-main-types
don't do any code generation, simply loads the model and print the
main-types of it
Default: false
-pmta, --print-main-types-attrib
don't do any code generation, simply loads the model and print the
main-types of it
-pmti, --print-main-types-info
print with info header
Default: false
Expand All @@ -120,6 +130,15 @@ Usage: de.lisaplus.atlas.DoCodeGen [options]
-rta, --remove-tag-all
remove a tag from all model types, f.e. -rta rest
Default: []
-rta2, --remove-tag-all-if-not-main
remove a tag from all model types that are no main types, f.e. -rta rest
Default: []
-rta2a, --remove-tag-all-if-not-main-attrib
don't do any code generation, simply loads the model and print the
main-types of it
-tmt, --tag-main-types
if this flag is set all maintypes will be extended with a 'mainType' tag
Default: false
-w, --white-list
white listed type, multiple usage possible
Default: []
Expand Down Expand Up @@ -195,3 +214,13 @@ def generatorScriptDefinedFunction(def someString) {
7. Break-Point should be triggered in IDE

This approach can also be used for other projects.

## Do NEXUS release
For uploading a binary release / release archive of jsonCodeGen to a NEXUS instance use corresponding release script [uploadReleaseToNexus.sh](bin/uploadReleaseToNexus.sh).
It needs some environment variables to work properly:

* NEXUS_RAW_ARCHIVE: URL to the directory, where the binary release is to be POSTed
* NEXUS_USER: Username use to authenticate at the NEXUS instance
* NEXUS_PWD: Password used to authenticate at the NEXUS instance (optional)

If no password is available, then curl will prompt for one!
4 changes: 4 additions & 0 deletions Releases.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.14.0
- switched to Groovy 4.x, Gradle 7.x and Java 17
- updated dependencies

## 0.13.1
- handle the right notation of external references: e.g. ./object_base.json#/definitions/ObjectBase

Expand Down
23 changes: 20 additions & 3 deletions bin/uploadReleaseToNexus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

scriptPos=${0%/*}

# Uploads a binary release / release archive of jsonCodeGen to a NEXUS instance
# This script relies on these environment variabels:
# * NEXUS_USER: Username use to authenticate at the NEXUS instance
# * NEXUS_PWD: Password used to authenticate at the NEXUS instance (optional)
# * NEXUS_RAW_ARCHIVE: URL to the directory, where the binary release is to be POSTed
# If no password is available, then curl will prompt for one!

# retrieve the version from project file
version=`cat "$scriptPos/../build.gradle" | grep project.version | grep = | sed -e "s-.* '--" -e "s-'--"`
echo "version: $version"
Expand Down Expand Up @@ -34,8 +41,7 @@ if ! gradle buildRelease; then
exit 1
fi

cd build/release

pushd "build/release" > /dev/null

releaseFile="jsonCodeGen_$version.tgz"

Expand All @@ -45,13 +51,24 @@ fi

tar -czf "$releaseFile" *

if ! curl -v --user "$NEXUS_USER" --upload-file "$releaseFile" \
# use password if availagle
if [ -z "$NEXUS_PWD" ]; then
user="$NEXUS_USER"
else
echo "Making us of env. variable NEXUS_PWD!"
user="$NEXUS_USER:$NEXUS_PWD"
fi

if ! curl -v --user $user --upload-file "$releaseFile" \
"$NEXUS_RAW_ARCHIVE/$releaseFile"
then
echo "error while upload release to nexus raw repo"
fi

git tag "$version"

echo "tagged version $version, please push it using command git push origin refs/tags/$version"

popd > /dev/null

popd > /dev/null
57 changes: 32 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
/*
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'maven'
// apply plugin: 'maven'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
*/
plugins {
id 'groovy'
id 'java'
id 'maven-publish'
id 'java-library'
}
sourceCompatibility = 17
targetCompatibility = 17

sourceCompatibility = 8

def mainClass='de.lisaplus.atlas.DoCodeGen'
def mc='de.lisaplus.atlas.DoCodeGen'

project.group = 'de.lisaplus.tools'
project.version = '0.13.2'
project.version = '0.14.0'


task sourcesJar(type: Jar) {
classifier = 'sources'
archiveClassifier = 'sources'
from sourceSets.main.allJava
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}

Expand All @@ -31,13 +39,13 @@ artifacts {
}

dependencies {
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'com.beust', name: 'jcommander', version: '1.69'
compile 'org.apache.commons:commons-lang3:3.3'
compile 'org.codehaus.groovy:groovy-all:2.5.7'
compile group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '3.0.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
runtimeOnly group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.11'
implementation group: 'com.beust', name: 'jcommander', version: '1.82'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation group: 'org.apache.groovy', name: 'groovy-all', version: '4.0.9'
implementation group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '5.1.1'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
}

clean {
Expand All @@ -46,7 +54,8 @@ clean {

task dependenciesToLibDir(type: Copy) {
into "$buildDir/release/lib"
from configurations.runtime
from sourceSets.main.runtimeClasspath
// from configurations.runtime
}

task buildRelease (type: Copy) {
Expand All @@ -70,14 +79,12 @@ task buildRelease (type: Copy) {
}

task zipRelease (type: Zip) {
doLast {
println 'zipRelease'
from "${buildDir}/release"
include '*'
include '*/*'
archiveName "$releaseArchiveName"
destinationDir(file("${buildDir}"))
}
// creates build/jsonCodeGen-[version].zip
println 'zipRelease'
from layout.buildDirectory.dir("release")
include '*'
include '*/*'
destinationDirectory = layout.buildDirectory.dir("${buildDir}")
}

task myRun (type: JavaExec, dependsOn: classes){
Expand All @@ -88,7 +95,7 @@ task myRun (type: JavaExec, dependsOn: classes){
jvmArgs '-Xdebug',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9009'
}
main = mainClass
mainClass = mc
classpath = sourceSets.main.runtimeClasspath
}

Expand Down Expand Up @@ -132,7 +139,7 @@ task buildDockerImage {
def imageName=['bash','docker/bin/image_conf.sh'].execute().text.trim()
println "create image: $imageName ..."
def cmd = ['docker', 'build', '-t', imageName,'.']
def sout = new StringBuilder(), serr = new StringBuilder()
def sout = new java.lang.StringBuilder(), serr = new java.lang.StringBuilder()
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(20000)
Expand Down
4 changes: 2 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ bin/run_jsonCodeGen.sh -m ../src/test/resources/schemas/vera.json \

## How to create a docker image
Requirements:
- installed Java v8
- installed Gradle
- installed Java v17
- installed Gradle v7.x
```bash
# show all available Gradle tasks (only for information)
gradle tasks --all
Expand Down
6 changes: 4 additions & 2 deletions docker/bin/image_conf.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
scriptPos=${0%/*}

imageBase=schlothauer/jsoncodegen
imageTag=0.11.3

if [ -f build.gradle ]; then
imageTag=`cat build.gradle | grep project.version | awk '{ print $3 }' | sed -e "s-'--g"`
if [ -f $scriptPos/../../build.gradle ]; then
imageTag=$(cat $scriptPos/../../build.gradle | grep project.version | awk '{ print $3 }' | sed -e "s-'--g")
fi

imageName="$imageBase:$imageTag"
Expand Down
3 changes: 2 additions & 1 deletion docker/image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM openjdk:8-jre-alpine
# FROM openjdk:8-jre-alpine
FROM azul/zulu-openjdk-alpine:17.0.4.1

ADD release /opt/jsonCodeGen

Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/de/lisaplus/atlas/DoCodeGen.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class DoCodeGen {
doCodeGen.run()
}
catch(ParameterException e) {
log.error("Encountered a problem while parsing the start parameters: {}", e)
e.usage()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TypeStringManipulation {
}

def breakTxt = { String txtToBreak,int charPerLine,String breakText='\n' ->
if (!txtToBreak) return EMPTY
if (!txtToBreak) return TypeStringManipulation.EMPTY
StringBuilder sb = new StringBuilder()
int txtLen = txtToBreak.length()
int aktPos = 0
Expand Down Expand Up @@ -155,15 +155,15 @@ class TypeStringManipulation {
}

def toLowerCase = { str ->
return str==null ? EMPTY : str.toLowerCase()
return str==null ? TypeStringManipulation.EMPTY : str.toLowerCase()
}

def toUpperCase = { str ->
return str==null ? EMPTY : str.toUpperCase()
return str==null ? TypeStringManipulation.EMPTY : str.toUpperCase()
}

def firstLowerCase = { str ->
if (!str) return EMPTY
if (!str) return TypeStringManipulation.EMPTY
def first = str.substring(0,1)
first = first.toLowerCase()
if (str.length()>1) {
Expand All @@ -176,7 +176,7 @@ class TypeStringManipulation {
}

def firstUpperCase = { str ->
if (!str) return EMPTY
if (!str) return TypeStringManipulation.EMPTY
def first = str.substring(0,1)
first = first.toUpperCase()
if (str.length()>1) {
Expand All @@ -189,19 +189,19 @@ class TypeStringManipulation {
}

def firstUpperCamelCase = { str ->
if (!str) return EMPTY
if (!str) return TypeStringManipulation.EMPTY
def firstUpper = firstUpperCase(str)
return convertAllUnderLinesToCamelCase(firstUpper)
}

def firstLowerCamelCase = { str ->
if (!str) return EMPTY
if (!str) return TypeStringManipulation.EMPTY
def firstLower = firstLowerCase(str)
return convertAllUnderLinesToCamelCase(firstLower)
}

def convertAllUnderLinesToCamelCase = { String str ->
if (!str) return EMPTY
if (!str) return TypeStringManipulation.EMPTY
def i_ = str.indexOf('_')
while (i_!=-1) {
def stopLen = str.length()-1
Expand Down Expand Up @@ -285,5 +285,5 @@ class TypeStringManipulation {
return Type.copyOf(type, [:])
}

private final static String EMPTY=''
private static final String EMPTY=''
}
Loading