nant exclude folder - nant

I am looping though my folders and need to exclude the svn folders. I thought I could simply add the exclude element, though that doesnt seem to work.
<foreach item="Folder" property="foldername">
<in>
<items>
<include name="YOUR_FOLDER\**" />
<exlcude name="YOUR_FOLDER\**/_svn" />
</items>
</in>
<do>
<foreach item="File" property="filename" in="${foldername}">
<do>
<echo message="${filename}" />
</do>
</foreach>
</do>
</foreach>
Can somebody help?

It works when adding simply:
<exclude name="YOUR_FOLDER\**_svn**" />

You'll want to include the .svn directories and everything in them as well, otherwise the exclude mask will only hit the .svn directories, but not .svn/prop-base, .svn/props, .svn/text-base and so on.
<foreach item="Folder" property="foldername">
<in>
<items>
<include name="YOUR_FOLDER/**" />
<exclude name="YOUR_FOLDER/**/.svn/**" />
<exclude name="YOUR_FOLDER/**/_svn/**" />
</items>
</in>
<do>
<foreach item="File" property="filename" in="${foldername}">
<do>
<echo message="${filename}" />
</do>
</foreach>
</do>
</foreach>
Also, are you really using the alternative _svn naming scheme for Subversion's data directories?

<copy failonerror="true" overwrite="true" todir="${BusinessServicesTarget}">
<fileset basedir="${BusinessServicesPath}">
<exclude name="*.*" />
<include name="/**/*.as?x" />
<exclude name="/**/**_SVN**" />
You need to use it in copy function not in foreach.

Related

How to compile GWT project to jar file and add it to another GWT project?

I have Three GWT projects. 2 common GWT(Bootstrap & Data Transfer Objects) projects, it doesnt contain any UI part. So, I want to compile these two projects and create jar and want to include it in third GWT project. I have done in Eclipse[Project->Export->Jar file]. It works fine. I want do it command line or through ant build.xml. Please if you know anyone, can you help on this.
We have a similar case and here is the target we use for building an external jar for our task engine. This will build you a jar from command line that can be included in other projects. In our case we have a large project that contains all of our domain objects and some services. We wanted to include this into our task engine.
<target name="taskengine-jar" depends="enhance">
<mkdir dir="build" />
<mkdir dir="build/META-INF"/>
<copy todir="build/META-INF">
<fileset dir="src/META-INF">
<include name="persistence.xml" />
<include name="server.properties" />
<include name="crypto.properties" />
<include name="sqlDrivers.xml" />
</fileset>
</copy>
<jar destfile="taskengine-jobs.jar">
<fileset dir="war/WEB-INF/classes">
<include name="com/hp/vf/server/**" />
<include name="com/hp/vf/shared/**" />
</fileset>
<fileset dir="build">
<include name="META-INF/**" />
</fileset>
<zipgroupfileset dir="war/WEB-INF/lib">
<include name="axis2.jar" />
<include name="javamail-1.4.4.jar" />
<include name="commons-pool-1.6.jar" />
<include name="openjpa-all-2.2.0.jar" />
<include name="commons-logging-adapters-1.1.1.jar" />
<include name="commons-logging-api-1.1.1.jar" />
<include name="commons-vfs2-2.0.jar" />
<include name="postgresql-9.0-801.jdbc4.jar" />
<include name="poi-3.8-beta5-20111217.jar"/>
<include name="poi-ooxml-schemas-3.8-beta5-20111217.jar"/>
<include name="poi-ooxml-3.8-beta5-20111217.jar"/>
<include name="itext-2.1.7.jar"/>
<include name="REngine.jar" />
<include name="Rserve.jar" />
<include name="jsoup-1.6.1.jar" />
<include name="jfreechart-1.0.13.jar" />
<include name="jcommon-1.0.16.jar" />
</zipgroupfileset>
<fileset dir="war/WEB-INF/lib">
<include name="addressing-1.1.1.mar" />
<include name="rampart-1.1.mar" />
</fileset>
</jar>
<delete dir="build" />
</target>
I think, the most easy and flexible way is to use Maven. Each project represents the separate Maven artefact which is stored in your local repository. And only one thing you should do in your main project is to add couple of dependencies to your POM file. That's it. I use this schema for a long time.

Trying create db using ant

My build.xml
<?xml version='1.0'?>
<project xmlns:ivy="antlib:org.apache.ivy.ant" name='myTest' basedir='.' default='usage'>
<property file='build.properties' />
<property name='src.dir' value='src' />
<property name='web.dir' value='war' />
<property name='build.dir' value='${web.dir}/WEB-INF/classes' />
<property name='name' value='myTest' />
<property name="sql.driver" value="org.postgresql.Driver"/>
<property name="sql.url" value="jdbc:postgresql://localhost:5432/tbook"/>
<property name="sql.user" value="postgres"/>
<property name="sql.pass" value="admin"/>
<path id='master-classpath'>
<fileset dir='${web.dir}/WEB-INF/lib'>
<include name='*.jar' />
</fileset>
<!-- We need the servlet API classes: -->
<!-- * for Tomcat 5/6 use servlet-api.jar -->
<!-- * for other app servers - check the docs -->
<fileset dir='${appserver.lib}'>
<include name='servlet*.jar' />
</fileset>
<pathelement path='${build.dir}' />
</path>
<target name='usage'>
<echo message='' />
<echo message='${name} build file' />
<echo message='-----------------------------------' />
<echo message='' />
<echo message='Available targets are:' />
<echo message='' />
<echo message='build --> Build the application' />
<echo message='deploy --> Deploy application as directory' />
<echo message='deploywar --> Deploy application as a WAR file' />
<echo message='resolve --> retrieve dependencies with ivy' />
<echo message='' />
</target>
<target name="createDB_PostgreSQl">
<sql driver="${sql.driver}"
url="${sql.url}"
userid="${sql.user}"
password="${sql.pass}"
src="db.sql">
<classpath refid="master-classpath"/>
</sql>
</target>
<target name="dropDB_PostgreSQl">
<input message="Do you really want to delete this table (y/n)?" validargs="y,n" addproperty="do.delete" />
<condition property="do.abort">
<equals arg1="n" arg2="${do.delete}"/>
</condition>
<fail if="do.abort">Build aborted by user.</fail>
<sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
<classpath>
<pathelement location="postgresql-9.0-802.jdbc4.jar"/>
</classpath>
drop database sample_project;
</sql>
</target>
<target name="createTables_PostgreSQL">
<sql driver="${sql.driver}" url="${sql.url}" userid="${sql.user}" password="${sql.pass}" >
<classpath refid="master-classpath"/>
<transaction src="user.sql"/>
</sql>
</target>
<target name='build' description='Compile main source tree java files'>
<mkdir dir='${build.dir}' />
<javac destdir='${build.dir}' source='1.5' target='1.5' debug='true'
deprecation='false' optimize='false' failonerror='true'>
<src path='${src.dir}' />
<classpath refid='master-classpath' />
</javac>
</target>
<target name="clean">
<delete includeemptydirs="false">
<fileset dir="build/" includes="**/**"/>
</delete>
</target>
<target name='deploy' depends='build' description='Deploy application'>
<copy todir='${deploy.path}/${name}' preservelastmodified='true'>
<fileset dir='${web.dir}'>
<include name='**/*.*' />
</fileset>
</copy>
</target>
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:retrieve />
</target>
<target name='deploywar' depends='build'
description='Deploy application as a WAR file'>
<war destfile='${name}.war' webxml='${web.dir}/WEB-INF/web.xml'>
<fileset dir='${web.dir}'>
<include name='**/*.*' />
</fileset>
</war>
<copy todir='${deploy.path}' preservelastmodified='true'>
<fileset dir='.'>
<include name='*.war' />
</fileset>
</copy>
</target>
</project>
Exception is:
org.postgresql.util.PSQLException:ERROR: CREATE DATABASE can not be executed inside a transaction block
Take a look at this thread from the past. http://archives.postgresql.org/pgsql-jdbc/2005-11/msg00132.php
Basically for the create db task add this autocommit="true"

How to print hidden files/folders list using NAnt script?

Current I try as below but that will skip all hidden files/folders. I want to see them.
Please help if you know the trick! Thank you.
<foreach item="Folder" property="folderName">
<in>
<items>
<include name=".\**" />
</items>
</in>
<do>
<echo message="${folderName}" />
</do>
</foreach>
Are you sure they are skipped because they're hidden? I'm more inclined that the files not listed are in default excludes. You should try disabling these excludes and see if that helps:
<foreach item="Folder" property="folderName">
<in>
<items defaultexcludes="false">
<include name=".\**" />
</items>
</in>
<do>
<echo message="${folderName}" />
</do>
</foreach>

how can I copy one file to multiple sub directories

I'm trying to use nant because I thought it would be the easiest, but i'm open to any solution that works on windows xp.
I have the following folder structure
basefolder
folder1
folder2
subfolder1
code
solutionname1
projectname.interface
projectname.simulation
projectname.testcase
bin
release
folder3
...
folderN
folder1 - folderN all have the same directory structure as folder2. I want to copy a file to the release folder in each folderN.
I currently have the following nant script
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://nant.sf.net/release/0.90/nant.xsd" name="CopyDll" default="FileCopy">
<property name="fileToCopy"
value="C:\file.dll"
overwrite="false"/>
<property name="baseDirectory" value="${directory::get-current-directory()}" overwrite="false"/>
<target name="FileCopy"
description="Copies file to multiple directories">
<foreach item="Folder"
in="${baseDirectory}"
property="foldername">
<in>
<items>
<include name="**\**\**\*.TestCase\bin\Release"/>
</items>
</in>
<do>
<copy file="${fileToCopy}"
todir="${foldername}"/>
<echo message="Copied file to ${foldername}"/>
</do>
</foreach>
</target>
</project>
This copies file.dll to each folderN directory.
What am I doing wrong?
Is there a better way to do this?
I figured it out. I had to change my foreach to look like this
<foreach item="Folder"
property="foldername">
<in>
<items>
<include name="${baseDirectory}\**\*.TestCase\bin\Release"/>
</items>
</in>
<do>
<copy file="${fileToCopy}"
todir="${foldername}"/>
<echo message="Copied file to ${foldername}"/>
</do>
</foreach>

How to echo the contents of a fileset in Nant?

Was trying to do something like this:
<copy>
<fileset id="mySet">
<include name="*.sql" />
</fileset>
</copy>
<echo message="Copied files: ${mySet} to directory: ${Folder}." />
But i get the following error:
'id' is an invalid attribute for a
tag. Datatypes can only be
declared at Project or Target level.
Thanks
You can do this by looping over the files in the set.
<fileset id="mySet">
<include name="*.sql" />
</fileset>
<copy>
<fileset refid="mySet" />
</copy>
<foreach item="File" property="filename">
<in>
<items refid="mySet" />
</in>
<do>
<echo message="Copied files: ${filename} to directory: ${Folder}." />
</do>
</foreach>
But depending on verbosity level the result of the copy action is echoed anyway.