Skip to content

Commit 423636d

Browse files
committed
Merge remote-tracking branch 'upstream/2.x' into 2.x
2 parents 5d10246 + ea01fdf commit 423636d

91 files changed

Lines changed: 530 additions & 94 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ versions
3333
out
3434
node
3535
node_modules
36+
build

docs/asciidoc/usage/usage.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Kotlin build also requires it via https://kotlinlang.org/docs/reference/kapt.htm
2828
<plugins>
2929
<plugin>
3030
<artifactId>maven-compiler-plugin</artifactId>
31-
<version>${maven-compiler-plugin.version}</version>
31+
<version>{mavenCompilerPluginVersion}</version>
3232
<configuration>
3333
<annotationProcessorPaths>
3434
<path>
@@ -51,7 +51,7 @@ Kotlin build also requires it via https://kotlinlang.org/docs/reference/kapt.htm
5151
<plugin>
5252
<artifactId>kotlin-maven-plugin</artifactId>
5353
<groupId>org.jetbrains.kotlin</groupId>
54-
<version>${kotlin.version}</version>
54+
<version>{kotlinVersion}</version>
5555
<configuration>
5656
<args>
5757
<arg>-java-parameters</arg>
@@ -101,7 +101,7 @@ Kotlin build also requires it via https://kotlinlang.org/docs/reference/kapt.htm
101101
<annotationProcessorPath>
102102
<groupId>io.jooby</groupId>
103103
<artifactId>jooby-apt</artifactId>
104-
<version>${jooby.version}</version>
104+
<version>{joobyVersion}</version>
105105
</annotationProcessorPath>
106106
</annotationProcessorPaths>
107107
</configuration>
@@ -130,20 +130,20 @@ Java build needs an annotationProcessor statement using `jooby-apt`.
130130
Kotlin builds needs a https://kotlinlang.org/docs/reference/kapt.html#using-in-gradle[kapt] dependency and statement using `jooby-apt`.
131131

132132
.Java
133-
[source, groovy, role="primary"]
133+
[source, groovy, role="primary", subs="verbatim,attributes"]
134134
----
135135
dependencies {
136136
annotationProcessor "io.jooby:jooby-apt:{joobyVersion}"
137137
}
138138
----
139139

140140
.Kotlin
141-
[source, groovy, role="secondary"]
141+
[source, groovy, role="secondary", subs="verbatim,attributes"]
142142
----
143143
buildscript {
144144
...
145145
dependencies {
146-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
146+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:{kotlinVersion}"
147147
}
148148
}
149149
@@ -207,7 +207,7 @@ done using `parameters` compiler option.
207207
<plugins>
208208
<plugin>
209209
<artifactId>maven-compiler-plugin</artifactId>
210-
<version>${maven-compiler-plugin.version}</version>
210+
<version>{mavenCompilerPluginVersion}</version>
211211
<configuration>
212212
...
213213
<compilerArgs>
@@ -227,7 +227,7 @@ done using `parameters` compiler option.
227227
<plugin>
228228
<artifactId>kotlin-maven-plugin</artifactId>
229229
<groupId>org.jetbrains.kotlin</groupId>
230-
<version>${kotlin.version}</version>
230+
<version>{kotlinVersion}</version>
231231
<configuration>
232232
...
233233
<args>

docs/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>jooby-project</artifactId>
9-
<version>2.6.1-SNAPSHOT</version>
9+
<version>2.6.1</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>org.jsoup</groupId>
7272
<artifactId>jsoup</artifactId>
73-
<version>1.12.1</version>
73+
<version>1.12.2</version>
7474
</dependency>
7575

7676
</dependencies>

jooby/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>jooby-project</artifactId>
9-
<version>2.6.1-SNAPSHOT</version>
9+
<version>2.6.1</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>

jooby/src/main/java/io/jooby/DefaultContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public interface DefaultContext extends Context {
396396
return result;
397397
}
398398
}
399-
return decoder(contentType).decode(this, type);
399+
return (T) decoder(contentType).decode(this, type);
400400
} catch (Exception x) {
401401
throw SneakyThrows.propagate(x);
402402
}

jooby/src/main/java/io/jooby/MessageDecoder.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,17 @@ public interface MessageDecoder {
2121
/**
2222
* Resolve parsing as {@link StatusCode#UNSUPPORTED_MEDIA_TYPE}.
2323
*/
24-
MessageDecoder UNSUPPORTED_MEDIA_TYPE = new MessageDecoder() {
25-
@Override public <T> T decode(Context ctx, Type type) {
26-
throw new UnsupportedMediaType(ctx.header("Content-Type").valueOrNull());
27-
}
24+
MessageDecoder UNSUPPORTED_MEDIA_TYPE = (ctx, type) -> {
25+
throw new UnsupportedMediaType(ctx.header("Content-Type").valueOrNull());
2826
};
2927

3028
/**
3129
* Parse HTTP body into the given type.
3230
*
3331
* @param ctx Web context.
3432
* @param type Target/expected type.
35-
* @param <T> Dynamic binding of the target type.
3633
* @return An instance of the target type.
3734
* @throws Exception Is something goes wrong.
3835
*/
39-
@Nonnull <T> T decode(@Nonnull Context ctx, @Nonnull Type type) throws Exception;
36+
@Nonnull Object decode(@Nonnull Context ctx, @Nonnull Type type) throws Exception;
4037
}

modules/jooby-apt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>modules</artifactId>
9-
<version>2.6.1-SNAPSHOT</version>
9+
<version>2.6.1</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>

modules/jooby-apt/src/main/java/io/jooby/internal/apt/HandlerCompiler.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static org.objectweb.asm.Opcodes.INVOKEINTERFACE;
4747
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
4848
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
49+
import static org.objectweb.asm.Opcodes.POP;
4950
import static org.objectweb.asm.Type.getMethodDescriptor;
5051
import static org.objectweb.asm.Type.getType;
5152

@@ -184,6 +185,8 @@ private void apply(ClassWriter writer, String moduleInternalName, String lambdaN
184185
/** Arguments. */
185186
processArguments(writer, apply, moduleInternalName, registry);
186187

188+
setDefaultResponseType(apply);
189+
187190
/** Invoke. */
188191
apply.visitMethodInsn(INVOKEVIRTUAL, owner.getInternalName(), methodName, methodDescriptor,
189192
false);
@@ -227,6 +230,20 @@ private void processArguments(ClassWriter classWriter, MethodVisitor visitor,
227230
}
228231
}
229232

233+
private void setDefaultResponseType(MethodVisitor visitor) throws Exception {
234+
TypeKind kind = executable.getReturnType().getKind();
235+
if (kind == TypeKind.VOID && getHttpMethod().equalsIgnoreCase(Router.DELETE)) {
236+
visitor.visitVarInsn(ALOAD, 1);
237+
visitor
238+
.visitFieldInsn(GETSTATIC, STATUS_CODE.getInternalName(), "NO_CONTENT",
239+
STATUS_CODE.getDescriptor());
240+
Method setResponseCode = Context.class.getDeclaredMethod("setResponseCode", StatusCode.class);
241+
visitor.visitMethodInsn(INVOKEINTERFACE, CTX.getInternalName(), setResponseCode.getName(),
242+
getMethodDescriptor(setResponseCode), true);
243+
visitor.visitInsn(POP);
244+
}
245+
}
246+
230247
private void processReturnType(MethodVisitor visitor) throws Exception {
231248
TypeKind kind = executable.getReturnType().getKind();
232249
if (kind == TypeKind.VOID) {
@@ -242,15 +259,14 @@ private void processReturnType(MethodVisitor visitor) throws Exception {
242259
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
243260

244261
visitor.visitVarInsn(ALOAD, 1);
245-
visitor
246-
.visitFieldInsn(GETSTATIC, STATUS_CODE.getInternalName(), "NO_CONTENT",
247-
STATUS_CODE.getDescriptor());
262+
visitor.visitVarInsn(ALOAD, 1);
263+
Method getResponseCode = Context.class.getDeclaredMethod("getResponseCode");
264+
visitor.visitMethodInsn(INVOKEINTERFACE, CTX.getInternalName(), getResponseCode.getName(),
265+
getMethodDescriptor(getResponseCode), true);
248266
Method sendStatusCode = Context.class.getDeclaredMethod("send", StatusCode.class);
249267
visitor.visitMethodInsn(INVOKEINTERFACE, CTX.getInternalName(), sendStatusCode.getName(),
250268
getMethodDescriptor(sendStatusCode), true);
251-
252269
} else {
253-
254270
Method wrapper = Primitives.wrapper(kind);
255271
if (wrapper == null) {
256272
TypeDefinition returnType = getReturnType();

modules/jooby-apt/src/test/java/output/MvcExtension.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class MvcExtension implements MvcFactory {
1313
private static void install(Jooby application, Provider<MyController> provider) throws Exception {
1414
application.get("/mypath", ctx -> {
1515
MyController myController = provider.get();
16-
return myController.controllerMethod();
16+
myController.controllerMethod();
17+
return ctx;
1718
}).attribute("RequireRole", Controller1527.Role.USER);
1819
}
1920

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package output;
22

3+
import io.jooby.Context;
34
import io.jooby.annotations.GET;
45
import io.jooby.annotations.Path;
56
import io.jooby.annotations.PathParam;
@@ -9,8 +10,7 @@
910

1011
public class MyController {
1112

12-
@GET("/mypath")
13-
public String controllerMethod() {
14-
return "/mypath";
13+
@GET("/default")
14+
public void controllerMethod() {
1515
}
1616
}

0 commit comments

Comments
 (0)