Version 18

    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.

     

    https://github.com/jbosstm/narayana

    org.jboss.narayana.compensations

    org.jboss.narayana.rts

    org.jboss.narayana.txframework

    org.jboss.xts

    org.jboss.jts.integration

    org.jboss.jts


    https://github.com/jbosstm/jboss-transaction-spi

    org.jboss.jboss-transaction-spi


    https://github.com/wildfly/wildfly

    org.jboss.as.transactions

    org.jboss.as.xts

    org.wildfly.extension.rts


    https://github.com/wildfly/wildfly-transaction-client

    org.wildfly.transaction.client

     

    https://github.com/wildfly/wildfly-http-client

    org.wildfly.http-client.transaction

     

    Narayana build

     

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

     

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

     

    ./build.sh 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/narayana-full-5.7.1.Final-SNAPSHOT-bin.zip`.

     

    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 https://github.com/wildfly/wildfly
    cd wildfly
    ./build.sh install -B -fae -DallTests -DskipTests

     

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

     

    ./build.sh clean install -B -fae -DallTests -DskipTests -Dversion.org.jboss.narayana=5.7.1.Final-SNAPSHOT

     

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

    • WildFly 12: `dist` and `feature-pack`
    rm -rf build/target dist/target && ./build.sh install -B -fae -DskipTests -Dversion.org.jboss.narayana=5.7.1.Final-SNAPSHOT -pl feature-pack,dist

     

    • WildFly 13: `dist` and `galleon-pack`
    ./build.sh clean install -B -fae -DallTests -DskipTests -pl dist,galleon-pack\
     -Dversion.org.jboss.narayana=5.8.3.Final-SNAPSHOT -Dversion.org.jboss.jboss-transaction-spi=7.6.1.Final-SNAPSHOT -Dversion.org.wildfly.transaction.client=1.0.3.ReadOnly

     

    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.

     

    cd $NARAYANA_HOME
    export JBOSS_HOME=path/to/wildfly-dist
    # run the script
    ./compile-narayana-update-jboss.sh

     

    The script is following

    (I do some changes time to time in my local copy of the script, you can check that variant as well at narayana-build.sh at Dropbox).

     

    #!/bin/sh
    
    # 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
    
    if [ "x$1" == "x-h" ] || [ "x$1" == "xhelp" ] || [ "x$1" == "x--help" ]; then
    echo "Usage:"
    echo " 1. go to Naryana source code folder"
    echo " 2. export JBOSS_HOME=path/to/jboss"
    echo " 3. run this script: $0"
    echo
    echo "`basename $0` [-h|help] [skip|nocompile|soft]"
    echo " help printing this help"
    echo " nocompile not compiling the source codes"
    echo " justcompile only compile, no copy source"
    echo "When JBOSS_HOME is not specified 'unset JBOSS_HOME' then only compilation is run"
    echo
    exit 0
    fi
    
    [ ! -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" != "xnocompile" ] && [ "x$1" != "xno-compile" ] && [ "x$1" != "xskip" ]; then
    rm -rf narayana-full/target
    ./build.sh clean install -Pcommunity -DskipTests -Didlj-enabled=true
    [ $? -ne 0 ] && echo "[ERROR] Compilation failed" && exit 1
    fi
    
    if [ "x$1" = "xjustcompile" ]; then
    exit 0
    fi
    
    [ "x$JBOSS_HOME" = "x" ] || [ ! -e "$JBOSS_HOME" ] && echo "Property JBOSS_HOME:'$JBOSS_HOME' does not point to any existing directory. Skipping the module update phase." && exit 3
    JBOSS_HOME=${JBOSS_HOME%/}
    
    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'"
    cp "$FILE_TO_COPY" "$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
    
    TXN_JAR='idlj'
    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
    pushd compensations
    updateModuleXml "$JBOSS_HOME/modules/system/layers/base/org/jboss/narayana/compensations/main" 'compensations'
    
    
    popd > /dev/null
    
    

     

    The script compiles 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.

     

    ./build.sh clean install -Pcommunity -DskipTests -Didlj-enabled=true -pl ArjunaJTA/cdi,ArjunaJTS/narayana-jts-idlj,narayana-full
    compile-narayana-update-jboss.sh 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

     

    ./update-module-xml.sh ./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

    (changes done at my local copy on my machine can be seen at update-module-xml.sh at Dropbox)

     

    #!/bin/sh
    # set -x
    
    [ "x$1" = "x" ] || [ "x$1" = "x-h" ] || [ "x$2" = "x" ] &&\
     echo "Usage: with jar file defined" &&\
     echo " `basename $0` <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 "Usage: with shortcut" &&\
     echo " `basename $0` " &&\
     echo " shortcuts are: xts|txnclient|wftc|spi|jts" &&\
     echo " when shortcut is used then \$JBOSS_HOME variable has to be defined" &&\
     echo "Example:" &&\
     echo " `basename $0` target/xts.jar xts" &&\
     exit 1
    
    # set -x
    FILE_TO_COPY="$1"
    MODULE_PATH_INPUT="$2"
    
    [ -e "$MODULE_PATH_INPUT" ] && MODULE_PATH="$MODULE_PATH_INPUT"
    [ ! -e "$MODULE_PATH" ] && MODULE_PATH="${JBOSS_HOME}/${MODULE_PATH_INPUT}"
    
    [ "x$MODULE_PATH_INPUT" = "xxts" ] && MODULE_PATH="${JBOSS_HOME}/modules/system/layers/base/org/jboss/xts/main"
    [[ "$MODULE_PATH_INPUT" =~ txnclient|wftc ]] && 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"
    
    MODULE_PATH=${MODULE_PATH%/}
    
    MODULE_XML="$MODULE_PATH/module.xml"
    FILE_TO_COPY_BASENAME=`basename "$FILE_TO_COPY"`
    REGEXP=`echo $FILE_TO_COPY_BASENAME | sed 's/-SNAPSHOT.*.jar//' | sed 's/-[0-9.]*\(Final\)\{0,1\}.*//'`
    REGEXP=`echo $REGEXP | sed 's/\.jar$//'`
    
    if [ ! -e "$MODULE_XML" ]; then
     echo "[ERROR] Wrong second argument '$MODULE_PATH_INPUT' as the path does not contain 'module.xml' and '$MODULE_XML' does not exist."
     [ -z ${JBOSS_HOME+x} ] && echo "[WARN] Consider to define variable \$JBOSS_HOME as it's unset"
     exit 3
    fi
    [ ! -e "$FILE_TO_COPY" ] && echo "File '$FILE_TO_COPY' does not exist to be copied under '$MODULE_PATH'" && exit 4
    
    cp "$FILE_TO_COPY" "$MODULE_PATH"
    
    sed -i "/$FILE_TO_COPY_BASENAME/d" "$MODULE_XML"
    sed -i "//" "$MODULE_XML"
    sed -i "s|\(.*\)|\1\n |" "$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.

     

    git clone https://github.com/wildfly/wildfly-transaction-client
    cd widlfly-transaction-client
    mvn clean install
    export JBOSS_HOME=~/jboss/wildfly/dist/target/wildfly-11.0.0.Final-SNAPSHOT
    echo $JBOSS_HOME
    update-module-xml.sh 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.