Skip to content

Commit

Permalink
Merge pull request #9042 from micronaut-projects/40xmergeup
Browse files Browse the repository at this point in the history
Merge branch 3.9.x into 4.0.x
  • Loading branch information
graemerocher authored Apr 3, 2023
2 parents d439f35 + 90859a7 commit 7356efa
Show file tree
Hide file tree
Showing 16 changed files with 697 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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 Down Expand Up @@ -41,8 +41,22 @@ public final class LogbackLoggingSystem implements LoggingSystem {

private final String logbackXmlLocation;

public LogbackLoggingSystem(@Nullable @Property(name = "logger.config") String logbackXmlLocation) {
this.logbackXmlLocation = logbackXmlLocation != null ? logbackXmlLocation : DEFAULT_LOGBACK_LOCATION;
/**
* @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
*/
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
30 changes: 25 additions & 5 deletions context/src/main/java/io/micronaut/logging/impl/LogbackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.micronaut.core.util.CollectionUtils;
import io.micronaut.logging.LoggingSystemException;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.function.Supplier;
Expand Down Expand Up @@ -52,18 +54,36 @@ private LogbackUtils() {
public static void configure(@NonNull ClassLoader classLoader,
@NonNull LoggerContext context,
@NonNull String logbackXmlLocation) {
configure(context, logbackXmlLocation, () -> classLoader.getResource(logbackXmlLocation), classLoader);
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;
}, classLoader);
}

/**
* Configures a Logger Context.
*
* Searches fpr a custom {@link Configurator} via a service loader.
* <p>
* Searches for a custom {@link Configurator} via a service loader.
* If not present it configures the context with the resource.
* </p>
*
* @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,
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ projectUrl=https://micronaut.io
developers=Graeme Rocher

# Dependency Versions
micronautMavenPluginVersion=3.5.2
micronautMavenPluginVersion=3.5.3
chromedriverVersion=79.0.3945.36
geckodriverVersion=0.26.0
webdriverBinariesVersion=1.4
Expand All @@ -56,7 +56,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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ managed-kotlin = "1.8.10"
managed-kotlin-coroutines = "1.6.4"
managed-maven-native-plugin = "0.9.13"
managed-methvin-directory-watcher = "0.16.1"
managed-netty = "4.1.87.Final"
managed-netty = "4.1.90.Final"
managed-netty-http3 = "0.0.16.Final"
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.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.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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
Loading

0 comments on commit 7356efa

Please sign in to comment.