Skip to content

Commit

Permalink
Merge branch '3.8.x' into 3.9.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
#	gradle/libs.versions.toml
  • Loading branch information
sdelamo committed Mar 30, 2023
2 parents d6a6928 + 4dd90d4 commit de1f1db
Show file tree
Hide file tree
Showing 20 changed files with 480 additions and 17 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -43,7 +43,7 @@ developers=Graeme Rocher
kapt.use.worker.api=true

# Dependency Versions
micronautMavenPluginVersion=3.5.2
micronautMavenPluginVersion=3.5.3
chromedriverVersion=79.0.3945.36
geckodriverVersion=0.26.0
webdriverBinariesVersion=1.4
Expand All @@ -52,7 +52,7 @@ kotlin.stdlib.default.dependency=false

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

org.gradle.caching=true
org.gradle.parallel=true
Expand Down
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Expand Up @@ -73,7 +73,7 @@ managed-micronaut-cache = "3.5.0"
managed-micronaut-cassandra = "5.1.1"
managed-micronaut-coherence = "3.7.2"
managed-micronaut-crac = "1.2.0"
managed-micronaut-data = "3.9.6"
managed-micronaut-data = "3.9.7"
managed-micronaut-discovery = "3.3.0"
managed-micronaut-elasticsearch = "4.3.0"
managed-micronaut-email = "1.5.0"
Expand All @@ -100,7 +100,7 @@ managed-micronaut-neo4j = "5.2.0"
managed-micronaut-nats = "3.1.0"
managed-micronaut-netflix = "2.1.0"
managed-micronaut-object-storage = "1.1.0"
managed-micronaut-openapi = "4.8.5"
managed-micronaut-openapi = "4.8.6"
managed-micronaut-oraclecloud = "2.3.4"
managed-micronaut-picocli = "4.3.0"
managed-micronaut-problem = "2.6.0"
Expand All @@ -112,7 +112,7 @@ managed-micronaut-rss = "3.2.0"
managed-micronaut-rxjava1 = "1.0.0"
managed-micronaut-rxjava2 = "1.3.0"
managed-micronaut-rxjava3 = "2.4.0"
managed-micronaut-security = "3.9.3"
managed-micronaut-security = "3.9.4"
managed-micronaut-serialization = "1.5.2"
managed-micronaut-servlet = "3.3.5"
managed-micronaut-spring = "4.5.1"
Expand All @@ -122,11 +122,11 @@ managed-micronaut-test-resources = "1.2.3"
managed-micronaut-toml = "1.1.3"
managed-micronaut-tracing = "4.5.0"
managed-micronaut-tracing-legacy = "3.2.7"
managed-micronaut-views = "3.8.1"
managed-micronaut-views = "3.8.2"
managed-micronaut-xml = "3.2.0"
managed-neo4j = "3.5.35"
managed-neo4j-java-driver = "4.4.9"
managed-netty = "4.1.87.Final"
managed-netty = "4.1.90.Final"
managed-reactive-pg-client = "0.11.4"
managed-reactive-streams = "1.0.4"
# This should be kept aligned with https://github.com/micronaut-projects/micronaut-reactor/blob/master/gradle.properties from the BOM
Expand Down
Expand Up @@ -153,11 +153,10 @@ class HttpResponseSpec extends AbstractMicronautSpec {
HttpHeaders headers = response.headers

then: // The content length header was replaced, not appended
!headers.names().contains("content-type")
!headers.names().contains("Content-Length")
headers.contains("content-length")
response.header("Content-Type") == "text/plain"
response.header("Content-Length") == "3"
response.header("content-type") == "text/plain"
response.header("content-length") == "3"
}

void "test server header"() {
Expand Down
@@ -0,0 +1,52 @@
/*
* 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.staticresources;

import io.micronaut.core.util.CollectionUtils;
import io.micronaut.http.HttpHeaders;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.server.tck.AssertionUtils;
import io.micronaut.http.uri.UriBuilder;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.Collections;

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

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

@Test
public void staticResource() throws IOException {
asserts(SPEC_NAME,
CollectionUtils.mapOf(
"micronaut.router.static-resources.assets.mapping", "/assets/**",
"micronaut.router.static-resources.assets.paths", "classpath:assets"),
HttpRequest.GET(UriBuilder.of("/assets").path("hello.txt").build()).accept(MediaType.TEXT_PLAIN),
(server, request) -> AssertionUtils.assertDoesNotThrow(server, request,
HttpStatus.OK,
"Hello World",
Collections.singletonMap(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN)));
}
}
1 change: 1 addition & 0 deletions http-server-tck/src/main/resources/assets/hello.txt
@@ -0,0 +1 @@
Hello World
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 original authors
* 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.
Expand All @@ -23,6 +23,7 @@
import io.micronaut.core.annotation.Nullable;
import io.micronaut.logging.LogLevel;
import io.micronaut.logging.LoggingSystem;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import org.slf4j.LoggerFactory;

Expand All @@ -41,8 +42,35 @@ public final class LogbackLoggingSystem implements LoggingSystem {

private final String logbackXmlLocation;

/**
* @deprecated Use {@link LogbackLoggingSystem#LogbackLoggingSystem(String, String)} instead
* @param logbackXmlLocation
*/
@Deprecated
public LogbackLoggingSystem(@Nullable @Property(name = "logger.config") String logbackXmlLocation) {
this.logbackXmlLocation = logbackXmlLocation != null ? logbackXmlLocation : DEFAULT_LOGBACK_LOCATION;
this(
System.getProperty("logback.configurationFile"),
logbackXmlLocation
);
}

/**
* @param logbackExternalConfigLocation The location of the logback configuration file set via logback properties
* @param logbackXmlLocation The location of the logback configuration file set via micronaut properties
* @since 3.8.8
*/
@Inject
public LogbackLoggingSystem(
@Nullable @Property(name = "logback.configurationFile") String logbackExternalConfigLocation,
@Nullable @Property(name = "logger.config") String logbackXmlLocation
) {
if (logbackExternalConfigLocation != null) {
this.logbackXmlLocation = logbackExternalConfigLocation;
} else if (logbackXmlLocation != null) {
this.logbackXmlLocation = logbackXmlLocation;
} else {
this.logbackXmlLocation = DEFAULT_LOGBACK_LOCATION;
}
}

@Override
Expand Down
42 changes: 37 additions & 5 deletions runtime/src/main/java/io/micronaut/logging/impl/LogbackUtils.java
Expand Up @@ -24,6 +24,8 @@
import io.micronaut.core.annotation.Nullable;
import io.micronaut.logging.LoggingSystemException;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Iterator;
import java.util.ServiceLoader;
Expand All @@ -37,6 +39,8 @@
*/
public final class LogbackUtils {

private static final String DEFAULT_LOGBACK_13_PROGRAMMATIC_CONFIGURATOR = "ch.qos.logback.classic.util.DefaultJoranConfigurator";

private LogbackUtils() {
}

Expand All @@ -50,26 +54,43 @@ private LogbackUtils() {
public static void configure(@NonNull ClassLoader classLoader,
@NonNull LoggerContext context,
@NonNull String logbackXmlLocation) {
configure(context, logbackXmlLocation, () -> classLoader.getResource(logbackXmlLocation));
configure(context, logbackXmlLocation, () -> {
// Check classpath first
URL resource = classLoader.getResource(logbackXmlLocation);
if (resource != null) {
return resource;
}
// Check file system
File file = new File(logbackXmlLocation);
if (file.exists()) {
try {
resource = file.toURI().toURL();
} catch (MalformedURLException e) {

throw new LoggingSystemException("Error creating URL for off-classpath resource", e);
}
}
return resource;
});
}

/**
* Configures a Logger Context.
*
* <p>
* Searches fpr a custom {@link Configurator} via a service loader.
* If not present it configures the context with the resource.
*
* @param context Logger Context
* @param context Logger Context
* @param logbackXmlLocation the location of the xml logback config file
* @param resourceSupplier A resource for example logback.xml
* @param resourceSupplier A resource for example logback.xml
*/
private static void configure(
@NonNull LoggerContext context,
@NonNull String logbackXmlLocation,
Supplier<URL> resourceSupplier
) {
Configurator configurator = loadFromServiceLoader();
if (configurator != null) {
if (isSupportedConfigurator(context, configurator)) {
context.getStatusManager().add(new InfoStatus("Using " + configurator.getClass().getName(), context));
programmaticConfiguration(context, configurator);
} else {
Expand All @@ -86,6 +107,17 @@ private static void configure(
}
}

private static boolean isSupportedConfigurator(LoggerContext context, Configurator configurator) {
if (configurator == null) {
return false;
}
if (DEFAULT_LOGBACK_13_PROGRAMMATIC_CONFIGURATOR.equals(configurator.getClass().getName())) {
context.getStatusManager().add(new InfoStatus("Skipping " + configurator.getClass().getName() + " as it's assumed to be from an unsupported version of Logback", context));
return false;
}
return true;
}

/**
* Taken from {@link ch.qos.logback.classic.util.ContextInitializer#autoConfig}.
*/
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Expand Up @@ -70,6 +70,8 @@ include "test-suite-graal"
include "test-suite-groovy"
include "test-suite-groovy"
include "test-suite-logback"
include "test-suite-logback-14"
include "test-suite-logback-external-configuration"
include "test-utils"

// benchmarks
Expand Down
26 changes: 26 additions & 0 deletions test-suite-logback-14/build.gradle
@@ -0,0 +1,26 @@
plugins {
id("io.micronaut.build.internal.convention-test-library")
}

description = "logback tests with a new version of logback than we support, just to check it runs. Can be removed when we upgrade as part of 4.0.0"

// Logback 1.4.x is Java 11+ compatible
def logbackVersion = JavaVersion.current().isJava11Compatible() ? "1.4.6" : "1.3.6"

dependencies {
testAnnotationProcessor(projects.injectJava)

testImplementation(libs.managed.micronaut.test.spock) {
exclude(group: "io.micronaut", module: "micronaut-aop")
}
testImplementation(projects.context)
testImplementation(projects.injectGroovy)

// Use a newer version of logback than we support
testImplementation("ch.qos.logback:logback-classic:${logbackVersion}")

testImplementation(projects.management)
testImplementation(projects.httpClient)

testRuntimeOnly(projects.httpServerNetty)
}
@@ -0,0 +1,31 @@
package io.micronaut.logback

import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import io.micronaut.context.annotation.Property
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import org.slf4j.LoggerFactory
import spock.lang.Specification

@MicronautTest
// Setting a level in a property forces a refresh, so the XML configuration is ignored. Without this in 3.8.x, the test fails.
@Property(name = "logger.levels.set.by.property", value = "DEBUG")
class LoggerConfigurationSpec extends Specification {

@Inject
@Client("/")
HttpClient client

void "if configuration is supplied, xml should be ignored"() {
given:
Logger fromXml = (Logger) LoggerFactory.getLogger("xml.config")
Logger fromProperties = (Logger) LoggerFactory.getLogger("set.by.property")

expect:
fromXml.level == Level.TRACE
fromProperties.level == Level.DEBUG
}
}

0 comments on commit de1f1db

Please sign in to comment.