-
Notifications
You must be signed in to change notification settings - Fork 202
Handle Spring Boot Profiles #955
base: master
Are you sure you want to change the base?
Handle Spring Boot Profiles #955
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok except one thing which i believe is a bug. I.e. when you specify multiples profiles in the yaml, I dont think it works.
propertiesResource = getResourceFromClasspath(compileClassLoader, | ||
"application-" + profile + ".properties"); | ||
props2.putAll(getPropertiesResource(propertiesResource)); | ||
props.putAll(props2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could put all of this logic into a method (from line 66 to line 71) and then call it for the case above the if, too (which has the same logic but without a profile name).
I.e. I would add a addApplicationProperties(props, compileClassLoader, profile)
with profile == null
means no profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok see what you mean
if (profilesValue instanceof Map) { | ||
Map profileMap = (Map) profilesValue; | ||
String[] arrayOfActiveProfiles = | ||
StringUtils.split((String) profileMap.get("active"), ","); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the same split as below with a regexp here, so you can skip the trim iteration (i.e. activeProfiles.split("\\s*,\\s*")
after checking that the map contains an active profile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually why not reuse method getActiveProfiles()
here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah true makes sense, modified the code
intersection(Arrays.asList(profileSplit), activeProfiles) | ||
.isEmpty()) { | ||
//if the profiles is in the list of active profiles we add it to our list of docs | ||
profileDocs.put(profiles, docRoot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you have to add an entry for every profile ? (not only a single entry for the comma separated list, which is not even normalized)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no thats taken care by previous block, this in case where the yaml has only one doc so ideally we will have only one profile.. i hope my understanding is right
--- | ||
|
||
spring: | ||
profiles: dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to have a test with multiple, comma separated profiles, too (as I suspect this is currently broken).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how this will come ??? you mean something like:
spring:
profiles: dev, qa
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhuss - i dont think spring.profiles can have multiple values https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html , so we dont need to worry on it . Only spring.profiles.active can have multiple values via comma seperation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, something like this as shown in https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-profile/src/main/resources/application.yml
Also, if it could not have multiple values, why did you split it then in the code above ? Also I believe it could be even a YAML list (same like for activeProfiles)
@@ -63,9 +52,18 @@ | |||
private static final String DEFAULT_SERVER_PORT = "8080"; | |||
|
|||
public enum Config implements Configs.Key { | |||
color {{ d = "false"; }}; | |||
color {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we keep the formatting here, as it looks a bit more concise then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry it was my bad when i did formatting IDEA split it as we.. wondering is there way to configure this style ;)
|
||
public String def() { return d; } protected String d; | ||
public String def() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here wrt formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
} | ||
|
||
if (profiles != null) { | ||
String[] profileSplit = profiles.split("\\s*,\\s*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If profiles can take multiple values, why do you split it here then ? And couldn't it be that profiles
could be also a list ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaiu activeProfiles
is a cascading mechanism where the profiles later in the list override the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's about spring.profiles.include
?
@ro14nd - made some logical changes in SpringBootUtil and added test case for include profile as well. I have kept the old logic still in tact, just wanted your thoughts before I clean them up. if you are ok with all logic + additional comments if any, will fix it and clean up unused methods then. |
Incorporated review as part of the latest commits
7a619b9
to
f510110
Compare
Thanks ! I hope I can do a review today, if not, the next slot is probably only Friday next week ;-( |
@rhuss Should we rebase this PR to make it work ? |
@kameshsampath I've not followed all the evolution of this issue but it seems you've added spring-boot dependency in the last solution. We've made many changes to this plugin in order to get rid of the dependency on spring-boot from the core (it brings also some spring stuff as transitive dependencies). Is it possible to restore the old logic, and fix the problems occurring with profiles? (probably with multiple profiles) |
817b376
to
2e10a9e
Compare
2e10a9e
to
942d031
Compare
I rebased this PR and reverted commit e27270b which introduced the spring-boot dependency. @kameshsampath is this PR still good to merge (even when not used with a spring-boot dep for parsing the files ?). If so, I will try to make a review this week. And yes, sorry for the looooooong delay ;-) |
@rhuss am sorry its been really long time, need to check it why I added the spring dep, am not sure I can do this over next few weeks, but will try to take a peep whenever I get time. sorry about it. |
@kameshsampath no problem. It was my fault anyway to not finish the review. Let me make another review, and maybe I can polish the PR myself. Lets see ... |
none's fault @rhuss .. just our timelines/bandwidth just did not synch |
Fix for #880 (replaces #881)