Repository navigation
Expand file tree
/
Copy pathbuild-android-port.sh
More file actions
executable file
·151 lines (127 loc) · 5.36 KB
/
Copy pathbuild-android-port.sh
File metadata and controls
executable file
·151 lines (127 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
# Build Codename One Android port using JDK 8 for Maven and JDK 17 for compilation
set -euo pipefail
log() {
echo "[build-android-port] $1"
}
# Normalize TMPDIR and compose paths without duplicate slashes
TMPDIR="${TMPDIR:-/tmp}"
TMPDIR="${TMPDIR%/}"
# Place downloaded tools outside the repository so it isn't filled with binaries
# Strip any trailing slash again at the join to be extra safe.
DOWNLOAD_DIR="${TMPDIR%/}/codenameone-tools"
log "The DOWNLOAD_DIR is ${DOWNLOAD_DIR}"
CN1_BINARIES_PARENT="$(cd .. && pwd -P)"
CN1_BINARIES="${CN1_BINARIES_PARENT%/}/cn1-binaries"
if [ ! -d "$CN1_BINARIES" ]; then
# Fallback to the maven build dir if the external one doesn't exist
CN1_BINARIES="$(pwd)/maven/target/cn1-binaries"
fi
ENV_DIR="$DOWNLOAD_DIR/tools"
ENV_FILE="$ENV_DIR/env.sh"
load_environment() {
if [ ! -f "$ENV_FILE" ]; then
return 1
fi
log "Workspace environment file metadata"
ls -l "$ENV_FILE" | while IFS= read -r line; do log "$line"; done
log "Workspace environment file contents"
sed 's/^/[build-android-port] ENV: /' "$ENV_FILE"
# shellcheck disable=SC1090
source "$ENV_FILE"
}
check_java_home() {
local name="$1" home="$2" version_pattern="$3"
if [ -z "$home" ]; then
log "$name is not set"
return 1
fi
if [ ! -x "$home/bin/java" ]; then
log "$name does not contain a java binary: $home/bin/java"
return 1
fi
local version_output
version_output="$("$home/bin/java" -version 2>&1 || true)"
if ! grep -q "$version_pattern" <<<"$version_output"; then
log "$name java -version output did not match $version_pattern"
log "$version_output"
return 1
fi
log "$name detected at $home (${version_output%%$'\n'*})"
return 0
}
validate_workspace() {
local missing=0
if ! check_java_home "JAVA_HOME" "${JAVA_HOME:-}" '1\.8'; then
missing=1
fi
if ! check_java_home "JAVA17_HOME" "${JAVA17_HOME:-}" '17\.'; then
missing=1
fi
if [ -z "${MAVEN_HOME:-}" ]; then
log "MAVEN_HOME is not set"
missing=1
elif [ ! -x "$MAVEN_HOME/bin/mvn" ]; then
log "Maven binary missing at $MAVEN_HOME/bin/mvn"
missing=1
else
log "Maven detected at $MAVEN_HOME"
fi
return $missing
}
log "Loading workspace environment from $ENV_FILE"
if ! load_environment; then
log "Workspace tools not found. Running setup-workspace.sh"
./scripts/setup-workspace.sh -q -DskipTests "$@"
if ! load_environment; then
log "Failed to create workspace environment at $ENV_FILE" >&2
exit 1
fi
fi
if validate_workspace; then
log "Workspace environment validated"
else
log "Workspace validation failed. Re-provisioning tools via setup-workspace.sh"
./scripts/setup-workspace.sh -q -DskipTests "$@"
if ! load_environment; then
log "Failed to create workspace environment at $ENV_FILE" >&2
exit 1
fi
if ! validate_workspace; then
echo "Failed to provision required JDK or Maven binaries" >&2
exit 1
fi
log "Workspace environment validated"
fi
log "Loaded environment: JAVA_HOME=${JAVA_HOME:-<unset>} JAVA17_HOME=${JAVA17_HOME:-<unset>} MAVEN_HOME=${MAVEN_HOME:-<unset>}"
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
"$JAVA_HOME/bin/java" -version
"$JAVA17_HOME/bin/java" -version
"$MAVEN_HOME/bin/mvn" -version
# Maven runs directly, with no virtual display: every step below passes
# -Djava.awt.headless=true or opens no window at all, and the CSS compiler
# these modules feed is headless by construction.
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
if [ ! -f "$BUILD_CLIENT" ]; then
if ! "$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml -Dcn1.binaries="$CN1_BINARIES" -P !download-cn1-binaries cn1:install-codenameone "$@"; then
[ -f maven/CodeNameOneBuildClient.jar ] && cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT" || true
fi
fi
# maven/android/pom.xml pulls Themes/AndroidMaterialTheme.res directly into
# the Android port jar (resource entry on Themes/), so no pre-staging copy
# under Ports/Android/src/ is needed. The .res is committed under Themes/ and
# kept in sync by .github/workflows/native-themes-sync.yml. For local iteration
# on native-themes/android-material/theme.css, run scripts/build-native-themes.sh.
# Reinstall the CSS compiler first so changes under maven/css-compiler/ and
# maven/css-cli/ reach the app build that follows this script. The maven
# plugin's css goal forks com.codename1.designer.css.CN1CSSCLI on a classpath
# it resolves from the local repository (codenameone-css-cli, which brings
# codenameone-css-compiler and codenameone-project-model), so a cached
# ~/.m2/repository would otherwise hand it the previous build's jars even when
# CSSTheme.java has changed, and the new parsing would silently miss the
# app's theme.res. The designer module has no part in this -- it is the
# resource editor, and no build runs it -- so it is not built here. Nothing
# else in this slice is needed later: `-pl android -am` below rebuilds core
# itself, and the plugin and the javase port come from setup-workspace.sh.
"$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml -pl css-cli -am -Dcn1.binaries="$CN1_BINARIES" -P !download-cn1-binaries -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Djava.awt.headless=true install
"$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml -pl android -am -Dcn1.binaries="$CN1_BINARIES" -P !download-cn1-binaries -T 1C -Dmaven.javadoc.skip=true -Dmaven.source.skip=true -Djava.awt.headless=true clean install "$@"