Building Narayana and updating WildFly modules

Version 7

    From beginning I work with Narayana on WildFly I struggle to build Narayana and update WildFly modules with the changes coming from the new build. This is necessary especially when working with some patches or fixes Narayana codebase belonging to issues coming from WildFly (JBoss EAP).


    by term 'updating Narayana modules in WildFly' I mean process after which the WildFly installation contains new Narayana jar files


    For WildFly 11 (JBoss EAP 7.1) we have following modules touching transactions.


    by default you can find the module.xml descriptor and jar files belonging to the WildFly module at path $WILDFLY_HOME/modules/system/layers/base/<module-name-slash-delimited>/main


    I'm putting here github project they are build from.














    Narayana build


    I focus mostly on jbosstm/narayana but few words on other too.


    For building Narayana core you can use `` with few parameters. I intentionally skip testing as I want to get the output jar files as fast as possible.


    ./ clean install -Pcommunity -DskipTests -Didlj-enabled=true


    The script uses maven to get artifacts installed to the local repository. The other result is that directory `narayana-full/target` contains zip file with Narayana release.

    That could be for example `narayana/target/`.


    WildFly build


    Now when I want to get WildFly with updated Narayana modules. I can take the WildFly sources

    and build it. I can do the following


    git clone
    cd wildfly
    ./ install -B  -fae -DallTests -DskipTests


    If I want to build with a specific version of Narayana I use property ``.


    ./ clean install -B  -fae -DallTests -DskipTests


    If I just rebuilding already built WildFly distribution and I'm just want to update the Narayana jars it's fine to build just `dist` and `feature-pack`


    rm -rf build/target dist/target && ./ install -B  -fae -DskipTests -pl feature-pack,dist


    The WildFly distribution can be then found at folder `dist/target/wildfly-*-SNAPSHOT`


    Script to update Narayana module jars


    But this still takes some time and it's harder to do when I have already in hand WILDFLY distribution

    which I want to patch. Thus I wrote a small script to help me in that.


    The usage is quite straightforward.


    export JBOSS_HOME=path/to/wildfly-dist
    # run the script


    The script is following


    # trying to compile narayana sources
    # and then unpack full distro of narayana
    # and copy narayana jar files to modules of jboss home
    # Usage:
    # 1. go to Naryana source code folder
    # 2. export JBOSS_HOME=path/to/jboss
    # 3. run this script
    [ "x$JBOSS_HOME" = "x" ] || [ ! -e "$JBOSS_HOME" ] && echo "Property JBOSS_HOME:'$JBOSS_HOME' does not point to directory" && exit 3
    [ ! -e "$PWD/ArjunaCore" ] && echo "You are probably not at directory with Narayana sources" && exit 4
    # when first argument of the script is skip then do not compile
    if [ "x$1" != "xskip" ] && [ "x$1" != "xnocompile" ] && [ "$x" != "xsoft" ]; then
      ./ clean install -Pcommunity -DskipTests -Didlj-enabled=true
      [ $? -ne 0 ] && echo "[ERROR] Compilation failed" && exit 1
    function updateModuleXml {
      local MODULE_PATH="$1"
      local FILE_TO_COPY_PART="$2"
      local FILE_TO_COPY_REGEXP="*${FILE_TO_COPY_PART}*.jar"
      local MODULE_XML="$MODULE_PATH/module.xml"
      local FILE_TO_COPY=`find -name "$FILE_TO_COPY_REGEXP" | grep -ve 'jbossxts-api' | grep -ve '-sources' | grep -ve '-tests' | grep -ve 'WEB-INF' | grep -ve '-javadoc'`
      local FILE_TO_COPY_BASENAME=`basename "$FILE_TO_COPY"` 
      [ "x$FILE_TO_COPY" = 'x' ] && echo "[ERROR] there is no file found for '$FILE_TO_COPY_PART'" && exit 2
      echo "Copying '$FILE_TO_COPY' to '$MODULE_PATH'"
      # backup module.xml file
      cp -b -f "$MODULE_XML" "$MODULE_PATH/module.xml.bkp"
      sed -i "/$FILE_TO_COPY_BASENAME/d" "$MODULE_XML"
      grep -qe "<!-- <resource.*${FILE_TO_COPY_PART}" "$MODULE_XML"
      [ $? -ne 0 ] && sed -i "s/\(<resource.*${FILE_TO_COPY_PART}.*jar.*\)/<!-- \1 -->/" "$MODULE_XML" 
      sed -i "s|\(<resources>.*\)|\1\n        <resource-root path=\"$FILE_TO_COPY_BASENAME\"/>|" "$MODULE_XML"
      echo "File '$MODULE_XML' was updated with resource '$FILE_TO_COPY_BASENAME'"
    pushd "$PWD" > /dev/null
    cd narayana-full/target
    find -type d -name '*-full-*' -print0 | xargs -0 -I file rm -rf file
    rm -rf ./unzipped
    unzip -q *-full-*.zip -d unzipped
    [ $? -ne 0 ] && echo "Can't unzip -full-*.zip at $PWD" && exit 3
    cd unzipped
    if [ "x$1" = "xjacorb" ] || [ "x$2" = "xjacorb" ]; then TXN_JAR='-jacorb'; fi
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/jts/main" "$TXN_JAR"
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/jts/integration/main" "narayana-jts-integration"
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/xts/main" 'jbossxts'
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/xts/main" 'jbosstxbridge'
    popd > /dev/null
    pushd rts/at
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/narayana/rts/main" 'restat-api'
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/narayana/rts/main" 'restat-integration'
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/narayana/rts/main" 'restat-bridge'
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/narayana/rts/main" 'restat-util'
    popd > /dev/null


    The script compile the whole Narayana distro, take the zip from the `narayana-full` and updates jars of Narayana modules under the JBOSS_HOME.


    If I want to build just part of the Narayana (let's say only ArjunaJTA/cdi maven module) you can rebuilt

    only the expected maven module and use parameter `skip` of the script to only update JBOSS_HOME but not running the Narayana compilation.


    ./ clean install -Pcommunity -DskipTests -Didlj-enabled=true -pl ArjunaJTA/cdi,ArjunaJTS/narayana-jts-idlj,narayana-full skip


    ArjunaJTA/cdi contains the updated code, the ArjunaJTS/narayana-jts-idlj causes the artifact which is put to WildFly to be rebuilt based on the compiled 'cdi' classes and narayana-full is required as '.zip' file is used by the update script.


    Update module.xml of other jars


    There is another script which I started to use for updating specific WildFly modules when

    I rebuilt from sources.


    The usage is following


    ./ ./XTS/jbossxts/target/jbossxts-5.7.1.Final-SNAPSHOT.jar ~/jboss/wildfly/dist/target/wildfly-11.0.0.Final-SNAPSHOT/modules/system/layers/base/org/jboss/xts/main


    The script is following


    # set -x
    [ "x$1" = "x" ] || [ "x$2" = "x" ] &&\
      echo "Usage:" &&\
      echo "  `basename $0` <jar-file-path> <module-path:path_to_module_main_folder>" &&\
      echo "Example:" &&\
      echo "  `basename $0` target/xts.jar ${JBOSS_HOME}/modules/system/layers/base/org/jboss/xts/main" &&\
      echo "  - or -" &&\
      echo "  `basename $0` target/xts.jar xts" &&\
      echo "  (shortcuts are xts/txnclient/spi/jts)" &&\
      exit 1
    [ "x$MODULE_PATH_INPUT" = "xxts" ] && MODULE_PATH="${JBOSS_HOME}/modules/system/layers/base/org/jboss/xts/main"
    [ "x$MODULE_PATH_INPUT" = "xtxnclient" ] && MODULE_PATH="${JBOSS_HOME}/modules/system/layers/base/org/wildfly/transaction/client/main"
    [ "x$MODULE_PATH_INPUT" = "xspi" ] && MODULE_PATH="${JBOSS_HOME}/modules/system/layers/base/org/jboss/jboss-transaction-spi/main"
    [ "x$MODULE_PATH_INPUT" = "xjts" ] && MODULE_PATH="${JBOSS_HOME}/modules/system/layers/base/org/jboss/jts/main"
    REGEXP=`echo $FILE_TO_COPY_BASENAME | sed 's/-SNAPSHOT.*.jar//' | sed 's/-[0-9.]*\(Final\)\{0,1\}.*//'`
    REGEXP=`echo $REGEXP | sed 's/\.jar$//'`
    [ ! -e "$MODULE_XML" ] && echo "module.xml at '$MODULE_XML' does not exist" && exit 3
    [ ! -e "$FILE_TO_COPY" ] && echo "File '$FILE_TO_COPY' does not exist to be copied under '$MODULE_PATH'" && exit 4
    sed -i "/<!-- <resource.*${REGEXP}/! s/\(<resource.*${REGEXP}.*jar.*\)/<!-- \1 -->/" "$MODULE_XML"
    sed -i "s|\(<resources>.*\)|\1\n        <resource-root path=\"$FILE_TO_COPY_BASENAME\"/>|" "$MODULE_XML"
    echo "File '$MODULE_XML' was updated with resource '$FILE_TO_COPY_BASENAME'"
    echo "File '$FILE_TO_COPY' copied and '$MODULE_XML' updated"


    I use this for example when I built the wildfly-transaction-client too.


    git clone
    cd widlfly-transaction-client
    mvn clean install
    export JBOSS_HOME=~/jboss/wildfly/dist/target/wildfly-11.0.0.Final-SNAPSHOT
    echo $JBOSS_HOME target/wildfly-transaction-client-1.0.0.CR5-SNAPSHOT.jar txnclient



    DISCLAIMER: the scripts work for me and there could be some bugs in them or for case of your environment.