changeset 1572:c789ce56f99b

Refactor and stabilize archetype verifiers, but don't run in default Make target reviewed-by: jerboaa review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-November/011795.html
author Jon VanAlten <jon.vanalten@redhat.com>
date Thu, 27 Nov 2014 04:08:51 -0700
parents 62148e99bbd7
children 872748861ab1
files Makefile distribution/tools/verify-archetype-ext.sh distribution/tools/verify-archetype-functions.sh distribution/tools/verify-archetype-multimodule.sh
diffstat 4 files changed, 279 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Nov 27 18:35:57 2014 -0500
+++ b/Makefile	Thu Nov 27 04:08:51 2014 -0700
@@ -25,18 +25,23 @@
     MAVEN_JAVADOC = javadoc:aggregate
 endif
 
-all: core verify-archetype-ext verify-archetype-multimodule
+# Default to just building core
+all: core
 
-# Default to just building core
 core:
 	$(MAVEN) -f $(POM) $(MAVEN_FLAGS) $(MAVEN_SKIP_TEST) clean $(GOAL) $(MAVEN_JAVADOC)
 
+verify-archetypes: skip-tests-and-install verify-archetype-ext verify-archetype-multimodule
+
 verify-archetype-ext:
 	$(BASH) distribution/tools/verify-archetype-ext.sh $(REPO_LOC) $(THERMOSTAT_HOME)
 
 verify-archetype-multimodule:
 	$(BASH) distribution/tools/verify-archetype-multimodule.sh $(REPO_LOC) $(THERMOSTAT_HOME)
 
+skip-tests-and-install: clean-repo create-repo-dir
+	$(MAVEN) -f $(POM) $(MAVEN_FLAGS) $(REPO_FLAG) -Dmaven.test.skip=true clean install
+
 # 
 # Cleaning the repo prevents things like not seeing build failures
 # after bundles have been renamed.
--- a/distribution/tools/verify-archetype-ext.sh	Thu Nov 27 18:35:57 2014 -0500
+++ b/distribution/tools/verify-archetype-ext.sh	Thu Nov 27 04:08:51 2014 -0700
@@ -1,5 +1,41 @@
 #!/bin/bash
 #
+# Copyright 2012-2014 Red Hat, Inc.
+#
+# This file is part of Thermostat.
+#
+# Thermostat 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 2, or (at your
+# option) any later version.
+#
+# Thermostat 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 Thermostat; see the file COPYING.  If not see
+# <http://www.gnu.org/licenses/>.
+#
+# Linking this code with other modules is making a combined work
+# based on this code.  Thus, the terms and conditions of the GNU
+# General Public License cover the whole combination.
+#
+# As a special exception, the copyright holders of this code give
+# you permission to link this code with independent modules to
+# produce an executable, regardless of the license terms of these
+# independent modules, and to copy and distribute the resulting
+# executable under terms of your choice, provided that you also
+# meet, for each linked independent module, the terms and conditions
+# of the license of that module.  An independent module is a module
+# which is not derived from or based on this code.  If you modify
+# this code, you may extend this exception to your version of the
+# library, but you are not obligated to do so.  If you do not wish
+# to do so, delete this exception statement from your version.
+#
+#####################################################################
+#
 # Debugging (uncomment as needed)
 #
 # Treat undefined variables as errors
@@ -9,23 +45,26 @@
 # Verbose output
 #set -xv
 
-if [ $# -ne 2 ]; then
-  echo "Usage: $0 LOCAL_MVN_REPO THERMOSTAT_HOME" 1>&2
-  exit 1
-fi
-
 M2_REPO=$1
 THERMOSTAT_HOME=$2
+KEEPTMP=$3
+ARTIFACT_ID=helloworld
+
+source distribution/tools/verify-archetype-functions.sh
+check_usage $@
+
+function install_plugin() {
+  # install built hello-world plugin
+  # put a filtered thermostat-plugin.xml in target
+  mkdir $PLUGIN_INSTALL_LOCATION
+  exit_if_bad_return_value $? "Plugin directory already exists."
+  cp target/helloworld-0.0.1-SNAPSHOT.jar target/classes/thermostat-plugin.xml $PLUGIN_INSTALL_LOCATION
+}
 
 echo Using m2 repo: $M2_REPO
 echo Using THERMOSTAT_HOME to which to install plugin to: $THERMOSTAT_HOME
 
-
-find "$M2_REPO" -name '*thermostat*' -print0 | xargs -0 rm -rf;
-mvn -Dmaven.test.skip=true -Dmaven.repo.local="$M2_REPO" clean install
-
 # Use the archetype in order to verify it works
-TMP_DIR=$(mktemp -d)
 pushd $TMP_DIR
 mvn archetype:generate -DarchetypeCatalog=local \
                        -Dmaven.repo.local="$M2_REPO" \
@@ -34,55 +73,36 @@
                           -DbundleSymbolicName=com.example.thermostat.helloworld \
                           -Dpackage=com.example.thermostat \
                           -DgroupId=com.example.thermostat \
-                          -DartifactId=helloworld \
+                          -DartifactId="$ARTIFACT_ID" \
                           -Dversion=0.0.1-SNAPSHOT \
                           -DmoduleName="Thermostat Hello World Extension Command"
+exit_if_bad_return_value $? "Could not generate plugin from archetype"
 
 # Build plugin
-pushd helloworld
+pushd ${ARTIFACT_ID}
 mvn -Dmaven.repo.local="$M2_REPO" package
+exit_if_bad_return_value $? "Could not build plugin"
 
-# install built hello-world plugin
-# put a filtered thermostat-plugin.xml in target
-if [ -e $THERMOSTAT_HOME/plugins/helloworld ]; then
-  rm -rf $THERMOSTAT_HOME/plugins/helloworld
-fi
-mkdir $THERMOSTAT_HOME/plugins/helloworld
-cp target/helloworld-0.0.1-SNAPSHOT.jar target/classes/thermostat-plugin.xml $THERMOSTAT_HOME/plugins/helloworld
-popd # plugin-build
+install_plugin
 
-popd
+popd # ARTIFACT_ID
+popd # TMP_DIR
 
 # Make thermostat runnable. I.e. prepare a thermostat user home
 # run devsetup
-USER_THERMOSTAT_HOME=$(mktemp -d)
-export USER_THERMOSTAT_HOME
 $THERMOSTAT_HOME/bin/thermostat-devsetup
+exit_if_bad_return_value $? "Error configuring Thermostat (devsetup)"
 
-# verify "example-command" shows up and works
-retval=0
-$THERMOSTAT_HOME/bin/thermostat help | grep example-command
-retval=$(( $retval + $? ))
-$THERMOSTAT_HOME/bin/thermostat example-command | grep "Hello World!"
-retval=$(( $retval + $? ))
+# verify "example-command" shows up in help
+$THERMOSTAT_EXE help | grep example-command
+exit_if_bad_return_value $? "Plugin command not appearing in Thermostat help"
 
-# Clean up if all went fine
-if [ $retval -eq 0 ]; then
-  rm -rf $TMP_DIR
-  rm -rf $USER_THERMOSTAT_HOME
-  rm -rf $THERMOSTAT_HOME/plugins/helloworld
-else
-  cat 1>&2 <<END
-Something went wrong. You may find the following info useful.
+# verify "example-command" works as expected
+$THERMOSTAT_HOME/bin/thermostat example-command | grep "Hello World!"
+exit_if_bad_return_value $? "Plugin command not working"
 
-Plug-in root should be: $TMP_DIR/helloworld
-Recompile with:
-  $ mvn -Dmaven.repo.local="$M2_REPO" clean package
+cleanup
 
-USER_THERMOSTAT_HOME was:     $USER_THERMOSTAT_HOME
-THERMOSTAT_HOME was:          $THERMOSTAT_HOME
-Plugin install directory was: $THERMOSTAT_HOME/plugins/helloworld
-END
-fi
+echo "Simple archetype OK"
 
-exit $retval
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/distribution/tools/verify-archetype-functions.sh	Thu Nov 27 04:08:51 2014 -0700
@@ -0,0 +1,108 @@
+#
+# Copyright 2012-2014 Red Hat, Inc.
+#
+# This file is part of Thermostat.
+#
+# Thermostat 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 2, or (at your
+# option) any later version.
+#
+# Thermostat 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 Thermostat; see the file COPYING.  If not see
+# <http://www.gnu.org/licenses/>.
+#
+# Linking this code with other modules is making a combined work
+# based on this code.  Thus, the terms and conditions of the GNU
+# General Public License cover the whole combination.
+#
+# As a special exception, the copyright holders of this code give
+# you permission to link this code with independent modules to
+# produce an executable, regardless of the license terms of these
+# independent modules, and to copy and distribute the resulting
+# executable under terms of your choice, provided that you also
+# meet, for each linked independent module, the terms and conditions
+# of the license of that module.  An independent module is a module
+# which is not derived from or based on this code.  If you modify
+# this code, you may extend this exception to your version of the
+# library, but you are not obligated to do so.  If you do not wish
+# to do so, delete this exception statement from your version.
+#####################################################################
+#
+# Common functionality for verifying both simple and multi-module archetypes
+
+THERMOSTAT_EXE="$THERMOSTAT_HOME/bin/thermostat"
+TMP_DIR=$(mktemp -d)
+PLUGIN_INSTALL_LOCATION="$THERMOSTAT_HOME/plugins/$ARTIFACT_ID"
+USER_THERMOSTAT_HOME="$TMP_DIR/userhome"
+export USER_THERMOSTAT_HOME
+
+function is_keeptmp_ok() {
+  if [ "x$1" ==  "x" -o "x$1" == "x--keepTmp" ]; then
+    return 0
+  fi
+  return -1
+}
+
+function check_usage() {
+  is_keeptmp_ok $3
+  if [ $? -ne 0 -o $# -lt 2 -o $# -gt 3 ]; then
+    echo "Usage: $0 <LOCAL_MVN_REPO> <THERMOSTAT_HOME> [--keepTmp]" 1>&2
+    exit 1
+  fi
+}
+
+function delete_dir_recursively() {
+  DIR_TO_CLEAN=$1
+  if [ -e $DIR_TO_CLEAN ]; then
+    rm -rf $DIR_TO_CLEAN
+  else
+    echo Warning: cannot delete directory that does not exist: $DIR_TO_CLEAN
+  fi
+}
+
+function cleanup_tempdirs() {
+  for DIR_TO_CLEAN in $@
+  do
+    delete_dir_recursively $DIR_TO_CLEAN
+  done
+}
+
+function cleanup() {
+  if [ "x$KEEPTEMP" != "x--keepTemp" ]; then
+    cleanup_tempdirs $TMP_DIR \
+          $PLUGIN_INSTALL_LOCATION \
+          $THERMOSTAT_HOME/webapp/WEB-INF/lib/"$ARTIFACT_ID"-storage-common-0.0.1-SNAPSHOT.jar
+  fi
+}
+
+function output_fail_information() {
+  cat 1>&2 <<END
+Something went wrong. You may find the following info useful.
+
+Plug-in root should be: $TMP_DIR/$ARTIFACT_ID
+Recompile with:
+  $ mvn -Dmaven.repo.local="$M2_REPO" clean package
+
+USER_THERMOSTAT_HOME was:     $USER_THERMOSTAT_HOME
+THERMOSTAT_HOME was:          $THERMOSTAT_HOME
+Plugin install directory was: $THERMOSTAT_HOME/plugins/$PLUGIN_DIR
+END
+}
+
+function exit_if_bad_return_value() {
+  RVAL=$1
+  if [ $RVAL -ne 0 ]; then
+    cleanup
+    shift
+    echo $@
+    output_fail_information
+    exit $RVAL
+  fi
+}
+
--- a/distribution/tools/verify-archetype-multimodule.sh	Thu Nov 27 18:35:57 2014 -0500
+++ b/distribution/tools/verify-archetype-multimodule.sh	Thu Nov 27 04:08:51 2014 -0700
@@ -1,5 +1,39 @@
 #!/bin/bash
 #
+# This file is part of Thermostat.
+#
+# Thermostat 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 2, or (at your
+# option) any later version.
+#
+# Thermostat 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 Thermostat; see the file COPYING.  If not see
+# <http://www.gnu.org/licenses/>.
+#
+# Linking this code with other modules is making a combined work
+# based on this code.  Thus, the terms and conditions of the GNU
+# General Public License cover the whole combination.
+#
+# As a special exception, the copyright holders of this code give
+# you permission to link this code with independent modules to
+# produce an executable, regardless of the license terms of these
+# independent modules, and to copy and distribute the resulting
+# executable under terms of your choice, provided that you also
+# meet, for each linked independent module, the terms and conditions
+# of the license of that module.  An independent module is a module
+# which is not derived from or based on this code.  If you modify
+# this code, you may extend this exception to your version of the
+# library, but you are not obligated to do so.  If you do not wish
+# to do so, delete this exception statement from your version.
+#
+#####################################################################
+#
 # Debugging (uncomment as needed)
 #
 # Treat undefined variables as errors
@@ -9,24 +43,54 @@
 # Verbose output
 #set -xv
 
-if [ $# -ne 2 ]; then
-  echo "Usage: $0 LOCAL_MVN_REPO THERMOSTAT_HOME" 1>&2
-  exit 1
-fi
-
 M2_REPO=$1
 THERMOSTAT_HOME=$2
-PLUGIN_DIR="foo-bar"
+KEEPTEMP=$3
 ARTIFACT_ID="helloworld-multimodule"
 
+source distribution/tools/verify-archetype-functions.sh
+check_usage $@
+
+WSS_PID="$TMP_DIR/web-storage-service.pid"
+WSS_OUTPUT="$TMP_DIR/wss_output.txt"
+
+function launch_and_wait_for_web_storage() {
+  $THERMOSTAT_EXE -Tbg $WSS_PID web-storage-service > $WSS_OUTPUT 2>&1
+  TRIES=0
+  while [[ ! -f $WSS_OUTPUT || ! `grep -e "Agent id:" < $WSS_OUTPUT` ]]; do
+    # don't wait forever
+    if [ $TRIES -ge 10 ]; then
+      return -1
+    fi
+    sleep 1
+    ((TRIES++))
+  done
+  return 0
+}
+
+function kill_and_wait_for_webstorage() {
+  if [ -f $WSS_PID ]; then
+    PID="$(cat $WSS_PID)"
+    kill "$PID"
+    TRIES=0
+    while ps -p $PID > /dev/null; do
+      # don't wait forever
+      if [ $TRIES -ge 15 ]; then
+        return -1
+      fi
+      sleep 1
+      ((TRIES++))
+    done
+  fi
+  return 0
+}
+
 echo Using m2 repo: $M2_REPO
 echo Using THERMOSTAT_HOME to which to install plugin to: $THERMOSTAT_HOME
 
-find "$M2_REPO" -name '*thermostat*' -print0 | xargs -0 rm -rf;
-mvn -Dmaven.test.skip=true -Dmaven.repo.local="$M2_REPO" clean install
+# BEGIN TEST
 
 # Use the archetype in order to verify it works
-TMP_DIR=$(mktemp -d)
 pushd $TMP_DIR
 mvn archetype:generate -DarchetypeCatalog=local \
                        -Dmaven.repo.local="$M2_REPO" \
@@ -38,37 +102,29 @@
                           -DartifactId="$ARTIFACT_ID" \
                           -Dversion=0.0.1-SNAPSHOT \
                           -DmoduleName="Thermostat Hello World Extension Command" \
-                          -DpluginDeployDir="$PLUGIN_DIR"
+                          -DpluginDeployDir="$ARTIFACT_ID"
+exit_if_bad_return_value $? "Could not generate plugin from archetype"
 
 # Build plugin
 pushd "$ARTIFACT_ID"
 mvn -Dmaven.repo.local="$M2_REPO" package
+exit_if_bad_return_value $? "Could not build plugin"
 
 # deploy.sh cleans up previously deployed bits (if any)
 # pass on THERMOSTAT_HOME which deploy.sh uses.
 THERMOSTAT_HOME=$THERMOSTAT_HOME bash deploy.sh
-popd # ARTIFACT_ID dir
+exit_if_bad_return_value $? "Could not deploy plugin"
+
+popd # ARTIFACT_ID
 popd # TMP_DIR
 
 # Make thermostat runnable. I.e. prepare a thermostat user home
 # run devsetup
-USER_THERMOSTAT_HOME=$(mktemp -d)
-export USER_THERMOSTAT_HOME
 $THERMOSTAT_HOME/bin/thermostat-devsetup
-
-# launch web-storage-service
-WSS_OUTPUT="$(mktemp)"
-$THERMOSTAT_HOME/bin/thermostat -Tbg $TMP_DIR/web-storage-service.pid web-storage-service > $WSS_OUTPUT 2>&1 
+exit_if_bad_return_value $? "Error configuring Thermostat (devsetup)"
 
-# Wait for web-storage-service to come up
-COUNT=0
-while [[ ! -f $WSS_OUTPUT || ! `grep -e "Agent id:" < $WSS_OUTPUT` ]]; do 
-	sleep 1
-	if [ $COUNT -ge 10 ]; then
-		break
-	fi
-	((COUNT++))
-done
+launch_and_wait_for_web_storage
+exit_if_bad_return_value $? "Web Storage Service not coming up"
 
 # Why head -n4? Output looks like the following:
 #
@@ -79,51 +135,25 @@
 # 
 # So the first two lines is prompt, 1 line header, one line with an agent ID
 # which we are actually interested in.
-AGENT_ID="$(echo -e "client-tester\ntester" | $THERMOSTAT_HOME/bin/thermostat list-vms | head -n4 | tail -n1 | cut -d' ' -f1 )"
+AGENT_ID="$(echo -e "client-tester\ntester" | $THERMOSTAT_EXE list-vms | head -n4 | tail -n1 | cut -d' ' -f1 )"
 
-# verify "example-command" shows up and works
-retval=0
-$THERMOSTAT_HOME/bin/thermostat help | grep example-command
-retval=$(( $retval + $? ))
-echo -e "client-tester\ntester" | $THERMOSTAT_HOME/bin/thermostat example-command -a $AGENT_ID | grep 'Message: Hello World!'
-retval=$(( $retval + $? ))
-
-# kill the process web-storage-service spawned earlier
-MONGO_PROCESSES="$(echo $(ps aux | grep mongod | grep -v grep | wc -l))"
-kill "$(cat $TMP_DIR/web-storage-service.pid)"
+# verify "example-command" shows up in help
+$THERMOSTAT_EXE help | grep example-command
+exit_if_bad_return_value $? "Plugin command not appearing in Thermostat help"
 
-# ensure web-storage-service closes before cleanup 
-COUNT=0
-MONGO_EXPECTED=$((MONGO_PROCESSES-1))
-while [[ $MONGO_PROCESSES -gt $MONGO_EXPECTED ]]; do 
-	sleep 1
-	MONGO_PROCESSES="$(echo $(ps aux | grep mongod | grep -v grep | wc -l))"
-	((COUNT++))
-	if [ $COUNT -ge 15 ]; then
-		retval=$(($retval+1))
-		break
-	fi
-done
+# verify "example-command" works as expected
+echo -e "client-tester\ntester" | $THERMOSTAT_EXE example-command -a $AGENT_ID | grep 'Message: Hello World!'
+exit_if_bad_return_value $? "Plugin command not working"
 
-if [ $retval -eq 0 ]; then
-  rm -rf $TMP_DIR
-  rm -rf $USER_THERMOSTAT_HOME
-  # clean-up plugin artifacts from THERMOSTAT_HOME which we've used for
-  # installation.
-  rm -rf $THERMOSTAT_HOME/plugins/$PLUGIN_DIR
-  rm -rf $THERMOSTAT_HOME/webapp/WEB-INF/lib/"$ARTIFACT_ID"-storage-common*.jar
-else
-  cat 1>&2 <<END
-Something went wrong. You may find the following info useful.
+kill_and_wait_for_webstorage
 
-Plug-in root should be: $TMP_DIR/$ARTIFACT_ID
-Recompile with:
-  $ mvn -Dmaven.repo.local="$M2_REPO" clean package
-
-USER_THERMOSTAT_HOME was:     $USER_THERMOSTAT_HOME
-THERMOSTAT_HOME was:          $THERMOSTAT_HOME
-Plugin install directory was: $THERMOSTAT_HOME/plugins/$PLUGIN_DIR
-END
+if [ $? -ne 0 ]; then
+  echo "Warning: Problem shutting down Web Storage Service"
 fi
 
-exit $retval
+cleanup
+
+echo "Multi-module archetype OK."
+
+exit 0
+