Skip to content

Commit c67265b

Browse files
Copilotedburns
andcommitted
Refactor handleBroadcastEventAsync to use Java 21 pattern matching switch; bump minimum Java to 21
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 2aea3a0 commit c67265b

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

.github/workflows/build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
node-version: 22
3939
- uses: actions/setup-java@v5
4040
with:
41-
java-version: "17"
41+
java-version: "21"
4242
distribution: "temurin"
4343
cache: "maven"
4444

.github/workflows/publish-maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Set up JDK 17
5454
uses: actions/setup-java@v5
5555
with:
56-
java-version: "17"
56+
java-version: "21"
5757
distribution: "temurin"
5858
cache: "maven"
5959
server-id: central

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Site](https://github.com/copilot-community-sdk/copilot-sdk-java/actions/workflows/deploy-site.yml/badge.svg)](https://github.com/copilot-community-sdk/copilot-sdk-java/actions/workflows/deploy-site.yml)
55
[![Coverage](.github/badges/jacoco.svg)](https://copilot-community-sdk.github.io/copilot-sdk-java/snapshot/jacoco/index.html)
66
[![Documentation](https://img.shields.io/badge/docs-online-brightgreen)](https://copilot-community-sdk.github.io/copilot-sdk-java/)
7-
[![Java 17+](https://img.shields.io/badge/Java-17%2B-blue?logo=openjdk&logoColor=white)](https://openjdk.org/)
7+
[![Java 21+](https://img.shields.io/badge/Java-21%2B-blue?logo=openjdk&logoColor=white)](https://openjdk.org/)
88
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
99

1010
#### Latest release
@@ -24,7 +24,7 @@ Java SDK for programmatic control of GitHub Copilot CLI, enabling you to build A
2424

2525
### Requirements
2626

27-
- Java 17 or later
27+
- Java 21 or later
2828
- GitHub Copilot CLI 0.0.411-1 or later installed and in PATH (or provide custom `cliPath`)
2929

3030
### Maven

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</scm>
3838

3939
<properties>
40-
<maven.compiler.release>17</maven.compiler.release>
40+
<maven.compiler.release>21</maven.compiler.release>
4141
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4242
<!-- Directory where the copilot-sdk repo will be cloned for tests -->
4343
<copilot.sdk.clone.dir>${project.build.directory}/copilot-sdk</copilot.sdk.clone.dir>

src/main/java/com/github/copilot/sdk/CopilotSession.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -618,27 +618,33 @@ void dispatchEvent(AbstractSessionEvent event) {
618618
* the event to handle
619619
*/
620620
private void handleBroadcastEventAsync(AbstractSessionEvent event) {
621-
if (event instanceof ExternalToolRequestedEvent toolEvent) {
622-
var data = toolEvent.getData();
623-
if (data == null || data.requestId() == null || data.toolName() == null) {
624-
return;
625-
}
626-
ToolDefinition tool = getTool(data.toolName());
627-
if (tool == null) {
628-
return; // This client doesn't handle this tool; another client will
621+
switch (event) {
622+
case ExternalToolRequestedEvent toolEvent -> {
623+
var data = toolEvent.getData();
624+
if (data == null || data.requestId() == null || data.toolName() == null) {
625+
return;
626+
}
627+
ToolDefinition tool = getTool(data.toolName());
628+
if (tool == null) {
629+
return; // This client doesn't handle this tool; another client will
630+
}
631+
executeToolAndRespondAsync(data.requestId(), data.toolName(), data.toolCallId(), data.arguments(),
632+
tool);
629633
}
630-
executeToolAndRespondAsync(data.requestId(), data.toolName(), data.toolCallId(), data.arguments(), tool);
631-
632-
} else if (event instanceof PermissionRequestedEvent permEvent) {
633-
var data = permEvent.getData();
634-
if (data == null || data.requestId() == null || data.permissionRequest() == null) {
635-
return;
634+
case PermissionRequestedEvent permEvent -> {
635+
var data = permEvent.getData();
636+
if (data == null || data.requestId() == null || data.permissionRequest() == null) {
637+
return;
638+
}
639+
PermissionHandler handler = permissionHandler.get();
640+
if (handler == null) {
641+
return; // This client doesn't handle permissions; another client will
642+
}
643+
executePermissionAndRespondAsync(data.requestId(), data.permissionRequest(), handler);
636644
}
637-
PermissionHandler handler = permissionHandler.get();
638-
if (handler == null) {
639-
return; // This client doesn't handle permissions; another client will
645+
default -> {
646+
// Other event types are not handled here
640647
}
641-
executePermissionAndRespondAsync(data.requestId(), data.permissionRequest(), handler);
642648
}
643649
}
644650

src/site/markdown/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Copilot: In Tokyo it's 75°F and sunny. Great day to be outside!
1818

1919
Before you begin, make sure you have:
2020

21-
- **Java 17+** installed
21+
- **Java 21+** installed
2222
- **GitHub Copilot CLI** installed and authenticated ([Installation guide](https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli))
2323

2424
Verify the CLI is working:

src/site/markdown/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Welcome to the documentation for the **Copilot SDK for Java** — a Java SDK for
88

99
### Requirements
1010

11-
- Java 17 or later
11+
- Java 21 or later
1212
- GitHub Copilot CLI 0.0.411-1 or later installed and in PATH (or provide custom `cliPath`)
1313

1414
### Installation

0 commit comments

Comments
 (0)