I have zip file "A.zip".It contains a folder "B".Inside this folder I have simple "a.sql" file.which I need to copy to destination folder "Test".I have used below code but still it is not working.Please let me know how can I do it.
<target name="unzip.ubview" description="Unzips the zipped dump file from latest build">
<echo message="Extracting zip file" />
<unzip src="${IMP_LOC}/A.zip" dest="E:/Test" overwrite="true">
<patternset>
<include name="a*.sql"/>
</patternset>
<mapper>
<globmapper from="B/*" to="*"/>
</mapper>
</unzip>
</target>
What about
<target name="unzip.ubview" description="Unzips the zipped dump file from latest build">
<echo message="Extracting zip file" />
<unzip src="${IMP_LOC}/A.zip" dest="E:/Test" overwrite="true">
<patternset>
<include name="B/a*.sql"/>
</patternset>
<mapper>
<globmapper from="B/*" to="*"/>
</mapper>
</unzip>
</target>
Related
I have a folder with multiple .zip files. I want to unzip them in the same folder, with the name same as that of the file.
eg.
temp/product_file1.zip
temp/product_file2.zip
temp/product_file3.zip
Output expected:
temp/product_file1
temp/product_file2
temp/product_file2
How can I make a generic code using Ant?
The code which I am using now is able to only unzip the last file.
<path id="warFilePath">
<fileset dir="/temp">
<include name="product_*.zip"/>
</fileset>
</path>
<property name="warFile" refid="warFilePath" />
<basename property="warFilename" file="${warFile}" suffix=".zip" />
<unzip dest="temp/${warFilename}">
<fileset dir="/temp">
<include name="${warFilename}.zip"/>
</fileset>
</unzip>
I have created a zip file with many folders and files in it.
<!-- Create the distribution directory -->
<mkdir dir="${buildDirectory}/core/dist"/>
<zip destfile="${buildDirectory}/core/dist/core.zip">
<zipfileset dir="${buildDirectory}/core/" prefix="core/bin">
<include name="*.jar" />
</zipfileset>
<zipfileset dir="${buildDirectory}/core/src/resources" prefix="core/conf">
<include name="log4j.properties" />
<include name="core.properties" />
<include name="conf.xml" />
</zipfileset>
<zipfileset dir="${buildDirectory}/algorithm/testData" prefix="core/data">
<include name="defs.properties" />
<include name="proto.aza" />
</zipfileset>
So the zip now has
/bin
/conf
/data
I also need to include (add) an empty /logs folder in the zip structure.
How do I do that.
thanks
The least clumsy way I can find of doing this is to create an empty directory somewhere first, and then include it in your zipfile. Cutting down your example a bit, to get a zip with just an empty logs directory in it, you could write:
<mkdir dir="${buildDirectory}/core/dist"/>
<mkdir dir="${buildDirectory}/core/dist/logs"/>
<zip destfile="${buildDirectory}/core/dist/core.zip">
<zipfileset dir="${buildDirectory}/core/dist/logs" fullpath="logs"/>
</zip>
I have particular requirement. I have multiple reports file in particlar directly. Currently I build up ant script reading all files and checking for the particular string using the below code.
<target name="GenerateReports" >
<property name="search.string" value="Internal Error" />
<fileset id="existing" dir="${report.dir}">
<patternset id="files">
<include name="*.txt" />
</patternset>
</fileset>
<fileset id="matches" dir="${report.dir}">
<patternset refid="files" />
<contains text="${search.string}" />
</fileset>
<fail message="Found '${search.string}' in one or more test cases results in '${report.dir}' One or more test cases are failed">
<condition>
<resourcecount when="greater" count="0" refid="matches" />
</condition>
</fail>
</target>
But i want to read each file and give the name of the file where the error exists in my report file.
How to read the each file name and read the content also.
<foreach target="-List-File-Names" param="foreach.file" inheritall="true">
<path>
<fileset dir="${report.dir}" includes="*.txt">
<contains text="${search.string}" />
</fileset>
</path>
</foreach>
<target name="-List-File-Names">
<dirname property="file.dir" file="${foreach.file}"/>
<!-- dirname now holds the file -->
</target>
Below is the Ant script i am trying in GAE project but when i look into the war file i see two class for each java file.
Just a fyi, WAR file created i open in winrar but even when i extract it winrar keeps on asking me to either replace existing file message. Not sure how even same file name & extension is present in one folder. Also i checked the "dist" & "classes" folder i does not have duplicate file.
<?xml version="1.0" ?>
<project name="AntExample1" default="war">
<path id="compile.classpath">
<fileset dir="war/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="build/classes"/>
<mkdir dir="dist" />
</target>
<target name="compile" depends="init" >
<javac destdir="build/classes" debug="true" srcdir="src">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="dist/AntExample.war" webxml="war/WEB-INF/web.xml">
<fileset dir="war"/>
<lib dir="war/WEB-INF/lib"/>
<classes dir="build/classes"/>
</war>
</target>
<target name="clean">
<delete dir="dist" />
<delete dir="build" />
</target>
</project>
Using Ant, I want to copy a list of files from one project to another, where each project has the same directory structure. Is there a way to get the following to work?
<project name="WordSlug" default="pull" basedir=".">
<description>
WordSlug: pull needed files
</description>
<property name="prontiso_home" location="../../prontiso/trunk"/>
<!-- I know this doesn't work, what's the missing piece? -->
<target name="pull" description="Pull needed files">
<copy todir="." overwrite="true">
<resources>
<file file="${prontiso_home}/application/views/scripts/error/error.phtml"/>
<file file="${prontiso_home}/application/controllers/CacheController.php"/>
<!-- etc. -->
</resources>
</copy>
</target>
</project>
Success is deriving the paths automatically:
${prontiso_home}/application/views/scripts/error/error.phtml copied to ./application/views/scripts/error/error.phtml
${prontiso_home}/application/controllers/CacheController.php copied to ./application/controllers/CacheController.php
Thanks!
Try creating a fileset:
<copy todir="." overwrite="true">
<fileset dir="${prontiso_home}/application/">
<include name="views/scripts/error/error.phtml,controllers/CacheController.php"/>
</fileset>
</copy>
Typically, however, you use fileset to define patterns of files to copy, such as "copy all PHP files in my application directory:
<fileset dir="${prontiso_home}/application/">
<include name="**/*.phtml,**/*.php"/>
</fileset>
OP here. I have a working solution:
<project name="WordSlug" default="pull" basedir=".">
<description>
WordSlug: pull needed files
</description>
<property name="prontiso_home" location="../../prontiso/trunk"/>
<target name="pull" description="Pull needed files">
<copy todir="." overwrite="true" verbose="true">
<fileset dir="${prontiso_home}">
<or>
<filename name="/application/views/scripts/error/error.phtml"/>
<filename name="/application/controllers/CacheController.php"/>
</or>
</fileset>
</copy>
</target>
</project>