diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4f49cc1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "jbss-substitute"] + path = jbss-substitute + url = git@github.com:Gepardec/jbss-substitute.git diff --git a/configs/database_with_freemarker_template/00_BOOTSTRAP b/configs/database_with_freemarker_template/00_BOOTSTRAP new file mode 100755 index 0000000..4993a3e --- /dev/null +++ b/configs/database_with_freemarker_template/00_BOOTSTRAP @@ -0,0 +1,52 @@ +#!/bin/sh + +if [ -z "$ENV_CONFIG" ]; then + ENV_CONFIG=$1 +fi + +if [ ! -d "$ENV_CONFIG" ]; then + echo "WARN: File $ENV_CONFIG doesn't exist! Set ENV_CONFIG or use argument" 1>&2 + echo "WARN: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + ENV_CONFIG=../environments/fm/example.env + echo "WARN: Example values from $ENV_CONFIG will be used!" 1>&2 + echo "WARN: Change this code in real-world environments" 1>&2 + echo "WARN: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + # exit 1 +fi + +########################### +# provide the script and libraries for template processing +########################### +provideSubstitute() { + echo "Let's try to get the latest freemarker-utilities" + JBSS_SUBSTITUTE=../../jbss-substitute/ + cp $JBSS_SUBSTITUTE/target/jbss-substitute-*-jar-with-dependencies.jar substitute.jar + cp $JBSS_SUBSTITUTE/src/main/resources/substitute.sh ./substitute + chmod a+x substitute + + if [ ! -x substitute ]; then + echo "Script substitute is missing or not executable!" 1>&2 + echo "Should be copied from $JBSS_SUBSTITUTE/src/main/resources" 1>&2 + exit 2 + fi + if [ ! -r substitute.jar ]; then + echo "Library jbss-substitute.jar is missing!" 1>&2; exit 3 + fi +} + +########################### +# convert all m4 templates in directory and subdirectories +########################### +convert() { + dir=$1 + echo "Configure Directory $dir" + for f in `find $dir -name "*.templ"`; do + dirname=`dirname $f` + basename=`basename $f .templ` + echo Process template $f + ./substitute -p "$ENV_CONFIG" -t $f -o $dirname/$basename + done +} + +provideSubstitute +convert `pwd` diff --git a/configs/database_with_freemarker_template/03_createDatasource.conf.templ b/configs/database_with_freemarker_template/03_createDatasource.conf.templ new file mode 100644 index 0000000..a9c9a3c --- /dev/null +++ b/configs/database_with_freemarker_template/03_createDatasource.conf.templ @@ -0,0 +1,14 @@ +/subsystem=datasources/data-source=bookingDatasource:add( \ + jndi-name="java:/datasources/bookingDatasource", \ + connection-url="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", \ + driver-name=h2, user-name=${CONF_DB_USER}, password=${CONF_DB_PASSWORD}) +/subsystem=datasources/data-source=bookingDatasource:enable + +<#list CONF_DBS_USER?keys as key> + +/subsystem=datasources/data-source=myDatasource${key}:add( \ + jndi-name="java:/datasources/myDatasource${key}", \ + connection-url="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", \ + driver-name=h2, user-name=${CONF_DBS_USER[key]}, password=${CONF_DBS_PASSWORD[key]}) +/subsystem=datasources/data-source=myDatasource${key}:enable + diff --git a/configs/database_with_template/04_deployment.conf b/configs/database_with_freemarker_template/04_deployment.conf similarity index 100% rename from configs/database_with_template/04_deployment.conf rename to configs/database_with_freemarker_template/04_deployment.conf diff --git a/configs/database_with_freemarker_template/substitute b/configs/database_with_freemarker_template/substitute new file mode 100755 index 0000000..5e574cd --- /dev/null +++ b/configs/database_with_freemarker_template/substitute @@ -0,0 +1,63 @@ +#!/bin/bash + +# Substitute script + +MY_PATH=$(readlink -f $0) +BIN_DIR=`dirname $MY_PATH` +BASE_DIR=$BIN_DIR/.. +CONFIG_DIR=$BASE_DIR +PRG=`basename $0` + +SAVE_DATE=`date +save_%Y_%m_%d-%H_%M_%S` +RM_ACTION=manual + +##################################################################### +## print_usage +##################################################################### +print_usage(){ +cat <&2 + +usage: $PRG -p properties_file -t template_file -o output_file + +Funktion: + Transforms the given freemarker template using properties from properties file and writes result to file + +EOF +} + +###################### Optionen bestimmen ################### + +while getopts "p:t:o:" option +do + case $option in + p) + PROP_FILE=$OPTARG;; + t) + TEMPLATE_FILE=$OPTARG;; + o) + OUTPUT_FILE=$OPTARG;; + *) + print_usage + exit 1 + ;; + esac +done + +shift `expr $OPTIND - 1` + + +##################### Beginn ######################### + +if [ ! -f $PROP_FILE ] || [ x$PROP_FILE = x ] +then + echo "Property file $PROP_FILE not found" + print_usage + exit 1 +fi + +if [ ! -f $TEMPLATE_FILE ] || [ x$TEMPLATE_FILE = x ] +then + echo "Template file $TEMPLATE_FILE not found" + exit 1 +fi +java -jar $BIN_DIR/substitute.jar $PROP_FILE $TEMPLATE_FILE $OUTPUT_FILE \ No newline at end of file diff --git a/configs/database_with_freemarker_template/substitute.jar b/configs/database_with_freemarker_template/substitute.jar new file mode 100644 index 0000000..0da4e0f Binary files /dev/null and b/configs/database_with_freemarker_template/substitute.jar differ diff --git a/configs/database_with_template/00_BOOTSTRAP b/configs/database_with_m4_template/00_BOOTSTRAP similarity index 56% rename from configs/database_with_template/00_BOOTSTRAP rename to configs/database_with_m4_template/00_BOOTSTRAP index e85a782..978e317 100755 --- a/configs/database_with_template/00_BOOTSTRAP +++ b/configs/database_with_m4_template/00_BOOTSTRAP @@ -5,8 +5,13 @@ if [ -z "$ENV_CONFIG" ]; then fi if [ ! -d "$ENV_CONFIG" ]; then - echo "Directory $ENV_CONFIG doesn't exist! Set ENV_CONFIG or use argument" 1>&2 - exit 1 + echo "WARN: Directory $ENV_CONFIG doesn't exist! Set ENV_CONFIG or use argument" 1>&2 + echo "WARN: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + ENV_CONFIG=../environments/example + echo "WARN: example values from $ENV_CONFIG will be used!" 1>&2 + echo "WARN: Change this code in real-world environments" 1>&2 + echo "WARN: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + # exit 1 fi diff --git a/configs/database_with_template/03_createDatasource.conf.m4 b/configs/database_with_m4_template/03_createDatasource.conf.m4 similarity index 100% rename from configs/database_with_template/03_createDatasource.conf.m4 rename to configs/database_with_m4_template/03_createDatasource.conf.m4 diff --git a/configs/database_with_m4_template/04_deployment.conf b/configs/database_with_m4_template/04_deployment.conf new file mode 100644 index 0000000..12ae815 --- /dev/null +++ b/configs/database_with_m4_template/04_deployment.conf @@ -0,0 +1 @@ +deploy ../deployments/jboss-seam-booking.ear diff --git a/configs/database_with_template/03_createDatasource.conf b/configs/database_with_template/03_createDatasource.conf deleted file mode 100644 index 4251d37..0000000 --- a/configs/database_with_template/03_createDatasource.conf +++ /dev/null @@ -1,7 +0,0 @@ - -/subsystem=datasources/data-source=bookingDatasource:add( \ - jndi-name="java:/datasources/bookingDatasource", \ - connection-url="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", \ - driver-name=h2, user-name=myuser , password=my_db_password ) - -/subsystem=datasources/data-source=bookingDatasource:enable diff --git a/configs/environments/fm/example.env b/configs/environments/fm/example.env new file mode 100644 index 0000000..aec6961 --- /dev/null +++ b/configs/environments/fm/example.env @@ -0,0 +1,9 @@ + +CONF_DB_USER=myuser +CONF_DB_PASSWORD=default_db_password + +CONF_DBS_USER_1=myuserone +CONF_DBS_PASSWORD_1=mypasswordone + +CONF_DBS_USER_2=myusertwo +CONF_DBS_PASSWORD_2=mypasswordtwo diff --git a/jbss-substitute b/jbss-substitute new file mode 160000 index 0000000..7013389 --- /dev/null +++ b/jbss-substitute @@ -0,0 +1 @@ +Subproject commit 70133893e23dacef91ddeca62870408cd86f5b8e diff --git a/modules/mod-mysql-connector/pom.xml b/modules/mod-mysql-connector/pom.xml index 17b39bb..c9e016b 100644 --- a/modules/mod-mysql-connector/pom.xml +++ b/modules/mod-mysql-connector/pom.xml @@ -5,7 +5,7 @@ 01_mod-mysql-connector pom - com.objectbay + com.gepardec.jbss jboss-modules-examples 1.0.0-SNAPSHOT diff --git a/modules/pom.xml b/modules/pom.xml index 132b4bd..a28d888 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - com.objectbay + com.gepardec.jbss jboss-modules-examples 1.0.0-SNAPSHOT pom diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a4f53e3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + com.gepardec.jbss + parent + 1.0.0-SNAPSHOT + pom + + modules + jbss-substitute + + + + + +