Skip to content

Commit b323bb8

Browse files
committed
Publish JPMS/OSGi services, and update documentation
1 parent d5e91e8 commit b323bb8

File tree

7 files changed

+56
-3
lines changed

7 files changed

+56
-3
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ A Java client for the [AdoptOpenJDK REST API](https://api.adoptopenjdk.net/).
1111

1212
![adoptopenjdk](./src/site/resources/adoptopenjdk.jpg?raw=true)
1313

14-
Usage
15-
===
14+
## Features
15+
16+
* Efficient, type-safe access to the AdoptOpenJDK API
17+
* Clean API/implementation separation for easy API mocking in applications
18+
* [JPMS](https://openjdk.java.net/projects/jigsaw/spec/)-ready
19+
* [OSGi](https://www.osgi.org)-ready
20+
* High coverage automated test suite
21+
* Apache 2.0 license
22+
* Fully documented (JavaDOC)
23+
24+
## Usage
1625

1726
Use the following Maven dependencies:
1827

@@ -44,3 +53,20 @@ try (var client = clients.createClient()) {
4453

4554
The API operates entirely synchronously and raises checked exceptions on
4655
failures.
56+
57+
The `net.adoptopenjdk.v3.api.AOV3ClientProviderType` interface is published
58+
both as a JPMS service and an [OSGi service](https://www.osgi.org) in order to
59+
allow for decoupling consumers from the `vanilla` implementation package:
60+
61+
```
62+
var clients =
63+
ServiceLoader.load(AOV3ClientProviderType.class)
64+
.findFirst()
65+
.orElseThrow(() -> new IllegalStateException(
66+
String.format("No implementations of %s are available", AOV3ClientProviderType.class)));
67+
68+
try (var client = clients.createClient()) {
69+
var request = client.availableReleases(...);
70+
var releases = request.execute();
71+
}
72+
```

net.adoptopenjdk.v3.tests/src/test/java/net/adoptopenjdk/v3/tests/AOV3ClientsTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package net.adoptopenjdk.v3.tests;
1616

17+
import net.adoptopenjdk.v3.api.AOV3ClientProviderType;
1718
import net.adoptopenjdk.v3.api.AOV3Error;
1819
import net.adoptopenjdk.v3.api.AOV3ExceptionHTTPRequestFailed;
1920
import net.adoptopenjdk.v3.api.AOV3ReleaseKind;
@@ -38,6 +39,7 @@
3839
import java.util.ArrayList;
3940
import java.util.Map;
4041
import java.util.Optional;
42+
import java.util.ServiceLoader;
4143

4244
public final class AOV3ClientsTest
4345
{
@@ -124,4 +126,15 @@ public void testRequestFailure0()
124126
);
125127
}
126128
}
129+
130+
@Test
131+
public void testService()
132+
throws Exception
133+
{
134+
final var clients =
135+
ServiceLoader.load(AOV3ClientProviderType.class)
136+
.findFirst()
137+
.orElseThrow(() -> new IllegalStateException(
138+
String.format("No implementations of %s are available", AOV3ClientProviderType.class)));
139+
}
127140
}

net.adoptopenjdk.v3.vanilla/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<artifactId>slf4j-api</artifactId>
4343
</dependency>
4444

45+
<dependency>
46+
<groupId>org.osgi</groupId>
47+
<artifactId>org.osgi.service.component.annotations</artifactId>
48+
<scope>provided</scope>
49+
</dependency>
4550
<dependency>
4651
<groupId>org.osgi</groupId>
4752
<artifactId>org.osgi.annotation.bundle</artifactId>

net.adoptopenjdk.v3.vanilla/src/main/java/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
module net.adoptopenjdk.v3.vanilla
1919
{
20+
requires static com.fasterxml.jackson.annotation;
2021
requires static org.osgi.annotation.bundle;
2122
requires static org.osgi.annotation.versioning;
22-
requires static com.fasterxml.jackson.annotation;
23+
requires static org.osgi.service.component.annotations;
2324

2425
requires transitive net.adoptopenjdk.v3.api;
2526

net.adoptopenjdk.v3.vanilla/src/main/java/net/adoptopenjdk/v3/vanilla/AOV3Clients.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import net.adoptopenjdk.v3.api.AOV3ClientProviderType;
1818
import net.adoptopenjdk.v3.api.AOV3ClientType;
19+
import org.osgi.service.component.annotations.Component;
1920

2021
import java.net.http.HttpClient;
2122
import java.util.Objects;
@@ -25,6 +26,7 @@
2526
* The default provider of v3 clients.
2627
*/
2728

29+
@Component(service = AOV3ClientProviderType.class)
2830
public final class AOV3Clients implements AOV3ClientProviderType
2931
{
3032
private final Supplier<HttpClient> clients;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
net.adoptopenjdk.v3.vanilla.AOV3Clients

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
<artifactId>org.osgi.annotation.versioning</artifactId>
118118
<version>1.1.0</version>
119119
</dependency>
120+
<dependency>
121+
<groupId>org.osgi</groupId>
122+
<artifactId>org.osgi.service.component.annotations</artifactId>
123+
<version>1.4.0</version>
124+
</dependency>
120125
<dependency>
121126
<groupId>org.immutables</groupId>
122127
<artifactId>value</artifactId>

0 commit comments

Comments
 (0)