Skip to content

Commit 06631a1

Browse files
authored
Added test and CI build
2 parents 16798e9 + f98d1e2 commit 06631a1

25 files changed

Lines changed: 2967 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
10+
jobs:
11+
android-compile:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: "17"
22+
cache: maven
23+
24+
- name: Set up Android SDK
25+
uses: android-actions/setup-android@v3
26+
27+
- name: Set up Codename One Build Client
28+
shell: bash
29+
run: |
30+
set -euo pipefail
31+
mkdir -p "$HOME/.codenameone"
32+
curl -fsSL https://github.com/codenameone/CodenameOne/raw/refs/heads/master/maven/CodeNameOneBuildClient.jar \
33+
-o "$HOME/.codenameone/CodeNameOneBuildClient.jar"
34+
35+
- name: Compute snapshot version
36+
id: versions
37+
shell: bash
38+
run: |
39+
set -euo pipefail
40+
current_version="$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)"
41+
if [[ "$current_version" == *-SNAPSHOT ]]; then
42+
snapshot_version="$current_version"
43+
else
44+
snapshot_version="${current_version}-SNAPSHOT"
45+
fi
46+
echo "snapshot_version=$snapshot_version" >> "$GITHUB_OUTPUT"
47+
48+
- name: Build cn1lib snapshot into local Maven repository
49+
shell: bash
50+
run: |
51+
set -euo pipefail
52+
mvn -B -ntp versions:set -DnewVersion="${{ steps.versions.outputs.snapshot_version }}" -DgenerateBackupPoms=false
53+
mvn -B -ntp -DskipTests install
54+
55+
- name: Generate Android source project from sample app
56+
working-directory: fingerprint-scanner-test
57+
shell: bash
58+
run: |
59+
set -euo pipefail
60+
export JAVA17_HOME="$JAVA_HOME"
61+
chmod +x mvnw
62+
xvfb-run -a ./mvnw -B -ntp package \
63+
-DskipTests \
64+
-Dopen=false \
65+
-Dcodename1.platform=android \
66+
-Dcodename1.buildTarget=android-source \
67+
-Dfingerprint.scanner.version="${{ steps.versions.outputs.snapshot_version }}"
68+
69+
- name: Build generated Android Gradle project
70+
working-directory: fingerprint-scanner-test/android/target/myappname-android-1.0-SNAPSHOT-android-source
71+
shell: bash
72+
run: |
73+
set -euo pipefail
74+
chmod +x gradlew
75+
./gradlew --no-daemon --stacktrace assembleDebug
76+
77+
ios-compile:
78+
runs-on: macos-latest
79+
steps:
80+
- name: Check out repository
81+
uses: actions/checkout@v4
82+
83+
- name: Set up JDK 17
84+
uses: actions/setup-java@v4
85+
with:
86+
distribution: temurin
87+
java-version: "17"
88+
cache: maven
89+
90+
- name: Set up Codename One Build Client
91+
shell: bash
92+
run: |
93+
set -euo pipefail
94+
mkdir -p "$HOME/.codenameone"
95+
curl -fsSL https://github.com/codenameone/CodenameOne/raw/refs/heads/master/maven/CodeNameOneBuildClient.jar \
96+
-o "$HOME/.codenameone/CodeNameOneBuildClient.jar"
97+
98+
- name: Compute snapshot version
99+
id: versions
100+
shell: bash
101+
run: |
102+
set -euo pipefail
103+
current_version="$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)"
104+
if [[ "$current_version" == *-SNAPSHOT ]]; then
105+
snapshot_version="$current_version"
106+
else
107+
snapshot_version="${current_version}-SNAPSHOT"
108+
fi
109+
echo "snapshot_version=$snapshot_version" >> "$GITHUB_OUTPUT"
110+
111+
- name: Build cn1lib snapshot into local Maven repository
112+
shell: bash
113+
run: |
114+
set -euo pipefail
115+
mvn -B -ntp versions:set -DnewVersion="${{ steps.versions.outputs.snapshot_version }}" -DgenerateBackupPoms=false
116+
mvn -B -ntp -DskipTests install
117+
118+
- name: Generate iOS source project from sample app
119+
working-directory: fingerprint-scanner-test
120+
shell: bash
121+
run: |
122+
set -euo pipefail
123+
chmod +x mvnw
124+
./mvnw -B -ntp package \
125+
-DskipTests \
126+
-Dopen=false \
127+
-Dcodename1.platform=ios \
128+
-Dcodename1.buildTarget=ios-source \
129+
-Dfingerprint.scanner.version="${{ steps.versions.outputs.snapshot_version }}"
130+
131+
- name: Build generated Xcode workspace
132+
working-directory: fingerprint-scanner-test/ios/target/myappname-ios-1.0-SNAPSHOT-ios-source
133+
shell: bash
134+
run: |
135+
set -euo pipefail
136+
xcodebuild \
137+
-workspace MyAppName.xcworkspace \
138+
-scheme MyAppName \
139+
-configuration Debug \
140+
-sdk iphonesimulator \
141+
-destination "generic/platform=iOS Simulator" \
142+
CODE_SIGNING_ALLOWED=NO \
143+
build
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/target/
2+
.idea/
3+
*.iml
4+
.DS_Store
5+
Thumbs.db

fingerprint-scanner-test/.mvn/jvm.config

Whitespace-only changes.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.6";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

fingerprint-scanner-test/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Codename One Project
2+
3+
This is a multi-module Maven project for a Codename One app.
4+
You can write the app in Java and/or Kotlin, and build for Android, iOS, desktop, and web.
5+
6+
## Getting Started
7+
8+
You selected a Java template. Start here:
9+
https://shannah.github.io/cn1-maven-archetypes/cn1app-archetype-tutorial/getting-started.html
10+
11+
## IntelliJ Users
12+
13+
This project should work in IntelliJ out of the box.
14+
You usually don't need to copy or tweak any project files.
15+
16+
## Help and Support
17+
18+
- Codename One website: https://www.codenameone.com
19+
- Codename One GitHub: https://github.com/codenameone/CodenameOne

0 commit comments

Comments
 (0)