Skip to content

Commit 1aafdf6

Browse files
committed
Improve build scripts and workflows
1 parent ae23c2f commit 1aafdf6

File tree

7 files changed

+74
-35
lines changed

7 files changed

+74
-35
lines changed

.github/workflows/pr.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
name: PR CI
22

3-
on:
3+
on:
44
pull_request:
55
branches:
66
- master
7+
paths-ignore:
8+
- 'scripts/**'
9+
- '**/*.md'
710
push:
811
branches:
912
- master
13+
paths-ignore:
14+
- 'scripts/**'
15+
- '**/*.md'
1016

1117
jobs:
1218
build-linux-jdk8-fx:

.github/workflows/scripts-android.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
name: Test Android build scripts
33

44
'on':
5-
push:
5+
pull_request:
66
paths:
77
- 'scripts/**'
8-
pull_request:
8+
- 'BUILDING.md'
9+
push:
10+
branches:
11+
- master
912
paths:
1013
- 'scripts/**'
14+
- 'BUILDING.md'
1115

1216
jobs:
1317
build-android:
1418
runs-on: ubuntu-latest
1519
steps:
1620
- uses: actions/checkout@v4
21+
- name: Setup workspace
22+
run: ./scripts/setup-workspace.sh -q -DskipTests
1723
- name: Build Android port
1824
run: |
19-
./scripts/setup-workspace.sh -q -DskipTests
25+
source tools/env.sh
2026
./scripts/build-android-port.sh -q -DskipTests

.github/workflows/scripts-ios.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
name: Test iOS build scripts
33

44
'on':
5-
push:
5+
pull_request:
66
paths:
77
- 'scripts/**'
8-
pull_request:
8+
- 'BUILDING.md'
9+
push:
10+
branches:
11+
- master
912
paths:
1013
- 'scripts/**'
14+
- 'BUILDING.md'
1115

1216
jobs:
1317
build-ios:
1418
runs-on: macos-latest
1519
steps:
1620
- uses: actions/checkout@v4
21+
- name: Setup workspace
22+
run: ./scripts/setup-workspace.sh -q -DskipTests
1723
- name: Build iOS port
1824
run: |
19-
./scripts/setup-workspace.sh -q -DskipTests
25+
source tools/env.sh
2026
./scripts/build-ios-port.sh -q -DskipTests

BUILDING.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Building Codename One
22

3-
This guide describes how to build Codename One and its Android and iOS ports locally using Maven. It includes reproducible steps for setting up the workspace and compiling each port.
3+
This document provides reproducible instructions for building Codename One and its Android and iOS ports with Maven. It is written so that both developers and automated tools can follow it step by step.
44

55
## Prerequisites
66

7-
- **JDK 11** for building the main project and the iOS port.
7+
- **JDK 11** (Codename One also builds with JDK 8, but these instructions use JDK 11).
88
- **JDK 17** for building the Android port.
99
- **Apache Maven 3.6+**.
10+
- macOS with Xcode (only for building the iOS port).
1011

1112
The `setup-workspace.sh` script downloads these dependencies automatically when they are not already installed.
1213

@@ -38,13 +39,14 @@ Clone the repository and run the setup script to install Maven, download JDK 11
3839
git clone https://github.com/codenameone/CodenameOne
3940
cd CodenameOne
4041
./scripts/setup-workspace.sh -DskipTests
42+
source tools/env.sh
4143
```
4244

43-
The script runs `mvn install` in `maven/`, installs `cn1-maven-archetypes`, and ensures `~/.codenameone/CodeNameOneBuildClient.jar` is installed by invoking the `cn1:install-codenameone` Maven goal. If that goal fails, the script copies the jar from `maven/CodeNameOneBuildClient.jar`.
45+
The script runs `mvn install` in `maven/`, installs `cn1-maven-archetypes`, and ensures `~/.codenameone/CodeNameOneBuildClient.jar` is installed by invoking the `cn1:install-codenameone` Maven goal. If that goal fails, the script copies the jar from `maven/CodeNameOneBuildClient.jar`. After the script finishes, `tools/env.sh` contains environment variables for the provisioned JDKs and Maven.
4446

4547
## Building the Android port
4648

47-
Run the Android build script. It requires `JAVA_HOME` pointing to JDK 11 and `JAVA_HOME_17` pointing to JDK 17. If these variables are unset, the script will look for the JDKs under `tools/` as provisioned by `setup-workspace.sh`:
49+
Run the Android build script. It sources the environment from `tools/env.sh`, ensuring `JAVA_HOME` points to JDK 11 and `JAVA_HOME_17` points to JDK 17. If the JDKs are missing, the script will run `setup-workspace.sh` to download them:
4850

4951
```bash
5052
./scripts/build-android-port.sh -DskipTests
@@ -54,7 +56,7 @@ The resulting artifacts are placed in `maven/android/target`.
5456

5557
## Building the iOS port
5658

57-
The iOS port can only be built on macOS with Xcode installed. The build script expects `JAVA_HOME` to point to JDK 11 and will search `tools/` if it is not set:
59+
The iOS port can only be built on macOS with Xcode installed. The build script sources `tools/env.sh` and ensures `JAVA_HOME` points to JDK 11, running `setup-workspace.sh` if necessary:
5860

5961
```bash
6062
./scripts/build-ios-port.sh -DskipTests
@@ -66,7 +68,7 @@ The build output is in `maven/ios/target`.
6668

6769
The `scripts` directory contains helper scripts:
6870

69-
- `setup-workspace.sh` – installs Maven, downloads JDK 11 and JDK 17, builds the core modules, installs Maven archetypes, and provisions the Codename One build client.
71+
- `setup-workspace.sh` – installs Maven, downloads JDK 11 and JDK 17, builds the core modules, installs Maven archetypes, provisions the Codename One build client, and writes `tools/env.sh`.
7072
- `build-android-port.sh` – builds the Android port using JDK 11 for Maven and JDK 17 for compilation.
7173
- `build-ios-port.sh` – builds the iOS port on macOS with JDK 11.
7274

scripts/build-android-port.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,33 @@ set -e
55
DIR="$(cd "$(dirname "$0")" && pwd)/.."
66
cd "$DIR"
77

8-
# Locate JDK 11
8+
if [ -f "$DIR/tools/env.sh" ]; then
9+
source "$DIR/tools/env.sh"
10+
fi
11+
912
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
10-
JAVA_HOME=$(ls -d "$DIR"/tools/jdk-11* 2>/dev/null | head -n1)
13+
echo "Provisioning workspace..."
14+
./scripts/setup-workspace.sh -q -DskipTests
15+
source "$DIR/tools/env.sh"
1116
fi
17+
1218
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
13-
echo "JAVA_HOME must point to JDK 11." >&2
19+
echo "Failed to set up JDK 11." >&2
1420
exit 1
1521
fi
1622

17-
# Locate JDK 17
1823
if [ -z "$JAVA_HOME_17" ] || ! "$JAVA_HOME_17/bin/java" -version 2>&1 | head -n1 | grep -q "17"; then
19-
JAVA_HOME_17=$(ls -d "$DIR"/tools/jdk-17* 2>/dev/null | head -n1)
24+
echo "Provisioning JDK 17..."
25+
./scripts/setup-workspace.sh -q -DskipTests
26+
source "$DIR/tools/env.sh"
2027
fi
28+
2129
if [ -z "$JAVA_HOME_17" ] || ! "$JAVA_HOME_17/bin/java" -version 2>&1 | head -n1 | grep -q "17"; then
22-
echo "JAVA_HOME_17 must point to JDK 17." >&2
30+
echo "Failed to set up JDK 17." >&2
2331
exit 1
2432
fi
2533

26-
export PATH="$JAVA_HOME/bin:$PATH"
34+
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
2735

2836
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
2937
if [ ! -f "$BUILD_CLIENT" ]; then

scripts/build-ios-port.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ fi
1515
DIR="$(cd "$(dirname "$0")" && pwd)/.."
1616
cd "$DIR"
1717

18-
# Locate JDK 11
19-
if [ -z "$JAVA_HOME" ]; then
20-
JAVA_HOME=$(ls -d "$DIR"/tools/jdk-11* 2>/dev/null | head -n1)
18+
if [ -f "$DIR/tools/env.sh" ]; then
19+
source "$DIR/tools/env.sh"
2120
fi
21+
22+
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
23+
echo "Provisioning workspace..."
24+
./scripts/setup-workspace.sh -q -DskipTests
25+
source "$DIR/tools/env.sh"
26+
fi
27+
2228
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
23-
echo "JAVA_HOME must point to JDK 11." >&2
29+
echo "Failed to set up JDK 11." >&2
2430
exit 1
2531
fi
2632

27-
export PATH="$JAVA_HOME/bin:$PATH"
33+
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
2834

2935
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
3036
if [ ! -f "$BUILD_CLIENT" ]; then

scripts/setup-workspace.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ ensure_jdk() {
2626
}
2727

2828
ensure_maven() {
29-
if ! command -v mvn >/dev/null; then
30-
local version="3.9.6"
29+
local version="3.9.6"
30+
MAVEN_HOME="$TOOLS_DIR/apache-maven-$version"
31+
if [ ! -d "$MAVEN_HOME" ]; then
3132
local archive="$TOOLS_DIR/apache-maven-$version-bin.tar.gz"
3233
echo "Downloading Maven $version..."
3334
curl -L -o "$archive" "https://archive.apache.org/dist/maven/maven-3/$version/binaries/apache-maven-$version-bin.tar.gz"
3435
tar -xzf "$archive" -C "$TOOLS_DIR"
3536
rm "$archive"
36-
MAVEN_HOME="$TOOLS_DIR/apache-maven-$version"
37-
export PATH="$MAVEN_HOME/bin:$PATH"
3837
fi
38+
export MAVEN_HOME
39+
export PATH="$MAVEN_HOME/bin:$PATH"
3940
}
4041

4142
detect_platform() {
@@ -54,17 +55,21 @@ detect_platform() {
5455

5556
detect_platform
5657

57-
JDK11_URL="https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28%2B6/"\
58-
"OpenJDK11U-jdk_${arch}_${platform}_hotspot_11.0.28_6.tar.gz"
59-
JDK17_URL="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16%2B8/"\
60-
"OpenJDK17U-jdk_${arch}_${platform}_hotspot_17.0.16_8.tar.gz"
58+
JDK11_URL="https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28%2B6/OpenJDK11U-jdk_${arch}_${platform}_hotspot_11.0.28_6.tar.gz"
59+
JDK17_URL="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16%2B8/OpenJDK17U-jdk_${arch}_${platform}_hotspot_17.0.16_8.tar.gz"
6160

6261
ensure_jdk JAVA_HOME 11 "$JDK11_URL"
6362
ensure_jdk JAVA_HOME_17 17 "$JDK17_URL"
64-
6563
ensure_maven
6664

67-
export PATH="$JAVA_HOME/bin:$PATH"
65+
cat > "$TOOLS_DIR/env.sh" <<EOF
66+
export JAVA_HOME="$JAVA_HOME"
67+
export JAVA_HOME_17="$JAVA_HOME_17"
68+
export MAVEN_HOME="$MAVEN_HOME"
69+
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:\$PATH"
70+
EOF
71+
72+
source "$TOOLS_DIR/env.sh"
6873

6974
mvn -f maven/pom.xml install "$@"
7075

0 commit comments

Comments
 (0)