Skip to content

Commit

Permalink
Merge pull request #1 from schlothauer-wauer/master
Browse files Browse the repository at this point in the history
Get latest code
  • Loading branch information
SpeedsterF2 authored Feb 22, 2023
2 parents 2c7fe94 + b5c69b0 commit 85e7b22
Show file tree
Hide file tree
Showing 117 changed files with 26,132 additions and 895 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.idea
*.log
.gradle
build
tmp
classes
out
*.swp
pushLatest.bat
src/main/groovy/de/lisaplus/atlas/DummyGenerator.groovy
src/main/groovy/de/lisaplus/atlas/TestStarter.groovy
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/java/jdk:11u3-zulu-alpine as build

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", \
"--add-modules", "java.base,java.logging,java.desktop,java.naming,java.prefs,java.xml,java.scripting,java.sql", \
"--output", "/custom_jre"]

FROM alpine:latest
COPY --from=build /custom_jre /opt/jre/

RUN ln -s /opt/jre/bin/java /usr/bin/

ADD build/release /opt/jsonCodeGen/

ENTRYPOINT ["/opt/jsonCodeGen/jsonCodeGen.sh"]

CMD ["--help"]
94 changes: 91 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A simple Groovy based program to do generation tasks from a JSON schema.

## Requirements
* Java 8
* Gradle v4.*
* Gradle v5.4*

## Unsupported JSON schema features
* patternProperties - make no sense in model description
Expand Down Expand Up @@ -52,8 +52,6 @@ A simple Groovy based program to do generation tasks from a JSON schema.
## Handle with gradle
### Using with gradle
```bash
# do a complete release to configured maven repository
gradle publish

# builds a release with all dependencies
# release is built in PROJECT_DIR/build/release
Expand All @@ -80,6 +78,53 @@ gradle myRun -PmyArgs="-o,/tmp/test_beans,-m,src/test/resources/test_schemas/mul
-gp,destFileNameExt=java,-gp,packageName=de.sw.atlas.test"
```
### Usage of the release

```bash
./jsonCodeGen.sh
Usage: de.lisaplus.atlas.DoCodeGen [options]
Options:
-at, --add-tag
add a text as tag to a specific type, f.e. -at User=unused
Default: []
-b, --black-list
black listed type, multiple usage possible
Default: []
-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: []
-h, --help

* -m, --model
Path to JSON schema to parse
-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
-pmts, --print-main-types-separator
separator to use for printing main types
-rt, --remove-tag
remove a tag from a specific type, f.e. -rt User=unused
Default: []
-rta, --remove-tag-all
remove a tag from all model types, f.e. -rta rest
Default: []
-w, --white-list
white listed type, multiple usage possible
Default: []
```

After you built a release with gradle or you download a release bundle you can start
the program with the contained start script. If you start it with the help option you
get a full description of the possible parameters
Expand Down Expand Up @@ -107,3 +152,46 @@ basic design.

## Usage
[see here](src/main/resources/docs/usage.md)

## Releases
[see here](Releases.md)

# Template Debugging
## General Remarks
From version 0.13.0 it is also possible to debug code from templates. This is
a common use case if the templates become more complicated. Unfortunately is it
not possible to debug code that is included direct into the template, but
with the '-gs' command line switch a external Groovy script can be injected into
the code generation templates.

If the switch is used, then inside the template is a 'script' variable available.
This variable points to the injected script and allows to call functions that
are declared as clojure inside the generator-script.

```Groovy
// example usage of a generator script defined function
${script.generatorScriptDefinedFunction(possibleParameter)}
```

```Groovy
// example function definition in a generator script
def generatorScriptDefinedFunction(def someString) {
return "Hello: $someString"
}
```
## Code Examples
* [example additional generator script](./src/test/resources/templates/handling_helper.groovy)
* [example template that utilize the script](./src/test/resources/templates/handling.txt)
* [test that combines both](./src/test/groovy/de/lisaplus/atlas/codegen/test/MultiFileTemplates.groovy)
* [test in a shell script](./bin/debug_example.sh)

## Steps to Debug template in IntelliJ
1. Open the jsonCodeGen project in IntelliJ
2. Open the generator library in the editor (example: `./src/test/resources/templates/handling_helper.groovy`)
3. Set a break point
4. Configure remote debugging in IntelliJ listen on port 8100
5. Run `bin/debug_example.sh` from command line
6. Start remote debugging in IntelliJ
7. Break-Point should be triggered in IDE

This approach can also be used for other projects.
66 changes: 66 additions & 0 deletions Releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## 0.13.1
- handle the right notation of external references: e.g. ./object_base.json#/definitions/ObjectBase

(Attention, the wrong reference style before that version, is still working)
## 0.8.4
- add additional generator parameters to improve plantuml view (ignoreAttribs,ignoreRefs,ignoreImplicitRefs, ignoreCompositions)

## 0.8.3
- ignoreTag, neededTag are handled now as lists for multi-file-generators
- rename 'pmta' command line switch to specify a required attribute for main types to 'mta'
- add 'tmt' command line switch to add automatically a 'mainType' tag to all main types

## 0.8.2
- needed fix in 'pmta' command line switch

## 0.8.1
- add to types schemaPath and schemaFileName attributes (to finally detect what are the interesting main types of a model)
- add a isMainType function to model type
- add command line switches pro print only main types

## 0.8.0
- command line switches for type black- and white-lists
- command line switch to add tags to types
- command line switch to remove a tag from types
- command line switch to remove a tag from all types
- enforce camel-case type names in models
- add guidTypeColor generator parameter for plantuml
- remove printTags generator parameter for plantuml
- add printTypeTags generator parameter for plantuml
- add printPropTags generator parameter for plantuml

## 0.7.5
- deep copy functions for types
- introduce pure array type to handle definitions where arrays contain only arrays, f.e. geoJson Polygons

```json
...
"FeatureAreaGeometry": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"coordinates": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
}
},
"projection": {
"type": "string"
}
},
"__tags": ["additional"]
},
...
```

## 0.7.4
- add attributes `selfReference` and `selfContainment` to model property type
20 changes: 20 additions & 0 deletions bin/debug_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# Example script to illustrate the template debugging option of jsonCodeGen

scriptPos=${0%/*}

debugStarterScript=$scriptPos/../build/release/jsonCodeGenDebug.sh
if ! [ -f "$debugStarterScript" ]; then
echo "debug starter script not found: $debugStarterScript"
echo "Maybe release is not created. Try to create a release at first and re-run the script"
echo "gradle clean buildRelease"
exit 1
fi

$debugStarterScript -g "multifiles=$scriptPos/../src/test/resources/templates/handling.txt" \
-gs "$scriptPos/../src/test/resources/templates/handling_helper.groovy" \
-m "$scriptPos/../src/test/resources/test_schemas/ds/incident.json" \
-o "$scriptPos/../tmp/handling" \
-gp "packageName=de.debug"


57 changes: 57 additions & 0 deletions bin/uploadReleaseToNexus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

scriptPos=${0%/*}

# retrieve the version from project file
version=`cat "$scriptPos/../build.gradle" | grep project.version | grep = | sed -e "s-.* '--" -e "s-'--"`
echo "version: $version"

pushd "$scriptPos/.." > /dev/null
if ! gradle publish; then
echo "error while publish jars to nexus"
popd > /dev/null
fi
popd > /dev/null

if [ -z "$NEXUS_USER" ]; then
echo "NEXUS_USER not defined"
exit 1
fi

if [ -z "$NEXUS_RAW_ARCHIVE" ]; then
echo "NEXUS_RAW_ARCHIVE not defined"
exit 1
fi

pushd "$scriptPos/.." > /dev/null
if ! gradle clean build; then
echo 'error while build'
exit 1
fi

if ! gradle buildRelease; then
echo 'error while build release'
exit 1
fi

cd build/release


releaseFile="jsonCodeGen_$version.tgz"

if [ -f "$releaseFile" ]; then
rm -f "$releaseFile"
fi

tar -czf "$releaseFile" *

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

git tag "$version"

popd > /dev/null

Loading

0 comments on commit 85e7b22

Please sign in to comment.