error while building project using Nant - nunit

I have file pro.build:
<?xml version="1.0" ?>
<project name="NAnt.NUnit2ReportTasks" default="build" basedir=".">
<sysinfo />
<target name="nunitreport">
<nunit2report out="HTML_TestResults.html">
<fileset>
<includes name="NUnitTestResult.xml" />
</fileset>
</nunit2report>
<echo message="HTML Test report generated." />
</target>
</project>
From command prompt(DOS), I am giving command,
Nant -buildfile:pro.build
But I am getting error
Target 'build' does not exist in this project
Can you help me resolving this?

With <project>'s default attribute you specify the target which should be executed if no other target is specified on the command line.
Problem: On the command line you're calling Nant -buildfile:pro.build so you are not specifying a target there. NAnt tries to execute default target build which is not present and fails.
Solution: Either you specify target nunitreport on the command line by calling Nant -buildfile:pro.build nunitreport. But since specifying a non-existent default target in your build file doesn't make much sense, I would suggest changing the default target:
<project name="NAnt.NUnit2ReportTasks" default="nunitreport" basedir=".">
<!-- ... -->
</project>

Specifing complete path for the buildfile could resolve the issue
nant –buildfile:"c:\FolderpathofAppdotbuildfileGoesHere\buildfilename.build"

Related

Phing update version number in XML manifest

I need to add the ability to a phing build to:
Parse an existing xml file within the project area to get an existing build number (in format 1.2.3)
Ask the user what type of 'change' this is (i.e. major, minor, fix)
Based on the response of the user at the time of run, upgrade the respective digit from the build number (if major increase 1 by 1; if minor increase 2 by 1; if fix increase 3 by 1)
Store the build number back into the original xml file
Have the new build number available for use when naming a zip file (later in the build).
Wondering if anyone already has a phing build file that does something like this or if you happen to know what phing tasks might help with these steps?
As a starting point you could do it without overhead using the version task (it uses a property file to store the version information) or with some more effort from a xml file.
The following example build script (documentation links can be found in the description attributes) contains both ways.
<?xml version="1.0" encoding="UTF-8" ?>
<project name="version test"
default="help"
phingVersion="3.0"
description="https://stackoverflow.com/questions/68584221/phing-update-version-number-in-xml-manifest"
>
<target name="help" description="usage help">
<echo>Usage:</echo>
<echo>bin/phing xml-file-based-workflow</echo>
<echo>bin/phing property-file-based-workflow</echo>
</target>
<target name="xml-file-based-workflow"
description="version handling with xml file"
depends="user-input,handle-xml-version,use-version"
/>
<target name="property-file-based-workflow"
description="version handling with property file"
depends="user-input,handle-property-version,use-version"
/>
<target name="user-input"
description="https://www.phing.info/guide/hlhtml/#InputTask"
hidden="true"
>
<input message="what is your release type?" propertyName="release.type" defaultValue="Bugfix"/>
</target>
<target name="handle-property-version"
description="https://www.phing.info/guide/hlhtml/#VersionTask"
hidden="true"
>
<version releasetype="${release.type}" file="VERSION.txt" property="version.number"/>
</target>
<target name="handle-xml-version"
description="
https://www.phing.info/guide/hlhtml/#XmlPropertyTask
https://www.phing.info/guide/hlhtml/#EchoPropertiesTask
https://www.phing.info/guide/hlhtml/#VersionTask
https://www.phing.info/guide/hlhtml/#DeleteTask
https://www.phing.info/guide/hlhtml/#EchoXMLTask
"
hidden="true"
>
<xmlproperty file="VERSION.xml" />
<echoproperties destfile="VERSION.txt" regex="/version\.number/"/>
<version releasetype="${release.type}" file="VERSION.txt" property="version.number"/>
<delete file="VERSION.txt"/>
<echoxml file="VERSION.xml">
<version>
<number>${version.number}</number>
</version>
</echoxml>
</target>
<target name="use-version"
description="https://www.phing.info/guide/hlhtml/#EchoTask"
hidden="true"
>
<echo message="${version.number}" />
</target>
</project>

eclipse.buildScript Complete Example Script for headless build

I am trying to generate a build script for a plugin outside the IDE
Below is mybuild.xml
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
<target name="build.plugin">
<antcall target="generateBuildScript" />
<ant dir="${workspace.dir}/${project.name}"
antfile="build.xml"
target="build.update.jar" />
<copy todir="${eclipse.dir}/plugins">
<fileset dir="${workspace.dir}/${project.name}">
<include name="*.jar"/>
</fileset>
</copy>
</target>
<target name="generateBuildScript">
<eclipse.buildScript elements="plugin#${project.name}"
buildDirectory="${workspace.dir}"
baseLocation="${eclipse.dir}"
configInfo="linux,gtk,win32,win32,x86"/>
</target>
</project>
Expecting build.xml to be generated Please Guide me
When I run above script
$java -jar {$Eclipse.Dir}/plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar -application org.eclipse.ant.core.antRunner -buildfile <Project_path>\mybuild.xml
I nothing is happening on build success.
Here i have found the answer may help some new bees like me..
<project name="com.foo.poo" xmlns='antlib:org.apache.tools.ant'>
...
</project>
As there is no default set, it is not generating the required jar file so
modified only the first line as
<project name="com.foo.poo" default="build.plugin" xmlns='antlib:org.apache.tools.ant'>
...
</project>
now the required jar is generated under plugin folder and even copied to plugin folder of eclipse.
baseLocation : Target Plugins Directory absolute path.
buildDirectory: Absolute path to the plugin folder in which the Plugin Project is present.

Setup Netbeans project on Jenkins

I have a Netbeans Project that I'm trying to build from Jenkins, using ant, in a linux environment.
I have copied the CopyLibStack.jar to /var/lib/Jenkins/nblibs/ and setup in the ant task with the following properties:
-Dj2ee.server.home="/var/lib/jenkins/tomcat/"
-Dlibs.CopyLibs.classpath=/var/lib/jenkins/nblibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
But it doesn’t work; it fails on a <copyfiles> task
If I install Jenkins on windows and set the properties to:
-Dj2ee.server.home="C:\Archivos de programa\Apache Software Foundation\Tomcat 6.0"
-Dlibs.CopyLibs.classpath=C:\\.jenkins\\nblibs\\org-netbeans-modules-java-j2seproject-copylibstask.jar
The project build without problems
If I run the ant task from the terminal with:
ant -file build.xml do-dist test -Dlibs.CopyLibs.classpath="/var/lib/jenkins/nblibs/copylibstask.jar" -Dj2ee.server.home="/var/lib/jenkins/tomcat/"
it builds fine too
I think that the problem is in the user jenkins, but I don't know how to fix it.
What can I do?
I had the same problem, which I have fixed :) (I'm using ubuntu 12.04). Find build.properties in ".netbeans/7.0" and look for the lib that you are missing... copy it to project.properties
Ex:
libs.CopyLibs.classpath=/opt/netbeans-7.0.1/java/ant/extra/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.javaee-api-6.0.classpath=/opt/netbeans-7.0.1/enterprise/modules/ext/javaee-api-6.0.jar
I found a recipe in this link basically you have to have Netbeans installed on your server so you can reuse the build.xml generated by Netbeans.
Create a file jenkins-build.xml at the same level as your build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="BioGatewayWS Stub" default="build" basedir=".">
<!-- create private folders -->
<mkdir dir="nbproject/private"/>
<!--- set variables needed by Ant when outside of Netbeans -->
<propertyfile file="nbproject/private/private.properties">
<!--<entry key="user.properties.file" value="/opt/NetBeans8/build.properties"/>-->
<entry key="user.properties.file" value="C:\Users\jm\AppData\Roaming\NetBeans\8.2\build.properties"/>
</propertyfile>
<!-- Build targets - these just chain a call to the original build file-->
<target name="build">
<!-- <ant dir="${basedir}" target="build"/>-->
<ant dir="${basedir}" target="default"/>
</target>
<target name="clean">
<ant dir="${basedir}" target="clean"/>
</target>
</project>
and run Ant:
ant -file jenkins-build.xml clean
ant -file jenkins-build.xml build
Thanks to the original author matt

NAnt ignoring property in included build file

I'm trying to make my project build file include a local build file, to allow for some customization for each developer, without having to keep exclulding the build file from version control commits etc.
But NAnt keeps ignoring the properties in my included build file, and not overwriting the properties set in the global build file.
For demo purposes this short build file behaves the same:
<project name="FooProject" default="showme" basedir="." >
<description>Foo</description>
<!-- Overwrite this property in local.build -->
<property name="database.connectionstring" overwrite="true" readonly="false" value="foo" />
<include buildfile="local.build" failonerror="true" verbose="true" />
<target name="showme" description="Show connectionstring variable">
<echo message="Connectionstring: ${database.connectionstring}" />
</target>
</project>
-and my local.build file looks like this:
<property name="database.connectionstring" value="bar" />
The expected output when running NAnt with this build file is "Connectionstring: bar", but the resulit is "Connectionstring: foo", no matter which combination of readonly and overwrite I try.
It does fail if I rename the file to something else, so NAnt is aware of the included file.
NAnt is v0.91 alpha.
Am I overlooking something or is NAnt not supposed to work like I expect?
It seems you should still wrap the contents of the included build file inside a project-element. Like so:
<project>
<property name="database.connectionstring" value="bar" />
</project>
When I did that the connectionstring was "bar".
Granted: I use Nant 0.91 final.

how to encode in Ant

I have a test script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" basedir=".">
<echo encoding="UTF-8" file="test.txt">测试</echo>
</project>
When I open test.txt. I only see "??"
Something more weird. The script run with no problem using Eclipse Ant tool, but it has problem with command line.
Both Eclipse and cmd are using the same Ant lib.
Use this encoding :
<echo encoding="UnicodeLittleUnmarked" file="test.txt">测试</echo>
And you will get the correct result in your file.
I found the reason.
Before running the Ant script, I need to set a system property:
Set ANT_OPTS=-D"file.encoding=UTF-8"
Then
<project name="test" basedir=".">
<echo file="test.txt">测试</echo>
</project>
runs successfully even if there is no encoding in the echo.
Can anyone tells me why the original one doesn't work?