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

Added support for interpolated variables #35

Merged
merged 7 commits into from
Feb 13, 2018

Conversation

csamarghitan
Copy link

It adds support for interpolated variables like
var1 = value1
var2 = ${var1}-value2
It will also expand ${sys:...} and ${env:...} keys.

As a draw back it increase the size of the pull-in because of the extra three libraries form Apache Commons.
Reference : http://commons.apache.org/proper/commons-configuration/userguide/howto_utilities.html#Utility_classes_and_Tips_and_Tricks

pom.xml Outdated
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
Copy link
Member

@rsandell rsandell Feb 5, 2018

Choose a reason for hiding this comment

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

@jglick @oleg-nenashev do you have any insight if these dependencies are safe to add?
´commons-beanutils´ is provided by core IIRC?

Copy link
Member

Choose a reason for hiding this comment

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

Cannot recall offhand, but should be checked.

Copy link
Member

Choose a reason for hiding this comment

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

@Bipolar please check

Copy link
Author

Choose a reason for hiding this comment

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

Indeed jenkins-core already provides beanutils, I've removed the dependency.

pom.xml Outdated
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

Cannot recall offhand, but should be checked.

@@ -82,6 +87,9 @@
properties.load(sr);
}

// Interpolated values in the properties
properties = interpolateProperties(properties);
Copy link
Member

Choose a reason for hiding this comment

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

I do not recommend changing the behavior of the readProperties step. Rather introduce a new step for interpolation if you want one. Or just leave this to a global library with @Grab for people who need it.

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe adding a new parameter telling the step to change behavior?

Copy link
Author

Choose a reason for hiding this comment

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

Sounds better with a parameter, the impact on the code is minimal.

<li>
<code>interpolate</code>:
Flag to indicate if the properties should be interpolated or not.
In case of error or cycling dependencies, the original properties will be returned.
Copy link
Member

Choose a reason for hiding this comment

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

An example would be nice here. Not all users understands what interpolated means :)

Copy link
Author

Choose a reason for hiding this comment

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

Done! I've added an extra example with interpolation.

@@ -39,6 +39,7 @@
*/
public class ReadPropertiesStep extends AbstractFileOrTextStep {
private Map defaults;
private Boolean interpolate = Boolean.FALSE;
Copy link
Member

Choose a reason for hiding this comment

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

a normal, basic boolean should suffice here, it defaults to false in Java.

* The value of <i>url</i> should be evaluated to http://localhost/resources with the interpolation on.
* @return the value of interpolated
*/
public Boolean getInterpolate() {
Copy link
Member

Choose a reason for hiding this comment

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

following the Java bean spec this should then be isInterpolate.

if ( properties == null)
return null;
Configuration interpolatedProp;
PrintStream logger = listener.getLogger();
Copy link
Member

Choose a reason for hiding this comment

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

You need to rebase your master branch. The listener field has been removed so you are getting a compilation failure here.

@rsandell rsandell merged commit f9309ce into jenkinsci:master Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants