Skip to content

Instantly share code, notes, and snippets.

@mgoellnitz
Last active December 19, 2023 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgoellnitz/829afbf4e49bcfef4c3d4f639b711dfa to your computer and use it in GitHub Desktop.
Save mgoellnitz/829afbf4e49bcfef4c3d4f639b711dfa to your computer and use it in GitHub Desktop.
CoreMedia Bean Generator in one Line - multi-version and workspace aware
#!/bin/bash
#
# Call the CoreMedia CAE Bean Generator for any CMS Release, with
# or without workspace context and without separate preparation steps.
#
# Copyright 2017-2023 Martin Goellnitz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# This script simplifies the download instructions from the CoreMedia
# manuals to just a "call this script" and adds the option "-v <version>" to
# the bean-generator for direct release selection.
# It tries to download the required version of the Bean Generator to
# ~/,bean-generator. The required version is taken from the workspace you're
# just in, or from the latest version provided by CoreMedia in their
# Maven repositories. Thus you have to setup maven to be able to access this
# repository in either case.
# This piece of code is supposed to work with CoreMedia CMS starting with
# version 6 (5.3.1) alongside with the related versions of CoreMedia
# LiveContext up to CMCC 11.
#
# wind up the directory tree until we find a folder of the given name $1
function windUp {
while [ `pwd` != "/" -a ! -d $1 ] ; do
cd ..
done
}
REPO_URL='https://repository.coremedia.com/nexus/content/groups/cms/com/coremedia/cms/bean-generator/'
export MAVEN_OPTS="-Dorg.slf4j.simpleLogger.defaultLogLevel=error"
CWD=`pwd`
VERSION="AUTO"
if [ "$1" = "-v" ] ; then
shift
VERSION=${1:-AUTO}
shift
fi
windUp workspace-configuration
if [ "$VERSION" == "AUTO" ] ; then
echo "Version auto-discovery"
if [ -f ./blueprint-parent/pom.xml ] ; then
VERSION=$(grep cms.version.*cms.version ./blueprint-parent/pom.xml|cut -d '>' -f 2|cut -d '<' -f 1)
echo "We're in a CMS-9 / LiveContext 3 Workspace Context for Version $VERSION"
else
if [ -d workspace-configuration ] ; then
if [ -d apps ] ; then
VERSION=$(grep cm.common.core.version apps/*/blueprint-parent/pom.xml|grep -v version...cm.common|tail -1|cut -d '>' -f 2|cut -d '<' -f 1)
echo "We're in a CoreMedia CMCC Workspace Context for Version $VERSION"
else
if [ -f ./pom.xml ] ; then
VERSION=$(grep cms.version.*cms.version ./pom.xml|cut -d '>' -f 2|cut -d '<' -f 1)
echo "We're in a CoreMedia 7/8 or LiveContext 2 Workspace Context for Version $VERSION"
fi
fi
fi
fi
if [ "$VERSION" == "AUTO" ] ; then
echo "No version discovered from workspace context - checking latest version provided by CoreMedia"
VERSION="RELEASE"
fi
fi
if [ ! -d ~/.bean-generator ] ; then
mkdir -p ~/.bean-generator/src/main/webapp/WEB-INF
touch ~/.bean-generator/src/main/webapp/WEB-INF/web.xml
POM=$(echo -e H4sICCQm9lkCA3BvbS54bWwAxVRNi9swEL3nVwjTq6Vs20MJivawUChsaGH7dZ2VJ4m2tmQkOc5S \
+t87kuPYCZTuqQVf5umN5r3nseXtsanZAX0wzq6LG74sGFrtKmN36+LL5/flu+JWLWTr3RPqyIht \
w7rYx9iuhGjggJZDC3qP3Pmd+PRxI97yZbolM1fHYM7svu95/ybzXi+XN+L75v6BGhsojQ0RrEbq \
CmYVMnjvNMQs6q/D2J8Yx1ANYJl5nOpCLRijRzauwvrrYFzlYykusEVi7bzr2g+VqpBTBAenneXa \
eWywMiDFeJyo4KPZgo5UPiLYHVr0EJ0vew9ti16KGSM1nFJXr36eufyE/ZJiPE1McvQDdvRKVA90 \
z1RmjRUG7U2bwlLfhlmMsmHRsS1GvWdxj8wiVlixJ/CBbZ1nwC5EMmMJyqXR4z4wchvxGLkU8xmn \
oS3ailbFYEga59DzAMzi066ZYuO6CRfRZepVfOVZ2nVumf3i7DI7aNei8p2NpkEphnIQLS5Vz+ps \
LEEeWxcMTZisnqHJqkkuR4cUGnoLNa/NAccUPdYIAcm7mYxYaFDdUeMmNbK7zYMUGRsJna9V2u9A \
Cz6NnafpGmHx2AWRB9ko5oLFTEE5KhBSpGvHETU8uy7Sjm+hq6MUp/qcnoU27F0MI0IYWnissVJb \
qAMlOpZji7jqkeI6sZdH+M9iyxtJZfP/85HicukW9NEPf2C1+A1t3H6cswUAAA==)
echo $POM|sed -e 's/\ /\n/g'|base64 -d|gunzip -c > ~/.bean-generator/pom.xml
fi
if [ "$VERSION" == "RELEASE" ] ; then
cd ~/.bean-generator
# Auto discovery is now somehow pointless, since 2207.2 is actually the last version to contain a bean generator
VERSION=2207.2
sed -ie 's/<version>.*<\/version>/<version>'$VERSION'<\/version>/g' pom.xml
mvn war:exploded -Dorg.slf4j.simpleLogger.defaultLogLevel=warn
LATEST=$(basename $(ls ~/.bean-generator/target/beangenerator-wrapper-${VERSION}/WEB-INF/lib/bean-generator*jar|tail -1) .jar)
VERSION=$(echo $LATEST|cut -d '-' -f 3)
fi
if [ "$VERSION" > "2207.2" ] ; then
# Limiting to latest version where beangenerator is present
VERSION="2207.2"
fi
echo "Using CMS Version $VERSION"
if [ ! -d ~/.bean-generator/target/beangenerator-wrapper-${VERSION}/WEB-INF/lib ] ; then
cd ~/.bean-generator
sed -ie 's/<version>.*<\/version>/<version>'$VERSION'<\/version>/g' pom.xml
mvn war:exploded -Dorg.slf4j.simpleLogger.defaultLogLevel=warn
fi
cd $CWD
if [ -d ~/.bean-generator/target/beangenerator-wrapper-${VERSION}/WEB-INF/lib ] ; then
echo "Calling CoreMedia Bean Generator"
java -jar ~/.bean-generator/target/beangenerator-wrapper-${VERSION}/WEB-INF/lib/bean-generator-$VERSION.jar $*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment