Skip to content

Commit c76e6aa

Browse files
committed
DES-6665 Fixed Java version detection.
* Check existence of java-version file instead of just the directory. * Use show-java-version as a cleaner way to detect Java version. * When using dump-mpr, read the entire output & wait for exit code - so that errors are not streamed to jq. * Log how exactly a Mendix version was detected.
1 parent 6b92294 commit c76e6aa

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

mxbuild/build

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@ fi
1515

1616
cd /workdir
1717

18-
if [ -f /workdir/project ]; then
19-
JAVA_VERSION=$(cat java-version)
18+
if [ -f /workdir/project/java-version ]; then
19+
echo "Using java-version to select Java version"
20+
JAVA_VERSION=$(cat /workdir/project/java-version)
2021
elif [ -f /opt/mendix/modeler/mx ]; then
21-
JAVA_VERSION=$(/opt/mendix/modeler/mx dump-mpr --unit-type 'Settings$ProjectSettings' /workdir/project/"${MPR_FILENAME}" | \
22-
jq -r '.units[] | select(.["$Type"]=="Settings$ProjectSettings") | .["settingsParts"][] | select(.["$Type"]=="Settings$RuntimeSettings").javaVersion | if (. == null or . == "null") then "Java11" else . end')
22+
if JAVA_VERSION=$(/opt/mendix/modeler/mx show-java-version /workdir/project/"${MPR_FILENAME}"); then
23+
echo "Using mx show-java-version to select Java version"
24+
elif JAVA_VERSION=$(PROJECT_SETTINGS=`/opt/mendix/modeler/mx dump-mpr --unit-type 'Settings$ProjectSettings' /workdir/project/"${MPR_FILENAME}"` && \
25+
echo -n $PROJECT_SETTINGS | \
26+
jq -r '.units[] | select(.["$Type"]=="Settings$ProjectSettings") | .["settingsParts"][] | select(.["$Type"]=="Settings$RuntimeSettings").javaVersion | if (. == null or . == "null") then "Java11" else . end'); then
27+
echo "Using mx dump-mpr to select Java version"
28+
else
29+
echo "Unable to detect Java version using mx tool"
30+
JAVA_VERSION=11
31+
fi
2332
else
33+
echo "mx tool is not available"
2434
JAVA_VERSION=11
2535
fi
2636

2737
JAVA_VERSION=$(echo -n $JAVA_VERSION| sed s/\^Java// | head)
2838

29-
echo "Detected Java $JAVA_VERSION"
39+
echo "Using Java $JAVA_VERSION"
3040
export JDK_HOME=/etc/alternatives/java_sdk_${JAVA_VERSION}
3141

3242
$MXBUILD_COMMAND \

0 commit comments

Comments
 (0)