How do I delete a folders that match pattern in phing - phing

I have a build_ folders in my directory like build_10320 or build_10321.
I need to write a target clean that deletes such a folder.
I am trying doing this
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false" >
<fileset dir="./">
<include name="./build_*" />
</fileset>
</delete>
</target>
But this doesn't work. Kindly help.

Phing still doesn't have the <dirset> feature working (which would be the natural choice). You can however make this work using <exec> & the relevant command for deleting files from your operating system.
For linux:
<exec command = "rm -rf ./build_*" passthru = "true" />

A <fileset> returns, as the name suggests, only files.
There is an undocumented <dirset> type that unfortunately cannot be used with <delete> at the moment.

With Phing 3.x you can use <dirset> inside the <delete> task.
<project name="delete-with-dirset" default="clean" basedir=".">
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false">
<dirset dir="./">
<include name="./build_*" />
</dirset>
</delete>
</target>
</project>

Related

Ant build.xml working Eclipse. Not working direct

My buildfile seems to be running correctly (and generating junit test reports) correctly when executing in Eclipse, however when I execute directly with: ant -buildfile C:\....\build.xml the files aren't produced - and the cmd output suggests it's not running the tests.
I have two eclipse projects. JUnitTest1 which is the code. JUnitTestUnitTests which contains the test code.
I've followed the instructions here to create my buildfile in eclipse (selecting only the test project) and can see the files drop into the junit directory.
When I run ant command directly, no files are generated and it doesn't look like it's running my tests.
Why aren't the changes made via the eclipse GUI reflected in the build.xml? I thought it was auto updated?
Here's the eclipse config
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. --><project basedir="." default="build" name="JUnitTest1UnitTests">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../../../tools/eclipse-mars/"/>
<property name="junit.output.dir" value="junit"/>
<property name="JUnitTest1.location" value="../JUnitTest1"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="JUnitTest1.classpath">
<pathelement location="${JUnitTest1.location}/bin"/>
<pathelement location="${JUnitTest1.location}/../../../../../tools/libs/hamcrest-core-1.3.jar"/>
<pathelement location="${JUnitTest1.location}/../../../../../tools/libs/junit-4.12.jar"/>
</path>
<path id="JUnitTest1UnitTests.classpath">
<pathelement location="bin"/>
<pathelement location="../../../../../tools/libs/hamcrest-core-1.3.jar"/>
<pathelement location="../../../../../tools/libs/junit-4.12.jar"/>
<path refid="JUnitTest1.classpath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall">
<ant antfile="build.xml" dir="${JUnitTest1.location}" inheritAll="false" target="clean"/>
</target>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects">
<ant antfile="build.xml" dir="${JUnitTest1.location}" inheritAll="false" target="build-project">
<propertyset>
<propertyref name="build.compiler"/>
</propertyset>
</ant>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="JUnitTest1UnitTests.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="JUnitTest1UnitTests">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="com.me.tests.MyTestClass" todir="${junit.output.dir}"/>
<classpath refid="JUnitTest1UnitTests.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
I believe I've fixed this.
Eclipse creates your build file and seperately, you configure your run configurations. These run configurations (where you specify the run order of the ant tasks) are not persisted or represented in the actual build file.
The default target of the build file is the target="build" ... So you need to manually edit the build file and use the depends="..." clause to chain together the dependancies of your tasks.
This page (read example build file and see final line) has a great explanation of the depends clause.

Deployment with e(fx)clipse - Build Error

I am trying to deploy a stand-alone build of my JavaFx application and have followed the tutorial from Code.Makery.
I am getting this error:
init-fx-tasks:
[taskdef] Could not load definitions from resource com/sun/javafx/tools/ant/antlib.xml. It could not be found.
do-deploy:
[copy] Copying 1 file to C:_source\MasterGuildWarsCode\build\dist\libs
BUILD FAILED C:_source\MasterGuildWarsCode\build\build.xml:91:
C:_source\MasterGuildWarsCode\resources does not exist.
Total time: 2 seconds
This is the section of my build.xml file that seems to be the problem:
<mkdir dir="dist/resources" />
<copy todir="dist/resources" >
<fileset dir="../resources" />
</copy>
<mkdir dir="package" />
<!-- Icons only for Windows -->
<mkdir dir="package/windows" />
<copy todir="package/windows">
<fileset dir="..">
<include name="AXI.ico" />
<include name="AXI.bmp" />
</fileset>
</copy>
<!-- Icons only for MacOS -->
<mkdir dir="package/macosx" />
<copy todir="package/macosx">
<fileset dir="..">
<include name="AXI.icns" />
</fileset>
</copy>
<fx:resources id="appRes">
<fx:fileset dir="dist" includes="MasterGuildWarsCode.jar"/>
<fx:fileset dir="dist" includes="libs/*"/>
<fx:fileset dir="dist" includes="resources/**"/>
</fx:resources>
Any help is greatly appreciated!
You may want to try this tutorial instead: Efxclipse/Tutorials/AddingE(fx)clipse to eclipse. I've tested it and works perfectly.
Make sure you follow all the steps. Specially this one: "Configure eclipse to use a JDK not a JRE". This will guarantee that you won't have any trouble when you ant build and run your app.
Looking at that tutorial (Step 4), there is a section like this in the build.xml:
<path id="fxant">
<filelist>
<file name="${java.home}\..\lib\ant-javafx.jar"/>
<file name="${java.home}\lib\jfxrt.jar"/>
<file name="${basedir}"/>
</filelist>
</path>
Do those jars exist at the specified paths in the JDK that Ant executes with?
A very similar question was asked here: JAVAFx Build Failed, with suggestion to change from
<file name="${java.home}\lib\jfxrt.jar"/>
to
<file name="${java.home}\lib\ext\jfxrt.jar"/>
I don't know whether that is correct or not, but I do suggest checking those paths.

error CS0246: The type or namespace name 'Form1' could not be found

Currently I am developing a NAnt script to build a Windows forms application. After build the NAnt script, I am getting the error as
error CS0246: The type or namespace name 'Form1' could not be found
(are you missing a using directive or an assembly reference? )
BUILD FAILED
C:\Program
Files\NAnt\examples\SampleWindowsApplication\Sample.Build(24,10):
External Program Failed:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe (return code was 1)”
Can anyone please advise to resolve this issue?
Please find my code below.
<?xml version="1.0"?>
<project name="SampleWindowsApplication" default="run">
<property name="basename" value="SampleWindowsApplication"/>
<property name="debug" value="true"/>
<target name="clean">
<delete>
<fileset>
<include name="bin/${basename}-??.exe"/>
</fileset>
</delete>
</target>
<target name="build">
<mkdir dir="bin" />
<assemblyfileset id="Sample.assemblies">
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Grid.Base.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Grid.Windows.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Shared.Base.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Shared.Windows.dll" />
<!--<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\System.Windows.Forms.dll" />-->
</assemblyfileset>
<csc target="exe" output="bin/${basename}.exe" debug="${debug}" >
<references refid="Sample.assemblies" />
<resources>
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\licenses.licx"/>
</resources>
<sources>
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Program.cs"/>
</sources>
</csc>
</target>
<target name="run" depends="build">
<exec program="bin/${basename}-cs.exe" basedir="."/>
</target>
</project>
Thanks in advance.
This is typically cause when you add a new file to your solution but don't commit them.
Check to make sure that Form1.cs and Form1.Designer.cs have been added to your source control repository. It looks like your project file was added and committed correctly but some source control tools require you to manually add new files before committing them.

EnversHibernateToolTask in NetBean build file issue

I'm trying to incorporate hibernate schema generator for Envers.
I've add this target:
<target name="schemaexport"
description="Exports a generated schema to DB and file">
<path id="hibernate.classpath">
<pathelement path="./lib/hibernate-persistence/*.jar" />
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.EnversHibernateToolTask"
classpathref="hibernate.classpath"/>
<hibernatetool destdir=".">
<classpath>
<fileset refid="lib.hibernate" />
<path location="${build.demo.dir}" />
<path location="${build.main.dir}" />
</classpath>
<jpaconfiguration persistenceunit="AuroraServicePU" />
<hbm2ddl
drop="false"
create="true"
export="false"
outputfilename="versioning-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
The problem is that I get the error
taskdef class org.hibernate.tool.ant.EnversHibernateToolTask cannot be found
using the classloader AntClassLoader[myproject\lib\hibernate-persistence*.jar]
Help will be great.
Thank you,
Ido.
I suspect your path is incorrect. I don't believe you can use wildcards in a pathelement.
Try changing your path to be:
<path id="hibernate.classpath">
<fileset dir="lib">
<include name="**/*.jar"/>
</fileset>
</path>
If that fails, run ant with the -v tag and check the debug for more hints.

Delete dir with nAnt and exclude sub folder?

I'm looking for my build to delete the contents of a directory without touching a certain folder. Below is what I'm trying, and it even looks wrong to me...aside from the fact that it bombs when I run it. Do I need to be deleting the contents of the dir explicitly and at the same time exclude my Reports folder?
<delete includeemptydirs="true">
<fileset dir="${PublishLocation}" >
<exclude name="**Reports**"/>
</fileset>
</delete>
Cheers.
It should be:
<delete>
<fileset basedir="${PublishLocation}">
<include name="**/*"/>
<exclude name="**/Reports/**/*" />
</fileset>
</delete>
Please notice the following:
includeemptydirs="true" is default
The attribute for fileset is basedir instead of dir
if you specify <exclude name="**/Reports/**" /> instead of <exclude name="**/Reports/**/*" /> all files named Reports are kept as well