Doug Cutting wrote:

> Andy Hedges wrote:
>
>>     As you can see for rtf I need to do more than just download the jar
>> file as there is not a precompiled version on the net. I have to
>> download the source and then run a number of steps to get to the
>> resulting jar. I'm not sure that the plugin's build.xml is the place to
>> be doing this as it seems to be called twice.
>
>
> The ant excerpts I sent were careful to only download things once.
>
> http://www.mail-archive.com/nutch-developers%40lists.sourceforge.net/msg03602.html
>
>
> Conditionals are not straightforward in Ant.  First, <available/> is
> used to note whether things have already been downloaded.  Then an
> "unless" attribute is used on the target that actually downloads
> things so that the target is conditioned on the results of the
> <available/>. Finally, override the "init-plugin" target to depend on
> the download task.  You could unpack & build the RTF parser in either
> the download or the init-plugin task, as you wish.

>
> Does that make sense?

Yes, it does. I was just concerned that the whole thing was getting
called twice in a single run. I'm used to ant build files where
everything is in targets (excluding classpath setup) and so it is
impossible for anything to be called twice in the same run. I missed the
fact that you could specify a download or init-plugin method and that
would get called. The available method you sent I understood. Your
method ensures that that the files are downloaded once over multiple
runs of the build - I hadn't got that far yet ;). On reflection I can
see that one could used the available/unless method to ensure it doesn't
run twice in the same run - I'm just used to using targets and depends
for that.

So I've modified the ant file and it works in the following way. If the
file hasn't been downloaded it does so. Even if the src has been
download it may not have been compiled and jared and so that is checked
and if necessary it is build. It then removes all the intermediate files
that were created (excluding the src).

Anyway here is the new build.xml
---
<?xml version="1.0"?>

<project name="parse-rtf" default="jar">

  <import file="../build-plugin.xml"/>
   
  <property name="rtf-src.jar" value="tmp/rtf_parser_src.jar"/>
  <property name="rtf-parser.jar" value="lib/rtf-parser.jar"/>
   
  <available file="${rtf-src.jar}" property="rtf-src.jar.available"/>
  <available file="${rtf-parser.jar}" property="rtf-parser.available"/>
   
  <target name="download-rtf-src" unless="rtf-src.jar.available">
      <mkdir dir="tmp"/>
    <get src="http://www.cobase.cs.ucla.edu/pub/javacc/rtf_parser_src.jar";
              dest="tmp/rtf_parser_src.jar"/>    
  </target>
   
  <target name="build-rtf-parser" depends="download-rtf-src"
unless="rtf-parser.available">
      <unjar src="${rtf-src.jar}"
            dest="tmp"/>
      <javacc target="tmp/rtf/RTFParser.jj"
        javacchome="${javacc.home}">
      </javacc>
   
      <mkdir dir="tmp/classes"/>
      <javac srcdir="tmp" destdir="tmp/classes"/>
      <jar destfile="${rtf-parser.jar}" basedir="tmp/classes"/>
        <delete>
          <fileset dir="tmp">
            <exclude name="*.jar"/>
          </fileset>
        </delete>
  </target>
   
  <target name="init-plugin" depends="build-rtf-parser">

      <!-- for junit test -->
      <mkdir dir="${build.test}/data"/>
      <copy file="sample/test.rtf" todir="${build.test}/data"/>
     
  </target>
</project>



>
> Doug
>
>
> -------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT Products from real users.
> Discover which products truly live up to the hype. Start reading now.
> http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Nutch-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nutch-developers




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Nutch-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nutch-developers

Reply via email to