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

Update dependency com.sun.xml.bind:jaxb-impl to v2.3.8 #12858

Merged
merged 13 commits into from
Mar 13, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '11', '14']
java: ['11', '14']
env:
WORKSPACE: ${{ github.workspace }}
GRADLE_OPTS: -Xmx1500m -Dfile.encoding=UTF-8
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/groovy-joint-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
run: env

# Select correct Groovy branch for this build:
- name: Checkout Groovy 3_0_X (Grails 5)
- name: Checkout Groovy 3_0_X (Grails 5 and later)
run: cd .. && git clone --depth 1 https://github.com/apache/groovy.git -b GROOVY_3_0_X --single-branch
if: github.ref == 'refs/heads/5.3.x' || github.base_ref == '5.3.x' || github.ref == 'refs/heads/5.2.x' || github.base_ref == '5.2.x' || github.ref == 'refs/heads/5.1.x' || github.base_ref == '5.1.x' || github.ref == 'refs/heads/5.0.x' || github.base_ref == '5.0.x' || github.ref == 'refs/heads/master' || github.base_ref == 'master'
- name: Checkout Groovy 2_5_X (Grails 4)
if: github.ref == 'refs/heads/6.0.x' || github.base_ref == '6.0.x' || github.ref == 'refs/heads/5.3.x' || github.base_ref == '5.3.x' || github.ref == 'refs/heads/5.2.x' || github.base_ref == '5.2.x' || github.ref == 'refs/heads/5.1.x' || github.base_ref == '5.1.x' || github.ref == 'refs/heads/5.0.x' || github.base_ref == '5.0.x' || github.ref == 'refs/heads/master' || github.base_ref == 'master'
- name: Checkout Groovy 2_5_X (Grails 4.0.x)
run: cd .. && git clone --depth 1 https://github.com/grails/grails-core.git -b GROOVY_2_5_X --single-branch
if: github.ref == 'refs/heads/4.1.x' || github.base_ref == '4.1.x' || github.ref == 'refs/heads/4.0.x' || github.base_ref == '4.0.x'
- name: Set CI_GROOVY_VERSION for Grails
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8']
java: ['11']
env:
GIT_USER_NAME: puneetbehl
GIT_USER_EMAIL: behlp@objectcomputing.com
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ subprojects { project ->
if(project.name == 'grails-dependencies') return
if(project.name == 'grails-bom') return

sourceCompatibility = "1.8"
targetCompatibility = "1.8"
sourceCompatibility = "1.11"
targetCompatibility = "1.11"

if(project.name =~ /^(grails-web|grails-plugin-|grails-test-suite|grails-test)/) {
dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
projectVersion=5.3.3-SNAPSHOT
projectVersion=6.0.0-SNAPSHOT
antVersion=1.10.13
aspectjVersion=1.9.19
asyncVersion=4.0.0
Expand All @@ -20,7 +20,7 @@ jakartaAnnotationApiVersion=2.0.0
jansiVersion=1.18
javaParserCoreVersion=3.15.14
javaxAnnotationApiVersion=1.3.2
jaxbVersion=2.3.1
jaxbVersion=2.3.8
jlineVersion=2.14.6
jnaVersion=5.13.0
junitVersion=4.13.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class MainClassFinder {
boolean found = false

MainMethodFinder() {
super(Opcodes.ASM4)
super(Opcodes.ASM7)
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private static void initializeState() {
final ClassReader classReader = new ClassReader(inputStream);
final String astTransformerClassName = AstTransformer.class.getSimpleName();
final ClassLoader finalClassLoader = classLoader;
classReader.accept(new ClassVisitor(Opcodes.ASM4) {
classReader.accept(new ClassVisitor(Opcodes.ASM7) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2017-2020 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 org.grails.core.cfg

import groovy.transform.Internal
import io.micronaut.context.env.yaml.ConstructIsoTimestampString
import org.yaml.snakeyaml.constructor.SafeConstructor
import org.yaml.snakeyaml.nodes.MappingNode
import org.yaml.snakeyaml.nodes.SequenceNode
import org.yaml.snakeyaml.nodes.Tag

/**
* Yaml constructor to create containers with sensible
* default array bounds.
*
* @author James Kleeh
* @since 6.0.0
*/
@Internal
class CustomSafeConstructor extends SafeConstructor {
CustomSafeConstructor() {
yamlConstructors.put(Tag.TIMESTAMP, new ConstructIsoTimestampString())
}

@Override
protected Map<Object, Object> newMap(MappingNode node) {
return createDefaultMap(node.getValue().size())
}

@Override
protected List<Object> newList(SequenceNode node) {
return createDefaultList(node.getValue().size())
}
}

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.grails.core.cfg

import grails.plugins.GrailsPlugin
import grails.util.BuildSettings
import grails.util.Environment
import grails.util.Metadata
import groovy.transform.CompileStatic
import io.micronaut.context.env.AbstractPropertySourceLoader
import io.micronaut.context.env.MapPropertySource
import io.micronaut.context.exceptions.ConfigurationException
import io.micronaut.core.io.ResourceLoader
import org.grails.config.NavigableMap
Expand All @@ -22,7 +24,7 @@ class MicronautGroovyPropertySourceLoader extends AbstractPropertySourceLoader {

@Override
int getOrder() {
return DEFAULT_POSITION
return DEFAULT_POSITION + 1
}

@Override
Expand All @@ -37,9 +39,10 @@ class MicronautGroovyPropertySourceLoader extends AbstractPropertySourceLoader {
appVersion: Metadata.getCurrent().getApplicationVersion())
try {
def configObject = configSlurper.parse(input.getText("UTF-8"))
def propertySource = new NavigableMap()
final Map<String, Object> propertySource = new NavigableMap()
propertySource.merge(configObject.flatten(), false)
finalMap.putAll(propertySource)
processEnvironmentSpecificProperties(finalMap, propertySource)
} catch (Throwable e) {
throw new ConfigurationException("Exception occurred reading configuration [" + name + "]: " + e.getMessage(), e)
}
Expand Down Expand Up @@ -68,4 +71,19 @@ class MicronautGroovyPropertySourceLoader extends AbstractPropertySourceLoader {
return Collections.singleton("groovy")
}

@Override
protected MapPropertySource createPropertySource(String name, Map<String, Object> map, int order) {
return super.createPropertySource("grails.$name", map, order)
}

void processEnvironmentSpecificProperties(finalMap, Map<String, Object> propertySource) {
final String environmentName = Environment.current.name
if (environmentName != null) {
final String environmentPrefix = GrailsPlugin.ENVIRONMENTS + '.' + environmentName + '.'
propertySource.keySet().stream()
.filter(k -> k.startsWith(environmentPrefix))
.forEach(propertyName -> { finalMap[propertyName.substring(environmentPrefix.length())] = propertySource.get(propertyName) })
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.grails.core.cfg

import grails.plugins.GrailsPlugin
import grails.util.Environment
import groovy.transform.CompileStatic
import io.micronaut.context.env.MapPropertySource
import io.micronaut.context.env.yaml.YamlPropertySourceLoader

/**
* Load properties from a YAML file. This class extends the Micronaut default implementation {@link io.micronaut.context.env.yaml.YamlPropertySourceLoader} where it adds support for Micronaut beans receive configuration from environments block.
*
* @author Puneet Behl
* @since 6.0.0
*/
@CompileStatic
class MicronautYamlPropertySourceLoader extends YamlPropertySourceLoader {

@Override
int getOrder() {
return super.getOrder() + 1
}

@Override
protected MapPropertySource createPropertySource(String name, Map<String, Object> map, int order) {
return super.createPropertySource("grails.$name", map, order)
}

/**
* Only process environment specific entries as the other entries are already processed by Micronaut default {@link io.micronaut.context.env.yaml.YamlPropertySourceLoader}
*
* @param finalMap The map with all the properties processed
* @param map The map to process
* @param prefix The prefix for the keys
*/
@Override
protected void processMap(Map<String, Object> finalMap, Map map, String prefix) {
final String env = Environment.current.name
if (env != null) {
final String grailsEnvironmentPrefix = GrailsPlugin.ENVIRONMENTS + '.' + env + '.'
((Map<String, Object>) map).entrySet().stream()
.filter(e -> e.key instanceof String && (((String) e.key).startsWith(GrailsPlugin.ENVIRONMENTS) || prefix.startsWith(GrailsPlugin.ENVIRONMENTS)))
.forEach(e -> {
Map.Entry entry = (Map.Entry) e
String key = entry.getKey().toString()
Object value = entry.getValue()
if (value instanceof Map && !((Map) value).isEmpty()) {
processMap(finalMap, (Map) value, prefix + key + '.')
} else if ((prefix + key).startsWith(grailsEnvironmentPrefix)) {
finalMap.put((prefix + key).substring(grailsEnvironmentPrefix.length()), value)
}
})
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.grails.core.cfg.MicronautYamlPropertySourceLoader
org.grails.core.cfg.MicronautGroovyPropertySourceLoader
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GrailsUtilTests {

@Test
public void testGrailsVersion() {
assertEquals("5.3.3-SNAPSHOT", GrailsUtil.getGrailsVersion());
assertEquals("6.0.0-SNAPSHOT", GrailsUtil.getGrailsVersion());
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.grails.core.cfg

import grails.util.Environment

trait EnvironmentAwareSpec {

Environment previous = null

void setEnvironment(Environment environment) {
if (System.hasProperty(Environment.KEY)) {
previous = Environment.getEnvironment(System.getProperty(Environment.KEY))
}
System.setProperty(Environment.KEY, environment ? environment.getName() : '')
}

void resetEnvironment() {
if (previous) {
System.setProperty(Environment.KEY, previous.getName())
} else {
System.setProperty(Environment.KEY, '')
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.grails.core.cfg

import grails.util.Environment
import org.grails.config.PropertySourcesConfig
import org.springframework.core.env.MutablePropertySources
import org.springframework.core.env.PropertySources
Expand All @@ -8,7 +9,11 @@ import org.springframework.core.io.Resource
import spock.lang.Specification

@SuppressWarnings("GrMethodMayBeStatic")
class GroovyConfigPropertySourceLoaderSpec extends Specification {
class GroovyConfigPropertySourceLoaderSpec extends Specification implements EnvironmentAwareSpec {

void setup() {
resetEnvironment()
}

void "test loading multiple configuration files"() {
setup:
Expand All @@ -17,6 +22,7 @@ class GroovyConfigPropertySourceLoaderSpec extends Specification {

GroovyConfigPropertySourceLoader groovyPropertySourceLoader = new GroovyConfigPropertySourceLoader()
Map<String, Object> finalMap = [:]
environment = Environment.TEST

when:
PropertySources propertySources = new MutablePropertySources()
Expand All @@ -25,8 +31,9 @@ class GroovyConfigPropertySourceLoaderSpec extends Specification {
def config = new PropertySourcesConfig(propertySources)

then:
config.size() == 7
config.size() == 9
config.getProperty("my.local.var", String.class) == "test"
config.getProperty("foo.bar", String.class) == "test"
config.getProperty("userHomeVar", String.class)

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.grails.core.cfg

import grails.util.Environment
import grails.util.SupplierUtil
import io.micronaut.context.ApplicationContext
import io.micronaut.context.ApplicationContextBuilder
import io.micronaut.context.ApplicationContextConfigurer
import io.micronaut.context.annotation.ContextConfigurer
import io.micronaut.context.env.PropertySource
import io.micronaut.spring.context.factory.MicronautBeanFactoryConfiguration
import org.springframework.core.convert.ConversionService
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.core.env.PropertyResolver
import org.springframework.lang.NonNull

import java.util.function.Supplier

trait MicronautContextAwareSpec {

ApplicationContext micronautContext
String[] environments = new String[5]
Supplier<ClassLoader> classLoader = SupplierUtil.memoized(() -> this.getClass().getClassLoader())

ApplicationContextBuilder micronautContextBuilder() {
if (Environment.current != null) {
environments[0] = Environment.current.getName()
}
final ApplicationContextBuilder builder = ApplicationContext.builder()
.classLoader(classLoader.get())
.deduceEnvironment(false)
.propertySources(PropertySource.of("grails-config", [(MicronautBeanFactoryConfiguration.PREFIX + ".bean-excludes"): (Object) beanExcludes]))
.environments(environments)

builder
}

ApplicationContext getMicronautContext() {
if (micronautContext == null) {
micronautContext = micronautContextBuilder().build()
}
micronautContext
}

ApplicationContext start() {
if (micronautContext != null) {
micronautContext.start()
}
}

List<Class<?>> getBeanExcludes() {
List beanExcludes = []
beanExcludes.add(ConversionService.class)
beanExcludes.add(org.springframework.core.env.Environment.class)
beanExcludes.add(PropertyResolver.class)
beanExcludes.add(ConfigurableEnvironment.class)
def objectMapper = io.micronaut.core.reflect.ClassUtils.forName("com.fasterxml.jackson.databind.ObjectMapper", classLoader.get()).orElse(null)
if (objectMapper != null) {
beanExcludes.add(objectMapper)
}
beanExcludes
}

void setClassLoader(ClassLoader classLoader) {
this.classLoader = SupplierUtil.memoized(() -> classLoader)
}

}
Loading