Ant not excluding files from build - ant

I'm currently building a tar:
<property name="dcc-shell.dir" value="."/>
<property name="dcc-mdp.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/>
<property name="mdp-code.dir" value="${dcc-mdp.dir}/*"/>
<property name="mdp-exclude.dir" value="${dcc-mdp.dir}/target"/>
<property name="dcc-srv.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/>
<property name="srv-code.dir" value="${dcc-srv.dir}/src/main/*"/>
<property name="dcc-trans.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/>
<property name="trans-code.dir" value="${dcc-trans.dir}/src/main/*"/>
<target name="create MDP.Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
excludes="${mdp-exclude.dir}"
basedir="${dcc-mdp.dir}"
/>
</target>
however it continuly keeps adding the target file and it's contents to the tar file dispite specifying the it to be excluded via excludes=dir

You need the "**" to exclude the directory and everything in it. These excludes are file based and not directory based.
<target name="create MDP.Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
excludes="${mdp-exclude.dir}/**"
basedir="${dcc-mdp.dir}"
/>
</target>

Its because your relative paths are off, your script is basically doing this:
Include all files from the directory:
./eq-mo-drop-copy-converter-mdp
but dont include this one:
./eq-mo-drop-copy-converter-mdp\target
Which really reads eq-mo-drop-copy-converter-mdp/eq-mo-drop-copy-converter-mdp\target which doesn't exist.
You need to specify exclude .\target\**

Through trial and error I found this to be a solution:
**/target/**

Related

ANT : 'ZIP' Task - how to prevent trailing slashes on ZIP entries?

I am using ANT to both unzip and then re-zip a "Open Packaging Convention" file.
It happens to be an EXCEL (*.xlsx) file: and the process works; but it seems that the ANT 'zip' task is creating the ZIP slightly differently that how it was created by EXCEL itself.
The ZIP entries created appear to have trailing slash characters.
I discovered this when opening the resultant ZIP with Apache POI (which has some unit-tests to detect and complain about this situation) with DEBUG logging on.
Here's an example of the WARNING log messages from Apache POI when re-opening up the re-zipped file:
2015-10-29 14:06:11 WARN ZipPackage:135 - Entry xl/worksheets/_rels/ is not valid, so this part won't be add to the package.
org.apache.poi.openxml4j.exceptions.InvalidFormatException: A part name shall not have a forward slash as the last character [M1.5]: /xl/worksheets/_rels/
Is there a way of avoiding this (annoying, but not critical) issue when using Ant ?
I'm running this on a Windows platform.
Here's my (simplified) 'build.xml' file.
<project name="repackage" default="repackage" basedir=".">
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="temp" location="temp"/>
<property name="extract" location="${temp}\extract"/>
<property name="inputfile" value="original.xlsx"/>
<target name="cleantemp">
<delete includeemptydirs="true">
<fileset dir="${temp}" includes="**/*"/>
</delete>
<mkdir dir="${extract}"/>
</target>
<target name="extract" depends="cleantemp">
<unzip src="${src}/${inputfile}" dest="${extract}"/>
</target>
<target name="reassemble" depends="extract">
<zip destfile="${build}/repair.xlsx" basedir="${extract}"/>
</target>
<target name="repackage" depends="reassemble">
</target>
</project>
It looks as if the parser you use didn't like directory entries (which end in a /). Use filesonly="true" in your <zip> task.

Pass Parameters to ant target in another directory

I am trying to pass parameters to an ant target in another build file in a different location .
Here is what I did :-
<target name="run">
<ant dir="../${dir}" target="package" inheritAll="false"/>
<property name="-Darg.vendor" value="arm"/>
<property name="-Darg.tech" value="tsmc40g"/>
</ant>
</target>
I pass the dir from command line and run the target package from the build file there.
I am trying to pass the parameters but it is not accepting them.
Can anyone please help me fix this
Don't include the command line switches :
<target name="run">
<ant dir="../${dir}" target="package" inheritAll="false"/>
<property name="arg.vendor" value="arm"/>
<property name="arg.tech" value="tsmc40g"/>
</ant>
</target>

how to use property ant?

I would ask about property ant.After some action I got property
<property name="prop" value="test"/>
in file build.properties .I have the property test
test=example
I want to get value from build.properties
but when I use
<echo>${${prop}}</echo>
I got error
Could somebody help me?How I can solve this problem?It's possible in general such way use property?
This should work assuming you have a build.properties file containing:
test=example
The build file might look like this:
<project basedir="." default="default">
<property file="build.properties"/>
<property name="prop" value="test"/>
<target name="default">
<echo>${test}</echo>
<echo>${prop}</echo>
</target>
</project>

Expanding * in Ant copy task

In ant copy task, in destination location there is a "random number" folder in the path. When i try to put a * in the path to handle it, Ant takes it literally, ie doesnt expand it, but creates a folder called "*" and copies there. How do I tell Ant to expand the * to actual folder name there (there is only 1 folder in there, so * wont expand to multiple folders)
<property name="dest" value="a/*/b/my.jar" />
<property name="src" value="my.jar" />
<copy file="${src}" tofile="${dest}" overwrite="true" verbose="true"/>
The copy task doesn't support wildcards in the tofile attribute. If the destination directory exists, but the destination file may not, then you can use a dirset to capture the directory. Something like:
<dirset dir="${basedir}" id="dest.dir">
<include name="a/*/b" />
</dirset>
<property name="dest" value="${toString:dest.dir}/my.jar"/>
<property name="src" value="my.jar" />
<copy file="${src}" tofile="${dest}" overwrite="true" verbose="true"/>
Instead of using the property helper (${toString:....}) syntax you might use the pathconvert task:
<pathconvert property="destdir" refid="dest.dir"/>
<property name="dest" value="${destdir}/my.jar"/>

Ant not creating tar files

I have a little ant script which should create 3 tar files.
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." >
<property name="dcc-shell.dir" value="${basedir}"/>
<property name="dcc-mdp.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/>
<property name="mdp-code.dir" value="${dcc-mdp.dir}/src/main/*"/>
<property name="dcc-srv.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/>
<property name="srv-code.dir" value="${dcc-srv.dir}/src/main/*"/>
<property name="dcc-trans.dir" value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/>
<property name="trans-code.dir" value="${dcc-trans.dir}/src/main/*"/>
<target name="create MDP Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
basedir="${dcc-mdp.dir}/**"
excludes="${dcc-mdp.dir}/target/*"
/>
</target>
<target name="create Trans Tar">
<tar destfile="${dcc-shell.dir}/trans.tar"
basedir="${dcc-trans.dir}/**"
excludes="${dcc-trans.dir}/target/*"
/>
</target>
<target name="create SRV Tar">
<tar destfile="${dcc-shell.dir}/srv.tar"
basedir="${dcc-srv.dir}/**"
excludes="${dcc-srv.dir}/target/*"
/>
</target>
</project>
The script runs fine:
Buildfile: C:\eq-Drop-Copy\eq-mo-drop-copy-converter-shell\build.xml
BUILD SUCCESSFUL
Total time: 94 milliseconds
However no tar files are created within the project. Somewhat of a mystery to myself
EDIT
I have been getting the following error!
<target name="create MDP.Tar">
<tar destfile="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/mdp.tar"
basedir="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/*"
excludes="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/target/*"
/>
</target>
I have changed the xml to the absoulet paths:
<target name="create MDP.Tar">
<tar destfile="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/mdp.tar"
basedir="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/*"
excludes="C:/eq-Drop-Copy/eq-mo-drop-copy-converter-shell/eq-mo-drop-copy-converter-mdp/target/*"
/>
</target>
However still the same error how can the basedir not exist the build file is contained within it. The basedir within the MDP target is pointing to an absoulet path and tar all the files within that. why would this be giving an error?
Most likely you called it without giving a target. Your printout does not show any tar targets executed.
Try calling it with target name as argument to ant. Then you will also find out that using spaces in target names may not be such a good idea.
I corrected several issues:
basedir attribute shouldn't have "*" in it. It'll automatically do the whole tree.
Targets can't contain spaces
You probably didn't specify targets. Therefore, I simply added a default target "create_all_tars", and used <antcall> to call the needed targets.
<project basedir="." default="create_all_tars" >
<property name="dcc-shell.dir"
value="${basedir}"/>
<property name="dcc-mdp.dir"
value="${dcc-shell.dir}/eq-mo-drop-copy-converter-mdp"/>
<property name="mdp-code.dir"
value="${dcc-mdp.dir}/src/main/*"/>
<property name="dcc-srv.dir"
value="${dcc-shell.dir}/eq-mo-drop-copy-converter-server"/>
<property name="srv-code.dir"
value="${dcc-srv.dir}/src/main/*"/>
<property name="dcc-trans.dir"
value="${dcc-shell.dir}/eq-mo-drop-copy-converter-transformer"/>
<property name="trans-code.dir"
value="${dcc-trans.dir}/src/main/*"/>
<target name="create_all_tars">
<antcall target="create_MDP_Tar"/>
<antcall target="create_Trans_Tar"/>
<antcall target="create_SRV_tar"/>
</target>
<target name="create_MDP_Tar">
<tar destfile="${dcc-shell.dir}/mdp.tar"
basedir="${dcc-mdp.dir}"
excludes="${dcc-mdp.dir}/target/**"/>
</target>
<target name="create_Trans_Tar">
<tar destfile="${dcc-shell.dir}/trans.tar"
basedir="${dcc-trans.dir}"
excludes="${dcc-trans.dir}/target/**"/>
</target>
<target name="create_SRV_Tar">
<tar destfile="${dcc-shell.dir}/srv.tar"
basedir="${dcc-srv.dir}"
excludes="${dcc-srv.dir}/target/**"/>
</target>
Does this help?

Resources