Ant add trailing zeros - ant

Hello i have a variable in Ant: ${env.BUILD_NUMBER}
And i wan't that this variable is always 6 characters long.
If not Ant should add trailing zeros.
1 should be 100000
39 should be 390000
5656 should be 565600
How is this possible using a Ant build script?
Thanks!

There is a solution using the PropertyFile Ant task described here: Re: Zero-Padding an Int Ant Property
You may also want to checkout the propertyregex task from Ant Contrib. See Replacing characters in Ant property

Related

Using Xtext from command line

I'm trying to achieve an independent command line flavor of Xtext
Input: grammar file (grammar.xtext)
Output: interpreter jar file (interpreter.jar)
Usage:
java -jar interpreter.jar input.mydsl
If input.mydsl has incorrect syntax, interpreter prints "ERROR" and exists
If input.mydsl has correct syntax, it should be interpreted.
I look for a complete solution based on maven that ideally has the following features:
small grammar, for instance, calculator of ints and strings
interpretation of 5+8*2 -> 21
interpretation of "abcd"+"ef" -> "abcdef"
simple type checker (5 +"text" -> error)
simple maven pom.xml that newbies can understand
easily ported to web (later)

Build with parameters in Jenkins

I have a script which runs a Jenkins job using buildWithParameters. The values given here contain "#" and this character is recognized as a comment, not as a character from that value:
http://jenkins:8080/job/test/buildWithParameters?token=token&var1=test#1&var2=test#2
In job var1 is test and var2 has no value.
Can you help me to resolve this issue?
I have found the solution. The "#" was replaced with "%23", the hex code of #.
http://jenkins:8080/job/test/buildWithParameters?token=token&var1=test%231&var2=test%232

How ant works when targets are repeated during runtime

I am a total noob with ant but more or less I have an idea about how it works. I have come across a situation that I fail to understand and I would appreciate any help.
This is going to be a bit long, sorry. I am trying to make it as clear as possible.
I have a set of targets that works like this : I will use "-" as substitute of "depends" :
- B - D - E - E1 - E2 unless property2 - E3 If property3 - E4 unless property4 - E5 - E6
doc-contracts
- C - E - E1 - E2 unless property2 - E3 If property3 - E4 unless property4 - E5 - E6
Just in case it is a bit confusing, "doc-contracts" depends on B and C and both paths end up calling target E.
This is the code of "doc-contracts" :
<target
name="doc-contracts"
depends="B,C"
description="Generates the documentation for contracts and annotations"
>
<foreach
target="doc-contracts-single"
param="doc-contracts-single.file"
inheritall="true"
>
<path>
<fileset dir="${properties.src.dir}">
<include name="*/*.csv"/>
</fileset>
</path>
</foreach>
</target>
Basically, for each csv it will call the target "doc-contracts-single". "doc-contracts-single" needs a path reference "pathReference" that is set inside target E.
The thing is that, when I run "doc-contracts" I get this output:
E6
E5
E4
E2
E1
E
D
B
C
doc-contracts
doc-contracts-single
ERROR: Reference pathReference has not been set at runtime, but was found during build file parsing, attempting to resolve. Future versions of Ant may
support referencing ids defined in non-executed targets.
doc-contracts-single
ERROR: Reference pathReference has not been set at runtime, but was found during build file parsing, attempting to resolve. Future versions of Ant may
support referencing ids defined in non-executed targets.
END
I have 2 questions:
As you can see, it only goes through E one time and I don't know why. I can understand that, once the first "branch" (B and all its tree of dependencies) the flow
could be interrupted in E2 if property2 is set (which I am pretty sure, it is what is happening). But then the code should at least go through E and E1 again since those 2
tasks doesn't have any condition, isn't it?. I have put echoes in all targets and it simply won't go inside targets E and E1. Under my understanding I should be getting this output:
E6
E5
E4
E2
E1
E
D
B (end of "first branch", which would be B and the chain of targets it generates)
E1
E
C (end of "first branch", which would be B and the chain of targets it generates)
doc-contracts
doc-contracts-single
ERROR: Reference pathReference has not been set at runtime, but was found during build file parsing, attempting to resolve. Future versions of Ant may
support referencing ids defined in non-executed targets.
doc-contracts-single
ERROR: Reference pathReference has not been set at runtime, but was found during build file parsing, attempting to resolve. Future versions of Ant may
support referencing ids defined in non-executed targets.
... (once for each .csv it finds)
END
Is this correct? Am I missunderstanding how ant flow works?
As I said before, the error I get when doc-contracts-single is executed is the following:
With ant 1.7 -> Reference pathReference has not been set at runtime, but was found during build file parsing, attempting to resolve. Future versions of Ant may
support referencing ids defined in non-executed targets.
With ant 1.9 -> Error as expected from the message in ant 1.7
I have echoed the content of "pathReference" and it looks fine and well defined until target "doc-contracts" calls "doc-contracts-single". Inside "doc-contracts-single"
the reference is lost. Can anyone explain to me why? I thought that when you set a path reference in your project, it could be used at any point in the rest
of the project. I can only think about 2 options:
1- Either some part of the script is deleting it's content, and I can't find which line is doing this
or
2- Because "doc-contracts" and "doc-contracts-single" are not related with "depends" (instead, one calls the other), they are in different scopes and the references set with one are not visible
from the other.
Sorry for such a long post. I have tried my best to explain the problem as clear as possible. Thanks in advance for your answers!

Remove "[string]" from BUILD_LOG_REGEX extracted lines

Here is my sample string.
[echo] The SampleProject solution currently has 85% code coverage.
My desired output should be.
The SampleProject solution currently has 85% code coverage.
Btw, I had this out because I'm getting through the logs in my CI using Jenkins.
Any help? Thanks..
You can try substText parameter in BUILD_LOG_REGEX token to substitute the text matching your regex
New optional arg: ${BUILD_LOG_REGEX, regex, linesBefore, linesAfter, maxMatches, showTruncatedLines, substText} which allows substituting text for the matched regex. This is particularly useful when the text contains references to capture groups (i.e. $1, $2, etc.)
Using below will remove prefix [echo] from all of your logs ,
${BUILD_LOG_REGEX, regex="^\[echo] (.*)$", maxMatches=0, showTruncatedLines=false, substText="$1"}
\[[^\]]*\] will match the bit you want to remove. Just use a string replace function to replace that bit with an empty string.
Andrew has the right idea, but with Perl-style regex syntaxes (which includes Java's built-in regex engine), you can do even better:
str.replaceAll("\\[.*?\\]", "");
(i.e., use the matching expression \[.*?\]. The ? specifies minimal match: so it will finish matching upon the first ] found.)

Strip Newline Character from command line output in Ant

I am writing an ant build script that does a sshexec and returns the output of the command ran into the outputproperty attribute.
The value of the outputproperty has a newline character on the end of them. Anyway I can strip that newline character from the output?
Regards,
Stephen
I managed to find the answer: The newline character represented by &#10 can be used when using the <equals> command.
Regards,
Steve

Resources