diff --git a/Dockerfile b/Dockerfile index ee4bc57..47acba9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 8826ec6..f037fc2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 @@ -89,6 +93,9 @@ 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 @@ -96,19 +103,22 @@ Usage: de.lisaplus.atlas.DoCodeGen [options] -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 @@ -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: [] @@ -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! diff --git a/Releases.md b/Releases.md index 439f9be..5c72def 100644 --- a/Releases.md +++ b/Releases.md @@ -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 diff --git a/bin/uploadReleaseToNexus.sh b/bin/uploadReleaseToNexus.sh index f94f979..780ced1 100755 --- a/bin/uploadReleaseToNexus.sh +++ b/bin/uploadReleaseToNexus.sh @@ -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" @@ -34,8 +41,7 @@ if ! gradle buildRelease; then exit 1 fi -cd build/release - +pushd "build/release" > /dev/null releaseFile="jsonCodeGen_$version.tgz" @@ -45,7 +51,15 @@ 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" @@ -53,5 +67,8 @@ 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 diff --git a/build.gradle b/build.gradle index 200f04e..b224654 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } @@ -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 { @@ -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) { @@ -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){ @@ -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 } @@ -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) diff --git a/docker/README.md b/docker/README.md index 6a84673..7838106 100644 --- a/docker/README.md +++ b/docker/README.md @@ -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 diff --git a/docker/bin/image_conf.sh b/docker/bin/image_conf.sh index 2d7c3ba..519001f 100755 --- a/docker/bin/image_conf.sh +++ b/docker/bin/image_conf.sh @@ -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" diff --git a/docker/image/Dockerfile b/docker/image/Dockerfile index 9239302..6aa6e67 100644 --- a/docker/image/Dockerfile +++ b/docker/image/Dockerfile @@ -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 diff --git a/src/main/groovy/de/lisaplus/atlas/DoCodeGen.groovy b/src/main/groovy/de/lisaplus/atlas/DoCodeGen.groovy index d03fabe..5ed92ee 100644 --- a/src/main/groovy/de/lisaplus/atlas/DoCodeGen.groovy +++ b/src/main/groovy/de/lisaplus/atlas/DoCodeGen.groovy @@ -163,6 +163,7 @@ class DoCodeGen { doCodeGen.run() } catch(ParameterException e) { + log.error("Encountered a problem while parsing the start parameters: {}", e) e.usage() } } diff --git a/src/main/groovy/de/lisaplus/atlas/codegen/TypeStringManipulation.groovy b/src/main/groovy/de/lisaplus/atlas/codegen/TypeStringManipulation.groovy index 1c95549..9218d5d 100644 --- a/src/main/groovy/de/lisaplus/atlas/codegen/TypeStringManipulation.groovy +++ b/src/main/groovy/de/lisaplus/atlas/codegen/TypeStringManipulation.groovy @@ -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 @@ -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) { @@ -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) { @@ -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 @@ -285,5 +285,5 @@ class TypeStringManipulation { return Type.copyOf(type, [:]) } - private final static String EMPTY='' + private static final String EMPTY='' } diff --git a/src/main/resources/bin/jsonCodeGen.groovy b/src/main/resources/bin/jsonCodeGen.groovy index 9aa2ea4..1181e36 100644 --- a/src/main/resources/bin/jsonCodeGen.groovy +++ b/src/main/resources/bin/jsonCodeGen.groovy @@ -1,8 +1,8 @@ /** * This is a platform independent start script for jsonCodeGen * Requirements: - * Java 8 - * Groovy > 2.4.7 + * Java 17 + * Groovy >= 4.0.0 * Created by eiko on 13.07.17. */ diff --git a/src/main/resources/bin/jsonCodeGen.sh b/src/main/resources/bin/jsonCodeGen.sh index 5ae39ad..327390d 100755 --- a/src/main/resources/bin/jsonCodeGen.sh +++ b/src/main/resources/bin/jsonCodeGen.sh @@ -38,7 +38,7 @@ esac args= for arg in "$@"; do - args="$args \"$arg\"" + args="$args $arg" done if [ -d $scriptPos/lib ]; then diff --git a/src/main/resources/bin/jsonCodeGenDebug.sh b/src/main/resources/bin/jsonCodeGenDebug.sh index d2af8f0..24e0ba6 100755 --- a/src/main/resources/bin/jsonCodeGenDebug.sh +++ b/src/main/resources/bin/jsonCodeGenDebug.sh @@ -38,7 +38,7 @@ esac args= for arg in "$@"; do - args="$args \"$arg\"" + args="$args $arg" done if [ -d $scriptPos/lib ]; then diff --git a/src/main/resources/conf/logback.xml b/src/main/resources/conf/logback.xml index d071390..b4a8797 100644 --- a/src/main/resources/conf/logback.xml +++ b/src/main/resources/conf/logback.xml @@ -23,4 +23,8 @@ + + + + \ No newline at end of file diff --git a/src/test/groovy/de/lisaplus/atlas/de/lisaplus/atlas/builder/test/xsd/SimpleXsdBuilder.groovy b/src/test/groovy/de/lisaplus/atlas/de/lisaplus/atlas/builder/test/xsd/SimpleXsdBuilder.groovy index 1bd7cdb..8533407 100644 --- a/src/test/groovy/de/lisaplus/atlas/de/lisaplus/atlas/builder/test/xsd/SimpleXsdBuilder.groovy +++ b/src/test/groovy/de/lisaplus/atlas/de/lisaplus/atlas/builder/test/xsd/SimpleXsdBuilder.groovy @@ -3,8 +3,6 @@ package de.lisaplus.atlas.de.lisaplus.atlas.builder.test.xsd import de.lisaplus.atlas.builder.XSDBuilder import org.junit.Test -import static junit.framework.Assert.assertTrue -import static org.junit.Assert.assertEquals import static org.junit.Assert.assertNotNull import static org.junit.Assert.assertTrue