Skip to content
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

Merge 3.9.x, fix TCK test and document breakage #9133

Merged
merged 47 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
860df1d
Bump micronaut-liquibase to 5.6.1 (#9040)
micronaut-build Mar 31, 2023
3614cbb
Bump micronaut-kafka to 4.5.3 (#9036)
micronaut-build Apr 3, 2023
b386c03
Support JDK 20 in annotation processors (#9022) (#9048)
graemerocher Apr 3, 2023
9110bb2
Bump micronaut-azure to 3.10.0 (#9050)
micronaut-build Apr 3, 2023
df65f6c
Bump micronaut-kubernetes to 4.0.0 (#9046)
micronaut-build Apr 4, 2023
3290103
Bump micronaut-liquibase to 5.7.1 (#9043)
micronaut-build Apr 4, 2023
2a8af7a
Merge branch '3.8.x' into 3.9.x
sdelamo Apr 4, 2023
46858e7
Bump micronaut-gcp to 4.10.0 (#9058)
micronaut-build Apr 4, 2023
9338ca6
build: add Micronaut Chatbots BOM (#9056)
sdelamo Apr 5, 2023
50c6e01
Bump micronaut-aws to 3.16.0 (#9065)
micronaut-build Apr 5, 2023
120e35a
Bump micronaut-micrometer to 4.8.3 (#9066)
micronaut-build Apr 5, 2023
2310670
Add ability to disable log in environments (#8946)
altro3 Apr 5, 2023
edfd75a
Bump micronaut-jms to 2.2.0 (#8729)
micronaut-build Apr 5, 2023
5d8af19
Bump micronaut-grpc to 3.6.0 (#9068)
micronaut-build Apr 5, 2023
e761475
Bump micronaut-security to 3.10.1 (#9082)
micronaut-build Apr 10, 2023
a783b1d
fix(deps): update netty monorepo to v4.1.91.final (#9079)
renovate[bot] Apr 10, 2023
3976532
Merge branch '3.8.x' into 3.9.x
sdelamo Apr 10, 2023
ce9b812
Bump micronaut-aws to 3.10.10 (#9084)
micronaut-build Apr 11, 2023
755f836
Update to Jackson 2.14.2 (#9064)
sdelamo Apr 11, 2023
b297e07
build: Micronaut Security 3.11.0 (#9087)
sdelamo Apr 11, 2023
b8ae15a
CRaC 1.2.2 (#9088)
sdelamo Apr 11, 2023
8d1db4e
Idea(8855)/service health indicator (#9061)
alexsimpson440dev Apr 12, 2023
1ef53a8
Bump micronaut-data to 3.10.0 (#9095)
micronaut-build Apr 12, 2023
2bdf5d4
Bump micronaut-aws to 3.17.0 (#9100)
micronaut-build Apr 12, 2023
940f37e
Deprecate `ConversionService.SHARED` and update custom converter docs…
wetted Apr 12, 2023
1a7b7b1
Load ApplicationContextConfigurer with passed classloader instead of …
Goldmensch Apr 13, 2023
8a63ced
Bump micronaut-elasticsearch to 4.4.0 (#9101)
micronaut-build Apr 13, 2023
ba2890e
[skip ci] Release v3.8.9
micronaut-build Apr 13, 2023
efb066a
build: managed-elasticsearch 7.17.9 (#9102)
sdelamo Apr 13, 2023
77d00c7
Back to 3.8.10-SNAPSHOT
micronaut-build Apr 13, 2023
0c8a08e
Merge branch '3.8.x' into 3.9.x
sdelamo Apr 13, 2023
8c37c57
build: crac 1.2.3
sdelamo Apr 13, 2023
a436cb8
discoery client 3.3.1
sdelamo Apr 13, 2023
04c93d8
build: rxjava 3 2.4.1
sdelamo Apr 13, 2023
9e397f9
build: test-resources 1.2.5
sdelamo Apr 13, 2023
cbcc42f
Bump micronaut-liquibase to 5.7.2 (#9109)
micronaut-build Apr 14, 2023
1cdac4a
bug: SslConfiguration::setProtocol (#9118)
sdelamo Apr 17, 2023
fb88999
Merge branch '3.8.x' into 3.9.x
sdelamo Apr 17, 2023
8fae07c
Add targetPackage property to the @Introspected annotation (#9105)
andriy-dmytruk Apr 17, 2023
dedfdd5
[skip ci] Release v3.9.0
micronaut-build Apr 17, 2023
277e6db
Back to 3.9.1-SNAPSHOT
micronaut-build Apr 17, 2023
0536d11
Add a TCK test for String based Exception handler (#9132)
timyates Apr 20, 2023
c732a47
Merge branch '3.9.x' into mergeup-3.9.x
timyates Apr 20, 2023
b176fa6
Fix ExceptionHandler TCK test
timyates Apr 20, 2023
97e30ba
Add breaking change
timyates Apr 20, 2023
4fb1e45
Better wording
timyates Apr 20, 2023
ad72f7e
Add in PR #9105
timyates Apr 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ final class BeanIntrospectionWriter extends AbstractAnnotationMetadataWriter {
* @param beanAnnotationMetadata The bean annotation metadata
* @param visitorContext The visitor context
*/
BeanIntrospectionWriter(ClassElement classElement, AnnotationMetadata beanAnnotationMetadata,
BeanIntrospectionWriter(String targetPackage, ClassElement classElement, AnnotationMetadata beanAnnotationMetadata,
VisitorContext visitorContext) {
super(computeReferenceName(classElement.getName()), classElement, beanAnnotationMetadata, true, visitorContext);
super(computeReferenceName(targetPackage, classElement.getName()), classElement, beanAnnotationMetadata, true, visitorContext);
final String name = classElement.getName();
this.classElement = classElement;
this.referenceWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
this.introspectionName = computeIntrospectionName(name);
this.introspectionName = computeShortIntrospectionName(targetPackage, name);
this.introspectionType = getTypeReferenceForName(introspectionName);
this.beanType = getTypeReferenceForName(name);
this.dispatchWriter = new DispatchWriter(introspectionType, Type.getType(AbstractInitializableBeanIntrospection.class));
Expand All @@ -151,17 +151,18 @@ final class BeanIntrospectionWriter extends AbstractAnnotationMetadataWriter {
* @param visitorContext The visitor context
*/
BeanIntrospectionWriter(
String targetPackage,
String generatingType,
int index,
ClassElement originatingElement,
ClassElement classElement,
AnnotationMetadata beanAnnotationMetadata,
VisitorContext visitorContext) {
super(computeReferenceName(generatingType) + index, originatingElement, beanAnnotationMetadata, true, visitorContext);
super(computeReferenceName(targetPackage, generatingType) + index, originatingElement, beanAnnotationMetadata, true, visitorContext);
final String className = classElement.getName();
this.classElement = classElement;
this.referenceWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
this.introspectionName = computeIntrospectionName(generatingType, className);
this.introspectionName = computeIntrospectionName(targetPackage, className);
this.introspectionType = getTypeReferenceForName(introspectionName);
this.beanType = getTypeReferenceForName(className);
this.dispatchWriter = new DispatchWriter(introspectionType);
Expand Down Expand Up @@ -949,22 +950,19 @@ private void pushAnnotationMetadata(ClassWriter classWriter, GeneratorAdapter st
}

@NonNull
private static String computeReferenceName(String className) {
String packageName = NameUtils.getPackageName(className);
private static String computeReferenceName(String packageName, String className) {
final String shortName = NameUtils.getSimpleName(className);
return packageName + ".$" + shortName + REFERENCE_SUFFIX;
}

@NonNull
private static String computeIntrospectionName(String className) {
String packageName = NameUtils.getPackageName(className);
private static String computeShortIntrospectionName(String packageName, String className) {
final String shortName = NameUtils.getSimpleName(className);
return packageName + ".$" + shortName + INTROSPECTION_SUFFIX;
}

@NonNull
private static String computeIntrospectionName(String generatingName, String className) {
final String packageName = NameUtils.getPackageName(generatingName);
private static String computeIntrospectionName(String packageName, String className) {
return packageName + ".$" + className.replace('.', '_') + INTROSPECTION_SUFFIX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private void processIntrospected(ClassElement element, VisitorContext context, A
final boolean metadata = introspected.booleanValue("annotationMetadata").orElse(true);
final Set<String> includedAnnotations = CollectionUtils.setOf(introspected.stringValues("includedAnnotations"));
final Set<AnnotationValue<Annotation>> indexedAnnotations = CollectionUtils.setOf(introspected.get("indexed", AnnotationValue[].class, new AnnotationValue[0]));
final String targetPackage = introspected.stringValue("targetPackage").orElse(element.getPackageName());

if (!classes.isEmpty()) {
AtomicInteger index = new AtomicInteger(0);
Expand All @@ -101,6 +102,7 @@ private void processIntrospected(ClassElement element, VisitorContext context, A
return;
}
final BeanIntrospectionWriter writer = new BeanIntrospectionWriter(
targetPackage,
element.getName(),
index.getAndIncrement(),
element,
Expand Down Expand Up @@ -129,6 +131,7 @@ private void processIntrospected(ClassElement element, VisitorContext context, A
continue;
}
final BeanIntrospectionWriter writer = new BeanIntrospectionWriter(
targetPackage,
element.getName(),
j++,
element,
Expand All @@ -147,6 +150,7 @@ private void processIntrospected(ClassElement element, VisitorContext context, A
}
} else {
final BeanIntrospectionWriter writer = new BeanIntrospectionWriter(
targetPackage,
element,
metadata ? element.getAnnotationMetadata() : null,
context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@
*/
String withPrefix() default "with";

/**
* @return The package to write introspections to. By default, uses the class package.
* @since 3.9.0
*/
@Experimental
String targetPackage() default "";

/**
* Allow pre-computed indexes for property lookups based on an annotation and a member.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.micronaut.core.annotation.Nullable;

/**
* Abstraction to load resources from the the classpath.
* Abstraction to load resources from the classpath.
*
* @author James Kleeh
* @author Graeme Rocher
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ kotlin.stdlib.default.dependency=false

# For the docs
graalVersion=22.0.0.2
micronautSecurityVersion=3.9.4
micronautSecurityVersion=3.11.0

org.gradle.caching=true
org.gradle.parallel=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* The access log format parser.
*
* <p>
* The syntax is based on <a href="https://httpd.apache.org/docs/current/mod/mod_log_config.html">Apache httpd log format</a>.
* Here are the supported directives:
* <ul>
Expand All @@ -43,17 +43,17 @@
* <li><b>%B</b> - Bytes sent, excluding HTTP headers</li>
* <li><b>%h</b> - Remote host name</li>
* <li><b>%H</b> - Request protocol</li>
* <li><b>%{<header>}i</b> - Request header. If the argument is omitted (<b>%i</b>) all headers will be printed</li>
* <li><b>%{<header>}o</b> - Response header. If the argument is omitted (<b>%o</b>) all headers will be printed</li>
* <li><b>%{<cookie>}C</b> - Request cookie (COOKIE). If the argument is omitted (<b>%C</b>) all cookies will be printed</li>
* <li><b>%{<cookie>}c</b> - Response cookie (SET_COOKIE). If the argument is omitted (<b>%c</b>) all cookies will be printed</li>
* <li><b>%{&lt;header&gt;}i</b> - Request header. If the argument is omitted (<b>%i</b>) all headers will be printed</li>
* <li><b>%{&lt;header&gt;}o</b> - Response header. If the argument is omitted (<b>%o</b>) all headers will be printed</li>
* <li><b>%{&lt;cookie&gt;}C</b> - Request cookie (COOKIE). If the argument is omitted (<b>%C</b>) all cookies will be printed</li>
* <li><b>%{&lt;cookie&gt;}c</b> - Response cookie (SET_COOKIE). If the argument is omitted (<b>%c</b>) all cookies will be printed</li>
* <li><b>%l</b> - Remote logical username from identd (always returns '-')</li>
* <li><b>%m</b> - Request method</li>
* <li><b>%p</b> - Local port</li>
* <li><b>%q</b> - Query string (excluding the '?' character)</li>
* <li><b>%r</b> - First line of the request</li>
* <li><b>%s</b> - HTTP status code of the response</li>
* <li><b>%{<format>}t</b> - Date and time. If the argument is omitted the Common Log Format format is used ("'['dd/MMM/yyyy:HH:mm:ss Z']'").
* <li><b>%{&lt;format&gt;}t</b> - Date and time. If the argument is omitted the Common Log Format format is used ("'['dd/MMM/yyyy:HH:mm:ss Z']'").
* If the format starts with begin: (default) the time is taken at the beginning of the request processing. If it starts with end: it is the time when the log entry gets written, close to the end of the request processing.
* The format should follow the DateTimeFormatter syntax.</li>
* <li><b>%u</b> - Remote user that was authenticated. Not implemented. Prints '-'.</li>
Expand All @@ -64,9 +64,9 @@
* </ul>
* <p>In addition, the following aliases for commonly utilized patterns:</p>
* <ul>
* <li><b>common</b> - <code>%h %l %u %t "%r" %s %b</code> Common Log Format (CLF)</li>
* <li><b>common</b> - {@code %h %l %u %t "%r" %s %b} Common Log Format (CLF)</li>
* <li><b>combined</b> -
* <code>%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"</code> Combined Log Format</li>
* {@code %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"} Combined Log Format</li>
* </ul>
*
* @author croudet
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.http.server.tck.tests;

import io.micronaut.context.annotation.Requires;
import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.server.exceptions.ExceptionHandler;
import io.micronaut.http.tck.AssertionUtils;
import jakarta.inject.Singleton;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Map;

import static io.micronaut.http.tck.TestScenario.asserts;

@SuppressWarnings({
"java:S5960", // We're allowed assertions, as these are used in tests only
"checkstyle:MissingJavadocType",
"checkstyle:DesignForExtension"
})
public class ErrorHandlerStringTest {
public static final String SPEC_NAME = "ErrorHandlerStringTest";

@Test
void testErrorHandlerWithStringReturn() throws IOException {
asserts(SPEC_NAME,
HttpRequest.GET("/exception/my").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON),
(server, request) -> AssertionUtils.assertDoesNotThrow(
server,
request,
HttpStatus.OK,
"hello",
Map.of(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
)
);
}

@Requires(property = "spec.name", value = SPEC_NAME)
@Controller("/exception")
static class ExceptionController {

@Get("/my")
void throwsMy() {
throw new MyException("bad");
}
}

static class MyException extends RuntimeException {
public MyException(String badThings) {
super(badThings);
}
}

@Requires(property = "spec.name", value = SPEC_NAME)
@Singleton
static class MyExceptionHandler implements ExceptionHandler<MyException, String> {

@Override
public String handle(HttpRequest request, MyException exception) {
return "hello";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void setProtocols(String[] protocols) {
* @param protocol The protocol
*/
public void setProtocol(String protocol) {
if (!StringUtils.isNotEmpty(protocol)) {
if (StringUtils.isNotEmpty(protocol)) {
this.protocol = protocol;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.micronaut.http.ssl

import spock.lang.Specification

class SslConfigurationSpec extends Specification {

void "setProtocol should override protocol"() {
given:
SslConfiguration configuration = new SslConfiguration()

expect:
configuration.protocol.isPresent()
"TLS" == configuration.protocol.get()

when:
configuration.protocol = "foo"

then:
configuration.protocol.isPresent()
"foo" == configuration.protocol.get()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,41 @@ class Test extends Auditable {
bean.updatedAt != null
}

void "test introspection can written to different package"() {
when:
def classLoader = buildClassLoader("test.Test", '''
package test;

import io.micronaut.core.annotation.Introspected;

@Introspected(targetPackage = "test.introspections")
public class Test {
private String name;
public Test(String name) {
this.name = name;
}
public String getName() {
return name;
}
}

''')
def introspectionName = 'test.introspections.$Test$Introspection'
def introspection = classLoader.loadClass(introspectionName).newInstance() as BeanIntrospection

then:
introspection != null
introspection.getProperty("name").isPresent()

when:
def introspectionRefName = 'test.introspections.$Test$IntrospectionRef'
def introspectionRef = classLoader.loadClass(introspectionRefName).newInstance() as BeanIntrospectionReference

then:
introspectionRef != null
introspectionRef.load() != null
}

void "test generics in arrays don't stack overflow"() {
given:
def introspection = buildBeanIntrospection('arraygenerics.Test', '''
Expand Down Expand Up @@ -1161,6 +1196,37 @@ class Test {}
applicationContext.close()
}

void "test create bean introspection for external class with custom package"() {
given:
def classLoader = buildClassLoader('test.Test', '''
package test;

import io.micronaut.core.annotation.Introspected;
import io.micronaut.inject.visitor.beans.OuterBean;

@Introspected(classes=OuterBean.InnerBean.class, targetPackage="test.micronaut.intro")
class Test {}
''')

when:"the reference is loaded"
def reference = classLoader.loadClass('test.micronaut.intro.$Test$IntrospectionRef0').newInstance() as BeanIntrospectionReference

then:"the reference is valid"
notThrown(ClassNotFoundException)
reference.getBeanType() == OuterBean.InnerBean.class
reference.load() != null

print(classLoader)

when:"the introspection is loaded"
def introspectionName = 'test.micronaut.intro.$io_micronaut_inject_visitor_beans_OuterBean$InnerBean$Introspection'
def introspection = classLoader.loadClass(introspectionName).newInstance() as BeanIntrospection

then:"the introspection is valid"
notThrown(ClassNotFoundException)
introspection.getProperty("name").isPresent()
}

void "test create bean introspection for interface"() {
given:
def context = buildContext('itfcetest.MyInterface','''
Expand Down
Loading