how to test symlinks with ant 1.9 - ant

I need to perform a command if the jar file is a file instead of a symlink. I have found a solution that works only with ant 1.10.
Does anyone know how to do it with ant 1.9 ?
Here is my build.xml.
<?xml version="1.0"?>
<project name="AsterixDecoder" default="bm" basedir=".">
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property environment="env"/>
<condition property="exists.CCM_ADDR">
<isset property="env.CCM_ADDR"/>
</condition>
<target name="compile" description="compile the source " >
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}" includeantruntime="false"/>
<mkdir dir="${build}/resources"/>
<copy todir="${build}/resources">
<fileset dir="resources"/>
</copy>
</target>
<target name="checkout" if="exists.CCM_ADDR">
<ccmcheckout file="${dist}/AsterixDecoder.jar"/>
</target>
<target name="dist" depends="compile, checkout"
description="generate the distribution" >
<jar jarfile="${dist}/AsterixDecoder.jar" filesetmanifest="mergewithoutmain">
<manifest>
<attribute name="Main-Class" value="fr.eurocontrol.escape.ground.asterixdecoder.AsterixDataTree"/>
<attribute name="Class-Path" value="."/>
</manifest>
<fileset dir="${build}"/>
</jar>
</target>
<target name="check.symlink">
<fileset dir="${dist}" id="fileset" includes="AsterixDecoder.jar">
<symlink/>
</fileset>
<pathconvert refid="fileset" property="is.symlink" setonempty="false"/>
</target>
<target name="reconcile" depends="check.symlink" if="exists.CCM_ADDR" unless="is.symlink">
<exec executable="ccm">
<arg value="reconcile"/>
<arg value="-udb"/>
<arg value="${dist}/AsterixDecoder.jar"/>
</exec>
</target>
<target name="bm" description="build management" depends="dist, reconcile">
</target>
</project>
Do not hesitate to make any suggestion of improvements. I am still a beginner in writing ant files.

The most straightforward way to do this would be to use the record function of Ant's symlink task. This creates a property file that lists all of the symlinks found within a given resource collection. Here's an example target:
<target name="default">
<symlink link="testdir" resource="build" />
<symlink action="record" linkfilename="links.record">
<fileset dir="." includes="*" />
</symlink>
<property file="links.record" />
<condition property="testdir.is.symlink">
<isset property="testdir" />
</condition>
<echo message="${testdir.is.symlink}" />
</target>

Related

PMD ANT script gives taskdef class net.sourceforge.pmd.ant.PMDTask cannot be found using the classloader AntClassLoader[]

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="info" name="MyProject">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="lib.dir" value="lib"/>
<property name="jar.name" value="${ant.project.name}"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" debug="true" nowarn="true" debuglevel="lines,vars,source"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${jar.name}.jar" basedir="${classes.dir}">
<exclude name="**/Main.class" />
<fileset dir="${src.dir}" includes="**/*.java">
<exclude name="**/Main.java" />
</fileset>
<zipgroupfileset dir="${lib.dir}" includes="*.jar">
<exclude name="**/Utils.jar" />
</zipgroupfileset>
</jar>
</target>
<target name="build" depends="jar"/>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" />
<target name="pmd">
<pmd shortFilenames="true" failuresPropertyName="failures.count" rulesetfiles="\path\pmd\ruleSet.xml">
<formatter type="html" toFile="pmd_report.html" toConsole="true"/>
<fileset dir="src">
<include name="**/*.java"/>
</fileset>
</pmd>
</target>
<target name="info">
<echo message="Available Targets:"/>
<echo message=" clean"/>
<echo message=" compile"/>
<echo message=" jar"/>
<echo message=" build"/>
<echo message=" pmd"/>
</target>
</project>
This script gives me this " taskdef class net.sourceforge.pmd.ant.PMDTask cannot be found using the classloader AntClassLoader[]"
I have added PMD library jar file in lib folder of the project,where other libraries are present as jar files.
But if i change add path ref to the library not as a jarfile , it works well.
<path id="pmd.classpath">
<fileset dir="C:\Users\PMD\pmd-bin-5.5.2">
<include name="**/*.jar"/>
</fileset>
</path>
May I know what is the problem? I am pretty new to ANT and PMD , any help will be appreciated.
Thanks
First thing to check is the file pmd-core-*.jar in your lib directory?
Secondly add a reference to the path in the taskdef task:
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="classpath"/>

Ant Build issue : Additonal folder getting created

need your help at the earliest and I have been breaking my head over this for a while.
Below is my Ant Script.
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="src.dir" value="${basedir}/allocator"/>
<property name="classes.dir" value="${basedir}/classes"/>
<property name="jar.dir" value="${basedir}/jar"/>
<property name="main-class" value="allocator.Allocator"/>
<path id="classpath_ref">
<pathelement path="${basedir}/"/>
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<target name="clean">
<delete dir="${classes.dir}" />
<delete dir="${build.dir}" />
<delete dir="${jar.dir}" />
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath_ref" includeantruntime="false">
<src path="${basedir}/supportlibraries"/>
<src path="${basedir}/com/xyz/framework"/>
</javac>
<copy todir="${build.dir}"><fileset dir="${src.dir}" excludes="**/*.java"/>
</copy>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java classname="${main-class}" fork="true" >
<arg line="username"/>
<arg line="password"/>
<classpath>
<path refid="classpath_ref"/>
<pathelement location="${jar.dir}/${ant.project.name}.jar"/>
</classpath>
</java>
</target>
<target name="main" depends="clean,run"/>
</project>
when i try to run the ant build from eclipse it is creating an additional folder allocator, supportlibraries and com/xyz/framework inside the class folder. why is it creating additional folder? because of the additional folders when the run target executes its not able to locate the allocator class. Please let me know if i am missing anything
Remove the <copy> from the "compile" <target>.
The <jar> in the "jar" target should be:
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
In the above snippet, basedir is ${classes.dir} instead of ${build.dir}.
I don't see a need for build.dir in your script. All references to it can likely be removed.

Could not find or load main class ant file

<target name="init">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="apidoc.dir" value="apidoc"/>
<property name="lib.dir" value="lib"/>
<property name="lib.res" value="resources.jar"/>
<property name="jar.path" value="${build.dir}/AntLabRun.jar"/>
<property name="main.class" value="edu.gatech.oad.antlab.pkg1.AntLabMain"/>
<path id="classpath">
<fileset dir="${lib.dir}" includes="lib.res"/>
</path>
</target>
<target name="jar" depends="compile">
<manifestclasspath property="jar.classpath" jarfile="${jar.path}">
<classpath refid="classpath"/>
</manifestclasspath>
<jar destfile="${jar.path}" basedir="${src.dir}">
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Class-Path" value="${jar.classpath}" />
</manifest>
</jar>
</target>
<target name="clean" depends="init">
<delete dir="${build.dir}"/>
<delete dir="${apidoc.dir}"/>
</target>
<target name="run" depends="jar">
<java jar="${jar.path}" fork="true"/>
</target>
<target name="all">
<antcall target="init"/>
<antcall target="prepare"/>
<antcall target="compile"/>
<antcall target="javadoc"/>
<antcall target="jar"/>
<antcall target="run"/>
</target>
Every time I run my jar it gives me this error, I don't know what is causing it. Everything else works fine and I've googled around and have found several posts with this same issue but nothing that worked for them seems to be working for me.
Try to add a classname="${main.class}" inside the java tag of the run target.
Also, I think that even when running your program, you need to add the libraries to the classpath.

Unable to find images when running selenium/sikuli scripts using Ant

I've written a couple selenium scripts (Java) and use sikuli to verify the images exist. It worked fine when I ran the tests through Eclipse/TestNG but with Ant I'm getting the following error:
[testng] [error] resources/x.png looks like a file, but can't be found on the disk. Assume it's text.
The following is my build.xml, please let me know if there's more information I can provide.
<project name="test" default="test">
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="lib.dir" location="lib" />
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="makedir" depends="clean">
<mkdir dir="${build.dir}" />
</target>
<!-- Compiles the java code -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath"/>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\build.test.ant.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="test.Main" />
</manifest>
</jar>
</target>
<taskdef resource="testngtasks" classpath="${lib.dir}/testng-6.5.2.jar"/>
<target name="test" depends="jar">
<testng
classpath="${build.dir}:${lib.dir}/selenium-java-2.24.1.jar:${lib.dir}/selenium-server-standalone-2.24.1.jar:${lib.dir}/sikuli-script.jar"
outputDir="${testng.report.dir}"
testname="test1">
<xmlfileset dir="." includes="testng.xml" />
</testng>
<fail message="BUILD FAILURE" if="failed" />
</target>
</project>

A sample of build.xml for ANTLR project?

A project's building process is suffering, unless it becomes automatic.
I have started with ANTLR since recently. ANT seems to be the very building tool for that purpose. Compile, jar, and test... But I have found little code source of the script build.xml for that purpose.
So would you guys would like to share your template build.xml for your antlr project (either Java task or ANTLR task will be fine)? Thanks.
This is roughly what I use:
<?xml version="1.0" encoding="UTF-8"?>
<project name="YourProject">
<property name="main.package" value="yourproject"/>
<property name="parser.package" value="${main.package}/parser"/>
<property name="main.src.dir" value="src/main"/>
<property name="test.src.dir" value="src/test"/>
<property name="grammar.src.dir" value="src/grammar"/>
<property name="grammar.file" value="${grammar.src.dir}/YourGrammar.g"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="main.build.dir" value="${classes.dir}/main"/>
<property name="test.build.dir" value="${classes.dir}/test"/>
<path id="classpath">
<pathelement location="${main.src.dir}"/>
<pathelement location="${test.src.dir}"/>
<pathelement location="${main.build.dir}"/>
<pathelement location="${test.build.dir}"/>
<!-- the ANTLR jar is in the lib directory, of course -->
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<!-- init target -->
<target name="compile" depends="init" description="Compiles all source files.">
<javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false">
<classpath refid="classpath"/>
</javac>
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
<classpath refid="classpath"/>
</javac>
</target>
<target name="generate" depends="init" description="Generates the lexer and parser from the .g grammar file.">
<echo>Generating the lexer and parser...</echo>
<java classname="org.antlr.Tool" fork="true" failonerror="true">
<arg value="-fo"/>
<arg value="${main.src.dir}/${parser.package}"/>
<arg value="${grammar.file}"/>
<classpath refid="classpath"/>
</java>
<!--
compile the generated parser and lexer source file to see
if there's no illegal code inside these source files
-->
<antcall target="compile"/>
</target>
<!-- other targets -->
</project>
Here's the core pieces of mine, which I think integrates a little better. I'm not sure when ANTLR's -make option was added--I'm using 3.2.
It assumes that grammars are kept in the packages where their generated parsers will be going.
Keeps generated source files separate from normal source files so that they can be cleaned
Only regenerates parser+lexer sources when they are older than grammar file
multiple grammars can be processed in a single pass
ANTLR errors are reported correctly by ant
<project name="MyProject">
<property name="lib.antlr" value="lib/antlr-3.2.jar" />
<property name="src.dir" value="${user.dir}" />
<property name="src.java" value="${src.dir}/java" />
<property name="build.dir" value="build" />
<property name="build.src" value="${build.dir}/src" />
<property name="build.classes" value="${build.dir}/classes" />
<path id="compile.class.path">
<pathelement location="${build.classes}" />
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${reports.dir}" />
</target>
<target name="generate" description="Generate parsers from ANTLR grammars">
<mkdir dir="${build.src}" />
<java jar="${lib.antlr}" fork="true" dir="${src.java}" failonerror="true">
<arg value="-verbose" />
<arg value="-make" />
<arg value="-o" />
<arg path="${build.src}" />
<arg value="com/example/io/Foo.g" />
<arg value="com/example/text/Bar.g" />
</java>
</target>
<target name="compile" depends="generate">
<property name="javac.debug" value="on" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes}" />
<javac destdir="${build.classes}" source="1.6" target="1.6" includeantruntime="false" debuglevel="lines,vars,source">
<src path="${src.java}" />
<src path="${build.src}" />
<include name="com/example/**/*.java" />
<classpath refid="compile.class.path"/>
</javac>
</target>
</project>
You can also look at How to use ant with ANTLR3.

Resources