Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Spring Boot Profiles #955

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kameshsampath
Copy link
Contributor

@kameshsampath kameshsampath commented May 30, 2017

Fix for #880 (replaces #881)

rhuss
rhuss previously requested changes May 30, 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.

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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"), ",");
Copy link
Contributor

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.

Copy link
Contributor

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 ?

Copy link
Contributor Author

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);
Copy link
Contributor

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)

Copy link
Contributor Author

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
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 good to have a test with multiple, comma separated profiles, too (as I suspect this is currently broken).

Copy link
Contributor Author

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

???

Copy link
Contributor Author

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

Copy link
Contributor

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 {{
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here wrt formatting.

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!

}

if (profiles != null) {
String[] profileSplit = profiles.split("\\s*,\\s*");
Copy link
Contributor

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 ?

Copy link
Contributor

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.

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 spring.profiles.include ?

@kameshsampath
Copy link
Contributor Author

@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.

@kameshsampath kameshsampath dismissed rhuss’s stale review June 11, 2017 06:59

Incorporated review as part of the latest commits

@rhuss
Copy link
Contributor

rhuss commented Jun 11, 2017

Thanks ! I hope I can do a review today, if not, the next slot is probably only Friday next week ;-(

@cmoulliard
Copy link
Contributor

@rhuss Should we rebase this PR to make it work ?

@nicolaferraro
Copy link
Member

@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).
Ideally we should replicate the same logic used by spring-boot, without importing spring-boot (unless they separate the logic into a tiny module).

Is it possible to restore the old logic, and fix the problems occurring with profiles? (probably with multiple profiles)

@rhuss rhuss self-assigned this Jul 24, 2018
@rohanKanojia rohanKanojia added the target/3.5 PR targeted to 3.5 label Jul 24, 2018
@rhuss rhuss changed the title Spring boot/issue 880 Allow default values for Spring Boot properties Jul 30, 2018
@rhuss rhuss changed the title Allow default values for Spring Boot properties Handle Spring Boot Profiles Jul 30, 2018
kameshsampath and others added 4 commits July 30, 2018 22:23
* added spring boot dependency to parse the spring boot properties
* using spring boot run to make it compute env and retrieved props from it
removed quoutes from -Dspring.profiles.active
@rhuss
Copy link
Contributor

rhuss commented Jul 30, 2018

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 ;-)

@kameshsampath
Copy link
Contributor Author

@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.

@rhuss
Copy link
Contributor

rhuss commented Jul 31, 2018

@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 ...

@kameshsampath
Copy link
Contributor Author

none's fault @rhuss .. just our timelines/bandwidth just did not synch

@rhuss rhuss added WIP target/4.0 PR for targeted to 4.0.x and removed target/3.5 PR targeted to 3.5 labels Jul 31, 2018
@rhuss rhuss added pr/wip Work in Progress, do not merge and removed WIP labels Sep 14, 2018
@rhuss rhuss added this to Planned in Sprint #156 Oct 1, 2018
@rhuss rhuss assigned lordofthejars and unassigned rhuss Oct 1, 2018
@lordofthejars lordofthejars moved this from Planned to In Progress in Sprint #156 Oct 15, 2018
@rhuss rhuss added this to Planned in Sprint #157 Oct 23, 2018
@rhuss rhuss removed this from Planned in Sprint #157 Oct 23, 2018
@rhuss rhuss moved this from In Progress to Planned in Sprint #156 Oct 23, 2018
@devang-gaur devang-gaur added the jkube/pending The issue/PR has to be taken care of in JKube https://github.com/eclipse/jkube label Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jkube/pending The issue/PR has to be taken care of in JKube https://github.com/eclipse/jkube pr/wip Work in Progress, do not merge target/4.0 PR for targeted to 4.0.x
Projects
No open projects
Sprint #156
  
Planned
Development

Successfully merging this pull request may close these issues.

None yet

7 participants