Skip to content

Commit

Permalink
Templates with freemarker
Browse files Browse the repository at this point in the history
  • Loading branch information
Erhard Siegl committed Mar 15, 2015
1 parent 0c569e7 commit dabdb37
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "jbss-substitute"]
path = jbss-substitute
url = [email protected]:Gepardec/jbss-substitute.git
52 changes: 52 additions & 0 deletions configs/database_with_freemarker_template/00_BOOTSTRAP
Original file line number Diff line number Diff line change
@@ -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`
Original file line number Diff line number Diff line change
@@ -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
</#list>
63 changes: 63 additions & 0 deletions configs/database_with_freemarker_template/substitute
Original file line number Diff line number Diff line change
@@ -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 <<EOF 1>&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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions configs/database_with_m4_template/04_deployment.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deploy ../deployments/jboss-seam-booking.ear
7 changes: 0 additions & 7 deletions configs/database_with_template/03_createDatasource.conf

This file was deleted.

9 changes: 9 additions & 0 deletions configs/environments/fm/example.env
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions jbss-substitute
Submodule jbss-substitute added at 701338
2 changes: 1 addition & 1 deletion modules/mod-mysql-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>01_mod-mysql-connector</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>com.objectbay</groupId>
<groupId>com.gepardec.jbss</groupId>
<artifactId>jboss-modules-examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.objectbay</groupId>
<groupId>com.gepardec.jbss</groupId>
<artifactId>jboss-modules-examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
Expand Down
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gepardec.jbss</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>modules</module>
<module>jbss-substitute</module>
</modules>
<dependencies>
</dependencies>
<build>
</build>
</project>

0 comments on commit dabdb37

Please sign in to comment.