Let's say I have a package abc.bcd.html.efg.Hello.html, I want to tear down the .html extension without changing the package. How do I do it?
You should be able to do this with a regex like
(.*)\.html$
(the dollar matching the end of the input string). This would correspond to
<propertyregex property="some.property" input="abc.bcd.html.efg.Hello.html"
regex="(.*)\.html$$" select="\1" />
using a double dollar to "escape" the single dollar sign from being treated as part of a property expansion by ant - see "$$ Expansion" on this page.
Related
I have a property that has to contain long list of strings and to improve readability I would like to define each value (that are quite long) in separate line, something like:
<property name="items" separator=",">
<item>A</item>
<item>B</item>
</property>
as equivalent to
<property name="items" value="A,B" />
Or something similar to <path> + <pathconvert> but not expanding paths.
Is it possible ?
Turns out there are string resources and a generic resource container:
<resources id="items">
<string>A</string>
<string>B</string>
</resources>
<pathconvert property="items" refid="items" pathsep="," />
Not supported by standard ANT.
There is a popular ant-contrib plugin that has a "foreach" task which acts upon comma separated properties, but I prefer to embed a proper programming language. groovy stands out due it's excellent Java and ANT integration.
Examples of list handling:
Change values of list in ANT
How can i pass two variable in one Ant target by spliting commas
I'm using the text parameter to get multi line parameters, and write them to file.
If I use the rebuild, the text parameter is loaded as a single line string (where newline is removed).
Does anyone have an idea on how to fix this? I guess the rebuild plugin is the problem...
The multi-line text parameter seems to be rather buggy. One workaround you may consider is to substitute newlines with some custom escape system and then convert the escape sequences back to newlines inside your build.
A more advanced solution would be to modify the plugin itself to convert the escape sequences into newlines and use that modified plugin in your Jenkins. I've done that sort of thing for Claim Plugin to display failed matrix jobs which it did not do on its own. If you decide to take this route I can walk you through the main steps.
I have just enhanced the plugin to add TextParameterValue.jelly
That works fine, since text and textarea are not that different except new lines just use StringParameterValue.jelly as template and use <f:textarea name="value" value="${it.value}" /> instead of <f:textbox name="value" value="${it.value}" />
I have this date format:
<entry key="buildDate" type="date" value="now" pattern="MM-dd-yyyy HH:mm:ss"/>
But ant gives me this result (in a key-value properties file):
buildDate=01-13-2012 14\:19\:59
Why ant add those slash in? because it is in a properties file?
Yes. The colons have special meaning in a Java properties file (they can act as key-value separators), so Ant needs to escape them with backslashes.
Ant doesn't add those \, it's Java.
See api docs for Properties, especially the store(Writer writer, String comments) method:
The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.
I have an ant project I'm converting to gradle. In the ant project, there is something like this:
<copy todir="dest_dir">
<fileset>
...
</fileset>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
The filter chain expands properties like ${property}, but ignores dollar signs without braces. I'm trying to replicate this behavior in gradle.
If I expand as below, gradle expands the files as a groovy template, which tries to expand dollar signs with braces.
copy {
from 'source_dir'
into 'dest_dir'
expand(project.properties)
}
If I filter with the ant ExpandProperties filter class, I get a NullPointerException. Is there an easy way to do this I've missed?
Ok, I figured this out. The ExpandProperties filter needs its project property set with the Ant project. This is how I got it configured to work:
copy {
from 'source_dir'
to 'dest_dir'
filter(org.apache.tools.ant.filters.ExpandProperties, project: ant.antProject)
}
This expands properties like ${property} exactly the same as Ant, without getting tripped up on dollar signs without braces.
In my ant build file, I have a property 'Version' that contains the version. Ex. 2.5.17.230
Now, I am using propertyregex of ant-contrib to replace all '.' (dot) characters with an underscore. I have written the statement as follows:
<propertyregex property="Version" input="${Version}" regexp="." replace="_" global="true" />
However, it does not work. I have even tried these in vain:
regexp="\." and regexp="[.]"
Can someone please help?
Thanks
The PropertyRegex documentation states that unless the override attribute is set to true, the task will not overwrite the property value if it's already set. And since you're trying to overwrite the Version property, your example will do nothing.
Got it! I was passing the same variable as input. I used another variable 'Version2' to get the result from propertyregex. Here is what it should have been:
<propertyregex property="Version2" input="${Version}" regexp="\." replace="_" global="true" />
Cheers!