From c2aa6181d198da48ad5068f86ab47421c0847738 Mon Sep 17 00:00:00 2001 From: Travis Tomsu Date: Mon, 24 Jul 2017 12:20:15 -0400 Subject: [PATCH] chore(springBoot): Upgrade to Spring Boot 1.5.4 (#195) --- build.gradle | 16 ++------ .../fiat/shared/FiatAuthenticationConfig.java | 2 +- fiat-core/fiat-core.gradle | 1 + ...YamlFileApplicationContextInitializer.java | 40 +++++++++++++++++++ .../model/resources/PermissionsSpec.groovy | 7 +--- .../resources/{config => }/application.yml | 0 .../java/com/netflix/spinnaker/fiat/Main.java | 2 +- .../spinnaker/fiat/config/FiatConfig.java | 2 +- 8 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/YamlFileApplicationContextInitializer.java rename fiat-core/src/test/resources/{config => }/application.yml (100%) diff --git a/build.gradle b/build.gradle index a4dfe9928..fd1cf801f 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { ext { - springBootVersion = "1.2.8.RELEASE" + springBootVersion = "1.5.4.RELEASE" } repositories { jcenter() @@ -24,7 +24,7 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath 'com.netflix.spinnaker.gradle:spinnaker-gradle-project:3.12.0' + classpath 'com.netflix.spinnaker.gradle:spinnaker-gradle-project:3.16.0' classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" } } @@ -36,7 +36,7 @@ allprojects { apply plugin: 'groovy' ext { - spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.93.0' + spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.107.0' } def checkLocalVersions = [spinnakerDependenciesVersion: spinnakerDependenciesVersion] @@ -59,16 +59,6 @@ allprojects { dependenciesVersion = spinnakerDependenciesVersion } - configurations.all { - resolutionStrategy { - eachDependency { - if (it.requested.group == 'org.springframework') { - it.useVersion '4.1.9.RELEASE' - } - } - } - } - test { testLogging { exceptionFormat = 'full' diff --git a/fiat-api/src/main/java/com/netflix/spinnaker/fiat/shared/FiatAuthenticationConfig.java b/fiat-api/src/main/java/com/netflix/spinnaker/fiat/shared/FiatAuthenticationConfig.java index 06f1f45b5..73398f37d 100644 --- a/fiat-api/src/main/java/com/netflix/spinnaker/fiat/shared/FiatAuthenticationConfig.java +++ b/fiat-api/src/main/java/com/netflix/spinnaker/fiat/shared/FiatAuthenticationConfig.java @@ -27,8 +27,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; diff --git a/fiat-core/fiat-core.gradle b/fiat-core/fiat-core.gradle index 3fddaa32c..dadad8276 100644 --- a/fiat-core/fiat-core.gradle +++ b/fiat-core/fiat-core.gradle @@ -17,4 +17,5 @@ dependencies { testCompile spinnaker.dependency("retrofitJackson") spinnaker.group("test") testCompile spinnaker.dependency("bootAutoConfigure") + testCompile spinnaker.dependency("bootActuator") } diff --git a/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/YamlFileApplicationContextInitializer.java b/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/YamlFileApplicationContextInitializer.java new file mode 100644 index 000000000..0ca841682 --- /dev/null +++ b/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/YamlFileApplicationContextInitializer.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017 Netflix, Inc. + * + * 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 + * + * http://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 com.netflix.spinnaker.fiat; + +import org.springframework.boot.env.YamlPropertySourceLoader; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.Resource; + +import java.io.IOException; + +// source: https://stackoverflow.com/a/37349492/5569046 +public class YamlFileApplicationContextInitializer implements ApplicationContextInitializer { + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + try { + Resource resource = applicationContext.getResource("classpath:application.yml"); + YamlPropertySourceLoader sourceLoader = new YamlPropertySourceLoader(); + PropertySource yamlTestProperties = sourceLoader.load("yamlTestProperties", resource, null); + applicationContext.getEnvironment().getPropertySources().addLast(yamlTestProperties); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/model/resources/PermissionsSpec.groovy b/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/model/resources/PermissionsSpec.groovy index 9a40c0ae6..2f0351757 100644 --- a/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/model/resources/PermissionsSpec.groovy +++ b/fiat-core/src/test/groovy/com/netflix/spinnaker/fiat/model/resources/PermissionsSpec.groovy @@ -18,19 +18,16 @@ package com.netflix.spinnaker.fiat.model.resources import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.SerializationFeature +import com.netflix.spinnaker.fiat.YamlFileApplicationContextInitializer import com.netflix.spinnaker.fiat.model.Authorization import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.EnableConfigurationProperties -import org.springframework.boot.test.ConfigFileApplicationContextInitializer -import org.springframework.boot.test.SpringApplicationConfiguration -import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource import spock.lang.Specification -@ContextConfiguration(classes = TestConfig, initializers = ConfigFileApplicationContextInitializer) +@ContextConfiguration(classes = TestConfig, initializers = YamlFileApplicationContextInitializer) class PermissionsSpec extends Specification { private static final Authorization R = Authorization.READ diff --git a/fiat-core/src/test/resources/config/application.yml b/fiat-core/src/test/resources/application.yml similarity index 100% rename from fiat-core/src/test/resources/config/application.yml rename to fiat-core/src/test/resources/application.yml diff --git a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java index ca8e677c5..2c009c645 100644 --- a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java +++ b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/Main.java @@ -19,7 +19,7 @@ import com.netflix.spinnaker.config.ErrorConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.web.SpringBootServletInitializer; +import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; diff --git a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java index 000ac1db5..0e05861ee 100644 --- a/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java +++ b/fiat-web/src/main/java/com/netflix/spinnaker/fiat/config/FiatConfig.java @@ -9,8 +9,8 @@ import lombok.val; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import;