Skip to content

Commit 07b13d7

Browse files
authored
Merge pull request #95 from SentryMan/nima
Fix Nima MediaType generation/Use JDK 19 For Nima Generator
2 parents cba0c51 + 4bb5618 commit 07b13d7

File tree

4 files changed

+68
-48
lines changed

4 files changed

+68
-48
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
name: Build
22

33
on: [push, pull_request, workflow_dispatch]
4-
54
jobs:
65
build:
7-
86
runs-on: ${{ matrix.os }}
97
permissions:
108
contents: read
119
packages: write
1210
strategy:
1311
fail-fast: false
1412
matrix:
15-
java_version: [11,17]
13+
java_version: [11, 17, 19]
1614
os: [ubuntu-latest]
1715

1816
steps:
19-
- uses: actions/checkout@v2
20-
- name: Set up Java
21-
uses: actions/setup-java@v2
22-
with:
23-
java-version: ${{ matrix.java_version }}
24-
distribution: 'zulu'
25-
- name: Maven cache
26-
uses: actions/cache@v2
27-
env:
28-
cache-name: maven-cache
29-
with:
30-
path:
31-
~/.m2
32-
key: build-${{ env.cache-name }}
33-
- name: Maven version
34-
run: mvn --version
35-
- name: Build with Maven
36-
run: mvn clean test
17+
- uses: actions/checkout@v2
18+
- name: Set up Java
19+
uses: actions/setup-java@v2
20+
with:
21+
java-version: ${{ matrix.java_version }}
22+
distribution: "zulu"
23+
- name: Maven cache
24+
uses: actions/cache@v2
25+
env:
26+
cache-name: maven-cache
27+
with:
28+
path: ~/.m2
29+
key: build-${{ env.cache-name }}
30+
- name: Maven version
31+
run: mvn --version
32+
- name: Build with Maven
33+
env:
34+
JAVA_VERSION: ${{ matrix.java_version }}
35+
run: |
36+
if (( JAVA_VERSION < 19 ));
37+
then
38+
mvn clean test -pl "!:avaje-http-nima-generator"
39+
else
40+
mvn clean test
41+
fi

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ build/
33
.idea/
44
*.iml
55
.gradle
6+
http-generator-nima/.settings/org.eclipse.m2e.core.prefs
7+
http-generator-nima/.settings/org.eclipse.jdt.core.prefs
8+
http-generator-nima/.settings/org.eclipse.jdt.apt.core.prefs
9+
http-generator-nima/.settings/org.eclipse.core.resources.prefs
10+
http-generator-nima/.project
11+
http-generator-nima/.classpath

http-generator-nima/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
<artifactId>avaje-http-nima-generator</artifactId>
1313

1414
<properties>
15-
<maven.compiler.source>17</maven.compiler.source>
16-
<maven.compiler.target>17</maven.compiler.target>
15+
<java.release>19</java.release>
16+
<maven.compiler.source>19</maven.compiler.source>
17+
<maven.compiler.target>19</maven.compiler.target>
1718
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1819
</properties>
1920

@@ -34,8 +35,8 @@
3435
<artifactId>maven-compiler-plugin</artifactId>
3536
<version>3.10.1</version>
3637
<configuration>
37-
<source>11</source>
38-
<target>11</target>
38+
<source>19</source>
39+
<target>19</target>
3940
<!-- Turn off annotation processing for building -->
4041
<compilerArgument>-proc:none</compilerArgument>
4142
</configuration>

http-generator-nima/src/main/java/io/avaje/http/generator/helidon/nima/ControllerMethodWriter.java

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package io.avaje.http.generator.helidon.nima;
22

33
import io.avaje.http.api.MediaType;
4-
import io.avaje.http.generator.core.*;
5-
6-
import java.util.List;
4+
import io.avaje.http.generator.core.Append;
5+
import io.avaje.http.generator.core.MethodParam;
6+
import io.avaje.http.generator.core.MethodReader;
7+
import io.avaje.http.generator.core.PathSegments;
8+
import io.avaje.http.generator.core.ProcessingContext;
9+
import io.avaje.http.generator.core.WebMethod;
710

811
/**
912
* Write code to register Web route for a given controller method.
@@ -18,12 +21,12 @@ class ControllerMethodWriter {
1821
ControllerMethodWriter(MethodReader method, Append writer, ProcessingContext ctx) {
1922
this.method = method;
2023
this.writer = writer;
21-
this.webMethod = method.getWebMethod();
24+
webMethod = method.getWebMethod();
2225
this.ctx = ctx;
2326
}
2427

2528
void writeRule() {
26-
final String fullPath = method.getFullPath();
29+
final var fullPath = method.getFullPath();
2730
// final String bodyType = method.getBodyType();
2831
// if (bodyType != null) {
2932
// writer.append(" rules.%s(\"%s\", Handler.create(%s.class, this::_%s));", webMethod.name().toLowerCase(), fullPath, bodyType, method.simpleName()).eol();
@@ -42,25 +45,25 @@ void writeHandler(boolean requestScoped) {
4245
// writeContextReturn();
4346
// }
4447

45-
final String bodyType = method.getBodyType();
48+
final var bodyType = method.getBodyType();
4649
if (bodyType != null) {
4750
writer.append(" // body - %s %s", bodyType, method.getBodyName()).eol();
4851
}// else if (method.isFormBody()) {
4952
// writer.append(", %s %s", "FormParams", "formParams");
5053
//}
5154

52-
final PathSegments segments = method.getPathSegments();
55+
final var segments = method.getPathSegments();
5356
if (!segments.isEmpty()) {
5457
writer.append(" var pathParams = req.path().pathParameters();").eol();
5558

5659
}
57-
List<PathSegments.Segment> matrixSegments = segments.matrixSegments();
58-
for (PathSegments.Segment matrixSegment : matrixSegments) {
60+
final var matrixSegments = segments.matrixSegments();
61+
for (final PathSegments.Segment matrixSegment : matrixSegments) {
5962
matrixSegment.writeCreateSegment(writer, ctx.platform());
6063
}
6164

62-
final List<MethodParam> params = method.getParams();
63-
for (MethodParam param : params) {
65+
final var params = method.getParams();
66+
for (final MethodParam param : params) {
6467
param.writeCtxGet(writer, segments);
6568
}
6669
writer.append(" ");
@@ -70,7 +73,7 @@ void writeHandler(boolean requestScoped) {
7073
}
7174

7275
if (method.includeValidate()) {
73-
for (MethodParam param : params) {
76+
for (final MethodParam param : params) {
7477
param.writeValidate(writer);
7578
}
7679
}
@@ -80,7 +83,7 @@ void writeHandler(boolean requestScoped) {
8083
writer.append("controller.");
8184
}
8285
writer.append(method.simpleName()).append("(");
83-
for (int i = 0; i < params.size(); i++) {
86+
for (var i = 0; i < params.size(); i++) {
8487
if (i > 0) {
8588
writer.append(", ");
8689
}
@@ -95,17 +98,22 @@ void writeHandler(boolean requestScoped) {
9598
}
9699

97100
private void writeContextReturn() {
98-
final String produces = method.getProduces();
101+
final var produces = method.getProduces();
102+
99103
if (produces == null) {
100-
// let it be automatically set
101-
} else if (MediaType.APPLICATION_JSON.equalsIgnoreCase(produces)) {
102-
writer.append(" res.writerContext().contentType(io.helidon.common.http.MediaType.APPLICATION_JSON);").eol();
103-
} else if (MediaType.TEXT_HTML.equalsIgnoreCase(produces)) {
104-
writer.append(" res.writerContext().contentType(io.helidon.common.http.MediaType.TEXT_HTML);").eol();
105-
} else if (MediaType.TEXT_PLAIN.equalsIgnoreCase(produces)) {
106-
writer.append(" res.writerContext().contentType(io.helidon.common.http.MediaType.TEXT_PLAIN);").eol();
107-
} else {
108-
writer.append( "res.writerContext().contentType(io.helidon.common.http.MediaType.parse(\"%s\"));", produces).eol();
104+
return;
105+
}
106+
107+
final var contentTypeString =
108+
" res.headers().contentType(io.helidon.common.http.HttpMediaType.";
109+
110+
switch (produces.toLowerCase()) {
111+
case MediaType.APPLICATION_JSON -> writer
112+
.append(contentTypeString + "APPLICATION_JSON);")
113+
.eol();
114+
case MediaType.TEXT_HTML -> writer.append(contentTypeString + "TEXT_HTML);").eol();
115+
case MediaType.TEXT_PLAIN -> writer.append(contentTypeString + "TEXT_PLAIN);").eol();
116+
default -> writer.append(contentTypeString + "create(\"%s\"));", produces).eol();
109117
}
110118
}
111119

0 commit comments

Comments
 (0)