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

making possible to override environment variables by system properties #875

Merged

Conversation

nykolaslima
Copy link
Contributor

When we are deploying in an environment like Amazon, we may need to update an environment variable on demand. Nowadays, we need to change the environment.properties in order to make this happen.

This pull request, allow us to override this properties using system properties.

We only allow user's to override properties that exists in environment.properties and do not allow to define only in system property.

#environment.properties
my.prop hello
//System.setProperty("my.prop", "bye");
environment.get("my.prop"); //bye
//System.setProperty("not.in.properties", "foo")
environment.get("not.in.properties"); //throw NoSuchElementException

@@ -63,6 +63,12 @@
<artifactId>xstream</artifactId>
<version>1.4.7</version>
</dependency>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I create a ValidationUtil class to do this?

I believe that notBlank method is something that we can use in many parts of the project.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use guava's Strings class:

http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Strings.html#isNullOrEmpty(java.lang.String)

On Tue Nov 11 2014 at 3:23:23 PM Nykolas Laurentino de Lima <
notifications@github.com> wrote:

In vraptor-core/pom.xml:

@@ -63,6 +63,12 @@
xstream
1.4.7

Should I create a ValidationUtil class to do this?

I believe that notBlank method is something that we can use in many parts
of the project.


Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/875/files#r20164752.

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, I think this feature is great. And I also believe that during
development environment, the properties should be reloaded for every
request.

On Tue Nov 11 2014 at 3:26:25 PM Chico Sokol chico.sokol@gmail.com wrote:

We can use guava's Strings class:

http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Strings.html#isNullOrEmpty(java.lang.String)

On Tue Nov 11 2014 at 3:23:23 PM Nykolas Laurentino de Lima <
notifications@github.com> wrote:

In vraptor-core/pom.xml:

@@ -63,6 +63,12 @@
xstream
1.4.7

Should I create a ValidationUtil class to do this?

I believe that notBlank method is something that we can use in many
parts of the project.


Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/875/files#r20164752.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, use @csokol suggestion. We can't add a new jar with a lot of classes only because one 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.

Thanks @csokol. I'll do this!

On Tuesday, November 11, 2014, csokol notifications@github.com wrote:

In vraptor-core/pom.xml:

@@ -63,6 +63,12 @@
xstream
1.4.7

We can use guava's Strings class:
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Strings.html#isNullOrEmpty(java.lang.String)
… <#1499fe486c772a65_>
On Tue Nov 11 2014 at 3:23:23 PM Nykolas Laurentino de Lima <
notifications@github.com
javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote: In
vraptor-core/pom.xml: > @@ -63,6 +63,12 @@ >
xstream > 1.4.7 >


Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/875/files#r20164940.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take it easy @garcia-jj. Already understood.

On Tuesday, November 11, 2014, Otávio Garcia notifications@github.com
wrote:

In vraptor-core/pom.xml:

@@ -63,6 +63,12 @@
xstream
1.4.7

Yes, use @csokol https://github.com/csokol suggestion. We can't add a
new jar with a lot of classes only because one method.


Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/875/files#r20165131.

Copy link
Member

Choose a reason for hiding this comment

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

@csokol About reload, sounds too fair. And its not too hard to implement. May we can do this feature in next pull request. What U think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it should be in different PR.

On Tue Nov 11 2014 at 3:31:57 PM Otávio Garcia notifications@github.com
wrote:

In vraptor-core/pom.xml:

@@ -63,6 +63,12 @@
xstream
1.4.7

@csokol https://github.com/csokol About reload, sounds too fair. And
its not too hard to implement. May we can do this feature in next pull
request. What U think?


Reply to this email directly or view it on GitHub
https://github.com/caelum/vraptor4/pull/875/files#r20165314.

@garcia-jj
Copy link
Member

Just labeling this pull request conflicts with #821, so #821 needs to be refactored before merge into master.

@nykolaslima What you think to add some docs about this search priority?

@nykolaslima
Copy link
Contributor Author

@garcia-jj sure! Doing this right now..

@nykolaslima
Copy link
Contributor Author

Done. Can you review please @garcia-jj? My english isn't so good.

@garcia-jj
Copy link
Member

After changes I think are ready to merge. Lets @Turini and @lucascs review the code.

I think that can be merged in this current release because there is no public API change, @Turini .

@nykolaslima
Copy link
Contributor Author

Fixed. Thanks! Let's wait for review 👍

If you have a common properties for other environments you can create a file called `environment.properties` with these common properties. So VRaptor will ask for properties first in the environment file, and if not found, will ask in the `environment.properties` file.

You can also override properties using System Properties. Properties defined by System Properties will override any other definitions.
Note: You can only use System Properties to override existing properties in property files and not to define a new one.
Copy link
Member

Choose a reason for hiding this comment

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

@nykolaslima, can you just add an simple example?
I think It'll help users to get the idea. What do you think?

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 think it would be nice...Gonna do it!

@Turini
Copy link
Member

Turini commented Nov 12, 2014

I think that can be merged in this current release because there
is no public API change, @Turini .

👍

@nykolaslima
Copy link
Contributor Author

@Turini what do you think now?

@nykolaslima
Copy link
Contributor Author

@Turini done. If you have any other suggestion please let me know. 👍

Turini added a commit that referenced this pull request Nov 12, 2014
…em-property

making possible to override environment variables by system properties
@Turini Turini merged commit a661389 into caelum:master Nov 12, 2014
@Turini
Copy link
Member

Turini commented Nov 12, 2014

thank you @nykolaslima

@nykolaslima nykolaslima deleted the override-environment-by-system-property branch November 12, 2014 16:07
@nykolaslima
Copy link
Contributor Author

No problem. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants