Skip to content

Commit 3b24ff0

Browse files
committed
Merge branch 'master' of https://github.com/rdebusscher/microprofile-starter into issue247
2 parents 545042d + 1e03bc2 commit 3b24ff0

File tree

14 files changed

+574
-222
lines changed

14 files changed

+574
-222
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ log.txt
5050
.classpath
5151
.settings/
5252
.vscode
53+
download.sh
54+
.checkstyle

src/main/java/org/eclipse/microprofile/starter/addon/microprofile/servers/MicroprofileServersAddon.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.microprofile.starter.core.exception.JessieConfigurationException;
3030
import org.eclipse.microprofile.starter.core.exception.JessieUnexpectedException;
3131
import org.eclipse.microprofile.starter.core.model.JessieModel;
32+
import org.eclipse.microprofile.starter.core.model.MicroProfileVersion;
3233
import org.eclipse.microprofile.starter.core.model.OptionValue;
3334
import org.eclipse.microprofile.starter.spi.MavenHelper;
3435

@@ -204,7 +205,12 @@ public void createFiles(JessieModel model) {
204205
String healthDirectory = model.getDirectory(true) + "/" + rootJava + "/health";
205206
directoryCreator.createDirectory(healthDirectory);
206207

207-
processTemplateFile(healthDirectory, "ServiceHealthCheck.java", alternatives, variables);
208+
if (alternatives.contains(MicroProfileVersion.Constants.MP3X_ALTERNATIVE)) {
209+
processTemplateFile(healthDirectory, "ServiceLiveHealthCheck.java", alternatives, variables);
210+
processTemplateFile(healthDirectory, "ServiceReadyHealthCheck.java", alternatives, variables);
211+
} else {
212+
processTemplateFile(healthDirectory, "ServiceHealthCheck.java", alternatives, variables);
213+
}
208214
}
209215

210216
if (microprofileSpecs.contains(MicroprofileSpec.CONFIG)) {

src/main/java/org/eclipse/microprofile/starter/core/model/MicroProfileVersion.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package org.eclipse.microprofile.starter.core.model;
2424

25+
import java.util.Collection;
26+
import java.util.Collections;
2527
import java.util.HashSet;
2628
import java.util.Set;
2729

@@ -31,7 +33,7 @@ public enum MicroProfileVersion {
3133
// @formatter:off
3234
NONE(null, "")
3335
, MP32("3.2", "MP 3.2")
34-
, MP30("3.0", "MP 3.0")
36+
, MP30("3.0", "MP 3.0", Collections.singletonList(Constants.MP3X_ALTERNATIVE))
3537
, MP22("2.2", "MP 2.2")
3638
, MP21("2.1", "MP 2.1")
3739
, MP20("2.0", "MP 2.0", "2.0.1")
@@ -52,6 +54,13 @@ public enum MicroProfileVersion {
5254
mavenVersion = code;
5355
}
5456

57+
MicroProfileVersion(String code, String label, Collection<String> alternatives) {
58+
this.code = code;
59+
this.label = label;
60+
this.alternatives = new HashSet<>(alternatives);
61+
mavenVersion = code;
62+
}
63+
5564
MicroProfileVersion(String code, String label, String mavenVersion) {
5665
this(code, label);
5766
this.mavenVersion = mavenVersion;
@@ -83,4 +92,8 @@ public static MicroProfileVersion valueFor(String code) {
8392
}
8493
return result;
8594
}
95+
96+
public static class Constants {
97+
public static final String MP3X_ALTERNATIVE = "mp3_x";
98+
}
8699
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ public Response getProject(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNone
9292
@QueryParam("artifactId") String artifactId,
9393
@QueryParam("mpVersion") MicroProfileVersion mpVersion,
9494
@QueryParam("javaSEVersion") JavaSEVersion javaSEVersion,
95-
@QueryParam("selectedSpecs") List<MicroprofileSpec> selectedSpecs) {
96-
return api.getProject(ifNoneMatch, supportedServer, groupId, artifactId, mpVersion, javaSEVersion, selectedSpecs);
95+
@QueryParam("selectedSpecs") List<MicroprofileSpec> selectedSpecs,
96+
@QueryParam("selectAllSpecs") boolean selectAllSpecs) {
97+
return api.getProject(ifNoneMatch, supportedServer, groupId, artifactId, mpVersion, javaSEVersion, selectedSpecs, selectAllSpecs);
9798
}
9899

99100
@Path("/project")

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,29 @@
1919
*/
2020
package org.eclipse.microprofile.starter.rest;
2121

22+
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.MicroprofileSpec;
23+
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.SupportedServer;
24+
import org.eclipse.microprofile.starter.core.model.JavaSEVersion;
25+
import org.eclipse.microprofile.starter.core.model.MicroProfileVersion;
26+
import org.eclipse.microprofile.starter.rest.model.Project;
27+
2228
import javax.inject.Inject;
29+
import javax.validation.constraints.NotNull;
30+
import javax.ws.rs.Consumes;
2331
import javax.ws.rs.GET;
2432
import javax.ws.rs.HeaderParam;
33+
import javax.ws.rs.POST;
2534
import javax.ws.rs.Path;
2635
import javax.ws.rs.Produces;
36+
import javax.ws.rs.QueryParam;
2737
import javax.ws.rs.core.HttpHeaders;
2838
import javax.ws.rs.core.Response;
39+
import java.util.List;
2940

3041
/**
42+
* Overwrites methods that are changed in subsequent APIs
43+
* to retain former behaviour.
44+
*
3145
* @author Michal Karm Babacek <[email protected]>
3246
*/
3347
@Path("/1")
@@ -51,4 +65,26 @@ public Response supportMatrix(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifN
5165
public Response supportMatrixServers(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch) {
5266
return api.supportMatrixServersV1(ifNoneMatch);
5367
}
68+
69+
@Path("/project")
70+
@GET
71+
@Produces({"application/zip", "application/json"})
72+
public Response getProject(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch,
73+
@QueryParam("supportedServer") SupportedServer supportedServer,
74+
@QueryParam("groupId") String groupId,
75+
@QueryParam("artifactId") String artifactId,
76+
@QueryParam("mpVersion") MicroProfileVersion mpVersion,
77+
@QueryParam("javaSEVersion") JavaSEVersion javaSEVersion,
78+
@QueryParam("selectedSpecs") List<MicroprofileSpec> selectedSpecs) {
79+
return api.getProjectV1(ifNoneMatch, supportedServer, groupId, artifactId, mpVersion, javaSEVersion, selectedSpecs);
80+
}
81+
82+
@Path("/project")
83+
@POST
84+
@Consumes({"application/json"})
85+
@Produces({"application/zip", "application/json"})
86+
@Override
87+
public Response projectPost(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch, @NotNull Project body) {
88+
return api.getProjectV1(ifNoneMatch, body);
89+
}
5490
}

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,57 @@
1919
*/
2020
package org.eclipse.microprofile.starter.rest;
2121

22+
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.MicroprofileSpec;
23+
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.SupportedServer;
24+
import org.eclipse.microprofile.starter.core.model.JavaSEVersion;
25+
import org.eclipse.microprofile.starter.core.model.MicroProfileVersion;
26+
import org.eclipse.microprofile.starter.rest.model.Project;
27+
28+
import javax.inject.Inject;
29+
import javax.validation.constraints.NotNull;
30+
import javax.ws.rs.Consumes;
31+
import javax.ws.rs.GET;
32+
import javax.ws.rs.HeaderParam;
33+
import javax.ws.rs.POST;
2234
import javax.ws.rs.Path;
35+
import javax.ws.rs.Produces;
36+
import javax.ws.rs.QueryParam;
37+
import javax.ws.rs.core.HttpHeaders;
38+
import javax.ws.rs.core.Response;
39+
import java.util.List;
2340

2441
/**
42+
* Overwrites methods that are changed in next version,
43+
* e.g. if getProject behaviour was changed in next version,
44+
* this retains the former behaviour (which is the same as in V1 in getProject's case).
45+
*
2546
* @author Michal Karm Babacek <[email protected]>
2647
*/
2748
@Path("/2")
2849
public class APIEndpointV2 extends APIEndpointLatest {
2950

51+
@Inject
52+
private APIService api;
53+
54+
@Path("/project")
55+
@GET
56+
@Produces({"application/zip", "application/json"})
57+
public Response getProject(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch,
58+
@QueryParam("supportedServer") SupportedServer supportedServer,
59+
@QueryParam("groupId") String groupId,
60+
@QueryParam("artifactId") String artifactId,
61+
@QueryParam("mpVersion") MicroProfileVersion mpVersion,
62+
@QueryParam("javaSEVersion") JavaSEVersion javaSEVersion,
63+
@QueryParam("selectedSpecs") List<MicroprofileSpec> selectedSpecs) {
64+
return api.getProjectV1(ifNoneMatch, supportedServer, groupId, artifactId, mpVersion, javaSEVersion, selectedSpecs);
65+
}
66+
67+
@Path("/project")
68+
@POST
69+
@Consumes({"application/json"})
70+
@Produces({"application/zip", "application/json"})
71+
@Override
72+
public Response projectPost(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch, @NotNull Project body) {
73+
return api.getProjectV1(ifNoneMatch, body);
74+
}
3075
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2019 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.ws.rs.Path;
23+
24+
/**
25+
* @author Michal Karm Babacek <[email protected]>
26+
*/
27+
@Path("/3")
28+
public class APIEndpointV3 extends APIEndpointLatest {
29+
30+
// Does not differ from latest in anything.
31+
32+
}

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

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,97 @@ public Response listOptions(MicroProfileVersion mpVersion) {
228228
return Response.ok(mpvToOptions.get(mpVersion)).build();
229229
}
230230

231+
public Response getProjectV1(String ifNoneMatch,
232+
SupportedServer supportedServer,
233+
String groupId, String artifactId,
234+
MicroProfileVersion mpVersion,
235+
JavaSEVersion javaSEVersion,
236+
List<MicroprofileSpec> selectedSpecs) {
237+
Project project = new Project();
238+
project.setSupportedServer(supportedServer);
239+
project.setGroupId(groupId);
240+
project.setArtifactId(artifactId);
241+
project.setMpVersion(mpVersion);
242+
project.setJavaSEVersion(javaSEVersion);
243+
project.setSelectedSpecs(selectedSpecs);
244+
245+
setDefaultsV1(project);
246+
247+
return processProject(ifNoneMatch, project);
248+
}
249+
250+
public Response getProjectV1(String ifNoneMatch, Project body) {
251+
setDefaultsV1(body);
252+
return processProject(ifNoneMatch, body);
253+
}
254+
231255
public Response getProject(String ifNoneMatch,
232256
SupportedServer supportedServer,
233257
String groupId, String artifactId,
234258
MicroProfileVersion mpVersion,
235259
JavaSEVersion javaSEVersion,
236-
List<MicroprofileSpec> selectedSpecs) {
260+
List<MicroprofileSpec> selectedSpecs,
261+
boolean selectAllSpecs) {
237262
Project project = new Project();
238263
project.setSupportedServer(supportedServer);
239264
project.setGroupId(groupId);
240265
project.setArtifactId(artifactId);
241266
project.setMpVersion(mpVersion);
242267
project.setJavaSEVersion(javaSEVersion);
243268
project.setSelectedSpecs(selectedSpecs);
269+
project.setSelectAllSpecs(selectAllSpecs);
270+
271+
setDefaults(project);
272+
244273
return processProject(ifNoneMatch, project);
245274
}
246275

247276
public Response getProject(String ifNoneMatch, Project body) {
277+
setDefaults(body);
248278
return processProject(ifNoneMatch, body);
249279
}
250280

281+
private void setDefaultsV1(Project p) {
282+
if (StringUtils.isBlank(p.getGroupId())) {
283+
p.setGroupId(EngineData.DEFAULT_GROUP_ID);
284+
}
285+
if (StringUtils.isBlank(p.getArtifactId())) {
286+
p.setArtifactId(EngineData.DEFAULT_ARTIFACT_ID);
287+
}
288+
if (p.getMpVersion() == null || p.getMpVersion() == MicroProfileVersion.NONE) {
289+
p.setMpVersion(
290+
p.getSupportedServer().getMpVersions().get(p.getSupportedServer().getMpVersions().size() - 1));
291+
}
292+
if (p.getJavaSEVersion() == null || p.getJavaSEVersion() == JavaSEVersion.NONE) {
293+
p.setJavaSEVersion(EngineData.DEFAULT_JAVA_SE_VERSION);
294+
}
295+
if (p.getSelectedSpecs() == null || p.getSelectedSpecs().isEmpty()) {
296+
p.setSelectedSpecs(mpvToOptions.get(p.getMpVersion()).getSpecs());
297+
}
298+
}
299+
300+
private void setDefaults(Project p) {
301+
if (StringUtils.isBlank(p.getGroupId())) {
302+
p.setGroupId(EngineData.DEFAULT_GROUP_ID);
303+
}
304+
if (StringUtils.isBlank(p.getArtifactId())) {
305+
p.setArtifactId(EngineData.DEFAULT_ARTIFACT_ID);
306+
}
307+
if (p.getMpVersion() == null || p.getMpVersion() == MicroProfileVersion.NONE) {
308+
p.setMpVersion(
309+
p.getSupportedServer().getMpVersions().get(p.getSupportedServer().getMpVersions().size() - 1));
310+
}
311+
if (p.getJavaSEVersion() == null || p.getJavaSEVersion() == JavaSEVersion.NONE) {
312+
p.setJavaSEVersion(EngineData.DEFAULT_JAVA_SE_VERSION);
313+
}
314+
if (p.getSelectedSpecs() == null) {
315+
p.setSelectedSpecs(Collections.emptyList());
316+
}
317+
if (p.getSelectedSpecs().isEmpty() && p.isSelectAllSpecs()) {
318+
p.setSelectedSpecs(mpvToOptions.get(p.getMpVersion()).getSpecs());
319+
}
320+
}
321+
251322
private Response validate(Project p) {
252323
if (p.getSupportedServer() == null) {
253324
return Response.status(Response.Status.BAD_REQUEST)
@@ -257,10 +328,6 @@ private Response validate(Project p) {
257328
.header("Content-Disposition", "attachment; filename=\"error.json\"")
258329
.build();
259330
}
260-
261-
if (StringUtils.isBlank(p.getGroupId())) {
262-
p.setGroupId(EngineData.DEFAULT_GROUP_ID);
263-
}
264331
if (!packageNameValidator.isValidPackageName(p.getGroupId())) {
265332
return Response.status(Response.Status.BAD_REQUEST)
266333
.entity(ERROR004)
@@ -269,9 +336,6 @@ private Response validate(Project p) {
269336
.header("Content-Disposition", "attachment; filename=\"error.json\"")
270337
.build();
271338
}
272-
if (StringUtils.isBlank(p.getArtifactId())) {
273-
p.setArtifactId(EngineData.DEFAULT_ARTIFACT_ID);
274-
}
275339
if (!packageNameValidator.isValidPackageName(p.getArtifactId())) {
276340
return Response.status(Response.Status.BAD_REQUEST)
277341
.entity(ERROR005)
@@ -280,10 +344,6 @@ private Response validate(Project p) {
280344
.header("Content-Disposition", "attachment; filename=\"error.json\"")
281345
.build();
282346
}
283-
if (p.getMpVersion() == null || p.getMpVersion() == MicroProfileVersion.NONE) {
284-
p.setMpVersion(
285-
p.getSupportedServer().getMpVersions().get(p.getSupportedServer().getMpVersions().size() - 1));
286-
}
287347
if (!mpvToOptions.get(p.getMpVersion()).getSupportedServers().contains(p.getSupportedServer())) {
288348
return Response.status(Response.Status.BAD_REQUEST)
289349
.type("application/json")
@@ -292,12 +352,6 @@ private Response validate(Project p) {
292352
.entity(ERROR002)
293353
.build();
294354
}
295-
if (p.getJavaSEVersion() == null || p.getJavaSEVersion() == JavaSEVersion.NONE) {
296-
p.setJavaSEVersion(EngineData.DEFAULT_JAVA_SE_VERSION);
297-
}
298-
if (p.getSelectedSpecs() == null || p.getSelectedSpecs().isEmpty()) {
299-
p.setSelectedSpecs(mpvToOptions.get(p.getMpVersion()).getSpecs());
300-
}
301355
if (!mpvToOptions.get(p.getMpVersion()).getSpecs().containsAll(p.getSelectedSpecs())) {
302356
return Response.status(Response.Status.BAD_REQUEST)
303357
.type("application/json")
@@ -324,7 +378,6 @@ private EngineData getEngineData(Project p) {
324378
}
325379

326380
private Response processProject(String ifNoneMatch, Project p) {
327-
328381
Response validatorResponse = validate(p);
329382
if (validatorResponse.getStatusInfo() != Response.Status.OK) {
330383
return validatorResponse;

0 commit comments

Comments
 (0)