Skip to content

Commit 5d753ad

Browse files
Convert BTDemo to Maven and add CI verification
- Restructured BTDemo project to standard Maven format (src/main/java, src/main/resources). - Created BTDemo/pom.xml with dependencies on cn1-bluetooth-lib and core libraries. - Added BTDemo module to root pom.xml. - Refactored BTDemo.java to remove dependency on external ca.weblite.codename1.json and use internal Map-based JSON handling. - Added GitHub Actions CI workflow to build and verify the project.
1 parent a43696b commit 5d753ad

File tree

6 files changed

+98
-17
lines changed

6 files changed

+98
-17
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up JDK 11
16+
uses: actions/setup-java@v2
17+
with:
18+
java-version: '11'
19+
distribution: 'adopt'
20+
- name: Build with Maven
21+
run: mvn -B clean install

BTDemo/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<groupId>com.codename1</groupId>
6+
<artifactId>cn1-bluetooth</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
<groupId>com.codename1.btle</groupId>
10+
<artifactId>BTDemo</artifactId>
11+
<version>1.0-SNAPSHOT</version>
12+
<packaging>jar</packaging>
13+
14+
<name>BTDemo</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.codenameone</groupId>
19+
<artifactId>codenameone-core</artifactId>
20+
<version>${cn1.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>com.codenameone</groupId>
24+
<artifactId>codenameone-javase</artifactId>
25+
<version>${cn1.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.codename1</groupId>
29+
<artifactId>cn1-bluetooth-lib</artifactId>
30+
<version>${project.version}</version>
31+
<type>pom</type>
32+
</dependency>
33+
</dependencies>
34+
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>com.codenameone</groupId>
39+
<artifactId>codenameone-maven-plugin</artifactId>
40+
<version>${cn1.plugin.version}</version>
41+
<configuration>
42+
<mainClassName>com.codename1.btle.BTDemo</mainClassName>
43+
</configuration>
44+
<executions>
45+
<execution>
46+
<goals>
47+
<goal>build</goal>
48+
</goals>
49+
</execution>
50+
</executions>
51+
</plugin>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.8.1</version>
56+
<configuration>
57+
<source>1.8</source>
58+
<target>1.8</target>
59+
</configuration>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
</project>

BTDemo/src/com/codename1/btle/BTDemo.java renamed to BTDemo/src/main/java/com/codename1/btle/BTDemo.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.codename1.btle;
22

3-
import ca.weblite.codename1.json.JSONException;
4-
import ca.weblite.codename1.json.JSONObject;
53
import com.codename1.bluetoothle.Bluetooth;
64
import com.codename1.components.MultiButton;
75
import com.codename1.ui.Display;
@@ -96,19 +94,17 @@ public void actionPerformed(ActionEvent evt) {
9694

9795
@Override
9896
public void actionPerformed(ActionEvent evt) {
99-
try {
100-
JSONObject res = (JSONObject) evt.getSource();
101-
System.out.println("response " + res);
102-
103-
if (res.getString("status").equals("scanResult")) {
104-
//if this is a new device add it
105-
if (!devices.containsKey(res.getString("address"))) {
106-
devices.put(res.getString("address"), res);
107-
updateUI();
108-
}
97+
Map res = (Map) evt.getSource();
98+
System.out.println("response " + res);
99+
100+
String status = (String) res.get("status");
101+
if ("scanResult".equals(status)) {
102+
//if this is a new device add it
103+
String address = (String) res.get("address");
104+
if (!devices.containsKey(address)) {
105+
devices.put(address, res);
106+
updateUI();
109107
}
110-
} catch (JSONException ex) {
111-
ex.printStackTrace();
112108
}
113109
}
114110
}, null, true, Bluetooth.SCAN_MODE_LOW_POWER, Bluetooth.MATCH_MODE_STICKY,
@@ -147,13 +143,13 @@ public void stop() {
147143
public void destroy() {
148144
}
149145

150-
private void updateUI() throws JSONException {
146+
private void updateUI() {
151147
devicesCnt.removeAll();
152148
Set keys = devices.keySet();
153149
for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
154150
String address = (String) iterator.next();
155-
JSONObject obj = (JSONObject) devices.get(address);
156-
MultiButton mb = new MultiButton(obj.getString("name"));
151+
Map obj = (Map) devices.get(address);
152+
MultiButton mb = new MultiButton((String) obj.get("name"));
157153
mb.setTextLine2(address);
158154
devicesCnt.add(mb);
159155
}
File renamed without changes.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<module>javase</module>
6969
<module>win</module>
7070
<module>lib</module>
71+
<module>BTDemo</module>
7172
</modules>
7273
<dependencyManagement>
7374
<dependencies>

0 commit comments

Comments
 (0)