-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,6 @@ database: | |
port: 5432 | ||
name: maurodatamapper | ||
--- | ||
apiUser: | ||
username: [email protected] | ||
password: password | ||
--- | ||
#Default for plugins/applications | ||
--- | ||
maurodatamapper: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
.../ox/softeng/maurodatamapper/application/boot/RuntimeGrailsApplicationPostProcessor.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |