Skip to content

Commit

Permalink
Merge branch 'release/4.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
olliefreeman committed Aug 8, 2021
2 parents 65b83d0 + ae521fd commit 443640a
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 15 deletions.
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ bootRun {

grails {
plugins {
compile "uk.ac.ox.softeng.maurodatamapper:mdm-core:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-security:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-authentication-apikey:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-authentication-basic:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-dataflow:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-datamodel:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-referencedata:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-terminology:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-profile:$version"
compile "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-federation:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-core:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-security:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-authentication-apikey:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-authentication-basic:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-dataflow:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-datamodel:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-referencedata:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-terminology:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-profile:$version"
runtimeOnly "uk.ac.ox.softeng.maurodatamapper:mdm-plugin-federation:$version"
}
if (OperatingSystem.current() == OperatingSystem.WINDOWS) {
logger.quiet('Using pathing Jar as running in Windows OS')
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Core Info
version=4.7.0
version=4.8.0
group=uk.ac.ox.softeng.maurodatamapper
# Gradle
gradleVersion=6.7.1
Expand Down
4 changes: 0 additions & 4 deletions grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ database:
port: 5432
name: maurodatamapper
---
apiUser:
username: [email protected]
password: password
---
#Default for plugins/applications
---
maurodatamapper:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/
package uk.ac.ox.softeng.maurodatamapper.application

import uk.ac.ox.softeng.maurodatamapper.application.boot.RuntimeGrailsApplicationPostProcessor

import grails.boot.GrailsApp
import grails.boot.config.GrailsApplicationPostProcessor
import grails.boot.config.GrailsAutoConfiguration
import groovy.transform.CompileStatic
import org.springframework.context.annotation.ComponentScan
Expand All @@ -28,4 +31,9 @@ class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}

@Override
GrailsApplicationPostProcessor grailsApplicationPostProcessor() {
new RuntimeGrailsApplicationPostProcessor(this, applicationContext, classes() as Class[])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package uk.ac.ox.softeng.maurodatamapper.application.boot

import uk.ac.ox.softeng.maurodatamapper.application.Application

import grails.boot.config.GrailsApplicationPostProcessor
import grails.core.DefaultGrailsApplication
import grails.core.GrailsApplicationLifeCycle
import grails.io.IOUtils
import groovy.util.logging.Slf4j
import org.grails.config.PropertySourcesConfig
import org.grails.config.yaml.YamlPropertySourceLoader
import org.springframework.boot.env.PropertySourceLoader
import org.springframework.context.ApplicationContext
import org.springframework.core.env.MutablePropertySources
import org.springframework.core.env.PropertySource
import org.springframework.core.io.Resource
import org.springframework.core.io.UrlResource

import java.nio.file.Path

/**
* @since 14/11/2017
*/
@Slf4j
class RuntimeGrailsApplicationPostProcessor extends GrailsApplicationPostProcessor {

public static final String APPLICATION_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE = 'applicationConfig: [classpath:/application.yml]'
public static final String RUNTIME_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE = 'runtimeConfiguration'
public static final String BUILD_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE = 'buildConfiguration'

RuntimeGrailsApplicationPostProcessor(GrailsApplicationLifeCycle lifeCycle,
ApplicationContext applicationContext, Class... classes) {
super(lifeCycle, applicationContext, classes)
}

@Override
protected void loadApplicationConfig() {
super.loadApplicationConfig()

PropertySourcesConfig config = ((DefaultGrailsApplication) grailsApplication).config
MutablePropertySources propertySources = config.getPropertySources()

try {
PropertySource propertySource = loadPropertySourceForResource(BUILD_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE, '/build.yml')
addPropertySourceToPropertySources(propertySource, APPLICATION_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE, config, propertySources)
} catch (Exception ignored) {
log.warn("Build configuration file was not loaded", ignored)
}

String filePath = System.getenv('runtime.config.path')
if(!filePath){
log.info("Runtime configuration file was not supplied")
return
}

try {
PropertySource propertySource = loadPropertySourceForFilePath(RUNTIME_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE, filePath)
String placement = propertySources.contains(BUILD_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE) ? BUILD_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE :
APPLICATION_CONFIGURATION_PROPERTIES_PROPERTY_SOURCE
addPropertySourceToPropertySources(propertySource, placement, config, propertySources)
} catch (Exception ignored) {
log.warn("Runtime configuration file was not loaded", ignored)
}
}


void addPropertySourceToPropertySources(PropertySource propertySource, String placement, PropertySourcesConfig config, MutablePropertySources propertySources) {
if (propertySource) {
propertySources.addBefore placement, propertySource
config.refresh()
log.info('Updated property sources to include properties from {} configuration file', propertySource.getName())
}
}

PropertySource loadPropertySourceForResource(String propertySourceName, String fileName) {
URL urlToConfig = IOUtils.findResourceRelativeToClass(Application, fileName)
loadPropertySourceForUrl(propertySourceName, urlToConfig)
}

PropertySource loadPropertySourceForFilePath(String propertySourceName, String filePath) {
URI uriToConfig = Path.of(filePath).toAbsolutePath().toUri()
loadPropertySourceForUrl(propertySourceName, uriToConfig.toURL())
}

PropertySource loadPropertySourceForUrl(String propertySourceName, URL uriToConfig) {
try {
Resource resource = new UrlResource(uriToConfig)
PropertySourceLoader propertySourceLoader = new YamlPropertySourceLoader()
return propertySourceLoader.load(propertySourceName, resource).first()
}
catch (Exception ignored) {
}
log.warn("Configuration file for [{}] not present at [{}]", propertySourceName, uriToConfig)
null
}
}

0 comments on commit 443640a

Please sign in to comment.