Skip to content

Commit 9a7ba4c

Browse files
authored
Merge pull request #204 from github/copilot/support-java-modularity
Add explicit Java module descriptor
2 parents 9a2a8c9 + d2ea79a commit 9a7ba4c

4 files changed

Lines changed: 56 additions & 9 deletions

File tree

config/checkstyle/checkstyle.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<property name="charset" value="UTF-8"/>
1212
<property name="severity" value="error"/>
1313

14-
<!-- Exclude json package, events package, and generated package (self-documenting DTOs) -->
14+
<!-- Exclude module descriptor, json package, events package, and generated package (self-documenting DTOs) -->
1515
<module name="BeforeExecutionExclusionFileFilter">
16-
<property name="fileNamePattern" value=".*[\\/](json|events|generated|rpc)[\\/].*\.java$"/>
16+
<property name="fileNamePattern" value="(^|.*[\\/])module-info\.java$|.*[\\/](json|events|generated|rpc)[\\/].*\.java$"/>
1717
</module>
1818

1919
<module name="TreeWalker">

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,6 @@
172172
<groupId>org.apache.maven.plugins</groupId>
173173
<artifactId>maven-jar-plugin</artifactId>
174174
<version>3.5.0</version>
175-
<configuration>
176-
<archive>
177-
<manifestEntries>
178-
<Automatic-Module-Name>com.github.copilot.sdk.java</Automatic-Module-Name>
179-
</manifestEntries>
180-
</archive>
181-
</configuration>
182175
</plugin>
183176
<!-- Clone or update the official copilot-sdk repository for test resources, and copy image to site -->
184177
<plugin>

src/main/java/module-info.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
/**
6+
* GitHub Copilot SDK for Java.
7+
*/
8+
module com.github.copilot.sdk.java {
9+
requires transitive com.fasterxml.jackson.annotation;
10+
requires com.fasterxml.jackson.core;
11+
requires transitive com.fasterxml.jackson.databind;
12+
requires com.fasterxml.jackson.datatype.jsr310;
13+
requires static com.github.spotbugs.annotations;
14+
requires static java.compiler;
15+
requires static java.net.http;
16+
requires java.logging;
17+
18+
exports com.github.copilot.sdk;
19+
exports com.github.copilot.sdk.generated;
20+
exports com.github.copilot.sdk.generated.rpc;
21+
exports com.github.copilot.sdk.json;
22+
23+
opens com.github.copilot.sdk to com.fasterxml.jackson.databind;
24+
opens com.github.copilot.sdk.generated to com.fasterxml.jackson.databind;
25+
opens com.github.copilot.sdk.json to com.fasterxml.jackson.databind;
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
package com.github.copilot.sdk;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
10+
import java.lang.module.ModuleDescriptor;
11+
import org.junit.jupiter.api.Test;
12+
13+
class ModuleDescriptorTest {
14+
15+
@Test
16+
void sdkHasExplicitModuleDescriptor() {
17+
Module module = CopilotClient.class.getModule();
18+
assertTrue(module.isNamed());
19+
assertEquals("com.github.copilot.sdk.java", module.getName());
20+
21+
ModuleDescriptor descriptor = module.getDescriptor();
22+
assertTrue(descriptor.exports().stream().anyMatch(export -> export.source().equals("com.github.copilot.sdk")));
23+
assertTrue(descriptor.exports().stream()
24+
.anyMatch(export -> export.source().equals("com.github.copilot.sdk.json")));
25+
assertTrue(descriptor.requires().stream()
26+
.anyMatch(require -> require.name().equals("com.fasterxml.jackson.databind")));
27+
}
28+
}

0 commit comments

Comments
 (0)