view Makefile @ 184:40990362e151

Improved reporter - for compatibility report thermostat versions are now diplayed in heading and title of pages. - fixed bug in replacePatterns method in CommonUtilities class, when there is more then one pattern on single line.
author Zdenek Zambersky <zzambers@redhat.com>
date Fri, 15 May 2015 19:09:02 +0200
parents e37e710e45df
children 7bc828291ea4
line wrap: on
line source

#   ThermostatQA
# 
#    Copyright (C) 2013  Red Hat
# 

SOURCE_DIR=src
BUILD_DIR=$(shell realpath -m bin)
CLASSES_DIR=$(BUILD_DIR)/classes
CLASSES_TEMP_DIR=$(BUILD_DIR)/.classes
REPORT_DIR=reports
LOGS_DIR=logs
TEMPLATE_DIR=templates
SCREENSHOTS_DIR=screenshots

JAVAC=javac
JAVA=java

DAILY_REPORT_NAME=daily_report.txt

#JAVA=/opt/jdk1.7.0_07/bin/java

ROOT_PACKAGE=org/thermostat/qa
ANNOTATIONS_PACKAGE=$(ROOT_PACKAGE)/annotations
COMMON_PACKAGE=$(ROOT_PACKAGE)/common
FRAMEWORK_PACKAGE=$(ROOT_PACKAGE)/framework
REPORTER_PACKAGE=$(ROOT_PACKAGE)/reporter
TEST_PACKAGE=org/thermostat/qa2/tests

FLOTR_NAME=prototype.flotr-0.2.0-alpha
FLOTR_ARCHIVE=$(FLOTR_NAME).zip
FLOTR_ADDRESS=http://flotr.googlecode.com/files/$(FLOTR_ARCHIVE)
FLOTR_DIR=$(BUILD_DIR)/flotr
FLOTR_LIB_DIR=$(FLOTR_DIR)/lib

TOMCAT_VERSION=7.0.59
TOMCAT_NAME=apache-tomcat-$(TOMCAT_VERSION)
TOMCAT_ARCHIVE=$(TOMCAT_NAME).tar.gz
TOMCAT_URL=http://apache.mirror.rafal.ca/tomcat/tomcat-$(shell echo "$(TOMCAT_VERSION)" | sed 's/\..*//g' )/v$(TOMCAT_VERSION)/bin/$(TOMCAT_ARCHIVE)
TOMCAT_DIR=$(BUILD_DIR)/$(TOMCAT_NAME)

# refers to tested thermostat
THERMOSTAT_VERSION=head
THERMOSTAT_REPO_URL=http://icedtea.classpath.org/hg/thermostat/
THERMOSTAT_USER_DIR=$(BUILD_DIR)/.thermostat
THERMOSTAT_DIR=$(BUILD_DIR)/thermostat
THERMOSTAT_WEB_DEPLOY_DIR=$(TOMCAT_DIR)/webapps/thermostat

# refers to thermostat against which compatibility is tested
THERMOSTAT_OTHER_VERSION=1.2
THERMOSTAT_OTHER_DIR=$(BUILD_DIR)/thermostat-other
THERMOSTAT_OTHER_REPO_URL=http://icedtea.classpath.org/hg/release/thermostat-1.2/

JAPI_COMPILANCE_CHECKER_VERSION=1.3.7
JAPI_COMPILANCE_CHECKER_NAME=japi-compliance-checker-$(JAPI_COMPILANCE_CHECKER_VERSION)
JAPI_COMPILANCE_CHECKER_URL=https://github.com/lvc/japi-compliance-checker/archive/$(JAPI_COMPILANCE_CHECKER_VERSION).tar.gz
JAPI_COMPILANCE_CHECKER_DIR=$(BUILD_DIR)/$(JAPI_COMPILANCE_CHECKER_NAME)

SCREENSHOT_SOURCE=xvfb

GNOME_KEYRING_USER_DATA_DIR=$(shell realpath -m "$(BUILD_DIR)/.gnome-keyring" )

JAVADOC_DIR=$(REPORT_DIR)/javadoc

KILL_DAEMONS=0

DATE=`date +%Y-%0m-%0d`
	
# all *.java files in src directory
ALL_SOURCES = $(shell find src -name *.java | tr '\n' ' ')

# all testsuites ( in $(SOURCE_DIR)/$(TEST_PACKAGE) package )
TESTS = $(shell ls -1 $(SOURCE_DIR)/$(TEST_PACKAGE) | grep -v package-info.java | sed -n -e 's/\([A-Za-z0-9]*\)\.java/\1/p')
COMPATIBILITY_TESTS = $(shell ls -1 $(SOURCE_DIR)/$(TEST_PACKAGE)/compatibility | grep -v package-info.java | sed -n -e 's/\([A-Za-z0-9]*\)\.java/\1/p')

.PHONY: all
all: build runtests

#### clean ####

clean:
	rm -rf $(JAVADOC_DIR)
	rm -rf $(BUILD_DIR)

cleanlogs: clean_logs

clean_logs:
	rm -rf $(LOGS_DIR)/$(DATE)

clean_all_logs:
	rm -rf $(LOGS_DIR)
	
clean_all:
	rm -rf $(JAVADOC_DIR)
	rm -rf $(BUILD_DIR)
	rm -rf $(SCREENSHOTS_DIR)
	rm -rf $(LOGS_DIR)

#### build ####

.PHONY: build
build: $(CLASSES_DIR)
	
$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

$(CLASSES_DIR): | ${BUILD_DIR}
	rm -rf $(CLASSES_TEMP_DIR)
	mkdir -p $(CLASSES_TEMP_DIR)
	$(JAVAC) -d $(CLASSES_TEMP_DIR) -sourcepath $(SOURCE_DIR)/ $(ALL_SOURCES)
	mkdir -p $(shell dirname $(CLASSES_DIR) )
	mv -T $(CLASSES_TEMP_DIR) $(CLASSES_DIR)

#### test ####

.PHONY: runtests
runtests:	$(TESTS)

$(TESTS): build tomcat thermostat-build testwarning checkdeps | $(GNOME_KEYRING_USER_DATA_DIR)
	killall mongod &> /dev/null || true
	killall gnome-keyring-daemon &> /dev/null || true
	mkdir -p $(BUILD_DIR)/backup
	mkdir -p $(SCREENSHOTS_DIR)
	mkdir -p $(LOGS_DIR)
	mkdir -p $(LOGS_DIR)/$(DATE)
	USER_THERMOSTAT_HOME=$(THERMOSTAT_USER_DIR) \
	$(JAVA) -cp $(CLASSES_DIR) \
	-Dtomcat.home=$(TOMCAT_DIR) \
	-Dthermostat.home=$(THERMOSTAT_DIR)/distribution/target/image \
	-Dthermostat.user.home=$(THERMOSTAT_USER_DIR) \
	-Dthermostat.executable.name=thermostat \
	-Dthermostat.executable.path=$(THERMOSTAT_DIR)/distribution/target/image/bin \
	-Dthermostat.webapp.path=$(THERMOSTAT_DIR)/web/war/target \
	-Dthermostat.version=$(THERMOSTAT_VERSION) \
	-Dscreenshot.source=$(SCREENSHOT_SOURCE) \
	-Dclean.after.gui.test=true	\
	-Dgnome-keyring.config.path=$(GNOME_KEYRING_USER_DATA_DIR) \
	-Dbackup.path=$(BUILD_DIR)/backup \
	org.thermostat.qa2.framework.TestRunner org.thermostat.qa2.tests.$@ 2>&1 | tee $(LOGS_DIR)/$(DATE)/$@.log

.PHONY: run-compatibility-tests
run-compatibility-tests:	$(COMPATIBILITY_TESTS)	

$(COMPATIBILITY_TESTS): build tomcat thermostat-build thermostat-other-build testwarning checkdeps | $(GNOME_KEYRING_USER_DATA_DIR)
	killall mongod &> /dev/null || true
	killall gnome-keyring-daemon &> /dev/null || true
	mkdir -p $(BUILD_DIR)/backup
	mkdir -p $(SCREENSHOTS_DIR)
	mkdir -p $(LOGS_DIR)
	mkdir -p $(LOGS_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION)/$(DATE)
	USER_THERMOSTAT_HOME=$(THERMOSTAT_USER_DIR) \
	$(JAVA) -cp $(CLASSES_DIR) \
	-Dtomcat.home=$(TOMCAT_DIR) \
	-Dthermostat.home=$(THERMOSTAT_DIR)/distribution/target/image \
	-Dthermostat.user.home=$(THERMOSTAT_USER_DIR) \
	-Dthermostat.executable.path=$(THERMOSTAT_DIR)/distribution/target/image/bin \
	-Dthermostat.version=$(THERMOSTAT_VERSION) \
	-Dthermostat.webapp.path=$(THERMOSTAT_DIR)/web/war/target \
	-Dthermostat.other.home=$(THERMOSTAT_OTHER_DIR)/distribution/target/image \
	-Dthermostat.other.version=$(THERMOSTAT_OTHER_VERSION) \
	-Dthermostat.other.webapp.path=$(THERMOSTAT_OTHER_DIR)/web/war/target \
	-Dgnome-keyring.config.path=$(GNOME_KEYRING_USER_DATA_DIR) \
	-Dbackup.path=$(BUILD_DIR)/backup \
	org.thermostat.qa2.framework.TestRunner org.thermostat.qa2.tests.compatibility.$@ 2>&1 | tee $(LOGS_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION)/$(DATE)/$@.log

.PHONY: testwarning
testwarning:
	@# if KILL_DAEMONS != 1 and mongo or gnome keyring is running
	@# warn user that they need to be killed
	@ps aux | grep -v "grep" | grep -q "mongod" ; \
	mongo=$$? ; \
	ps aux | grep -v "grep" | grep -q "gnome-keyring-daemon" ; \
	gnomekeyring=$$? ; \
	if [ $(KILL_DAEMONS) -eq 0 ] && [ $$mongo -eq 0 -o $$gnomekeyring -eq 0 ] ; then \
		echo "--------------------------------------------------------------------" ; \
		echo "This test suite runs mongo database and gnome-keyring daemons with" ; \
		echo "custom configuration, so it will kill any running instance of these" ; \
		echo "daemons before start of testing." ; \
		echo ; \
		while true; do \
			echo "Do you want to continue? (yes/no)" ; \
			read answer ; \
			case "$${answer}" in \
				yes) \
					break \
				;; \
				no) \
					echo "Canelling ..." ; \
					exit 1 \
				;; \
				*) \
					echo "unrecognized answer: $${answer}" ; \
					echo ; \
				;; \
			esac \
		done \
	fi ; \
	true

.PHONY: checkdeps
checkdeps:
	@which netstat &> /dev/null || { echo "netstat required by testsuite is missing please install it" ; false ; }
	@which xdotool &> /dev/null || { echo "xdotool required by testsuite is missing please install it" ; false ; }
	@which gnome-keyring-daemon &> /dev/null || { echo "gnome-keyring-daemon required by testsuite is missing please install it" ; false ; }
	@which import &> /dev/null || { echo "import (ImageMagick) required by testsuite is missing please install it" ; false ; }

.PHONY: listtests
listtests:
	for tst in $(TESTS); do \
	echo $$tst ; \
	done

run-api-test: japi-compilance-checker | $(BUILD_DIR)/thermostat-tested.xml $(BUILD_DIR)/thermostat-other.xml
	perl $(JAPI_COMPILANCE_CHECKER_DIR)/japi-compliance-checker.pl -lib Thermostat -old $(BUILD_DIR)/thermostat-other.xml -new $(BUILD_DIR)/thermostat-tested.xml || true

#### reports & javadoc ####

report:	$(CLASSES_DIR) flotr
	mkdir -p $(REPORT_DIR)
	cp -u $(TEMPLATE_DIR)/style.css $(REPORT_DIR)/style.css
	cp -r $(FLOTR_DIR) $(REPORT_DIR)
	$(JAVA) -cp $(CLASSES_DIR) \
	-Dthermostat.version=$(THERMOSTAT_VERSION) \
	-Dlogs.path=$(LOGS_DIR) \
	-Dreports.path=$(REPORT_DIR) \
	org.thermostat.qa2.reporter.Reporter

report-compatibility-tests:	$(CLASSES_DIR) flotr
	mkdir -p $(REPORT_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION)
	cp -u $(TEMPLATE_DIR)/style.css $(REPORT_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION)/style.css
	cp -r $(FLOTR_DIR) $(REPORT_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION)
	$(JAVA) -cp $(CLASSES_DIR) \
	-Dthermostat.version=$(THERMOSTAT_VERSION) \
	-Dthermostat.other.version=$(THERMOSTAT_OTHER_VERSION) \
	-Dlogs.path=$(LOGS_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION)/ \
	-Dreports.path=$(REPORT_DIR)/compatibility/$(THERMOSTAT_OTHER_VERSION) \
	org.thermostat.qa2.reporter.Reporter

javadoc:
	mkdir -p $(JAVADOC_DIR)
	javadoc -d $(JAVADOC_DIR) -classpath src org.thermostat.qa.testsuites
	cp -r patterns $(JAVADOC_DIR)/org/thermostat/qa/testsuites/
	cp -r scripts $(JAVADOC_DIR)/org/thermostat/qa/testsuites/

#### other ####

#create a directory outputtexts/versionN for the current version
#of the output_texts (can be found in the test.properties)
#generate output help messages into files

generate-messages: thermostat-build | $(THERMOSTAT_USER_DIR)/data/setup-complete.stamp
	mkdir -p outputtexts/$(THERMOSTAT_VERSION)
	thermostat=$(THERMOSTAT_DIR)/distribution/target/image/bin/thermostat ; \
	helpParams=( \
	    "agent" \
	    "connect" \
	    "disconnect" \
	    "dump-heap" \
	    "find-objects" \
	    "find-root" \
	    "gui" \
	    "list-heap-dumps" \
	    "list-vms" \
	    "object-info" \
	    "ping" \
	    "save-heap-dump-to-file" \
	    "show-heap-histogram" \
	    "service" \
	    "shell" \
	    "storage" \
	    "vm-info" \
	    "vm-stat" \
	) ; \
	export USER_THERMOSTAT_HOME=$(THERMOSTAT_USER_DIR) ; \
	echo "exit" | $$thermostat shell > outputtexts/$(THERMOSTAT_VERSION)/output_of_exit_therm_shell.txt ; \
	echo -e "help\nexit" | $$thermostat shell > outputtexts/$(THERMOSTAT_VERSION)/output_of_help_therm_shell.txt ; \
	$$thermostat > outputtexts/$(THERMOSTAT_VERSION)/thermostat.txt ; \
	$$thermostat help > outputtexts/$(THERMOSTAT_VERSION)/thermostat_help.txt ; \
	for param in $${helpParams[@]} ; do \
	    $$thermostat help $$param > outputtexts/$(THERMOSTAT_VERSION)/thermostat_help_$${param}.txt ; \
	done

#make icons in given dir smaller / remove unnecessary pixels
cuticons:  $(ALL_CLASSES)
	$(JAVA) -cp $(CLASSES_DIR) org.thermostat.qa.framework.IconCut

#generate pattern defs on std output
patternsdef:  $(ALL_CLASSES)
	$(JAVA) -cp $(CLASSES_DIR) org.thermostat.qa.framework.PatternDefinitionsGenerator


#### OTHER SOFTWARE ####	
	
#### FLOTR ####
	
.PHONY: flotr
flotr:	$(FLOTR_DIR)/flotr-0.2.0-alpha.js $(FLOTR_LIB_DIR)/canvas2image.js $(FLOTR_LIB_DIR)/canvastext.js $(FLOTR_LIB_DIR)/prototype-1.6.0.2.js

$(FLOTR_DIR)/flotr-0.2.0-alpha.js: $(BUILD_DIR)/$(FLOTR_ARCHIVE)
	mkdir -p $(FLOTR_DIR)
	unzip -j -o $? flotr-0.2.0-alpha/flotr/flotr-0.2.0-alpha.js -d $(FLOTR_DIR)

$(FLOTR_LIB_DIR)/canvas2image.js: $(BUILD_DIR)/$(FLOTR_ARCHIVE)
	mkdir -p $(FLOTR_LIB_DIR)
	unzip -j -o $? flotr-0.2.0-alpha/flotr/lib/canvas2image.js -d $(FLOTR_LIB_DIR)

$(FLOTR_LIB_DIR)/canvastext.js: $(BUILD_DIR)/$(FLOTR_ARCHIVE)
	mkdir -p $(FLOTR_LIB_DIR)
	unzip -j -o $? flotr-0.2.0-alpha/flotr/lib/canvastext.js -d $(FLOTR_LIB_DIR)

$(FLOTR_LIB_DIR)/prototype-1.6.0.2.js: $(BUILD_DIR)/$(FLOTR_ARCHIVE)
	mkdir -p $(FLOTR_LIB_DIR)
	unzip -j -o $? flotr-0.2.0-alpha/flotr/lib/prototype-1.6.0.2.js -d $(FLOTR_LIB_DIR)

$(BUILD_DIR)/$(FLOTR_ARCHIVE):
	wget -P $(BUILD_DIR) $(FLOTR_ADDRESS)

#### TOMCAT ####

.PHONY: tomcat
tomcat: | $(TOMCAT_DIR)

$(TOMCAT_DIR): | $(BUILD_DIR)
	wget -P $(BUILD_DIR) $(TOMCAT_URL)
	tar xf $(BUILD_DIR)/$(TOMCAT_ARCHIVE) -C $(BUILD_DIR)
	if [ "$(BUILD_DIR)/$(TOMCAT_NAME)" != "$(TOMCAT_DIR)" ] ; then \
		mkdir -p "$(TOMCAT_DIR)" ; \
		mv -T "$(BUILD_DIR)/$(TOMCAT_NAME)" "$(TOMCAT_DIR)" ; \
	fi

#### THERMOSTAT ####
	
.PHONY: thermostat
thermostat: thermostat-build thermostat-setup


.PHONY: thermostat-setup
thermostat-setup: $(THERMOSTAT_WEB_DEPLOY_DIR) | $(THERMOSTAT_USER_DIR)/data/setup-complete.stamp

$(THERMOSTAT_USER_DIR)/data/setup-complete.stamp: | $(THERMOSTAT_USER_DIR) $(THERMOSTAT_DIR)/distribution/target/image
	# init storage and add agent-tester and client-tester users in custom user dir 	
	killall mongod || true
	export USER_THERMOSTAT_HOME=$(THERMOSTAT_USER_DIR) &&\
	if [ -f "$(THERMOSTAT_DIR)/distribution/target/image/bin/thermostat-devsetup" ] ; then \
		$(THERMOSTAT_DIR)/distribution/target/image/bin/thermostat-devsetup; \
	fi &&\
	$(THERMOSTAT_DIR)/distribution/target/image/bin/thermostat storage --start &&\
	echo -e \
		"use thermostat\n\
		db.auth(\"mongodevuser\", \"mongodevpassword\")\n\
		db.addUser(\"agent-tester\",\"heslo1\")\n\
		db.addUser(\"client-tester\",\"heslo2\")\n\
		exit\n" \
	| mongo 127.0.0.1:27518; \
	$(THERMOSTAT_DIR)/distribution/target/image/bin/thermostat storage --stop

$(THERMOSTAT_USER_DIR): | $(THERMOSTAT_DIR)
	mkdir -p $(THERMOSTAT_USER_DIR)
	
$(THERMOSTAT_WEB_DEPLOY_DIR): tomcat thermostat-build
	rm -rf $(THERMOSTAT_WEB_DEPLOY_DIR)
	mkdir -p $(THERMOSTAT_WEB_DEPLOY_DIR)
	cp -rT	"$$( echo $(THERMOSTAT_DIR)/web/war/target/*.war | sed 's/.war$$//g' )" $(THERMOSTAT_WEB_DEPLOY_DIR)

.PHONY: thermostat-build
thermostat-build: | $(THERMOSTAT_DIR)/distribution/target/image	
	
$(THERMOSTAT_DIR)/distribution/target/image: | $(THERMOSTAT_DIR)/pom.xml
	cd $(THERMOSTAT_DIR) &&\
	mvn -Dmaven.test.skip=true clean install
	
$(THERMOSTAT_DIR)/pom.xml: | $(THERMOSTAT_DIR)
	hg clone $(THERMOSTAT_REPO_URL) $(THERMOSTAT_DIR)

$(THERMOSTAT_DIR): | ${BUILD_DIR}
	mkdir -p $(THERMOSTAT_DIR)

.PHONY: thermostat-other-build
thermostat-other-build: | $(THERMOSTAT_OTHER_DIR)/distribution/target/image

$(THERMOSTAT_OTHER_DIR)/distribution/target/image: | $(THERMOSTAT_OTHER_DIR)/pom.xml
	cd $(THERMOSTAT_OTHER_DIR) &&\
	mvn -Dmaven.test.skip=true clean install

$(THERMOSTAT_OTHER_DIR)/pom.xml: | $(THERMOSTAT_OTHER_DIR)
	hg clone $(THERMOSTAT_OTHER_REPO_URL) $(THERMOSTAT_OTHER_DIR)
	
$(THERMOSTAT_OTHER_DIR): | ${BUILD_DIR}
	mkdir -p $(THERMOSTAT_OTHER_DIR)
	
#### GNOME KEYRING ####

$(GNOME_KEYRING_USER_DATA_DIR):
	# create custom config directory for gnome-keyring and copy data there
	mkdir -p $(GNOME_KEYRING_USER_DATA_DIR)
	cp -r storageconfig/keyrings $(GNOME_KEYRING_USER_DATA_DIR)

#### Java API Compliance Checker ####

.PHONY: japi-compilance-checker
japi-compilance-checker: | $(JAPI_COMPILANCE_CHECKER_DIR)/japi-compliance-checker.pl

$(JAPI_COMPILANCE_CHECKER_DIR)/japi-compliance-checker.pl: | $(BUILD_DIR)/$(JAPI_COMPILANCE_CHECKER_VERSION).tar.gz
	mkdir -p $(JAPI_COMPILANCE_CHECKER_DIR)
	tar xf $(BUILD_DIR)/$(JAPI_COMPILANCE_CHECKER_VERSION).tar.gz -C $(BUILD_DIR)

$(BUILD_DIR)/$(JAPI_COMPILANCE_CHECKER_VERSION).tar.gz:
	wget -P $(BUILD_DIR) $(JAPI_COMPILANCE_CHECKER_URL)

$(BUILD_DIR)/thermostat-template.xml: thermostat-other-build
	@# fill template with public packages listed in README.api of "other" thermostat
	packages="$$( cat $(THERMOSTAT_OTHER_DIR)/README.api \
	| sed -n '1,/^Internal/p' \
	| grep com.redhat.thermostat \
	| sed "s/^.*com.redhat.thermostat/com.redhat.thermostat/g" )" ; \
	version="\$${version}" ; \
	archives="\$${archives}" ; \
	eval echo \""$$(cat $(TEMPLATE_DIR)/japi-compliance-checker-template.xml)"\" > $@

$(BUILD_DIR)/thermostat-other.xml: $(BUILD_DIR)/thermostat-template.xml thermostat-build thermostat-other-build
	@# create xml for "other" thermostat by filling common template with its version and jars
	version="$(THERMOSTAT_OTHER_VERSION)" ; \
	archives="$$( find $(THERMOSTAT_OTHER_DIR)/distribution/target/image/libs -name "*thermostat*.jar")" ; \
	eval echo \""$$(cat $(BUILD_DIR)/thermostat-template.xml)"\" > $@

$(BUILD_DIR)/thermostat-tested.xml: $(BUILD_DIR)/thermostat-template.xml thermostat-build thermostat-other-build
	@# create xml for tested thermostat by filling common template with with its version and jars
	version="$(THERMOSTAT_VERSION)" ; \
	archives="$$( find $(THERMOSTAT_DIR)/distribution/target/image/libs -name "*thermostat*.jar")" ; \
	eval echo \""$$(cat $(BUILD_DIR)/thermostat-template.xml)"\" > $@