What does fork="true" do in nant script targets? - nant

What is the difference between
<target name="target_fork" description="with fork" fork="true">
</target>
and
<target name="target_nofork" description="no fork">
</target>
I always thought it meant that the target would come back and continue execution when it calls other targets or external build files only if fork is true. But some quick nant test scripts are not proving this.

Updated:
The property fork=true has no effect.
The term fork usually means that the code you run in a task, not target as you suggest, will execute in a different process (Virtual Machine in Java-lingo).
It is up to the implementer of a task, for instance NUnit in NAnt or the Java task in ANT, to define meaning of the fork property.

Related

Unittest an entire netbeans application including dependent projects

Here is the situation:
I have a java application (netbeans project) that uses several java libraries (each of them is a netbeans project). I have an automated build script that builds the application using ant without the netbeans IDE. The command to build the application is
ant jar
That works fine, it recursively builds jars for all dependent libraries and finally the application jar.
Now, I want to run all my unit tests in the automated build. The default ant target depends on the targets jar, test, and javadoc, so I thought I could simply call
ant
as the build command. As before, all jars are built for the dependent libraries, but only the unit tests for the application project are executed (same for javadoc, btw.).
So, how do I get ant to run the unit tests for each dependent library project recursively?
Used versions are: netbeans 8, junit 4.
The only solution I found is to add a dependency into the build.xml used by ant for every library and the application project:
<target name="-pre-jar" depends="test" />
But that would mean to execute all tests on every build of a jar file. And since netbeans uses these build.xml files as well, every simple build would lead to executing all unit tests.
After some testing I think I've found a solution that works.
I had to add the following code into the build.xml of each netbeans project whose unit tests should be run (fyi: the build.xml is provided by netbeans for personal changes to the build process).
<target name="-pre-jar" depends="test-on-release" />
<target name="test-on-release" if="release.runtests">
<antcall target="test" />
</target>
Then, if I run ant on the commandline I have to define the property release.runtests to enable the execution of unittests:
ant -Drelease.runtests= jar
If I remove the definition of the property from the call, the target test-on-release is not executed and thus the tests are not run. The same happens when I use the netbeans IDE to build a project.
That said, it is a solution, not the solution, at least not the solution I had hoped for. It would be much more convenient if there was a way to run the test target recursively without having to edit all these build.xml files. Maybe that is not possible with the constraints given by the netbeans-generated build files.

Eclipse: Automatically run Ant scripts in sequent order

I am using Eclipse's Ant view to run my build files. I have to run a couple of files in a specific order and I wonder whether there is any possibility to automate this (I'm sure there is...). However, they need to run subsequently, i.e. script two may not start until script one finished successfully. Most of my Ant scripts trigger Maven commands.
Is there any Eclipse plugin or feature that can assist me in running my Ant files automatically? Maybe even shutdown and restart my Java EE server before and after building?
I'd like to double-click just once and have my toolchain work, while I... get myself another cup of coffee.
I can think of two options:
Write a wrapper Ant script/target that calls the others in the desired order. It's been a number of years since I wrote any Ant but I remember doing that, probably using the <ant> task. It might make sense to simply define a target that has dependencies/prerequisites in the right sequence (in conjunction with the <import> task to pull in the separate buildfiles). Here is a discussion about the difference between these two approaches.
Use Eclipse's External Tool feature to invoke a batch/shell script that calls each Ant target.
This is what I finally came up with:
<project default="all" basedir=".." name="Build all projects">
<property name="folder.project.a" value="MyProjectA" />
<property name="folder.project.b" value="MyOtherProjectB" />
<!-- Target to build all projects -->
<target name="all" depends="projectA, projectB" />
<target name="projectA">
<echo>Building project A.</echo>
<ant antfile="${folder.project.a}/my_build_file.xml" />
</target>
<target name="projectB">
<echo>Building project B.</echo>
<ant antfile="${folder.project.b}/my_other_build_file.xml" />
</target>
</project>

How to run junit tests at build time in netbeans and jenkins?

I'm trying to set up a project to run junit tests at build time, so that every member of the team and the Jenkins build server runs the tests when it builds.
I believe we have set up a fairly standard webproject in Netbeans, but I can't seem to find anyone solving this problem on stackoverflow or google.
How would you go about doing this?
Go to file: /nbproject/build-impl.xml and fidn the dist target. It should look like this:
<target depends="init,compile,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/>
Copy paste it into /build.xml, and add the "test" target into it:
<target depends="init,compile,test,-pre-dist,do-dist,-post-dist" description="Build distribution (WAR)." name="dist"/>
This was in Netbeans 7.3. It now builds and runs the tests on every build, also on the Jenkins build server.
Never modify your build-impl.xml! Netbeans regenerates this file when you perform any changes to your project.
The better approach would be to modify your build.xml and add a post-jar task:
<target name="-post-jar" depends="test"/>

Call custom tool from TFS build

We are using TFS2010 for our web sites's builds and we're in the process of creating fully automated builds. At the moment the sites are built and deployed in remote servers.
The sites contains several configuration files that we would like to transform as part of the build. As there are some rules to create the correct config files we would like to use a custom tool for that purpose (.exe), not to use xml transformations for it.
From what we can see in the build template, MSBuild copies the files to a drop folder and then pushes them to the remote IIS site. We would like to hook our custom tool to this process and do the transformations in the build server before the site is published. The problem is that the MSBuild task is a single node in the build template and we can't find a place where to invoke our tool. Before the MSBuild step, there is no code deployed to the drop folder, after the MSBuild step the code was already deployed to the remote server.
Any ideas on how to plug the custom tool in the correct workflow step?
What is the msbuild target, that you use? I think you can define your own target in csproj file to do the following:
execute your custom tool against required files
run usual build target (or whatever target you normally use)
Edit
E.g. in a .csproj file you could define the following:
<Target Name="buildWithCustomTool">
<!-- Exec your custom tool -->
<Exec Command="your command" />
<!-- Call the build target which will run as normally -->
<CallTarget Targets="Build" />
</Target>
Hope it helps,
Ivan

NAnt script for running multiple test assemblies

I'm just getting into TDD, and from looking around, the general concensis seems to be to have a one to one mapping from a code project to a test project. My question is, if you follow this route, and have multiple test assemblies, what is the best way to run these as part of an NAnt script? If it makes a difference, I am using NUnit as my testing framework.
You can create a "test project" via the NUnit GUI, and save it to a file. In the GUI, you can add to the project the test dlls, which in turn reference the ones under test.
You can then pass that file to the NUnit console from within NAnt. e.g.
<property name="nunit.output" value="${dir.reports.nunit}\nunit-results.xml" />
<property name="nunit.input" value="proj.nunit" />
<exec program="${dir.tools}\nunit\bin\nunit-console.exe" failonerror="true">
<arg value="${nunit.input}" />
<arg value="/xml:${nunit.output}" />
</exec>
This way, NAnt need not know about the test dlls, just the NUnit project that contains that information.
I'd suggest the best way to go about this is to compile both projects from NAnt individually using the CSC command referencing each project file (csproj) rather than the solution. Then use the nunit-console command (as a separate Nant task) to execute your tests.
Whether you have one build large script/file that does this or separate separate ones for each project or task is up to you (or how complex your projects are).
The way I have my team's builds set up is that I have one 'master' build script which calls into other build scripts to perform specific tasks. For example 'master' calls 'compile' and then 'test' (passing in the results of the 'compile' script appropriately). This way the compilation of my core project is separated from the automated testing.