<commit_before>source setdir.sh
source stringvalidator.sh
source util.sh
source help.sh

_build_log(){
	appServer=$1

	timestamp=$(_timestamp_clock)
	timestamp=${timestamp//[:]/}

	logStructure=("d" "logs" "${branch}" "${appServer}" "$(_timestamp_date)")

	for (( i=0; i<${#logStructure[@]}; i++ )); do
		logDir=${logDir}/${logStructure[i]}
		if [ ! -e $logDir ]; then
			mkdir $logDir
			cd $logDir
		else
			cd $logDir
		fi
	done

	export logFile=$logDir/$branch-build-$(_gitlog)-${timestamp}.log
}

_clean_hard(){
	echo "[INFO] Deleting all files and folder in the bundles directory..."
	cd $bundleDir
	rm -rf deploy osgi data logs
	rm -rf ${appServer}*

	echo "[INFO] DONE."
	cd $baseDir
}

_clean_bundle(){
	echo "[INFO] Deleting liferay home folders..."
	cd $bundleDir
	rm -rf data logs
	echo "[INFO] DONE."
	echo

	cd $baseDir

	echo "[INFO] Deleting temp files..."
	cd $tomcatDir
	rm -rf temp work
	echo "[INFO] DONE."
	echo

	cd $baseDir
}

_clean_source(){
	cd $buildDir

	git reset --hard -q

	git clean -fdqx -e "*.anthonychu.properties"

	cd $baseDir
}

_config(){
	source(){
		echo "[INFO] Building properties..."

		cd $buildDir/../properties
		cp *.anthonychu.properties $buildDir

		cd $buildDir
		sed -i "s/app.server.type=/app.server.type=${appServer}/g" app.server.anthonychu.properties
		sed -i "s/app.server.type=/app.server.type=${appServer}/g" build.anthonychu.properties
		echo -e "\napp.server.parent.dir=${bundleDir}" >> app.server.anthonychu.properties
		echo -e "\napp.server.parent.dir=${bundleDir}" >> build.anthonychu.properties

		if [[ $appServer == jboss ]]; then
			echo -e "\napp.server.${appServer}.version=6.0.1" >> app.server.anthonychu.properties
		fi

		echo "[INFO] Done."
	}

	appServer(){
		appServer=$1

		echo "[INFO] Increasing memory limit..."
		if [[ $appServer == tomcat ]]; then
			sed -i "s/-Xmx[[:digit:]][[:digit:]][[:digit:]][[:digit:]]m/-Xmx2048m/g" $tomcatDir/bin/setenv.sh
			sed -i "s/-XX:MaxPermSize=[[:digit:]][[:digit:]][[:digit:]]m/-XX:MaxPermSize=1024m/g" $tomcatDir/bin/setenv.sh
		elif [[ $appServer == wildfly ]]; then
			sed -i "s/-Xmx[[:digit:]][[:digit:]][[:digit:]][[:digit:]]m/-Xmx2048m/g" $bundleDir/wildfly-10.0.0/bin/standalone.conf
			sed -i "s/-XX:MaxMetaspaceSize=[[:digit:]][[:digit:]][[:digit:]]m/-XX:MaxMetaspaceSize=1024m/g" $bundleDir/wildfly-10.0.0/bin/standalone.conf
		fi
		echo "[INFO] Done."

		if [[ $branch == ee-6.2.x ]]; then
			echo "[INFO] Changing port for ee-6.2.x..."
			sed -i "s/\"8/\"7/g" $tomcatDir/conf/server.xml
			echo "[INFO] DONE."
		fi
	}

	$1
}

_getAppServer(){
	local appServer=$1

	if [[ $(_validateAppServer $appServer) == false ]]; then
		if [[ $(StringValidator isNull $1) == true ]]; then
			echo "tomcat"
		else
			echo "$appServer is not a valid app server."
			exit
		fi
	else
		echo $appServer
		shift
	fi
}

_gitlog(){
	cd $buildDir
	git log --oneline --pretty=format:%h -1
	cd $baseDir
}

_rebuild_db(){
	echo "[INFO] Rebuilding database..."
	mysql -e "drop database if exists $database; create database $database char set utf8;"
	echo "[INFO] DONE."
	echo
	cd $baseDir
}

_timestamp_clock(){
	date +%T%s<commit_msg>Do null check before app server check<commit_after>source setdir.sh
source stringvalidator.sh
source util.sh
source help.sh

_build_log(){
	appServer=$1

	timestamp=$(_timestamp_clock)
	timestamp=${timestamp//[:]/}

	logStructure=("d" "logs" "${branch}" "${appServer}" "$(_timestamp_date)")

	for (( i=0; i<${#logStructure[@]}; i++ )); do
		logDir=${logDir}/${logStructure[i]}
		if [ ! -e $logDir ]; then
			mkdir $logDir
			cd $logDir
		else
			cd $logDir
		fi
	done

	export logFile=$logDir/$branch-build-$(_gitlog)-${timestamp}.log
}

_clean_hard(){
	echo "[INFO] Deleting all files and folder in the bundles directory..."
	cd $bundleDir
	rm -rf deploy osgi data logs
	rm -rf ${appServer}*

	echo "[INFO] DONE."
	cd $baseDir
}

_clean_bundle(){
	echo "[INFO] Deleting liferay home folders..."
	cd $bundleDir
	rm -rf data logs
	echo "[INFO] DONE."
	echo

	cd $baseDir

	echo "[INFO] Deleting temp files..."
	cd $tomcatDir
	rm -rf temp work
	echo "[INFO] DONE."
	echo

	cd $baseDir
}

_clean_source(){
	cd $buildDir

	git reset --hard -q

	git clean -fdqx -e "*.anthonychu.properties"

	cd $baseDir
}

_config(){
	source(){
		echo "[INFO] Building properties..."

		cd $buildDir/../properties
		cp *.anthonychu.properties $buildDir

		cd $buildDir
		sed -i "s/app.server.type=/app.server.type=${appServer}/g" app.server.anthonychu.properties
		sed -i "s/app.server.type=/app.server.type=${appServer}/g" build.anthonychu.properties
		echo -e "\napp.server.parent.dir=${bundleDir}" >> app.server.anthonychu.properties
		echo -e "\napp.server.parent.dir=${bundleDir}" >> build.anthonychu.properties

		if [[ $appServer == jboss ]]; then
			echo -e "\napp.server.${appServer}.version=6.0.1" >> app.server.anthonychu.properties
		fi

		echo "[INFO] Done."
	}

	appServer(){
		appServer=$1

		echo "[INFO] Increasing memory limit..."
		if [[ $appServer == tomcat ]]; then
			sed -i "s/-Xmx[[:digit:]][[:digit:]][[:digit:]][[:digit:]]m/-Xmx2048m/g" $tomcatDir/bin/setenv.sh
			sed -i "s/-XX:MaxPermSize=[[:digit:]][[:digit:]][[:digit:]]m/-XX:MaxPermSize=1024m/g" $tomcatDir/bin/setenv.sh
		elif [[ $appServer == wildfly ]]; then
			sed -i "s/-Xmx[[:digit:]][[:digit:]][[:digit:]][[:digit:]]m/-Xmx2048m/g" $bundleDir/wildfly-10.0.0/bin/standalone.conf
			sed -i "s/-XX:MaxMetaspaceSize=[[:digit:]][[:digit:]][[:digit:]]m/-XX:MaxMetaspaceSize=1024m/g" $bundleDir/wildfly-10.0.0/bin/standalone.conf
		fi
		echo "[INFO] Done."

		if [[ $branch == ee-6.2.x ]]; then
			echo "[INFO] Changing port for ee-6.2.x..."
			sed -i "s/\"8/\"7/g" $tomcatDir/conf/server.xml
			echo "[INFO] DONE."
		fi
	}

	$1
}

_getAppServer(){
	local appServer=$@

	if [[ $(StringValidator isNull $appServer) == true ]]; then
		echo "tomcat"
	else
		if [[ $(_validateAppServer $appServer) == true ]]; then
			echo $appServer
		else
			echo "$appServer is not a valid app server"
			exit
		fi
	fi
}

_gitlog(){
	cd $buildDir
	git log --oneline --pretty=format:%h -1
	cd $baseDir
}

_rebuild_db(){
	echo "[INFO] Rebuilding database..."
	mysql -e "drop database if exists $database; create database $database char set utf8;"
	echo "[INFO] DONE."
	echo
	cd $baseDir
}

_timestamp_clock(){
	date +%T%s
{'fraction_non_alphanumeric': 0.18984126984126984, 'fraction_numerical': 0.012698412698412698, 'mean_word_length': 3.762660619803477, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '27877', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2382, 'n_words': 564}