Skip to content

Commit

Permalink
[KIECLOUD-304] - MAVEN_SETTINGS_XML is not honored by jboss-kie-modul…
Browse files Browse the repository at this point in the history
…es scripts. (#312)

Signed-off-by: Filippe Spolti <fspolti@redhat.com>
  • Loading branch information
spolti authored and errantepiphany committed Aug 27, 2019
1 parent e86bcd5 commit 722c723
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
type: shell
name: install dependencies
command: |
sudo apt-get install libxml2-utils
sudo apt-get install libxml2-utils maven
- run:
type: shell
name: install bats-core
Expand Down
Expand Up @@ -23,9 +23,24 @@ function configure_maven_settings() {
# env var used by KIE to first find and load global settings.xml
local m2Home=$(mvn -v | grep -i 'maven home: ' | sed -E 's/^.{12}//')
export M2_HOME="${m2Home}"

# KIECLOUD-304
local mavenSettings="${HOME}/.m2/settings.xml"
# maven module already takes care if the provided file exist, if a non existent file or directory is set
# it will automatically fallback to the default settings.xml
if [ ! -z "${MAVEN_SETTINGS_XML}" ]; then
log_info "Custom maven settings provided, validating ${MAVEN_SETTINGS_XML}, if this file is not the value that was set, probably the value set points to a non existent file or directory. Enable debug for details."
validationResult=$(mvn help:effective-settings -s "${MAVEN_SETTINGS_XML}")
if [ $? -eq 0 ]; then
mavenSettings="${MAVEN_SETTINGS_XML}"
else
log_error "$validationResult"
log_info "Falling back to ${mavenSettings}"
fi
fi
# see scripts/jboss-kie-wildfly-common/configure.sh
# used by KIE to then override with custom settings.xml
JBOSS_KIE_ARGS="${JBOSS_KIE_ARGS} -Dkie.maven.settings.custom=${HOME}/.m2/settings.xml"
JBOSS_KIE_ARGS="${JBOSS_KIE_ARGS} -Dkie.maven.settings.custom=${mavenSettings}"
}

function configure_mbeans() {
Expand Down
60 changes: 60 additions & 0 deletions jboss-kie-wildfly-common/tests/bats/jboss-kie-wildfly-common.bats
@@ -0,0 +1,60 @@
#!/usr/bin/env bats

export JBOSS_HOME=$BATS_TMPDIR/jboss_home
mkdir -p $JBOSS_HOME/bin/launch

cp $BATS_TEST_DIRNAME/../../../tests/bats/common/logging.bash $JBOSS_HOME/bin/launch/logging.sh
cp $BATS_TEST_DIRNAME/../../../jboss-kie-wildfly-common/added/launch/jboss-kie-wildfly-security-login-modules.sh $JBOSS_HOME/bin/launch
load $BATS_TEST_DIRNAME/../../added/launch/jboss-kie-wildfly-common.sh

echo "fake xml" > $JBOSS_HOME/bin/launch/settings-non-readable.xml
echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd\">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
</settings>" > $JBOSS_HOME/bin/launch/settings.xml

teardown() {
rm -rf $JBOSS_HOME
}

@test "test if the MAVEN_SETTINGS_XML is correctly configured with default config" {
expected=" -Dkie.maven.settings.custom=${HOME}/.m2/settings.xml"
configure_maven_settings
echo "expected=${expected}"
echo "JBOSS_KIE_ARGS=$JBOSS_KIE_ARGS"
[ "${JBOSS_KIE_ARGS}" = "${expected}" ]
}

@test "test if the MAVEN_SETTINGS_XML is correctly configured with a existent and valid settings.xml" {
export MAVEN_SETTINGS_XML="/tmp/jboss_home/bin/launch/settings.xml"
expected=" -Dkie.maven.settings.custom=/tmp/jboss_home/bin/launch/settings.xml"
configure_maven_settings
echo "expected=${expected}"
echo "JBOSS_KIE_ARGS=$JBOSS_KIE_ARGS"
echo "${lines[@]}"
[ "${JBOSS_KIE_ARGS}" = "${expected}" ]
}

@test "test if the MAVEN_SETTINGS_XML is correctly configured with non existent settings.xml" {
export MAVEN_SETTINGS_XML="/fake/path"
expected=" -Dkie.maven.settings.custom=${HOME}/.m2/settings.xml"
configure_maven_settings || true
echo "expected=${expected}"
echo "JBOSS_KIE_ARGS=$JBOSS_KIE_ARGS"
echo "${lines[@]}"
echo $output
[ "${JBOSS_KIE_ARGS}" = "${expected}" ]
}

@test "test if the MAVEN_SETTINGS_XML is correctly configured with a existent and not valid settings.xml" {
export MAVEN_SETTINGS_XML="/tmp/jboss_home/bin/launch/settings-non-readable.xml"
expected=" -Dkie.maven.settings.custom=${HOME}/.m2/settings.xml"
configure_maven_settings || true
echo "expected=${expected}"
echo "JBOSS_KIE_ARGS=$JBOSS_KIE_ARGS"
echo $output
[ "${JBOSS_KIE_ARGS}" = "${expected}" ]
}
Expand Up @@ -16,7 +16,7 @@ teardown() {
rm -rf $JBOSS_HOME
}

@test "test if the standalone configuration file is correctly formmated" {
@test "test if the standalone configuration file is correctly formatted" {
run format_xml
assert_xml ${CONFIG_FILE} $BATS_TEST_DIRNAME/expectations/formatter/standalone-expected.xml
}
Expand Down

0 comments on commit 722c723

Please sign in to comment.