How to enable verbose output using the ant task and inheritall="false" - ant

When starting a build in verbose mode (ant -v) the verbose mode is not propagated to the "subants". The ant task looks like this:
<ant antfile="${buildproject}" inheritall="false" target="${target}" output="${output.file}">
<property name="repo.global" value="/repo"/>
<property name="proj.property.prefix" value="${property_prefix}"/>
</ant>
We don't want to propagate all properties because we try to remove an old build system. Any ideas how to preserve the "verbose" output without using the exec task?

I had to deal with something similar just last month. You probably need to define you own task to change the loglevel in a script. The following blog entry (http://codefeed.com/blog/?p=82) helped a lot. The author provides all the necessary source code.

If you don't want to create your own task with all that hassle, there is a embedded-javascript-snippet answer in this SO-question.

Related

JMeter overriding properties with spaces in non GUI mode with ANT

I need to pass parameter values to jmeter properties like this:
#echo off
cd E:\apache-jmeter-2.11\bin
jmeter.bat -n
-t E:\OMS.P01-AccountCreation.jmx
-l E:\result.csv
-j E:\jmeter.log
-Jthreadgroup.count=1
-JPRIMARY_STREET_NUMBER=1234
-JPRIMARY_STREET_NAME=DONALDTRUMP AVENUE
But this will fail as the name 'DONALDTRUMP AVENUE' has an space. It will try to read 'AVENUE' as a different parameter. Is there any way to make it read as a whole value? thanks
EDIT
It works if I add "" to enclose it. However, when I try the same thing with ANT, it throws the same error. Does anyone knows how can I solve it?
EDIT 2
I tried again with command line instead of ant. I think I found the problem. I cant add too many parameters (I'm adding like 22 parameters) I'm not sure if there is a parameter limit or if there is a length limit for the whole command line.
I don't know how you're passing properties to Ant but normally smart people don't have any problems with spaces in property values. Are you aware that:
Ant doesn't know anything regarding -J command line argument
Ant knows nothing about JMeter properties
So if you need to pass to JMeter something you can change via Ant command-line you need to do something like:
In build.xml
<target name="jmeter">
<jmeter
jmeterhome="/path/to/your/jmeter"
testplan ="OMS.P01-AccountCreation.jmx"
resultlog="result.jtl">
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="jmeter.save.saveservice.bytes" value="true"/>
<property name="threadgroup.count" value="${threadgroup.count}"/>
<property name="PRIMARY_STREET_NUMBER" value="${PRIMARY_STREET_NUMBER}"/>
<property name="JPRIMARY_STREET_NAME" value="${PRIMARY_STREET_NAME}"/>
</jmeter>
</target>
When launching JMeter test via Ant:
ant -Dthreadgroup.count=1 -DPRIMARY_STREET_NUMBER=1234 -DPRIMARY_STREET_NAME="DONALDTRUMP AVENUE"
References:
Command prompt (Cmd. exe) command-line string limitation
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Ant attributes duplication for javac

I have an Ant build with a lot of javac tasks.
I want all of them to be executed with the following attributes:
debug = "true" debuglevel = "lines,vars,source"
(by default debugging information is turned off which makes it harder to investigate the console).
Is it possible to provide such attributes in some centralized place which will have influence for all javac tasks in current Ant build? (I don't want duplicating them over all javac tasks...)
You need ant's presetdef
From the example
<presetdef name="my.javac">
<javac debug="${debug}" deprecation="${deprecation}"
srcdir="${src.dir}" destdir="${classes.dir}">
<src path="${gen.dir}"/>
</javac>
</presetdef>
Instead of my.javac, you can put javac.
You can define this in one build file and import every where else.

passing option to ant in cruisecontrol

I have following code in config.xml file:
<schedule interval = "300">
<ant anthome="/usr/share/ant"
antworkingdir="${GitDir}"
uselogger="true"
usedebug="true"/>
</schedule>
And when I execute build through it, I am just getting output, like I've been typing just ant in command line.
I need to be able to execute following command from Cruisecontrol:
ant debug
If this is making any difference, I need to be able to build android application.
How this can be done?
Thank you on advance.
You're already using the right attributes in your config.xml to start your ant scripts with loglevel debug
...
usedebug="true"
...
is equivalent to ant -debug ...
see http://cruisecontrol.sourceforge.net/main/configxml.html#ant for details.

run all tests marked #Ignore

I want to make a Jenkins job to run an ant task to run all tests in my codebase which are tagged #Ignore because using annotations like #Category(IgnoredTest.class) do not work with our test run parallelization. After a lot of searching it looks undoable, but I still have hope. Help?
JUnit 4.10
I'm not sure what the impediment is with your "test run parallelization", but you might be able to do this with a rule if you're willing to use a custom "ignore" annotation instead of the JUnit one. The reason for that is that JUnit handles #Ignored tests at the Runner level, specifically in the BlockJUnit4ClassRunner.runChild() (by default). If you could find a way to use a custom Runner in Ant, you could come up with one to meet your needs pretty easily, but I don't know if that's easily doable in Ant.
As I first mentioned, though, you can easily use a different annotation and a rule to choose which methods to run. I made up a quick example of such a rule on github, along with a test that uses it. My little example uses a system property for switching, but you can also obviously make it switch on anything you can think of that you can get your hands on here.
You can clone and run this example with:
git clone git#github.com:zzantozz/testbed tmp
cd tmp
mvn test -pl stackoverflow/9611070-toggleable-custom-ignore -q
mvn test -pl stackoverflow/9611070-toggleable-custom-ignore -q -D junit.invertIgnores
The one downside of this approach that I can think of is that your tests won't get properly marked as "ignored" because that's also done by the BlockJUnit4ClassRunner.runChild() method, and if you peek at ParentRunner.runLeaf() (which runChild() delegates to), you'll see that the notifier, which is what you need to report ignored tests, isn't passed down far enough to be used by a Rule. Again, it's something you'd need a custom Runner for.
You could create a special ant target that removes the #Ignore annotation and add an #ignore annotation to any active #Test annotated method
the target would be something like this:
<project name="anyname" default="test" basedir=".">
..
..
<target name="enable-ignored-test" depends="copy-code-to-replace-ignored">
<fileset id="fsTestCase" dir="." includes="**/*Test.java">
</fileset>
<replaceregexp flags="gm">
<regexp pattern="^#Ignore"/>
<substitution expression=""/>
<fileset refid="${fsTestCase}"/>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="#Test"/>
<substitution expression="#Ignore #Test"/>
<fileset refid="${fsTestCase}"/>
</replaceregexp>
</target>
<target name="run-ignored-tests" depends="enable-ignored-test,test" />
..
..
</project>

checking latest version in version control

i am currently writing an ANT script which will include some intelligence to check for things. I am using SnapshotCM from True Blue Software as my version control and using CruiseControl as a framework for my nightly build.
Basically, I will need to always check for the latest version found in my version control and execute commands. In this case here is an example:
<project name="nightly_build" default="main" basedir="checkout">
<target name="init">
<property file="initial.properties"/>
</target>
<target name="main" depends="init">
<!-- need some code to set variable -->
<!-- need some code to increment variable -->
<!-- need some code here to check for the latest version -->
<exec executable="C:/Program Files/True Blue Software/SnapshotCM/wco.exe">
<arg line='-f -R "C:/Work/7.10.000_Tip/7.10.000_Tip_GUI_TEST/"'/>
</exec>
</target>
</project>
In the code above, I will load the "initial.properties" file.
The algorithm should be as follow:
load the initial properties file
get the build_number
increment build_number by 1 (let this new variable be X)
if X is found, increament X by 1 (if not found jump to 6.)
if X is found, repeat 4 (until X cannot be found)
else use the build number inside the <arg line ='-f -R "C:/..../7.10.100.X..../"'/>
The initial.properties file is as follow:
Major_Version=7
Minor_Version=10
Project_Number=100
Build_Number=036
Product_Version=${Major_Version}.${Minor_Version}.${Project_Number}.${Build_Number}
can anyone guide me on that?
Ant is not a programming language. It's a dependency matrix language.
That means you don't specify execution order in Ant. Ant will calculate the order it needs to run the targets. It also means Ant doesn't have the ability to do loops, or even change the value of a property once it is set.
There are a few packages that build upon Ant. The old standby is the Antcontrib. Antcontrib has the concept of variables which are like mutable properties. It also has various looping structures. However, I'm not sure if the <foreach> or <for> tasks will do what you want...
Searching sequentially for the next build number is something you can do in a shell script. In fact, I highly recommend this.
I use Ant for builds only and keep my CM functions outside of my build.xml file. Instead, I rely on my build system to do everything that's not related to the build itself. This includes checking out the code, saving the artifacts, and compiling unit tests. This way, if I change the way I use my continuous build system or my version control system, I don't have to modify my build.xml files.

Resources