Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Added dummy spring boot application
Browse files Browse the repository at this point in the history
removed quoutes from -Dspring.profiles.active
  • Loading branch information
kameshsampath authored and rhuss committed Jul 30, 2018
1 parent bbf1914 commit 662d182
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2016 Red Hat, Inc.
*
* Red Hat licenses this file to you 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 io.fabric8.maven.core.util;

/**
* @author kameshs
*/
public class DummySpringBootApplication {
public static void main(String[] args) {
//nothing here...
}
}
20 changes: 12 additions & 8 deletions core/src/main/java/io/fabric8/maven/core/util/SpringBootUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.boot.env.PropertySourcesLoader;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -71,29 +70,34 @@ public static Properties runAndLoadPropertiesUsingEnv(List<String> activeProfile
SpringApplication sbBuilder;

if (activeProfiles != null && activeProfiles.size() > 0) {
sbBuilder = new SpringApplicationBuilder(AnnotationConfigApplicationContext.class)
sbBuilder = new SpringApplicationBuilder(DummySpringBootApplication.class)
.web(false)
.headless(true)
.bannerMode(Banner.Mode.OFF)
.profiles(activeProfiles.toArray(new String[activeProfiles.size()]))
.build();
} else {
sbBuilder = new SpringApplicationBuilder(AnnotationConfigApplicationContext.class)
sbBuilder = new SpringApplicationBuilder(DummySpringBootApplication.class)
.web(false)
.headless(true)
.bannerMode(Banner.Mode.OFF)
.build();
}

ConfigurableApplicationContext ctx = sbBuilder.run();

Properties applicationProperties = new Properties();
try {
ConfigurableApplicationContext ctx = sbBuilder.run();

applicationProperties = new Properties();

for (PropertySource propertySource : ctx.getEnvironment().getPropertySources()) {
for (PropertySource propertySource : ctx.getEnvironment().getPropertySources()) {

if (propertySource != null && propertySource instanceof MapPropertySource) {
applicationProperties.putAll(((MapPropertySource) propertySource).getSource());
if (propertySource != null && propertySource instanceof MapPropertySource) {
applicationProperties.putAll(((MapPropertySource) propertySource).getSource());
}
}
} catch (Exception e) {
//swallow it ..
}

return applicationProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public void testPropertiesInclude() throws Exception {
FileUtils.copyFile(ResourceUtils.getFile(testAppPropertyResource), new File("target/test-classes",
"application.yml"), "UTF-8", null, true);

SpringApplication sbBuilder = new SpringApplicationBuilder(AnnotationConfigApplicationContext.class)
.web(false)
.headless(true)
.bannerMode(Banner.Mode.OFF)
.build();

ConfigurableApplicationContext ctx = sbBuilder.run();

Properties props = SpringBootUtil.getApplicationProperties(project,Collections.<String>emptyList());

assertNotEquals(0, props.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ protected List<String> getExtraJavaOptions() {
//Spring boot active profiles
String strActiveProfiles = getConfig(activeProfiles);
if (strActiveProfiles != null) {
opts.add("-Dspring.profiles.active=\"" + strActiveProfiles + "\"");
//String[] profiles = strActiveProfiles.split(",");
//Quoting is having issue with spring boot considering the string with quotes as profile name
//if (profiles.length > 1) {
opts.add("-Dspring.profiles.active=" + strActiveProfiles);
//} else {
// opts.add("-Dspring.profiles.active=" + strActiveProfiles);
//}
}
return opts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void javaOptionsWithActiveProfiles() throws IOException, MojoExecutionExc
Map<String, String> env = configs.get(0).getBuildConfiguration().getEnv();
String javaOptions = env.get("JAVA_OPTIONS");
assertNotNull(javaOptions);
assertTrue(javaOptions.equals("-Dspring.profiles.active=\"dev,qa\""));
assertTrue(javaOptions.equals("-Dspring.profiles.active=dev,qa"));
}

@Test
Expand All @@ -105,7 +105,7 @@ public void javaOptionsWithActiveProfileWithSpaces() throws IOException, MojoExe
Map<String, String> env = configs.get(0).getBuildConfiguration().getEnv();
String javaOptions = env.get("JAVA_OPTIONS");
assertNotNull(javaOptions);
assertTrue(javaOptions.equals("-Dspring.profiles.active=\"dev, qa\""));
assertTrue(javaOptions.equals("-Dspring.profiles.active=dev, qa"));
}


Expand Down

0 comments on commit 662d182

Please sign in to comment.