I want to know if this is possible:
Referring to files in zipfileset which may or may no exist due to build output
how can i handle this in zipfileset
Any ideas?
Thanks
Regards
Karthik
Include/exclude works for files, but not directories.
At least as of 1.8.x (which is what I'm using, didn't check 1.6), you can use:
<zipfileset dir="something" prefix="" erroronmissingdir="false">
to not yield that error.
The "erroronmissingdir" attribute allows a fix for this condition.
I don't see any problem with it.
Here is an example zip (jar) file:
$ jar tvf src.zip
0 Wed Nov 30 11:54:38 GMT 2011 META-INF/
62 Wed Nov 30 11:54:38 GMT 2011 META-INF/MANIFEST.MF
0 Wed Nov 30 11:53:28 GMT 2011 src/
0 Wed Nov 30 11:57:14 GMT 2011 src/a/
0 Wed Nov 30 11:53:38 GMT 2011 src/a/exists.txt
0 Wed Nov 30 11:57:14 GMT 2011 src/a/other.txt
Here is an example build file to test the behaviour of zipfileset for existent and non-existent files:
<project default="test">
<target name="test">
<pathconvert property="found">
<zipfileset src="src.zip">
<include name="src/a/not-exists.txt"/>
<include name="src/a/exists.txt"/>
</zipfileset>
</pathconvert>
<echo message="found: ${found}"/>
<mkdir dir="extract"/>
<copy todir="extract">
<zipfileset src="src.zip">
<include name="src/a/not-exists.txt"/>
<include name="src/a/exists.txt"/>
</zipfileset>
</copy>
</target>
</project>
Here is the output from this sample:
$ ant
Buildfile: C:\tmp\ant\build.xml
test:
[echo] found: C:\tmp\ant\src.zip:src/a/exists.txt
[mkdir] Created dir: C:\tmp\ant\extract
[copy] Copying 1 resource to C:\tmp\ant\extract
BUILD SUCCESSFUL
Total time: 0 seconds
There are no errors from the attempt to access non-existent files.
And here is the result in the dir files were copied to from the zip:
$ find extract/
extract/
extract/src
extract/src/a
extract/src/a/exists.txt
Related
I am trying to read a property file (xml) in ANT.
Following is the sample data.
<WebLogicDomain>
<Domain>MyDomain</Domain>
<Environment>DEV</Environment>
<Servers>
<Server id = '1'>
<Host>Host1</Host>
<Port>14100</Port>
<AliasName>adminserver</AliasName>
<IsAdmin>true</IsAdmin>
<AdminServerHost>adminHost</AdminServerHost>
<ClusterName>#NA</ClusterName>
<MinHeap>512MB</MinHeap>
<MaxHeap>2048MB</MaxHeap>
</Server>
<Server id = '2'>
<Host>Host2</Host>
<Port>14110</Port>
<AliasName>managedserver01</AliasName>
<IsAdmin>false</IsAdmin>
<AdminServerHost>adminHost</AdminServerHost>
<ClusterName>Cluster1</ClusterName>
<MinHeap>512MB</MinHeap>
<MaxHeap>2048MB</MaxHeap>
</Server>
</Servers>
</WebLogicDomain>
With this property file I can easily access Domain & Environment properties but How do I get specific Server Properties?
If I need to get ${WebLogicDomain.Servers.Server[1].Host} i.e Host present at index 1, how do I get that?
Follwoing doesn't work as expected.
<project name="SampleProject">
<xmlproperty file="buildproperties.xml" />
<target name="init">
<echo> ******** XML property file has been loaded. ******** </echo>
<echo> Domain name is : ${WebLogicDomain.Domain}</echo>
<echo> Environment is : ${WebLogicDomain.Environment}</echo>
<echo> First Server Details are : ${WebLogicDomain.Servers.Server[1].Host} </echo>
</target>
</project>
When I run the init target, I get following error.
init:
[echo] ******** XML property file has been loaded. ********
[echo] Domain name is : MyDomain
[echo] Environment is : DEV
[echo] First Server Details are : ${WebLogicDomain.Servers.Server[1].Host}
When Ant's xmlproperty task finds multiple elements with the same name in the same location, it saves them to a single property as a comma-delimited list. Try using the xmlproperty task to view all the properties that your build has loaded, along with corresponding nested elements. DOM information, unfortunately, is mostly lost. You can try to rely on the order in which the properties are listed, using regex to extract the relevant information, but this will almost certainly be awkward and unreliable.
<xmlproperty file="weblogic.xml" />
<echoproperties prefix="WebLogicDomain" />
Output:
[echoproperties] #Ant properties
[echoproperties] #Thu Feb 15 16:42:17 PST 2018
[echoproperties] WebLogicDomain.Domain=MyDomain
[echoproperties] WebLogicDomain.Environment=DEV
[echoproperties] WebLogicDomain.Servers.Server(id)=1,2
[echoproperties] WebLogicDomain.Servers.Server.AdminServerHost=adminHost,adminHost
[echoproperties] WebLogicDomain.Servers.Server.AliasName=adminserver,managedserver01
[echoproperties] WebLogicDomain.Servers.Server.ClusterName=\#NA,Cluster1
[echoproperties] WebLogicDomain.Servers.Server.Host=Host1,Host2
[echoproperties] WebLogicDomain.Servers.Server.IsAdmin=true,false
[echoproperties] WebLogicDomain.Servers.Server.MaxHeap=2048MB,2048MB
[echoproperties] WebLogicDomain.Servers.Server.MinHeap=512MB,512MB
[echoproperties] WebLogicDomain.Servers.Server.Port=14100,14110
If you really need to do XML parsing that is more complicated than basic string retrieval, there's a 3rd party plugin called XmlTask that can accomplish this. http://www.oopsconsultancy.com/software/xmltask/
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath location="lib/xmltask.jar"/>
</taskdef>
<target name="default">
<xmltask source="weblogic.xml">
<copy path="WebLogicDomain/Servers/Server[#id='1']/Host/text()" property="server.1.host"/>
</xmltask>
<echo message="${server.1.host}" />
</target>
Output:
[echo] Host1
I am trying to get UMLGraph complied on my MacBook Pro(OSX 10.9.5) and getting an error when trying to run 'ant build.xml'. Has anyone had this issue? Here is the error:
UMLGraph-5.7_2.3-SNAPSHOT$ ant build.xml
Buildfile: /Users/jeremy/UMLGraph-5.7_2.3-SNAPSHOT/build.xml
[echo] git describe --abbrev=6 => 'version'
BUILD FAILED
/Users/jeremy/UMLGraph-5.7_2.3-SNAPSHOT/build.xml:50: The following error occurred while executing this line:
/Users/jeremy/UMLGraph-5.7_2.3-SNAPSHOT/build.xml:27: exec returned: 128
Total time: 1 second
Here is a snip of line 50 and a few lines above it from build.xml:
23 <sequential>
24 <echo message="git describe --abbrev=6 => '#{outputproperty}'"/>
25 <exec executable="git"
26 failonerror="true"
27 outputproperty="#{outputproperty}">
28 <arg value="describe"/>
29 <arg value="--abbrev=6"/>
30 <arg value="HEAD"/>
31 <redirector>
32 <outputfilterchain>
33 <tokenfilter>
34 <replaceregex pattern="R" replace=""/>
35 <replaceregex pattern="_" replace="."/>
36 <replaceregex pattern="-" replace="."/>
37 <replaceregex pattern="(-.*)$" replace="-SNAPSHOT"/>
38 </tokenfilter>
39 </outputfilterchain>
40 </redirector>
41 </exec>
42 <echo message="gitversion returned '${#{outputproperty}}'"/>
43 </sequential>
44 </macrodef>
45
46 <!-- define Maven coordinates; see https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-7c.DeploySnaps hotsandStageReleaseswithAnt -->
47 <property name="groupId" value="org.umlgraph" />
48 <property name="artifactId" value="UmlGraph" />
49 <!-- <property name="version" value="1.0-SNAPSHOT" /> -->
50 <gitversion outputproperty="version"/>
Here are the instructions in the README.txt:
UMLGraph - Declarative Drawing of UML Diagrams
UMLGraph allows the declarative specification and drawing of
UML class and sequence diagrams. You can browse the system's
documentation from the doc/index.html page, or print it from
doc/indexw.html.
To install the elements required to run UMLGraph, simply copy
the contents of the lib directory to a location consistent with
your installation's conventions (for example to /usr/local/lib).
To compile the Java doclet from the source code run ant on the
build.xml file.
If you change the source code, you can run regression tests by
executing "ant test".
Project home page: http://www.umlgraph.org
GitHub page: git#github.com:dspinellis/UMLGraph.git
Diomidis Spinellis - November 2005, August 2008, April 2012
I copied the files from lib/ to /usr/local/lib, like the instructions said, but it appears I am not building it correctly.
Thanks for any help.
In order to get the project compiled you must clone it from GitHub. This is required in order to obtain the version string.
I want to set file name with date and time attached to it so I want to create file named as behat-20140913-195915.html however the example below sets the name as behat-yyyymmdd-hhiiss.html. Anyone know the solution to problem?
I followed this example
Note: These two don't work too: ${DSTAMP} ${TSTAMP}
<?xml version="1.0" encoding="UTF-8"?>
<project name="Sport" default="build-default" basedir=".">
<tstamp>
<format property="TODAY_MY" pattern="yyyymmdd-hhiiss" locale="en,UK" />
</tstamp>
<target name="build" description="Runs everything in order ..." depends="behat-bdd" />
<target name="behat">
<echo msg="Running Behat tests ..." />
<exec logoutput="true" checkreturn="true"
command="bin/behat -f progress --format html --out ${dir-report}/behat-${TODAY_MY}.html" dir="./" />
</target>
</project>
The tstamp task is documented in the ANT manual. It describes how the pattern format comes from the SimpleDateFormat object:
http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
I suggest trying the following:
Example
Buildfile: build.xml
build:
[echo] date: 20140913-203419
build.xml
<project name="demo" default="build">
<tstamp>
<format property="TODAY_MY" pattern="yyyyMMdd-HHmmss" locale="en,UK" />
</tstamp>
<target name="build">
<echo message="date: ${TODAY_MY}"/>
</target>
</project>
Software versions
$ ant -v
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
$ java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
I am trying to execute the "who -m" command from Apache ant without success.
Here is my ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="default" default="who.am.i">
<target name="who.am.i">
<exec executable="who" outputproperty="myOutput">
<arg value="-m"/>
</exec>
<echo message="I am = ${myOutput}"/>
</target>
</project>
The result is blank.
[echo] I am =
If I run exec without the argument, it displays the correct result:
<exec executable="who" outputproperty="myOutput">
</exec>
[echo] host.name = gary tty8 2014-02-03 12:04 (:0)
[echo] gary pts/0 2014-02-03 12:09 (:0)
[echo] gary pts/1 2014-02-03 12:23 (:0)
[echo] gary pts/2 2014-02-04 11:36 (:0)
[echo] gary pts/4 2014-02-05 13:27 (:0)
[echo] gary pts/7 2014-02-04 12:23 (:0)
[echo] gary pts/8 2014-02-06 12:44 (:0)
If I run the who -m command from a terminal it displays what I am looking for:
who -m
gary pts/8 2014-02-06 12:44 (:0)
Any ideas why ant is not accepting the -m argument?
Try executing as shell executable to see it that helps. It helps to invoke shell with exact unix command you want to run.
<exec executable="sh" outputproperty="myOutput">
<arg value="who -m"/>
</exec>
You don't mention which flavour of Unix you have, but on Solaris I get this error message when I try your task:
[echo] $ Must be attached to terminal for 'am I' option
In contrast, on OSX it appears to work, but says:
[echo] I am = mjc tty?? Feb 7 02:35
note the ?? - it's also not finding the terminal for the session.
I suspect that in your case it is silently failing for the same reason as the Solaris test - namely that the shell forked by Ant (i.e. by java) isn't associated with your terminal session.
(There may well be a workaround, but I'm not aware of it, and if there is one, it is unlikely to be portable.)
At the end of the day I decided to go another route.
In ~/.bashrc I added the following line:
who -m | awk '{print $5}' > ~/.whoami.out
And to make it global I just added it to /etc/bashrc
This will write to the ~/.whoami.out file every time I log into the remote system.
In my ant script I read the content of this file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="default" default="default">
<target name="test.who.key">
<loadfile property="who.key" srcFile="${user.home}/.whoami.out" failonerror="false"/>
<condition property="who.cond">
<isset property="who.key"/>
</condition>
<condition property="who.cond2">
<not>
<isset property="who.key"/>
</not>
</condition>
</target>
<target name="init.who.key" depends="test.who.key" if="who.cond">
<echo message="WHO EXIST"/>
<property name="whoAmI" value="${who.key}"/>
</target>
<target name="init.not.who.key" depends="test.who.key" if="who.cond2">
<echo message="WHO DOES NOT EXIST"/>
<property name="whoAmI" value=""/>
</target>
<target name="default" depends="init.who.key, init.not.who.key">
<echo message="whoAmI = ${whoAmI}"/>
</target>
</project>
I have a properties file that I want to echo out the values
<HSMKeys>
<Key domain="default" value="TestA" />
<Key domain="fixed" value="TestB" />
</HSMKeys>
as
[echo] domain=default value=TestA
[echo] domain=fixed value=TestB
How can I do this, ie loop over the properties file and have the two variables that would be in the echo.
I have tried the following
<for list="${HSMKeys.Key.domain}" param="domain">
<sequential>
<echo>domain=#{domain}</echo>
</sequential>
</for>
ie I can only get at one attribute value at a time, not both at once.
Thanks.
As #thekbb has stated this is not a properties file, however, ANT supports the parsing of XML files as properties.
<project name="demo" default="print">
<xmlproperty file="properties.xml"/>
<target name="print">
<echoproperties prefix="HSMKeys."/>
</target>
</project>
Produces the following output:
print:
[echoproperties] #Ant properties
[echoproperties] #Tue Dec 03 23:44:14 GMT 2013
[echoproperties] HSMKeys.Key=,
[echoproperties] HSMKeys.Key(domain)=default,fixed
[echoproperties] HSMKeys.Key(value)=TestA,TestB
May not be exactly what you need but has the advantage of not requiring additional jars like Ant-contrib.
That's not a properties file. Properties files are key/value pairs. How are you populating list?
a property file ant will understand will look like:
domain.default=TestA
domain.fixed=testB
I recommend avoiding ant-contrib at all costs... what are you really trying to do?
you could simply use echoproperties
<project name="test" default="echo" basedir=".">
<property file="build.properties" />
<target name="echo" >
<echoproperties prefix="domain."/>
</target>
</project>