Using the nested element module in cvs task in ant build.xml - ant

I have problems connecting to CVS using ant build.xml.
I figured out the reason was whitespaces in package attribute of CVS task as:
<cvs cvsRoot=":pserver:user#xx.xxx.xxx.xx:/CVSREPO_CCP_MIG" dest="${basedir}" package="My Test Project"/>
I learned from the ant website( http://ant.apache.org/manual/Tasks/cvs.html ) that we may Use a nested <module> element if you want to specify a module with spaces in its name. This specifies a package/module to work on, unlike the package attribute, modules specified using this attribute can contain spaces in their name.
I tried using the following:
<cvs cvsRoot=":pserver:user#xx.xxx.xxx.xx:/CVSREPO_CCP_MIG" dest="${basedir}">
<module name="My Test Project"/>
</cvs>
This again complains:
build.xml:39: cvs doesn't support the nested "module" element.
How can I use the module element with the CVS tag?
The Ant version is 1.7.x.

As suggested by the comments above, the nested "module" element is available for Ant ver 1.8 +.
However, if you are on one of the earlier versions, you may specify your package/module name under package attribute of CVS task by adding '"' on the either end of the attribute value.
e.g. We can replace package="My Test Project" with package=""My Test Project"" in here.

Related

Ant: Are jarfile and destfile the same?

In the Ant documentation on the jar command, it says that the destfile attribute is required.
However there is an example at the bottom that uses the jarfile attribute and does not use the destfile attribute. Also, I have functioning code from a work colleague that uses the jarfile attribute in a build.xml file for a Netbeans project.
So it would seem that destfile is not required, or can be replaced by jarfile.
Are jarfile and destfile identical?
Are there cases where you should use one and cases where you should use the other?
Thanks in advance
Yes, jarfile is a deprecated alias for destfile.
The implementation of jar is a subclass of the implementation of zip - as is ear and war. Each of them has a special (zip|jar|war|ear)file attribute. With Ant 1.5 we decided to unify this to destfile and deprecate the task-specific attributes.
Obviously we forgot to update all references inside the manual :-)

In Gradle how do I reference an imported ant task with special chars?

I have an ant build which contains tasks of format
build
build.foo.bar
So to add dependencies in gradle the first one is easy
build.dependsOn(...)
But the second one is interpreted as method nesting. I suspect there's a standard groovy way to do this but I haven't cracked it.
How do I reference an ant task containing periods in an build.gradle file?
project.tasks['build.foo.bar'].dependsOn(...)
should do the trick.
See Project.tasks, which returns a TaskContainer (extending TaskCollection), and TaskCollection.getAt() which, as its doc says, can be called using the [] operator.

how i can traverse the xml path dynamically in antscript?

Could anyone tell me, how can I traverse the xml path dynamically in antscript? If the parent tag is given from command line arguement. with this , i have to form child tag path ..access the xml file , to pull the value form the formed xml tag path.
ant -DId=abc
Given file is
<abc>
<Age>16</Age>
</abc>
Is this correct to give output 16?
<echo>${${Id}.Age}</echo>
ANT is not a scripting language, and properties within properties is unfortunately not supported :-(
My suggested solution is an embedded groovy script
<target name="parse">
<groovy>
def data = new XmlSlurper().parse(new File("data.xml"))
println data.Age
</groovy>
</target>
Conveniently (in your case) the groovy xml parser ignores the name of the root tag, meaning you don't have to pass it as a parameter.
See also the following similar question:
How to <foreach> in a <macrodef>?

Can I add conditional defines in the msbuild command line?

I have the following sample code:
program boohoo;
{$APPTYPE CONSOLE}
{$IFDEF boo}
{$MESSAGE warn 'boo'}
{$ENDIF}
{$IFDEF hoo}
{$MESSAGE warn 'hoo'}
{$ENDIF}
begin
end.
In the project options the conditional boo is defined. I would like to be able to add the conditional hoo as part of my msbuild command line.
I have tried it like this:
msbuild boohoo.dproj /p:Config=Release;DCC_Define="$(DCC_Define);hoo"
The output shows hoo but not boo. When I use verbose output to see the dcc32 command I see
-D$;hoo
Clearly I can do it like this:
msbuild boohoo.dproj /p:Config=Release;DCC_Define="boo;hoo"
but naturally I want to use whatever conditionals are declared in the project options plus what I specify on the command line.
Is there any way for me to specify this property with reference to the value from the underlying configuration?
Disclaimer: don't use MsBuild myself yet, all taken from the docs and some IDE experimentation
According to MsBuild command line reference ( http://msdn.microsoft.com/en-us/library/ms164311.aspx ):
/property:name=value
Sets or overrides these project-level properties, where name is the
property name and value is the property value. Use a semicolon or a
comma to separate multiple properties, or specify each property
separately. /p is also acceptable. For example:
/property:WarningLevel=2;OutputDir=bin\Debug
setting or overriding is all you can do for a property value. Adding to a property value from the project file is either not possible or a case of a hidden feature.
But I guess what you could do is define a custom property in your dproj file with an " " as its default value:
<PropertyGroup>
<ExtraDefines> </ExtraDefines>
</PropertyGroup>
reference that in your defines statement
<DCC_Define>DUNIT;$(ExtraDefines);$(DCC_Define)</DCC_Define>
which in the IDE should be DUNIT;$(ExtraDefines)
and then specify it on the command line:
msbuild boohoo.dproj /p:Config=Release;ExtraDefines="hoo"
I did test adding the $(ExtraDefines) to the Include options for the project using the IDE. And at least that didn't barf at me, even without having the option defined in the dproj. The commandline the IDE produced from this was:
...rad studio\7.0\bin\dcc32.exe --no-config -B -Q -DDEBUG;DUNIT; -E....
Which seems to indicate that the $(ExtraDefines) got eliminated as it had no value. And that it should be picked up using MSBuild and specififying a value on the command line.
Almost 5 years later, but all answers are not quite elegant ))
Recently, I've faced the same problem
And here is the solution:
Usually, DCC_Define is defined in a .dproj file like this:
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_Define>boo;$(DCC_Define)</DCC_Define>
We all have tried to define DCC_Define via /property:DCC_Define=blah-blah
But accordingly to How to: Build the Same Source Files with Different Options:
The property value that is specified on the command line takes precedence over any value that is set for the same property in the project file, and that value in the project file takes precedence over the value in an environment variable.
So, failure (that is the question here!)
BUT! How to: Use Environment Variables in a Build
To use an environment variable in an MSBuild project
Reference the environment variable the same way you would a variable declared in your project file. For example, the following
code references the BIN_PATH environment variable:
<FinalOutput>$(BIN_PATH)\MyAssembly.dll</FinalOutput>
So, we must define environment variable with the name DCC_Define and values of our ADDITIONAL conditionals
> set DCC_Define=hoo;doo;moo;foo
and then simply run
> msbuild boohoo.dproj /p:Config=Release
DCC32 will get then -Dboo;hoo;doo;moo;foo
Straightforward solution is to create a new build configuration (say, boohooRelease), add both boo and hoo conditional defines to it and compile as msbuild boohoo.dproj /p:Config=boohooRelease. Not exactly what you are trying to do, but it works.
I just tried the following and it worked, so don't know whether Microsoft has changed it:
msbuild "myApp.dproj" /t:build /property:DCC_Define="boo"
remember to add the double quote "", otherwise it won't work
Another way is to create a wrapper project file like this:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Full" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Full">
<CreateProperty Value="$(DCC_Define);$(ExtraDefines)">
<Output TaskParameter="Value" PropertyName="DCC_Define"/>
</CreateProperty>
</Target>
<Import Project="example.dproj" />
</Project>
and invoke like this:
msbuild.exe "/t:Clean;Full;Build" "/p:config=Debug" /p:ExtraDefines=SOME_DEFINE wrapper.proj
It is certainly less elegant but you don't have to modify the .dproj file.

How can an ANT build file insert the version number in the generated Javadocs?

I use an ANT build file to build my project and also generate the JavaDocs with it. Therefore I use the "javadoc"-command from ANT. Until now I have the version number inserted directly in the .java-file with the "#version"-literal. So if I want to increase the version number I have to open every .java-file and change the number.
Is it possible to define the version number once in the ANT file and let ANT insert this version number into the JavaDocs itself? How can you do this?
Looking at the available options of the JavaDoc task I would use the Header atribute/element which allows to include HTML text defined in every generated file. The HTML text is defined in the the ANT task similar to the doctitle attribute:
<javadoc ...>
<header><![CDATA[<p>Version: ${myversion}</p>]]></header>
</javadoc>
http://ant.apache.org/manual/Tasks/javadoc.html

Resources