Skip to content

Commit 2b938b7

Browse files
committed
Improve workspace detection in Android app build script
1 parent 21e6d25 commit 2b938b7

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

scripts/build-android-app.sh

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,37 @@ TMPDIR="${TMPDIR%/}"
1515
DOWNLOAD_DIR="${TMPDIR%/}/codenameone-tools"
1616
ENV_DIR="$DOWNLOAD_DIR/tools"
1717

18-
if [ -f "$ENV_DIR/env.sh" ]; then
19-
# shellcheck disable=SC1090
20-
source "$ENV_DIR/env.sh"
21-
else
22-
log "Workspace tools not provisioned; running setup-workspace.sh"
23-
./scripts/setup-workspace.sh -q -DskipTests
24-
# shellcheck disable=SC1090
25-
source "$ENV_DIR/env.sh"
26-
fi
27-
28-
if [ -z "${JAVA_HOME:-}" ] || [ ! -x "$JAVA_HOME/bin/java" ]; then
29-
log "JAVA_HOME is not set correctly. Please run scripts/setup-workspace.sh first." >&2
30-
exit 1
31-
fi
32-
if [ -z "${JAVA_HOME_17:-}" ] || [ ! -x "$JAVA_HOME_17/bin/java" ]; then
33-
log "JAVA_HOME_17 is not set correctly. Please run scripts/setup-workspace.sh first." >&2
34-
exit 1
35-
fi
36-
if [ -z "${MAVEN_HOME:-}" ] || [ ! -x "$MAVEN_HOME/bin/mvn" ]; then
37-
log "Maven is not available. Please run scripts/setup-workspace.sh first." >&2
18+
ensure_workspace() {
19+
local attempt
20+
for attempt in 1 2; do
21+
if [ -f "$ENV_DIR/env.sh" ]; then
22+
# shellcheck disable=SC1090
23+
source "$ENV_DIR/env.sh"
24+
fi
25+
26+
if [ -n "${JAVA_HOME:-}" ] && [ -x "$JAVA_HOME/bin/java" ] && \
27+
[ -n "${JAVA_HOME_17:-}" ] && [ -x "$JAVA_HOME_17/bin/java" ] && \
28+
[ -n "${MAVEN_HOME:-}" ] && [ -x "$MAVEN_HOME/bin/mvn" ]; then
29+
return 0
30+
fi
31+
32+
if [ "$attempt" -eq 1 ]; then
33+
log "Workspace tools not provisioned; running setup-workspace.sh"
34+
./scripts/setup-workspace.sh -q -DskipTests
35+
fi
36+
done
37+
38+
if [ -z "${JAVA_HOME:-}" ] || [ ! -x "$JAVA_HOME/bin/java" ]; then
39+
log "JAVA_HOME is not set correctly. Please run scripts/setup-workspace.sh first." >&2
40+
elif [ -z "${JAVA_HOME_17:-}" ] || [ ! -x "$JAVA_HOME_17/bin/java" ]; then
41+
log "JAVA_HOME_17 is not set correctly. Please run scripts/setup-workspace.sh first." >&2
42+
else
43+
log "Maven is not available. Please run scripts/setup-workspace.sh first." >&2
44+
fi
3845
exit 1
39-
fi
46+
}
47+
48+
ensure_workspace
4049

4150
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
4251

0 commit comments

Comments
 (0)