Skip to content
Permalink
Browse files

Merge remote-tracking branch 'origin/release-25.0.0' into develop

  • Loading branch information...
RangerRick committed Sep 6, 2019
2 parents f11272f + 3e9b94e commit 1aa2eb01241b9b310d50483c31651349ae4c310c
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.opennms</groupId>
<artifactId>org.opennms.core</artifactId>
<version>26.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opennms.core</groupId>
<artifactId>org.opennms.core.cli</artifactId>
<packaging>jar</packaging>
<name>OpenNMS :: Core :: CLI Tools</name>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<!-- disable source generation -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution><phase/></execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
<escapeString>\</escapeString>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/assembly/shunit.xml</descriptor>
</descriptors>
<tarLongFileMode>posix</tarLongFileMode>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<activation>
<os><family>!windows</family></os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>shell script tests</id>
<phase>test</phase>
<goals><goal>exec</goal></goals>
<configuration>
<executable>${project.basedir}/src/test/shell/run-tests.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
@@ -0,0 +1,21 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"
>
<id>shunit</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<outputDirectory></outputDirectory>
<directory>${project.basedir}/src/test/shell</directory>
<excludes>
<exclude>spec</exclude>
<exclude>spec/**/*</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
@@ -109,3 +109,18 @@ __onms_get_real_path() {

echo "$file_to_find"
}

# given a JAVA_HOME, output a major.minor.micro version string for that Java version
__onms_get_java_version_string() {
home="$1"; shift
full_version_string="$("${home}"/bin/java -version 2>&1 | grep ' version ')"
#version_string="$(printf '%s' "${full_version_string}" | sed -e 's,^.* version ,,' -e 's,^"\(.*\)"$,\1,' -e 's,-[A-Za-z]*$,,' -e 's,^1\.,,')"
version_string="$(printf '%s' "${full_version_string}" | sed -e 's,^.* version ,,' -e 's, LTS$,,' -e 's, [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$,,' -e 's,^"\(.*\)"$,\1,' -e 's,-[A-Za-z]*$,,')"
if (printf '%s' "${version_string}" | grep -Eq '^[0-9\._]+$'); then
# valid parsed version string, only numbers and periods
printf '%s\n' "${version_string}"
else
(>&2 printf 'WARNING: unsure how to handle Java version output: %s\n' "${full_version_string}")
printf ''
fi
}
@@ -1,11 +1,11 @@
#!/bin/bash

MYDIR="$(dirname "$0")"
MYDIR="$(cd "$MYDIR" || exit 1; pwd)"
FINDJAVADIR="$(dirname "$0")"
FINDJAVADIR="$(cd "$FINDJAVADIR" || exit 1; pwd)"

# shellcheck disable=SC1090
if [ -e "${MYDIR}/_lib.sh" ]; then
. "${MYDIR}/_lib.sh"
if [ -e "${FINDJAVADIR}/_lib.sh" ]; then
. "${FINDJAVADIR}/_lib.sh"

# if $JAVA_SEARCH_DIRS is already set, make sure it is treated as an array
__onms_convert_to_array JAVA_SEARCH_DIRS
@@ -33,20 +33,6 @@ compare_versions() {
printf '%s' '0'
}

get_java_version_string() {
home="$1"; shift
full_version_string="$("${home}"/bin/java -version 2>&1 | grep ' version ')"
#version_string="$(printf '%s' "${full_version_string}" | sed -e 's,^.* version ,,' -e 's,^"\(.*\)"$,\1,' -e 's,-[A-Za-z]*$,,' -e 's,^1\.,,')"
version_string="$(printf '%s' "${full_version_string}" | sed -e 's,^.* version ,,' -e 's, LTS$,,' -e 's, [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$,,' -e 's,^"\(.*\)"$,\1,' -e 's,-[A-Za-z]*$,,')"
if (printf '%s' "${version_string}" | grep -Eq '^[0-9\._]+$'); then
# valid parsed version string, only numbers and periods
printf '%s\n' "${version_string}"
else
(>&2 printf 'WARNING: unsure how to handle Java version output: %s\n' "${full_version_string}")
printf ''
fi
}

usage() {
cat <<END
usage: $0 [-h] [-v] [minimum_jdk_version] [maximum_jdk_version] [path-to-java]
@@ -152,7 +138,7 @@ main() {
while read -r javabin; do
javabin="$(__onms_get_real_path "${javabin}")"
javahome="$(printf '%s' "${javabin}" | sed -e 's,/bin/java$,,')"
version_string="$(get_java_version_string "$javahome")"
version_string="$(__onms_get_java_version_string "$javahome")"
[ -n "$DEBUG" ] && (>&2 printf '* %s = %s\n' "${javahome}" "${version_string}")

comparison="$(compare_versions "${min_java_version}" "${version_string}")"
@@ -0,0 +1,52 @@
#!/bin/bash

PRINTJAVADIR="$(dirname "$0")"
PRINTJAVADIR="$(cd "$PRINTJAVADIR" || exit 1; pwd)"

# shellcheck disable=SC1090
if [ -e "${PRINTJAVADIR}/_lib.sh" ]; then
. "${PRINTJAVADIR}/_lib.sh"
fi

usage() {
cat <<END
usage: $0 [-h] [-s] <java_home>
-h this help
-s short output (just the major version)
This script will print the version of the JDK specified on the CLI.
END
}

PRINT_HELP=0
PRINT_SHORT=0

while getopts hs OPT; do
case "${OPT}" in
h)
PRINT_HELP=1
;;
s)
PRINT_SHORT=1
;;
*)
;;
esac
done
shift $((OPTIND -1))

if [ "$PRINT_HELP" -eq 1 ] || [ -z "$1" ]; then
usage
exit 1
fi

java_home="$1"; shift
version="$(__onms_get_java_version_string "$java_home")"

if [ "$PRINT_SHORT" -eq 1 ]; then
version="$(echo "$version" | cut -d. -f1)"
fi

echo "$version"
@@ -1,10 +1,18 @@
#!/bin/bash

EXECUTEDIR="$(dirname "$0")"
EXECUTEDIR="$(cd "$EXECUTEDIR" || exit 1; pwd)"

if [ -z "$SHUNITDIR" ]; then
SHUNITDIR="$EXECUTEDIR"
fi
export SHUNITDIR

TESTFILE="$1"
TESTNAME="$(echo "$TESTFILE" | sed -e 's,^.*/spec/,,' -e 's,.spec.sh$,,')"
DIRNAME="$(dirname "$TESTFILE")"

cd "$DIRNAME" || exit 1

echo "=== running test: $TESTNAME ==="
exec "$TESTFILE"
exec "$TESTFILE"
File renamed without changes.
@@ -18,6 +18,20 @@ get_testdir() {
echo "$TARGETDIR/shunit/$1"
}

makeFakeJava() {
if [ -z "$4" ]; then
echo "usage: makeFakeJava <java_home> <is_openjdk> <version> <build>"
exit 1
fi
mkdir -p "$1"/{bin,include,jre/bin,jre/lib,lib}
sed -e "s,@fake_java_version@,$3,g" \
-e "s,@fake_java_build@,$4,g" \
-e "s,@fake_openjdk@,$2,g" \
"$SHUNITDIR/fakejava" > "$1/bin/java"
cp "$1/bin/java" "$1/jre/bin/java"
chmod 755 "$1/bin/java" "$1/jre/bin/java"
}

# runCommand <project> @cmd
runCommand() {
__project="$1"; shift
@@ -43,4 +57,4 @@ runCommand() {
PROJECTDIR="$(find_projectdir)"
TARGETDIR="$PROJECTDIR/target"

export PROJECTDIR TARGETDIR
export PROJECTDIR TARGETDIR
@@ -1,18 +1,24 @@
#!/bin/bash

MYDIR="$(dirname "$0")"
MYDIR="$(cd "$MYDIR" || exit 1; pwd)"
SHUNITDIR="$(dirname "$0")"
SHUNITDIR="$(cd "$SHUNITDIR" || exit 1; pwd)"

cd "$MYDIR" || exit 1
WORKDIR="$1"; shift
if [ -z "$WORKDIR" ]; then
WORKDIR="$SHUNITDIR"
fi

cd "$WORKDIR" || exit 1

SHELLCHECK="$(command -v shellcheck 2>/dev/null)"
export SHELLCHECK

export SHUNITDIR WORKDIR SHELLCHECK

FAILED=false

if [ -n "$SHELLCHECK" ] && [ -x "$SHELLCHECK" ]; then
# shellcheck disable=SC2035,SC2044
for FILE in $(find * -name \*.sh); do
for FILE in $(find "$WORKDIR" -name \*.sh); do
echo "=== shellcheck $FILE ==="
# shellcheck disable=SC2046
if ! "$SHELLCHECK" "$FILE"; then
@@ -22,8 +28,8 @@ if [ -n "$SHELLCHECK" ] && [ -x "$SHELLCHECK" ]; then
fi

# shellcheck disable=SC2044
for FILE in $(find "$MYDIR" -name \*.spec.sh); do
if ! "$MYDIR/execute-test.sh" "$FILE"; then
for FILE in $(find "$WORKDIR" "$SHUNITDIR" -name \*.spec.sh | sort -u); do
if ! "$SHUNITDIR/execute-test.sh" "$FILE"; then
FAILED=true
fi
done
File renamed without changes.
@@ -3,10 +3,11 @@
# shellcheck disable=SC2034
OVERRIDEABLE_ARRAYS=(TEST_FOO TEST_BAR TEST_BAZ TEST_ADDITIONAL_OPTIONS)

# shellcheck disable=SC1091
. ../init.sh
# shellcheck disable=SC1090,SC1091
. "$SHUNITDIR/init.sh"

TESTDIR="$(get_testdir _lib)"
find "$TESTDIR" -type f \( -name \*.sh -o -name runjava\* \) -exec chmod a+x {} \;

makeTestPath() {
# shellcheck disable=SC2154
@@ -60,7 +61,7 @@ assertArrayLengthEquals() {

setUp() {
# shellcheck disable=SC1090
. "$PROJECTDIR/src/main/resources/bin/_lib.sh"
. "$PROJECTDIR/target/classes/bin/_lib.sh"

unset TEST_FOO
unset TEST_BAR
@@ -71,7 +72,7 @@ setUp() {

testShellcheck() {
if [ -n "$SHELLCHECK" ] && [ -x "$SHELLCHECK" ]; then
"$SHELLCHECK" "$PROJECTDIR/src/main/resources/bin/_lib.sh"
"$SHELLCHECK" "$PROJECTDIR/target/classes/bin/_lib.sh"
assertTrue "shellcheck on bin/_lib.sh should pass" $?
fi
}
@@ -455,5 +456,5 @@ testGetRealPathOnAbsoluteDoubleLinkNoRealpathExe() {
}


# shellcheck disable=SC1091
. ../shunit2
# shellcheck disable=SC1090,SC1091
. "$SHUNITDIR/shunit2"

0 comments on commit 1aa2eb0

Please sign in to comment.
You can’t perform that action at this time.