Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
Closes gh-36122
  • Loading branch information
wilkinsona committed Jun 29, 2023
2 parents b32697b + e2f8fcf commit abaade2
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or 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 @@ -29,7 +29,6 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory;

/**
Expand All @@ -45,7 +44,6 @@
@EnableConfigurationProperties(FreeMarkerProperties.class)
@Import({ FreeMarkerServletWebConfiguration.class, FreeMarkerReactiveWebConfiguration.class,
FreeMarkerNonWebConfiguration.class })
@ImportRuntimeHints(FreeMarkerRuntimeHints.class)
public class FreeMarkerAutoConfiguration {

private static final Log logger = LogFactory.getLog(FreeMarkerAutoConfiguration.class);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or 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 @@ -20,8 +20,11 @@
import java.util.Arrays;
import java.util.List;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar;
import org.springframework.util.ClassUtils;

/**
* {@link TemplateAvailabilityProvider} that provides availability information for
Expand All @@ -32,8 +35,10 @@
*/
public class FreeMarkerTemplateAvailabilityProvider extends PathBasedTemplateAvailabilityProvider {

private static final String REQUIRED_CLASS_NAME = "freemarker.template.Configuration";

public FreeMarkerTemplateAvailabilityProvider() {
super("freemarker.template.Configuration", FreeMarkerTemplateAvailabilityProperties.class, "spring.freemarker");
super(REQUIRED_CLASS_NAME, FreeMarkerTemplateAvailabilityProperties.class, "spring.freemarker");
}

protected static final class FreeMarkerTemplateAvailabilityProperties extends TemplateAvailabilityProperties {
Expand All @@ -60,4 +65,19 @@ public void setTemplateLoaderPath(List<String> templateLoaderPath) {

}

static class FreeMarkerTemplateAvailabilityRuntimeHints extends BindableRuntimeHintsRegistrar {

FreeMarkerTemplateAvailabilityRuntimeHints() {
super(FreeMarkerTemplateAvailabilityProperties.class);
}

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
if (ClassUtils.isPresent(REQUIRED_CLASS_NAME, classLoader)) {
super.registerHints(hints, classLoader);
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.log.LogMessage;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
Expand All @@ -60,7 +59,6 @@
@AutoConfiguration(after = WebMvcAutoConfiguration.class)
@ConditionalOnClass(MarkupTemplateEngine.class)
@EnableConfigurationProperties(GroovyTemplateProperties.class)
@ImportRuntimeHints(GroovyTemplateRuntimeHints.class)
public class GroovyTemplateAutoConfiguration {

private static final Log logger = LogFactory.getLog(GroovyTemplateAutoConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or 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 @@ -20,8 +20,11 @@
import java.util.Arrays;
import java.util.List;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar;
import org.springframework.util.ClassUtils;

/**
* {@link TemplateAvailabilityProvider} that provides availability information for Groovy
Expand All @@ -32,8 +35,10 @@
*/
public class GroovyTemplateAvailabilityProvider extends PathBasedTemplateAvailabilityProvider {

private static final String REQUIRED_CLASS_NAME = "groovy.text.TemplateEngine";

public GroovyTemplateAvailabilityProvider() {
super("groovy.text.TemplateEngine", GroovyTemplateAvailabilityProperties.class, "spring.groovy.template");
super(REQUIRED_CLASS_NAME, GroovyTemplateAvailabilityProperties.class, "spring.groovy.template");
}

protected static final class GroovyTemplateAvailabilityProperties extends TemplateAvailabilityProperties {
Expand All @@ -60,4 +65,19 @@ public void setResourceLoaderPath(List<String> resourceLoaderPath) {

}

static class GroovyTemplateAvailabilityRuntimeHints extends BindableRuntimeHintsRegistrar {

GroovyTemplateAvailabilityRuntimeHints() {
super(GroovyTemplateAvailabilityProperties.class);
}

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
if (ClassUtils.isPresent(REQUIRED_CLASS_NAME, classLoader)) {
super.registerHints(hints, classLoader);
}
}

}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
org.springframework.aot.hint.RuntimeHintsRegistrar=\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityRuntimeHints,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityRuntimeHints,\
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.JacksonAutoConfigurationRuntimeHints,\
org.springframework.boot.autoconfigure.template.TemplateRuntimeHints

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

import org.junit.jupiter.api.Test;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint;
import org.springframework.beans.factory.aot.AotServices;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityProperties;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityRuntimeHints;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
Expand Down Expand Up @@ -84,4 +90,14 @@ void availabilityOfTemplateWithCustomSuffix() {
.isTrue();
}

@Test
void shouldRegisterFreeMarkerTemplateAvailabilityPropertiesRuntimeHints() {
assertThat(AotServices.factories().load(RuntimeHintsRegistrar.class))
.hasAtLeastOneElementOfType(FreeMarkerTemplateAvailabilityRuntimeHints.class);
RuntimeHints hints = new RuntimeHints();
new FreeMarkerTemplateAvailabilityRuntimeHints().registerHints(hints, getClass().getClassLoader());
TypeHint typeHint = hints.reflection().getTypeHint(FreeMarkerTemplateAvailabilityProperties.class);
assertThat(typeHint).isNotNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

import org.junit.jupiter.api.Test;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint;
import org.springframework.beans.factory.aot.AotServices;
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityProperties;
import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityRuntimeHints;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
Expand Down Expand Up @@ -84,4 +90,14 @@ void availabilityOfTemplateWithCustomSuffix() {
.isTrue();
}

@Test
void shouldRegisterGroovyTemplateAvailabilityPropertiesRuntimeHints() {
assertThat(AotServices.factories().load(RuntimeHintsRegistrar.class))
.hasAtLeastOneElementOfType(GroovyTemplateAvailabilityRuntimeHints.class);
RuntimeHints hints = new RuntimeHints();
new GroovyTemplateAvailabilityRuntimeHints().registerHints(hints, getClass().getClassLoader());
TypeHint typeHint = hints.reflection().getTypeHint(GroovyTemplateAvailabilityProperties.class);
assertThat(typeHint).isNotNull();
}

}

0 comments on commit abaade2

Please sign in to comment.