Skip to content

Helidon 4.0-M2 #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: [17, 20]
java_version: [17, 21-ea]
os: [ubuntu-latest]

steps:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public class WidgetController {
## DI Usage
The annotation processor will generate controller adapters to register routes to Javalin/Helidon. The natural way to use the generated adapters is to get a DI library to find and wire them. This is what the examples below do; they use [Avaje-Inject](https://avaje.io/inject/) to do this. The AP will automatically detect the presence of avaje-inject and generate the class to use avaje-inject's `@Component` as the DI annotation.

There isn't a hard requirement to use Avaje for dependency injection. In the absence of avaje-inject, the generated class will use `@jakarta.inject.Singleton` or `@javax.inject.Singleton` depending on what's on the classpath. Any DI library that can find and wire the generated @Singleton beans can be used. You can even use Dagger2 or Guice to wire the controllers if you so desire.
There isn't a hard requirement to use Avaje for dependency injection. In the absence of avaje-inject, the generated class will use `@jakarta.inject.Singleton` or `@javax.inject.Singleton` depending on what's on the classpath. Any DI library that can find and wire the generated @Singleton beans can be used. You can even use Dagger2 or Guice to wire the controllers if you so desire.

To force the AP to generate with `@javax.inject.Singleton`(in the case where you have both jakarta and javax on the classpath), use the compiler arg `-AuseJavax=true`
To force the AP to generate with `@javax.inject.Singleton`(in the case where you have both jakarta and javax on the classpath), use the compiler arg `-AuseJavax=true`
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -111,7 +111,7 @@ get all the services and register them with the Helidon `HttpRouting`.
List<HttpFeature> routes = BeanScope.builder().build().list(HttpFeature.class);
final var builder = HttpRouting.builder();

routes.forEach(builder::register);
routes.forEach(builder::addFeature);

WebServer.builder()
.addRouting(builder.build())
Expand Down
6 changes: 3 additions & 3 deletions http-generator-helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<artifactId>avaje-http-helidon-generator</artifactId>

<properties>
<java.release>20</java.release>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<java.release>21</java.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void writeContextReturn() {
}

final var produces = producesOp.map(MediaType::parse).orElse(MediaType.APPLICATION_JSON);
final var contentTypeString = " res.headers().contentType(HttpMediaType.";
final var contentTypeString = " res.headers().contentType(MediaTypes.";
switch (produces) {
case APPLICATION_JSON -> writer.append(contentTypeString).append("APPLICATION_JSON);").eol();
case TEXT_HTML -> writer.append(contentTypeString).append("TEXT_HTML);").eol();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class ControllerWriter extends BaseControllerWriter {

private static final String AT_GENERATED = "@Generated(\"avaje-helidon-generator\")";
private static final String IMPORT_HTTP_STATUS = "import static io.helidon.common.http.Http.Status.*;";
private static final String IMPORT_HTTP_STATUS = "import static io.helidon.http.Http.Status.*;";

private final boolean useJsonB;
private final Map<String, UType> jsonTypes;
Expand All @@ -42,22 +42,22 @@ class ControllerWriter extends BaseControllerWriter {
} else {
this.jsonTypes = Map.of();
}
reader.addImportType("io.helidon.common.http.HttpMediaType");
reader.addImportType("io.helidon.common.media.type.MediaTypes");
reader.addImportType("io.helidon.common.parameters.Parameters");
reader.addImportType("io.helidon.nima.webserver.http.HttpRouting");
reader.addImportType("io.helidon.nima.webserver.http.ServerRequest");
reader.addImportType("io.helidon.nima.webserver.http.ServerResponse");
reader.addImportType("io.helidon.nima.webserver.http.HttpFeature");
reader.addImportType("io.helidon.common.http.Http.Header");
reader.addImportType("io.helidon.webserver.http.HttpRouting");
reader.addImportType("io.helidon.webserver.http.ServerRequest");
reader.addImportType("io.helidon.webserver.http.ServerResponse");
reader.addImportType("io.helidon.webserver.http.HttpFeature");
reader.addImportType("io.helidon.http.Http.HeaderNames");
if (reader.isIncludeValidator()) {
reader.addImportType("io.helidon.common.http.Http");
reader.addImportType("io.helidon.http.Http");
}
if (reader.methods().stream()
.map(MethodReader::webMethod)
.anyMatch(w -> CoreWebMethod.FILTER == w)) {
reader.addImportType("io.helidon.nima.webserver.http.FilterChain");
reader.addImportType("io.helidon.nima.webserver.http.RoutingRequest");
reader.addImportType("io.helidon.nima.webserver.http.RoutingResponse");
reader.addImportType("io.helidon.webserver.http.FilterChain");
reader.addImportType("io.helidon.webserver.http.RoutingRequest");
reader.addImportType("io.helidon.webserver.http.RoutingResponse");
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ private void writeClassStart() {
}

if (reader.isIncludeValidator()) {
writer.append(" private static final Http.HeaderName HEADER_ACCEPT_LANGUAGE = Header.create(\"Accept-Language\");").eol();
writer.append(" private static final Http.HeaderName HEADER_ACCEPT_LANGUAGE = HeaderNames.create(\"Accept-Language\");").eol();
}

writer.append(" private final %s %s;", controllerType, controllerName).eol();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.avaje.prism.AnnotationProcessor;

@AnnotationProcessor
public class NimaProcessor extends BaseProcessor {
public class HelidonProcessor extends BaseProcessor {

@Override
protected PlatformAdapter providePlatformAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class NimaPlatformAdapter implements PlatformAdapter {

static final String NIMA_REQ = "io.helidon.nima.webserver.http.ServerRequest";
static final String NIMA_RES = "io.helidon.nima.webserver.http.ServerResponse";
static final String NIMA_REQ = "io.helidon.webserver.http.ServerRequest";
static final String NIMA_RES = "io.helidon.webserver.http.ServerResponse";
static final String HELIDON_FORMPARAMS = "io.helidon.common.parameters.Parameters";

@Override
Expand Down Expand Up @@ -74,7 +74,7 @@ public void writeReadParameter(Append writer, ParamType paramType, String paramN
case FORMPARAM -> writer.append("formParams.first(\"%s\").orElse(null)", paramName);

case HEADER -> writer.append(
"req.headers().value(Header.create(\"%s\")).orElse(null)", paramName);
"req.headers().value(HeaderNames.create(\"%s\")).orElse(null)", paramName);

case COOKIE -> writer.append("req.headers().cookies().first(\"%s\").orElse(null)", paramName);

Expand Down
2 changes: 1 addition & 1 deletion http-generator-helidon/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
requires java.compiler;
requires java.sql;

provides javax.annotation.processing.Processor with io.avaje.http.generator.helidon.nima.NimaProcessor;
provides javax.annotation.processing.Processor with io.avaje.http.generator.helidon.nima.HelidonProcessor;

// SHADED: All content after this line will be removed at package time
requires transitive io.avaje.http.generator.core;
Expand Down
8 changes: 4 additions & 4 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<assertj.version>3.24.1</assertj.version>
<jackson.version>2.14.1</jackson.version>
<jex.version>2.5</jex.version>
<avaje-inject.version>9.0</avaje-inject.version>
<nima.version>4.0.0-M1</nima.version>
<avaje-inject.version>9.5</avaje-inject.version>
<nima.version>4.0.0-M2</nima.version>
</properties>

<modules>
Expand All @@ -30,9 +30,9 @@

<profiles>
<profile>
<id>jdk19plus</id>
<id>jdk20plus</id>
<activation>
<jdk>[19,20,21]</jdk>
<jdk>21</jdk>
</activation>
<modules>
<module>test-nima</module>
Expand Down
22 changes: 9 additions & 13 deletions tests/test-nima-jsonb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<artifactId>test-nima-jsonb</artifactId>

<properties>
<java.release>20</java.release>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<java.release>21</java.release>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.useModulePath>false</surefire.useModulePath>
</properties>
Expand All @@ -34,21 +34,21 @@
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsonb</artifactId>
<version>1.7-RC1</version>
<version>1.8-RC1</version>
</dependency>
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-hibernate-validator</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>${nima.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.nima.http.media</groupId>
<artifactId>helidon-nima-http-media-jsonb</artifactId>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonb</artifactId>
<version>${nima.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -78,8 +78,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<enablePreview>true</enablePreview>
<release>20</release>
<release>21</release>
<annotationProcessorPaths>
<path>
<groupId>io.avaje</groupId>
Expand All @@ -103,9 +102,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<groupId>io.repaint.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.avaje.http.api.Controller;
import io.avaje.http.api.ExceptionHandler;
import io.helidon.nima.webserver.http.ServerRequest;
import io.helidon.nima.webserver.http.ServerResponse;
import io.helidon.webserver.http.ServerRequest;
import io.helidon.webserver.http.ServerResponse;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import io.avaje.http.api.Put;
import io.avaje.http.api.QueryParam;
import io.avaje.http.api.Valid;
import io.helidon.common.http.HttpMediaType;
import io.helidon.nima.webserver.http.ServerRequest;
import io.helidon.nima.webserver.http.ServerResponse;
import io.helidon.common.media.type.MediaTypes;
import io.helidon.webserver.http.ServerRequest;
import io.helidon.webserver.http.ServerResponse;

@Controller
public class HelloController {
Expand All @@ -41,7 +41,7 @@ byte[] testBytes() {

@Get("/helidon")
void testHelidon(ServerRequest req, ServerResponse res) {
res.headers().contentType(HttpMediaType.TEXT_PLAIN);
res.headers().contentType(MediaTypes.TEXT_PLAIN);
res.send("success path:" + req.path());
}

Expand Down
7 changes: 3 additions & 4 deletions tests/test-nima-jsonb/src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

import io.avaje.inject.BeanScope;
import io.avaje.jsonb.Jsonb;
import io.helidon.nima.webserver.WebServer;
import io.helidon.nima.webserver.http.HttpFeature;
import io.helidon.nima.webserver.http.HttpRouting;
import io.helidon.nima.webserver.http.HttpService;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.http.HttpFeature;
import io.helidon.webserver.http.HttpRouting;

public class Main {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.example;

import io.avaje.http.api.*;
import io.helidon.nima.webserver.http.FilterChain;
import io.helidon.nima.webserver.http.RoutingResponse;
import io.helidon.nima.webserver.http.ServerRequest;
import io.helidon.nima.webserver.http.ServerResponse;
import io.helidon.webserver.http.FilterChain;
import io.helidon.webserver.http.RoutingResponse;
import io.helidon.webserver.http.ServerRequest;
import io.helidon.webserver.http.ServerResponse;

import java.io.InputStream;
import java.util.LinkedHashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import io.avaje.http.generator.helidon.nima.NimaProcessor;
import io.avaje.http.generator.helidon.nima.HelidonProcessor;

class NimaProcessorTest {

Expand All @@ -46,7 +46,7 @@ void runAnnotationProcessor() throws Exception {
final var task =
compiler.getTask(
new PrintWriter(System.out), null, null, List.of("--release=20", "-AdisableDirectWrites=true"), null, files);
task.setProcessors(List.of(new NimaProcessor()));
task.setProcessors(List.of(new HelidonProcessor()));

assertThat(task.call()).isTrue();
}
Expand All @@ -62,7 +62,7 @@ void runAnnotationProcessorWithJsonB() throws Exception {
final var task =
compiler.getTask(
new PrintWriter(System.out), null, null, List.of("--release=19"), null, files);
task.setProcessors(List.of(new NimaProcessor()));
task.setProcessors(List.of(new HelidonProcessor()));

assertThat(task.call()).isTrue();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-nima-jsonb/src/test/java/org/example/TestPair.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.avaje.http.client.HttpClient;
import io.avaje.http.hibernate.validator.BeanValidator;
import io.avaje.jsonb.Jsonb;
import io.helidon.nima.webserver.WebServer;
import io.helidon.nima.webserver.http.HttpRouting;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.http.HttpRouting;

public class TestPair {

Expand Down
35 changes: 15 additions & 20 deletions tests/test-nima/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<artifactId>test-nima</artifactId>

<properties>
<maven.compiler.source>20</maven.compiler.source>
<maven.compiler.target>20</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand All @@ -30,26 +30,21 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>${nima.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.nima.http.media</groupId>
<artifactId>helidon-nima-http-media-jsonb</artifactId>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonb</artifactId>
<version>${nima.version}</version>
</dependency>

<!-- <dependency>-->
<!-- <groupId>io.helidon.nima.http2</groupId>-->
<!-- <artifactId>helidon-nima-http2-webserver</artifactId>-->
<!-- <version>4.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.helidon.nima.websocket</groupId>-->
<!-- <artifactId>helidon-nima-websocket-webserver</artifactId>-->
<!-- <version>4.0.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-helidon-generator</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -59,7 +54,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>20</release>
<release>21</release>
<annotationProcessorPaths>
<path>
<groupId>io.avaje</groupId>
Expand All @@ -72,8 +67,8 @@
<version>${avaje-inject.version}</version>
</path>
</annotationProcessorPaths>
<source>19</source>
<target>19</target>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
Expand Down
Loading