Skip to content

Commit 0b6517c

Browse files
committed
Fixed build
1 parent 86f8a5c commit 0b6517c

File tree

3 files changed

+75
-30
lines changed

3 files changed

+75
-30
lines changed

scripts/build-android-port.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22
# Build Codename One Android port using JDK 11 for Maven and JDK 17 for compilation
33
set -euo pipefail
4+
5+
# Normalize TMPDIR so it has no trailing slash
6+
TMPDIR="${TMPDIR%/}"
47
DOWNLOAD_DIR="${TMPDIR:-/tmp}/codenameone-tools"
58
ENV_DIR="$DOWNLOAD_DIR/tools"
69

@@ -11,7 +14,7 @@ else
1114
source "$ENV_DIR/env.sh"
1215
fi
1316

14-
if ! "${JAVA_HOME:-}/bin/java" -version 2>&1 | grep -q '11\.0'; then
17+
if ! "${JAVA_HOME_11:-}/bin/java" -version 2>&1 | grep -q '11\.0'; then
1518
echo "Failed to provision JDK 11" >&2
1619
exit 1
1720
fi

scripts/build-ios-port.sh

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ if ! command -v xcodebuild >/dev/null; then
99
echo "Xcode command-line tools not found." >&2
1010
exit 1
1111
fi
12-
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
13-
cd "$ROOT"
14-
if [ -f "$ROOT/tools/env.sh" ]; then
15-
source "$ROOT/tools/env.sh"
12+
13+
# Normalize TMPDIR so it has no trailing slash
14+
TMPDIR="${TMPDIR%/}"
15+
DOWNLOAD_DIR="${TMPDIR:-/tmp}/codenameone-tools"
16+
ENV_DIR="$DOWNLOAD_DIR/tools"
17+
18+
if [ -f "$ENV_DIR/env.sh" ]; then
19+
source "$ENV_DIR/env.sh"
1620
else
1721
./scripts/setup-workspace.sh -q -DskipTests
18-
source "$ROOT/tools/env.sh"
19-
fi
20-
if ! "${JAVA_HOME:-}/bin/java" -version 2>&1 | grep -q '11\.0'; then
21-
./scripts/setup-workspace.sh -q -DskipTests
22-
source "$ROOT/tools/env.sh"
23-
fi
24-
if ! "${JAVA_HOME:-}/bin/java" -version 2>&1 | grep -q '11\.0'; then
25-
echo "Failed to provision JDK 11" >&2
26-
exit 1
22+
source "$ENV_DIR/env.sh"
2723
fi
24+
2825
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
2926
"$JAVA_HOME/bin/java" -version
3027
"$MAVEN_HOME/bin/mvn" -version

scripts/setup-workspace.sh

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
###
3-
# Prepare Codename One workspace by installing Maven, provisioning JDK 8 and JDK 17,
3+
# Prepare Codename One workspace by installing Maven, provisioning JDK 8, 11 and 17,
44
# building core modules, and installing Maven archetypes.
55
###
66
set -euo pipefail
@@ -9,12 +9,21 @@ log() {
99
echo "[setup-workspace] $1"
1010
}
1111

12+
# Normalize TMPDIR so it has no trailing slash
13+
TMPDIR="${TMPDIR%/}"
14+
1215
# Place downloaded tools outside the repository so it isn't filled with binaries
1316
DOWNLOAD_DIR="${TMPDIR:-/tmp}/codenameone-tools"
1417
mkdir -p "$DOWNLOAD_DIR"
1518
ENV_DIR="$DOWNLOAD_DIR/tools"
1619
mkdir -p "$ENV_DIR"
1720

21+
# Reuse previously saved environment if present (so we can skip downloads)
22+
if [ -f "$ENV_DIR/env.sh" ]; then
23+
# shellcheck disable=SC1090
24+
source "$ENV_DIR/env.sh"
25+
fi
26+
1827
JAVA_HOME="${JAVA_HOME:-}"
1928
JAVA_HOME_17="${JAVA_HOME_17:-}"
2029
MAVEN_HOME="${MAVEN_HOME:-}"
@@ -40,18 +49,33 @@ if [ "$os" = "mac" ] && [ "$arch" = "aarch64" ]; then
4049
fi
4150

4251
JDK8_URL="https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u462-b08/OpenJDK8U-jdk_${arch_jdk8}_${os}_hotspot_8u462b08.tar.gz"
52+
JDK11_URL="https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28%2B6/OpenJDK11U-jdk_${arch}_${os}_hotspot_11.0.28_6.tar.gz"
4353
JDK17_URL="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16%2B8/OpenJDK17U-jdk_${arch}_${os}_hotspot_17.0.16_8.tar.gz"
4454
MAVEN_URL="https://archive.apache.org/dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz"
4555

4656
install_jdk() {
4757
local url="$1" dest_var="$2"
48-
local tmp="$DOWNLOAD_DIR/jdk.tgz"
49-
log "Downloading JDK from $url"
50-
curl -fL "$url" -o "$tmp"
58+
local archive="$DOWNLOAD_DIR/$(basename "$url")"
59+
60+
if [ -f "$archive" ]; then
61+
log "Using cached JDK archive $(basename "$archive")"
62+
else
63+
log "Downloading JDK from $url"
64+
curl -fL "$url" -o "$archive"
65+
fi
66+
67+
# Find top directory name inside the tarball
5168
local top
52-
top=$(tar -tzf "$tmp" 2>/dev/null | head -1 | cut -d/ -f1 || true)
53-
tar -xzf "$tmp" -C "$DOWNLOAD_DIR"
54-
rm "$tmp"
69+
top=$(tar -tzf "$archive" 2>/dev/null | head -1 | cut -d/ -f1 || true)
70+
71+
# Extract only if target directory doesn't already exist
72+
if [ -n "$top" ] && [ -d "$DOWNLOAD_DIR/$top" ]; then
73+
log "JDK already extracted at $DOWNLOAD_DIR/$top"
74+
else
75+
log "Extracting JDK to $DOWNLOAD_DIR"
76+
tar -xzf "$archive" -C "$DOWNLOAD_DIR"
77+
fi
78+
5579
local home="$DOWNLOAD_DIR/$top"
5680
if [ -d "$home/Contents/Home" ]; then
5781
home="$home/Contents/Home"
@@ -61,43 +85,64 @@ install_jdk() {
6185

6286
log "Ensuring JDK 8 is available"
6387
if [ ! -x "${JAVA_HOME:-}/bin/java" ] || ! "${JAVA_HOME:-}/bin/java" -version 2>&1 | grep -q '8\.0'; then
64-
log "Provisioning JDK 8 (this may take a while)..."
88+
log "Provisioning JDK 8..."
6589
install_jdk "$JDK8_URL" JAVA_HOME
6690
else
6791
log "Using existing JDK 8 at $JAVA_HOME"
6892
fi
6993

94+
log "Ensuring JDK 11 is available"
95+
if [ ! -x "${JAVA_HOME_11:-}/bin/java" ] || ! "${JAVA_HOME_11:-}/bin/java" -version 2>&1 | grep -q '11\.0'; then
96+
log "Provisioning JDK 11..."
97+
install_jdk "$JDK11_URL" JAVA_HOME_11
98+
else
99+
log "Using existing JDK 11 at $JAVA_HOME_11"
100+
fi
101+
70102
log "Ensuring JDK 17 is available"
71103
if [ ! -x "${JAVA_HOME_17:-}/bin/java" ] || ! "${JAVA_HOME_17:-}/bin/java" -version 2>&1 | grep -q '17\.0'; then
72-
log "Provisioning JDK 17 (this may take a while)..."
104+
log "Provisioning JDK 17..."
73105
install_jdk "$JDK17_URL" JAVA_HOME_17
74106
else
75107
log "Using existing JDK 17 at $JAVA_HOME_17"
76108
fi
77109

78110
log "Ensuring Maven is available"
79111
if ! [ -x "${MAVEN_HOME:-}/bin/mvn" ]; then
80-
tmp="$DOWNLOAD_DIR/maven.tgz"
81-
log "Downloading Maven from $MAVEN_URL"
82-
curl -fL "$MAVEN_URL" -o "$tmp"
83-
tar -xzf "$tmp" -C "$DOWNLOAD_DIR"
84-
rm "$tmp"
85-
MAVEN_HOME="$DOWNLOAD_DIR/apache-maven-3.9.6"
112+
local mvn_archive="$DOWNLOAD_DIR/$(basename "$MAVEN_URL")"
113+
if [ -f "$mvn_archive" ]; then
114+
log "Using cached Maven archive $(basename "$mvn_archive")"
115+
else
116+
log "Downloading Maven from $MAVEN_URL"
117+
curl -fL "$MAVEN_URL" -o "$mvn_archive"
118+
fi
119+
local mvn_top
120+
mvn_top=$(tar -tzf "$mvn_archive" 2>/dev/null | head -1 | cut -d/ -f1 || true)
121+
if [ -n "$mvn_top" ] && [ -d "$DOWNLOAD_DIR/$mvn_top" ]; then
122+
log "Maven already extracted at $DOWNLOAD_DIR/$mvn_top"
123+
else
124+
log "Extracting Maven to $DOWNLOAD_DIR"
125+
tar -xzf "$mvn_archive" -C "$DOWNLOAD_DIR"
126+
fi
127+
MAVEN_HOME="$DOWNLOAD_DIR/$mvn_top"
86128
else
87129
log "Using existing Maven at $MAVEN_HOME"
88130
fi
89131

90132
log "Writing environment to $ENV_DIR/env.sh"
91133
cat > "$ENV_DIR/env.sh" <<ENV
92134
export JAVA_HOME="$JAVA_HOME"
135+
export JAVA_HOME_11="$JAVA_HOME_11"
93136
export JAVA_HOME_17="$JAVA_HOME_17"
94137
export MAVEN_HOME="$MAVEN_HOME"
95138
export PATH="\$JAVA_HOME/bin:\$MAVEN_HOME/bin:\$PATH"
96139
ENV
97140

141+
# shellcheck disable=SC1090
98142
source "$ENV_DIR/env.sh"
99143

100144
log "JDK 8 version:"; "$JAVA_HOME/bin/java" -version
145+
log "JDK 11 version:"; "$JAVA_HOME_11/bin/java" -version
101146
log "JDK 17 version:"; "$JAVA_HOME_17/bin/java" -version
102147
log "Maven version:"; "$MAVEN_HOME/bin/mvn" -version
103148

@@ -120,4 +165,4 @@ log "Installing cn1-maven-archetypes"
120165
if [ ! -d cn1-maven-archetypes ]; then
121166
git clone https://github.com/shannah/cn1-maven-archetypes
122167
fi
123-
(cd cn1-maven-archetypes && "$MAVEN_HOME/bin/mvn" -q -DskipTests -DskipITs=true -Dinvoker.skip=true install)
168+
(cd cn1-maven-archetypes && "$MAVEN_HOME/bin/mvn" -q -DskipTests -DskipITs=true -Dinvoker.skip=true install)

0 commit comments

Comments
 (0)