ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: In AntLib defined type not accessible
Date Thu, 11 Jan 2007 09:10:32 GMT
You cannot (currently) do that like that.
However you can use ant types to do the same thing.
-------------------------------------------
src/mymapper/MyMapper.java
-------------------------------------------
package mymapper;
import org.apache.tools.ant.util.FileNameMapper;

public class MyMapper implements FileNameMapper {
    public void setFrom(String from) {}
    public void setTo(String to) {}
    public String[] mapFileName(String sourceFileName) {
        return new String[] {
            sourceFileName.toUpperCase()};
    }
}
------------------------------------
src/mymapper/antlib.xml
-----------------------------------

<antlib xmlns:current="ant:current">
  <typedef name="mymapper"
           classname="mymapper.MyMapper"/>

  <macrodef name="copyMapUpper">
    <attribute name="todir"/>
    <attribute name="fromdir"/>
    <sequential>
      <copy todir="@{todir}">
        <fileset dir="@{fromdir}"/>
        <mapper>
          <current:mymapper/>
        </mapper>
      </copy>
    </sequential>
  </macrodef>
</antlib>

(Note the use of current: to resolve the namespace that the mymapper
type is placed in - see:
http://ant.apache.org/manual/CoreTypes/antlib.html#currentnamespace)

--------------------------
build.xml:
-------------------------
<project default="t" xmlns:my="antlib:mymapper">
  <target name="t">
    <mkdir dir="classes"/>
    <javac srcdir="src" destdir="classes"
           debug="yes"/>
    <copy todir="classes">
      <fileset dir="src"/>
    </copy>
    <typedef uri="antlib:mymapper" classpath="classes"/>
    <mkdir dir="upper"/>
    <my:copyMapUpper todir="upper" fromdir="src"/>
  </target>
</project>

(For ant.1.6.5, you need to add resource="mymapper/antlib.xml"
to the <typedef uri=../>)

    <typedef uri="antlib:mymapper"
             resource="mymapper/antlib.xml"
             classpath="classes"/>

Peter

On 1/10/07, Jan.Materne@rzf.fin-nrw.de <Jan.Materne@rzf.fin-nrw.de> wrote:
> I have an AntLib for which I wrote a FileNameMapper.
> I cant use that mapper from inside the antlib.xml:
>
>
> antlib.xml
> ---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
> -8-<----
> <antlib>
>     <macrodef name="mask">
>         <attribute name="dir"/>
>         <sequential>
>             <move todir="@{dir}">
>                 <fileset dir="@{dir}"/>
>                 <!--
>                         public String[] mapFileName(String filename) {
>                                 return new
> String[]{filename.replaceAll(from, to)};
>                         }
>                 -->
>                 <mapper
>
> classname="org.apache.tools.ant.taskdefs.optional.ccm.ReplaceAllMapper"
>                         from="-"
>                         to="__"
>                 />
>             </move>
>         </sequential>
>     </macrodef>
> </antlib>
> ---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
> -8-<----
>
>
>
> build.xml
> ---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
> -8-<----
> <project xmlns:ccm="antlib:org.apache.tools.ant.taskdefs.optional.ccm"
> default="menu">
>     <taskdef uri="antlib:org.apache.tools.ant.taskdefs.optional.ccm"
>
> resource="org/apache/tools/ant/taskdefs/optional/ccm/antlib.xml"
>              classpath="../../build/antlib_ccm.jar"/>
>
>         <target name="mapper.prepare">
>                 <mkdir dir="testdir/dir-1/dir-2/dir-3"/>
>                 <echo
> file="testdir/dir-1/dir-2/dir-3/one-two-three-four-five.txt" message="a
> file"/>
>         </target>
>         <target name="mapper.mask">
>                 <ccm:mask dir="testdir"/>
>         </target>
>
> </project>
> ---8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<------
> -8-<----
>
>
> When running normally I get "ClassNotFoundException"
>
> The following error occurred while executing this line:
>
> jar:file:/C:/ant/rzf/CCM_AntLib/build/antlib_ccm.jar!/org/apache/tools/a
> nt/taskdefs/optional/ccm/antlib.xml:180:
>   java.lang.ClassNotFoundException:
> org.apache.tools.ant.taskdefs.optional.ccm.ReplaceAllMapper
>
> When invoking with -lib that works. But I dont want our developers
> always to type "-lib ......" or to disrupt the "clean" Ant installation.
>
> Any ideas with that classloader issue? (best on Java1.4+Ant 1.6.5)
>
>
> Jan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message