From f869e80bd19acf2ff33bb66aa38ae72cbf23ae55 Mon Sep 17 00:00:00 2001 From: jensp Date: Wed, 1 Mar 2017 13:59:50 +0000 Subject: [PATCH] CCM NG: Build helper script: Application server to use is now deduced from the profile name for test subcommands. git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4610 8810af33-2d31-482b-a856-94f89814c4df Former-commit-id: f82f771eb2d66297d44a3055ac4cf6a314f984c7 --- ccm-readme.txt | 193 +++++++++++++++++++++------------- ccm.sh | 275 +++++++++++++++++++++++++++++-------------------- 2 files changed, 282 insertions(+), 186 deletions(-) diff --git a/ccm-readme.txt b/ccm-readme.txt index 1988b69f8..cf761bc07 100644 --- a/ccm-readme.txt +++ b/ccm-readme.txt @@ -2,22 +2,19 @@ ccm.sh is a helper script for building and running LibreCCM in a development environment. It provides shortcuts for several Maven goals. The available subcommands are: -build-site [PROFILE] : Builds the Maven project site. -build [PROFILE] : Builds LibreCCM using the - provided profile -build-module MODULE [PROFILE] : Build a specific LibreCCM - module. -test-all [-s [-r RUNTIME]] [PROFILE] : Run tests for all modules. -test-module [-s [-r RUNTIME]] MODULE [PROFILE] : Run tests for a specific - LibreCCM module. -run-test [-s [-r RUNTIME]] MODULE TEST [PROFILE]: Run a specific testsuite or - a single test. -install-runtime [RUNTIME] : Download and install a - runtime (application server) - into ./runtime. -run [-r RUNTIME] [BUNDLE] : Run a runtime - (application server) -help : Show this help message. +build-site [PROFILE] : Builds the Maven project site. +build [PROFILE] : Builds LibreCCM using the provided + profile +build-module MODULE [PROFILE] : Build a specific LibreCCM module. +test-all [[PROFILE] [start]] : Run tests for all modules. +test-module MODULE [[PROFILE] [start]]: Run tests for a specific LibreCCM + module. +test MODULE TEST [[PROFILE] [start]] : Run a specific testsuite or a single + test method. +install-runtime [RUNTIME] : Download and install a runtime + (application server) into ./runtime. +run [-r RUNTIME] [BUNDLE] : Run a runtime (application server) +help : Show this help message. build-site [PROFILE] ==================== @@ -49,81 +46,121 @@ build-module MODULE [PROFILE] Build a specific LibreCCM module. Equivalent to - mvn clean package -pl $MODULE -am + mvn clean package -pl MODULE -am without a profile and to - mvn clean package -P$PROFILE -pl $MODULE -am + mvn clean package -PPROFILE -pl MODULE -am with a profile. -test-all [-s [-r RUNTIME]] [PROFILE] +test-all [[PROFILE] [start]] +============================ + +Run all tests for all modules. The name of the (optional) profile is used to +determine if a runtime (application server) is started and which application +server is started. Some profiles use Arquillian container adapters which don't +require a running application server. Others requires a running a application +server. For those profiles the application server deduced from the profile +name is started if the last parameter is "start". Otherwise the application +server must be started manully before running the tests. Please note that the +use of the "start" parameter is not recommanded because is may causes +problems. It is recommanded to either start the application server manually or +to use a profile which uses an Arquillian container adapter which starts the +application server itself. + +This subcommand is equivalent to the Maven command + + mvn clean test -PPROFILE + +with a profile and to + + mvn clean test + +without a profile. + +test-module MODULE [[PROFILE] [start]] +====================================== + +Runs the tests for a specific module. The name of the module is a mandatory +parameter. + +The name of the (optional) profile is +used to to determine if a runtime (application server) is started and +application server is started. Some profiles use Arquillian container adapters +which dont't require a running application server. Others require a running +application server. For those profiles the application is deduced from the +profile is started if the the last parameter is "start". Otherwise the +application server must be started manually before running the tests. Please +note that the use of the "start" parameter is not recommanded. It is +recommanded to either start the application server manually or to use a +profile which uses a container adapter which starts the application server +itself. + +This subcommand is equivalent to the Maven command + + mvn clean test -pl MODULE -am -PPROFILE + +with a profile and to + + mvn clean test -pl MODULE -am + +without a profile. + +test MODULE TEST [[PROFILE] [start]] ==================================== -Run all tests for all modules. If the -s flag is set a application server is -started in the background before the tests are run and stopped afterwards. -If no runtime is provided using -r RUNTIME Wildfly is used as runtime. See -the section "run" for Wildfly specific details. - -If a profile is provided the profile is used to run the tests. - -test-module [-s [-r RUNTIME]] MODULE [PROFILE] -============================================== - -Runs the tests for a specific module. If the -s flag is set a application -server is started in the background before the tests are run and stopped -afterwards. If no runtime is provided using -r RUNTIME Wildfly is used as -runtime. See the section "run" for Wildfly specific details. - -This subcommand has one mandatory parameter: The module which tests are run. -Optionally a profile can be provided. - -run-test [-s [-r RUNTIME]] MODULE TEST [PROFILE] -================================================ - -Runs the a specific testsuite or a single test. -If the -s flag is set a application -server is started in the background before the tests are run and stopped -afterwards. If no runtime is provided using -r RUNTIME Wildfly is used as -runtime. See the section "run" for Wildfly specific details. - -This subcommand has two mandatory parameter: -The module which contains the test(suite) to run and the test to run. The test -to run must be provided in the following syntax: +Runs the a specific testsuite or a single test. Module and test are mandatory +parameters. The testsuite or test to run is set using the following syntax: fully.qualified.classname.of.testclass[#test-method] -Optionally are profile can be provided. +The name of the (optional) profile is +used to to determine if a runtime (application server) is started and +application server is started. Some profiles use Arquillian container adapters +which dont't require a running application server. Others require a running +application server. For those profiles the application is deduced from the +profile is started if the the last parameter is "start". Otherwise the +application server must be started manually before running the tests. Please +note that the use of the "start" parameter is not recommanded. It is +recommanded to either start the application server manually or to use a +profile which uses a container adapter which starts the application server +itself. + +This subcommand is equivalent to the Maven command + + mvn clean test -Dtest=TEST -DfailIfNoTests=false -pl MODULE -am -PPROFILE + +with a profile and to + + mvn clean test -Dtest=TEST -DfailIfNoTests=false -pl MODULE -am + +without a profile. Some examples: Run all tests in the class org.libreccm.configuration.EqualsAndHashCodeTest in the ccm-core module: -ccm.sh runtest ccm-core org.libreccm.configuration.EqualsAndHashCodeTest +ccm.sh test ccm-core org.libreccm.configuration.EqualsAndHashCodeTest Run all tests in the class org.libreccm.core.CcmObjectRepositoryTest in the -ccm-core module. This tests is run using Arquillian and requires a runtime and -is only run when an integration test profile is used: +ccm-core module. These tests is run using Arquillian and require a runtime and +is only run when an integration test profile is used. The application server +must be started before the test are invoked. -ccm.sh runtest -s ccm-core org.libreccm.core.CcmObjectRepositoryTest -wildfly-remote-h2-mem +ccm.sh test ccm-core org.libreccm.core.CcmObjectRepositoryTest wildfly-remote-h2-mem + +This example runs the same tests as the previous example but uses a managed +profile. The application server will started by Arquillian automatically: + +ccm.sh test ccm-core org.libreccm.core.CcmObjectRepositoryTest +wildfly-managed-h2-mem Or if you only want to run the saveChangedCcmObject test: -ccm.sh runtest -s ccm-core -org.libreccm.core.CcmObjectRepositoryTest#saveChangedCcmObject wildfly-remote-h2-mem - -The last two examples used the default runtime (Wildfly). Invoking without a -specific runtime is equivalent to - -ccm.sh runtest -s -r wildfly ccm-core org.libreccm.core.CcmObjectRepositoryTest wildfly-remote-h2-mem - -ccm.sh runtest -s -r wildfly ccm-core org.libreccm.core.CcmObjectRepositoryTest#saveChangedCcmObject wildfly-remote-h2-mem - - - - +ccm.sh test ccm-core +org.libreccm.core.CcmObjectRepositoryTest#saveChangedCcmObject wildfly-managed-h2-mem install-runtime [RUNTIME] @@ -169,18 +206,28 @@ using Wildfly's administration UI available at http://localhost:9990 -Wildfly specific details ------------------------- +Supported iApplication server +============================= + +Wildfly +------- If the JBOSS_HOME environment variable is set the script will use the server -in the directory provided by JBOSS_HOME. You may provide a value for this -variable when calling the script: +in the directory provided by JBOSS_HOME for starting Wildfly. +You may provide a value for this variable when calling the script: JBOSS_HOME=/path/to/wildfly ./ccm.sh run [wildfly] +For profiles using the wildfly-arquillian-container-remote adapter Wildfly +must be started manually. The subcommands for running test have an optional +parameter for starting Wildfly automatically if a remote profile is used, but +this is not recommanded. If a profile is used which uses +wildfly-arquillian-container-managed Arquillian starts the container +automatically. + If JBOSS_HOME is not set the script will look for a Wildfly installation in ./runtime. The install-runtime subcommand can be used to install Wildfly -there. +there. The script passes this parameter to Maven in the required form. The datasource configuration is done using Wildfly's administration UI. To create a datasource open a browser and go to diff --git a/ccm.sh b/ccm.sh index 820748729..dcaa238c7 100755 --- a/ccm.sh +++ b/ccm.sh @@ -67,7 +67,7 @@ starttestruntime() { fi pushd $wildflyhome - sh "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PID_FILE=$wildflypidfile ./bin/standalone.sh" + LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$wildflypidfile ./bin/standalone.sh & popd echo "Waiting 120s for Wildfly to start up..." sleep 120 @@ -109,7 +109,7 @@ stoptestruntime() { echo "Setting wildflyhome..." wildflyhome="./runtime/wildfly-$wildflyversion" else - echo "There is not Wildfly in ./runtime/ and JBOSS_HOME is not set." + echo "There is no Wildfly in ./runtime/ and JBOSS_HOME is not set." echo "Please call install-runtime or set JBOSS_HOME" exit 1 fi @@ -129,126 +129,180 @@ stoptestruntime() { # Run all tests testall() { - - startruntime=false - runtime="wildfly" - profile="" - - if [ "$1" = "-s" ]; then - startruntime=true - if [ "$2" = "-r" ]; then - runtime=$3 - profile=$4 - else - profile=$2 + echo "Running all tests for all modules..." + if [[ $1 =~ ^wildfly-managed.* ]]; then + echo "...using a managed Wildfly container" + wildflyhome="" + if [ -n "$JBOSS_HOME" ]; then + echo "...JBOSS_HOME environment variable is set. Using Wildfly installation at $JBOSS_HOME." + wildflyhome=$JBOSS_HOME + elif [ -d "./runtime/wildfly-$wildflyversion" ]; then + echo "...using Wildfly installation in runtime directory" + pushd $wildflyhome + wildflyhome=`pwd` + popd + else + echo -e "\e[41mThere is no Wildfly-$wildflyversion in ./runtime nore is JBOSS_HOME set. Please install Wildfly-$wildflyversion into runtime by calling install-runtime or set the JBOSS_HOME environment variable to a valid location.\e[0m" + exit 1 + fi + + echo "...using profile $1" + echo "" + if [ -n $STARTUP_TIMEOUT ]; then + mvn clean test -Djboss.home=$wildflyhome -DstartuptimeoutInSeconds=$STARTUP_TIMEOUT -P$1 + else + mvn clean test -Djboss.home=$wildflyhome -P$1 fi - fi - if [ $startruntime ]; then - starttestruntime $runtime - fi + elif [[ $1 =~ ^wildfly-remote.* ]]; then + echo "...using a remote Wildfly container" + if [[ $2 == "start" ]]; then + echo "...starting runtime" + starttestruntime wildfly + else + echo "...runtime is started manually" + fi + + echo "...using profile $1" + mvn clean test -P$1 + + if [[ $2 == "start" ]]; then + echo "...stopping runtime" + fi + else + if [[ -n $1 ]]; then + echo -n -e "\e[43m" + echo "Warning: " + echo "The provided profile starts with an unknown prefix. Tests" + echo "which require a running application server may fail. " + echo -n -e "\e[0m" + + fi - if [ -n "$profile" ]; then - echo "Running tests for all modules with profile $profile..." - mvn clean test -P$profile - else - echo "Running tests for all modules..." mvn clean test fi - - if [ $startruntime ]; then - stoptestruntime $runtime - fi } # Run tests for a module testmodule() { - startruntime=false - runtime="wildfly" - module="" - profile="" - - if [ "$1" = "-r" ]; then - startruntime=true - if [ "$2" = "-r" ]; then - runtime=$3 - module=$4 - profile=$5 - else - module=$2 - profile=$3 - fi - fi - - if [ -z "$module" ]; then - echo "Error: No module to test. Exiting." + if [[ -z $1 ]]; then + echo -e "\e[41mUsage: ccm.sh test-module MODULE [PROFILE] [start]\e[0m" exit 1 fi - if [ $startruntime ]; then - starttestruntime $runtime - fi + echo "Running tests for module $1..." + if [[ $2 =~ ^wildfly-managed.* ]]; then + echo "...using a managed Wildfly container." + wildflyhome="" + if [ -n "$JBOSS_HOME" ]; then + echo "...JBOSS_HOME enviromentment variable is set Using Wildfly installation at $JBOSS_HOME." + wildflyhome=$JBOSS_HOME + elif [ -d "./runtime/wildfly-$wildflyversion" ]; then + echo "...using Wildfly installation in runtime-directory" + pushd $wildflyhome + wildflyhome=`pwd` + popd + else + echo -e "\e[41mThere is no Wildfly-$wildfly-version in ./runtime nore is JBOSS_HOME set. Please install Wildfly-$wildfly-version into ./runtime by calling install-runtime or set the JBOSS_HOME environment variable to valid location.\e[0m" + exit 1 + fi - if [ -n "$profile" ]; then - echo "Running tests for module $module with profile $profile..." - mvn clean test -P$profile -pl $module -am + echo "...using profile $2" + echo "" + if [ -n $STARTUP_TIMEOUT ]; then + mvn clean test -Djboss.home=$wildflyhome -DstartupTimeoutInSeconds=$STARTUP_TIMEOUT -pl $1 -am -P$1 + else + mvn clean test -Djboss.home=$wildflyhome -pl $1 -am -P$2 + fi + elif [[ $2 =~ ^wildfly-remote.* ]]; then + echo "Using a remote Wildfly container..." + if [[ $3 == "start" ]]; then + echo "...starting runtime" + starttestruntime wildfly + else + echo "...runtime is started manually" + fi + + echo "...using profile $2" + mvn clean test -pl $1 -am -P$2 + + if [[ $3 == "start" ]]; then + echo "...stopping runtime" + fi else - echo "Running tests for module $module..." - mvn clean test -pl $module $am - fi + if [[ -n $2 ]]; then + echo -n -e "\e[43m" + echo "Warning: " + echo "The provided profile starts with an unknown prefix. Tests" + echo "which require a running application server may fail. " + echo -n -e "\e[0m" + fi - if [ $startruntime ]; then - stoptestruntime $runtime + mvn clean test -pl $1 -am fi } # Run a single testsuite or test runtest() { - - startruntime=false - runtime="wildfly" - module="" - testtorun="" - profile="" - if [ "$1" = "-r" ]; then - startruntime=true - if [ "$2" = "-r" ]; then - runtime=$3 - module=$4 - profile=$5 + if [ -z "$1" -o -z "$2" ]; then + echo -e "\e[41mUsage: ccm.sh test-module MODULE TEST [PROFILE] [start]\e[0m" + exit 1 + fi + + echo "Running test $2 from module $1..." + if [[ $3 =~ ^wildfly-managed.* ]]; then + echo "...using a managed Wildfly container." + wildflyhome="" + if [ -n "$JBOSS_HOME" ]; then + echo "...JBOSS_HOME environment variable is set. Using Wildfly installation at $JBOSS_HOME." + wildflyhome=$JBOSS_HOME + elif [ -d "./runtime/wildfly-$wildflyversion" ]; then + echo "...using Wildfly installation in runtime directory" + pushd ./runtime/wildfly-$wildflyversion + wildflyhome=`pwd` + popd else - module=$2 - profile=$3 + echo -e "\e[41mThere is no Wildfly-$wildfly-version in ./runtime nore is JBOSS_HOME set. Please install Wildfly-$wildfly-version into ./runtime by calling install-runtime or set the JBOSS_HOME environment variable to valid location.\e[0m" + exit 1 + fi + + echo "...using Wildfly in $wildflyhome" + echo "...using profile $3" + echo "" + if [ -n $STARTUP_TIMEOUT ]; then + mvn clean test -Djboss.home=$wildflyhome -DstartupTimeoutInSeconds=$STARTUP_TIMEOUT -Dtest=$2 -DfailIfNoTests=false -pl $1 -am -P$3 + else + mvn clean test -Djboss.home=$wildflyhome -Dtest=$2 -DfailIfNoTests=false -pl $1 -am -P$3 + fi + elif [[ $3 =~ ^wildfly-remote.* ]]; then + echo "Using a remote Wildfly container..." + if [[ $4 == "start" ]]; then + echo "...starting runtime" + starttestruntime wildfly + else + echo "...runtime is started manually" fi - fi - if [ -z module ]; then - echo "No module provided. Please provide the module which contains the test to run. Exiting." - exit 1 - fi + mvn clean test -Dtest=$2 -DfailIfNoTests=false -pl $1 -am -P$3 - if [ -z testtorun ]; then - echo "No test to run provided. Exiting." - exit 1 - fi - - if [ $startruntime ]; then - starttestruntime $runtime - fi - - if [ -n "$profile" ]; then - echo "Running tests for module $module with profile $profile..." - mvn clean test -Dtest=$testtorun -DfailIfNoTests=false -P$profile -pl $module -am + if [[ $4 == "start" ]]; then + echo "...stopping runtime" + stoptestruntime wildfly + fi else - echo "Runnign tests for module $module..." - mvn clean test -D$testtorun -pl $module $am - fi + if [[ -n $3 ]]; then + echo -n -e "\e[43m" + echo "Warning: " + echo "The provided profile starts with an unknown prefix. Tests" + echo "which require a running application server may fail. " + echo -n -e "\e[0m" + fi - if [ $startruntime ]; then - stoptestruntime $runtime + mvn clean test -Dtest=$2 -DfailIfNoTests=false -pl $1 -am fi + } @@ -430,26 +484,21 @@ stopruntime() { showhelp() { echo "ccm.sh is a helper script for building and running LibreCCM in a - development environment. It provides shortcuts for several Maven goals. The - available subcommands are: +development environment. It provides shortcuts for several Maven goals. The available subcommands are: - build-site [PROFILE] : Builds the Maven project - site. - build [PROFILE] : Build all LibreCCM - modules. - build-module MODULE [PROFILE] : Build a specific LibreCCM - module. - test-all [-s [-r RUNTIME]] [PROFILE] : Run tests for all modules. - test-module [-s [-r RUNTIME]] MODULE [PROFILE] : Run tests for a specific - LibreCCM module. - run-test [-s [-r RUNTIME]] MODULE TEST [PROFILE]: Run a specific testsuite - or a single test. - install-runtime [RUNTIME] : Download and install a - runtime (application - server) into ./runtime - run [-r RUNTIME] [BUNDLE] : Run a runtime - (application server) - help : Show this help message. + build-site [PROFILE] : Builds the Maven project site. + build [PROFILE] : Build all LibreCCM modules. + build-module MODULE [PROFILE] : Build a specific LibreCCM module. + test-all [[PROFILE] [start]] : Run all tests for all modules. + test-module MODULE [[PROFILE] [start]] : Run all tests for a specific + LibreCCM module. + run-test MODULE TEST [[PROFILE] [start]]: Run a specific testsuite or a + single test method. + install-runtime [RUNTIME] : Download and install a runtime + (application server) into + ./runtime + run [-r RUNTIME] [BUNDLE] : Run a runtime (application server) + help : Show this help message. A detailed description of the subcommands is provided in ccm-readme.txt" @@ -464,7 +513,7 @@ case $1 in build-module) buildmodule $2 ;; test-all) testall $2 $3 $4 ;; test-module) testmodule $2 $3 $4 $5 ;; - run-test) runtest $2 $3 $4 $5 $6 ;; + test) runtest $2 $3 $4 $5 ;; install-runtime) installruntime $2 ;; run) run $2 $3 $4 ;; stop-runtime) stopruntime $2 ;;