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

Support environment variables and system properties in configuration files #716

Merged
merged 1 commit into from
Dec 30, 2015
Merged

Support environment variables and system properties in configuration files #716

merged 1 commit into from
Dec 30, 2015

Conversation

guwirth
Copy link
Collaborator

@guwirth guwirth commented Dec 19, 2015

  • introduce new class CxxSettings
  • overload Settings.getClearString to replace environment variables in values
  • replace all Settings with CxxSettings

todo: unit test

@ALL: any feedback to this approach?

@guwirth guwirth added this to the M 0.9.5 milestone Dec 19, 2015
@guwirth guwirth self-assigned this Dec 19, 2015
@jmecosta
Copy link
Member

Try to to support also vars that are passed as arguments.

For example

-DRoot=c:\src

Usually those are more useful than environment variables. Both should be coded. Suppose the you can use get clear property to retrieve the the props that are ${} before looking into the environment

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 19, 2015

@jmecosta good idea will try. Do you know how sonar runner is handling this defines?
E.g. - DRoot=c:\src is this an environment variable afterwords or can I use an API to get them?

@jmecosta
Copy link
Member

I dont think it matters, we they reached the plugin I think they are already parsed properly

@jmecosta jmecosta closed this Dec 19, 2015
@jmecosta jmecosta reopened this Dec 19, 2015
@jmecosta
Copy link
Member

I think you can use the settings class to get those.

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 20, 2015

This PR is always crashing on server side.

  • first try was to replace all Settings with CxxSettings: server crash during start up
  • next try to move and use CxxSettings only internally: crash during configuration creation

@ALL someone experience with this? Is it possible to extend Settings? Is there something I have to register on server side?

import java.util.Properties;
import org.sonar.api.config.Settings;

public class CxxSettings extends Settings {
Copy link
Member

Choose a reason for hiding this comment

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

wonder if the internals of Settings will be in proper state when it arrives to the plugin. i would assume core to create its own instance of Settings class, likely when CxxSettings gets into the plugin it comes without any information about the settings.

perhaps this class cannot be used like this, and might explain the issue in server side. Could this be done in a helper class that receives Settings and then returns the value as per you implementation below?

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 23, 2015

This version is working. Maybe someone more familiar with Java can have a look to it.

@jmecosta
Copy link
Member

Looks good to me, I don't know what are the java patterns that should be used in this case but for me it looks functional

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 23, 2015

The point with this solution is, that the CxxSettings(Settings settings) Ctor creates a copy of Settings. If someone is changing the values of the original Settings afterwards this will not affect CxxSettings. I'm not sure if this is relevant (except unit tests) because after starting an analysis the Settings have to be stable anyway?

Other approach could be to use inside CxxSettings a reference and the pimpl pattern. But this means all methodes must be duplicated.

@guwirth guwirth changed the title Support environment variables in configuration files Support environment variables and system properties in configuration files Dec 24, 2015
@guwirth
Copy link
Collaborator Author

guwirth commented Dec 24, 2015

Ready to merge 👍

Support environment variables and system properties in configuration files: use ${xxx} as placeholder

@jmecosta
Copy link
Member

Let me test it first. Try to do it before end of year.

On Thu, Dec 24, 2015, 10:56 Günter Wirth [email protected] wrote:

Ready to merge [image: 👍]

Support environment variables and system properties in configuration
files: use ${xxx} as placeholder


Reply to this email directly or view it on GitHub
#716 (comment)
.

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 24, 2015

Ok. Happy xmas.

Von meinem iPhone gesendet

Am 24.12.2015 um 10:02 schrieb Jorge Costa [email protected]:

Let me test it first. Try to do it before end of year.

On Thu, Dec 24, 2015, 10:56 Günter Wirth [email protected] wrote:

Ready to merge [image: 👍]

Support environment variables and system properties in configuration
files: use ${xxx} as placeholder


Reply to this email directly or view it on GitHub
#716 (comment)
.


Reply to this email directly or view it on GitHub.

@jmecosta
Copy link
Member

Merry Xmas also..

On Thu, Dec 24, 2015, 15:45 Günter Wirth [email protected] wrote:

Ok. Happy xmas.

Von meinem iPhone gesendet

Am 24.12.2015 um 10:02 schrieb Jorge Costa [email protected]:

Let me test it first. Try to do it before end of year.

On Thu, Dec 24, 2015, 10:56 Günter Wirth [email protected]
wrote:

Ready to merge [image: 👍]

Support environment variables and system properties in configuration
files: use ${xxx} as placeholder


Reply to this email directly or view it on GitHub
<
#716 (comment)

.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#716 (comment)
.

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 29, 2015

@jmecosta did you have some time for testing? Can I merge this?

@jmecosta
Copy link
Member

i will do it today.

On Tue, 29 Dec 2015 at 12:28 Günter Wirth [email protected] wrote:

@jmecosta https://github.com/jmecosta did you have some time for
testing? Can I merge this?


Reply to this email directly or view it on GitHub
#716 (comment)
.

@jmecosta
Copy link
Member

@guwirth few things i spotted:

if passing -DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults i dont get the parser to replace the AnalysisReportsDir

environment variables work, however if using
set AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults

what i get in the plugin is:
D:SonarVersionsMultLanguageProject.cxxresults

so it does not support the windows separators.

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 29, 2015

😕 thx for testing. Will try to improve it.

Am 29.12.2015 um 12:41 schrieb Jorge Costa [email protected]:

@guwirth few things i spotted:

if passing -DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults i dont get the parser to replace the AnalysisReportsDir

environment variables work, however if using
set AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults

what i get in the plugin is:
D:SonarVersionsMultLanguageProject.cxxresults

so it does not support the windows separators.


Reply to this email directly or view it on GitHub.

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 29, 2015

if passing -DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults i dont get the parser to replace the AnalysisReportsDir

There are three types to replace:

  1. SQ properties from configuration file or -D parameter
  2. Java system properties
  3. environment variables

Currently I replace only 2 & 3. Will add also 1.

environment variables work, however if using
set AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults
what i get in the plugin is:
D:SonarVersionsMultLanguageProject.cxxresults

In case of 2 & 3 I have to replace \ with \ or / to behave like defined in config file.

@jmecosta
Copy link
Member

Ok so its possible to support the windows paths, I know that using the
sonar runner this would not work. If you are able to get it working then
would be really nice

On Tue, Dec 29, 2015, 20:15 Günter Wirth [email protected] wrote:

if passing
-DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults i dont
get the parser to replace the AnalysisReportsDir

There are three types to replace:

  1. SQ properties from configuration file or -D parameter
  2. Java system properties
  3. environment variables

Currently I replace only 2 & 3. Will add also 1.

environment variables work, however if using
set AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults
what i get in the plugin is:
D:SonarVersionsMultLanguageProject.cxxresults

In case of 2 & 3 I have to replace \ with \ or / to behave like defined
in config file.


Reply to this email directly or view it on GitHub
#716 (comment)
.

- CxxSettings clones Settings in ctor
- format for placeholder is ${xxx} - supported are environment variables, Java system properties and SonarQube properties
- backslashes in values from environment variables and Java system properties are replaced with slashes to support Windows paths
@guwirth
Copy link
Collaborator Author

guwirth commented Dec 30, 2015

-DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject

For this case you have to define it like in config file. Can't replace \ with / because I don't know which properties are from config file and which are from command line.

works now:

-DAnalysisReportsDir=D:/SonarVersions/MultLanguageProject
-DAnalysisReportsDir="D:/SonarVersions/MultLanguageProject"

environment variables work, however if using set AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults what i get in the plugin is: D:SonarVersionsMultLanguageProject.cxxresults

It's working now.

@guwirth
Copy link
Collaborator Author

guwirth commented Dec 30, 2015

CxxSettings supports variables in configuration files …

  • CxxSettings clones Settings in ctor
  • format for placeholder is ${xxx}
  • supported are environment variables, Java system properties and SonarQube properties
  • backslashes in values from environment variables and Java system properties are replaced with slashes to support Windows paths

@jmecosta
Copy link
Member

Ok I will test again in a bit. Thanks

On Wed, Dec 30, 2015, 09:27 Günter Wirth [email protected] wrote:

-DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject

For this case you have to define it like in config file. Can't replace
with / because I don't know which properties are from config file and which
are from command line.

works now:

-DAnalysisReportsDir=D:/SonarVersions/MultLanguageProject
-DAnalysisReportsDir="D:/SonarVersions/MultLanguageProject"

environment variables work, however if using set
AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults what i
get in the plugin is: D:SonarVersionsMultLanguageProject.cxxresults

It's working now.


Reply to this email directly or view it on GitHub
#716 (comment)
.

@jmecosta
Copy link
Member

works fine now, thanks. for me it can be merged

On Wed, 30 Dec 2015 at 09:29 Jorge Costa [email protected] wrote:

Ok I will test again in a bit. Thanks

On Wed, Dec 30, 2015, 09:27 Günter Wirth [email protected] wrote:

-DAnalysisReportsDir=D:\SonarVersions\MultLanguageProject

For this case you have to define it like in config file. Can't replace
with / because I don't know which properties are from config file and which
are from command line.

works now:

-DAnalysisReportsDir=D:/SonarVersions/MultLanguageProject
-DAnalysisReportsDir="D:/SonarVersions/MultLanguageProject"

environment variables work, however if using set
AnalysisReportsDir=D:\SonarVersions\MultLanguageProject.cxxresults what i
get in the plugin is: D:SonarVersionsMultLanguageProject.cxxresults

It's working now.


Reply to this email directly or view it on GitHub
#716 (comment)
.

guwirth added a commit that referenced this pull request Dec 30, 2015
Support environment variables and system properties in configuration files
@guwirth guwirth merged commit 0bd42d2 into SonarOpenCommunity:master Dec 30, 2015
@guwirth guwirth deleted the enhancement/environment-variables branch April 3, 2016 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants