Skip to content

Commit 0ccf8b3

Browse files
authored
Add Build Tool support at the /supportMatrix/servers endpoint (#439)
1 parent 1ce86d8 commit 0ccf8b3

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2021 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* You may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
package org.eclipse.microprofile.starter.rest;
21+
22+
import javax.inject.Inject;
23+
import javax.ws.rs.GET;
24+
import javax.ws.rs.HeaderParam;
25+
import javax.ws.rs.Path;
26+
import javax.ws.rs.Produces;
27+
import javax.ws.rs.core.HttpHeaders;
28+
import javax.ws.rs.core.Response;
29+
30+
/**
31+
*
32+
*/
33+
@Path("/6")
34+
public class APIEndpointV6 extends APIEndpointLatest {
35+
36+
@Inject
37+
private APIService api;
38+
39+
@Path("/supportMatrix/servers")
40+
@GET
41+
@Produces({"application/json"})
42+
public Response supportMatrixServers(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch) {
43+
return api.supportMatrixServersv6(ifNoneMatch);
44+
}
45+
46+
47+
48+
}

src/main/java/org/eclipse/microprofile/starter/rest/APIService.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public void init() {
120120

121121
List<JavaSEVersion> supportedJavaVersions = selector.getSupportedVersion(s, mpv);
122122
List<StandaloneMPSpec> mpStandaloneSpecs = defineStandaloneSpecs(mpv, s);
123-
serverOptions.add(new ServerOptions(mpv, mpSpec, mpStandaloneSpecs, supportedJavaVersions));
123+
List<BuildTool> buildTools = defineBuildTools(s);
124+
serverOptions.add(new ServerOptions(mpv, mpSpec, buildTools, mpStandaloneSpecs, supportedJavaVersions));
124125
});
125126
serversToOptions.put(s, serverOptions);
126127
}
@@ -135,6 +136,15 @@ public void init() {
135136
}
136137
}
137138

139+
private List<BuildTool> defineBuildTools(SupportedServer supportedServer) {
140+
List<BuildTool> result = new ArrayList<>();
141+
result.add(BuildTool.MAVEN);
142+
if (supportedServer.hasGradleSupport()) {
143+
result.add(BuildTool.GRADLE);
144+
}
145+
return result;
146+
}
147+
138148
private List<StandaloneMPSpec> defineStandaloneSpecs(MicroProfileVersion version, SupportedServer supportedServer) {
139149
List<StandaloneMPSpec> result = new ArrayList<>();
140150
for (StandaloneMPSpec standaloneMPSpec : StandaloneMPSpec.values()) {
@@ -265,6 +275,30 @@ public Response supportMatrixServersV3(String ifNoneMatch) {
265275
return Response.ok(serversAndSpecsDescriptions, MediaType.APPLICATION_JSON_TYPE).tag(serversToOptionsEtag).build();
266276
}
267277

278+
public Response supportMatrixServersv6(String ifNoneMatch) {
279+
if (ifNoneMatch != null) {
280+
if (serversToOptionsEtag.toString().equals(ifNoneMatch)) {
281+
return Response.notModified().build();
282+
}
283+
}
284+
List<SupportedServer> servers = new ArrayList<>(serversToOptions.keySet());
285+
Collections.shuffle(servers);
286+
Map<SupportedServer, List<ServerOptions>> rndServersToOptions = new LinkedHashMap<>(servers.size());
287+
for (SupportedServer s : servers) {
288+
List<ServerOptions> options = serversToOptions.get(s);
289+
// Without the buildTool
290+
List<ServerOptions> newOptions = options.stream()
291+
.map(se -> new ServerOptions(se.mpVersion, se.mpSpecs, se.javaSEVersions))
292+
.collect(Collectors.toList());
293+
rndServersToOptions.put(s, newOptions);
294+
}
295+
Map<String, Map> serversAndSpecsDescriptions = new HashMap<>(2);
296+
serversAndSpecsDescriptions.put("configs", rndServersToOptions);
297+
serversAndSpecsDescriptions.put("descriptions", specsDescriptions);
298+
299+
return Response.ok(serversAndSpecsDescriptions, MediaType.APPLICATION_JSON_TYPE).tag(serversToOptionsEtag).build();
300+
}
301+
268302
public Response supportMatrixServers(String ifNoneMatch) {
269303
if (ifNoneMatch != null) {
270304
if (serversToOptionsEtag.toString().equals(ifNoneMatch)) {

src/main/java/org/eclipse/microprofile/starter/rest/model/ServerOptions.java

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

2222
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.MicroprofileSpec;
2323
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.StandaloneMPSpec;
24+
import org.eclipse.microprofile.starter.core.model.BuildTool;
2425
import org.eclipse.microprofile.starter.core.model.JavaSEVersion;
2526
import org.eclipse.microprofile.starter.core.model.MicroProfileVersion;
2627

@@ -35,14 +36,26 @@ public class ServerOptions {
3536
public final MicroProfileVersion mpVersion;
3637
public final List<String> mpSpecs;
3738
public final List<JavaSEVersion> javaSEVersions;
39+
public final List<String> buildTools;
3840

3941
public ServerOptions(MicroProfileVersion mpVersion,
4042
List<MicroprofileSpec> mpSpecs,
43+
List<BuildTool> buildTools,
4144
List<StandaloneMPSpec> mpStandaloneSpecs,
4245
List<JavaSEVersion> javaSEVersions) {
4346
this.mpVersion = mpVersion;
4447
this.mpSpecs = mpSpecs.stream().map(spec -> spec.getCode().toUpperCase()).collect(Collectors.toList());
48+
this.buildTools = buildTools.stream().map(Enum::name).collect(Collectors.toList());
4549
this.mpSpecs.addAll(mpStandaloneSpecs.stream().map(spec -> spec.getCode().toUpperCase()).collect(Collectors.toList()));
4650
this.javaSEVersions = javaSEVersions;
4751
}
52+
53+
public ServerOptions(MicroProfileVersion mpVersion,
54+
List<String> mpSpecs,
55+
List<JavaSEVersion> javaSEVersions) {
56+
this.mpVersion = mpVersion;
57+
this.mpSpecs = mpSpecs;
58+
this.buildTools = null;
59+
this.javaSEVersions = javaSEVersions;
60+
}
4861
}

src/main/resources/REST-README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The latest mpVersion with no specs but the basic hello world JAX-RS endpoint is
2525

2626
# Versions
2727

28-
There are currently 3 versions of the API to retain backward compatibility. ```/api/``` is the latest;
28+
There are currently 6 versions of the API to retain backward compatibility. ```/api/``` is the latest;
2929
use e.g. ```/api/1/``` to get the legacy behaviour.
3030

3131
# Get available MicroProfile versions
@@ -282,6 +282,8 @@ If it is preferred to acquire all valid options in a one request the ```supportM
282282
The integration code [SHOULD](https://tools.ietf.org/html/rfc2119) use [Etag](https://tools.ietf.org/html/rfc7232#section-2.3) response header
283283
and [If-None-Match](https://tools.ietf.org/html/rfc7232#section-3.2) request header so as to avoid unnecessary deserialization of identical responses.
284284

285+
The ```supportMatrix/servers``` endpoint returns the support for a Build Tool (Maven and or Gradle) for each MP version and runtime combination.
286+
285287
## MicroProfile versions as keys
286288

287289
```

0 commit comments

Comments
 (0)