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

Conversation

@kameshsampath
Copy link
Contributor

  • Support for adding Spring Boot profiles as JAVA_OPTIONS when the user provides configuration via activeProfiles

  • ability to handle multiple application yaml docs with/without spring active profiles

This pull resolves #797 and avoids #880 which can now be customised via profile during build

@codecov
Copy link

codecov bot commented Mar 15, 2017

Codecov Report

Merging #881 into master will decrease coverage by 3.77%.
The diff coverage is 59.01%.

@@             Coverage Diff             @@
##             master    #881      +/-   ##
===========================================
- Coverage     22.37%   18.6%   -3.78%     
+ Complexity      580     491      -89     
===========================================
  Files           164     160       -4     
  Lines          8684    8403     -281     
  Branches       1530    1502      -28     
===========================================
- Hits           1943    1563     -380     
- Misses         6529    6648     +119     
+ Partials        212     192      -20

@rhuss rhuss changed the title Issue 880 Add profile support in spring-boot Mar 15, 2017
Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamesh sorry, sorry for the long delay (shame on me :(. No excuse, but were busy time (and I couldn't work much on any other f-m-p issue, too).

In principle the PR, however I have some comments (see below) and I wonder what we should do with other advanced features like includes.

I really would like to have a check how spring-boot itself does the parsing, maybe we can avoid to reinvent the wheel.

Properties props = getPropertiesFromYamlResource(ymlResource,activeProfiles);
props.putAll(getPropertiesResource(propertiesResource));

if(activeProfiles!=null){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor thing, but it would be awesome if you could stick to the spacing conventions of the projects (e.g. spaces between braces and operators)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

ymlResource = compileClassLoader.findResource("application-"+profile+".yml");
Properties props2 = getPropertiesFromYamlResource(ymlResource,activeProfiles);
propertiesResource = compileClassLoader.findResource("application-"+profile+".properties");
props2.putAll(getPropertiesResource(propertiesResource));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks duplicated to the snippet above. Please extract this is into an extra method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have moved to new method - not sure that what you really meant.

Properties properties = new Properties();
if (source != null) {
properties.putAll(getFlattenedMap(source));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code block is quite large. Could we split it up in some smaller chunks by moving parts into methods ?

It's really hard to follow and understand what it does with all the different state variables. would be very awesome if this would be easier to understand (tbh I'm not sure whether I fully grasped it)

I even wouldn't mind if we would have two passes through the document, one to detect the active profiles and the other to parse the profiles. I think this would it much easier to understand and we would need to cover less corner cases.


if (profilesValue instanceof LinkedHashMap) {
Map porfMap = (Map) profilesValue;
String[] actProfiles = StringUtils.split((String) porfMap.get("active"), ",");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's about whitespaces before and after commas ? So maybe we should .trim() the profile names before putting them into the profile list.

activeProfiles.addAll(Arrays.asList(actProfiles));
}
} else if (profilesValue instanceof String) {
profiles = (String) profilesValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you process the logic by splitting up the profiles string right here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

//Spring boot active profiles
String strActiveProfiles = getConfig(activeProfiles);
if(strActiveProfiles!=null) {
opts.add("-Dspring.profiles.active="+strActiveProfiles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better embedd it in quotes or escape spaces when "activeProfiles" contain spaces (like in "a, b")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quoted it - but we need to see how it works hen deployed in k8s, sometimes i see it does not work as expected ..

String strActiveProfiles = getConfig(activeProfiles);

Properties properties = SpringBootUtil.getApplicationProperties(getContext().getProject(),
SpringBootUtil.getActiveProfiles(strActiveProfiles));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, please use a singe method in SpringBootUtils.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method added

String strActiveProfiles = getConfig(activeProfiles);

Properties properties = SpringBootUtil.getApplicationProperties(getContext().getProject(),
SpringBootUtil.getActiveProfiles(strActiveProfiles));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same, one method please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method added

project.getPlugin(anyString); result = null;
project.getVersion(); result = "1.0.0"; minTimes = 0;
context.getConfig(); result = config;
config.getConfig("spring-boot","activeProfiles");result="dev,qa";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be cool to have a test with spaces after the comma, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new test and mock context with spaces in profiles

Properties properties = SpringBootUtil.getSpringBootApplicationProperties(getContext().getProject());
String strActiveProfiles = getContext().getConfig().getConfig("spring-boot","activeProfiles");

Properties properties = SpringBootUtil.getApplicationProperties(getContext().getProject(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same again, one method instead of two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new method added

@kameshsampath
Copy link
Contributor Author

since i need the old branch for logic reference shall we use the the PR #955

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spring-boot generator can not handle multi-profile configuration

2 participants