Badiou30120
Badiou30120

Reputation: 73

Ant task: add a file to an archive with a parameter

everyone!

I'm currently struggling with an Ant task for a DITA plugin. It would consist in adding a file (whatever the extension is) to an archive via the command line. The idea is to set a parameter like this :

dita -f mymap.ditamap -transtype htmlCustom -Dadd-file=fileOfMyChoice.txt

The part that interests me is the last one: -Dadd-file=fileOfMyChoice.txt

So far, I've tried to include two choices into my target.

  1. The user sets a add-file parameter and its value is added into the fileset with the base set of generated files.
  2. Or, nothing is passed via this parameter and the base set of generated files is included in the fileset.

The part that is still challenging to me if the one that identifies if a parameter add-file is passed and how its value is transmitted in a fileset.

If you have any pointers for me, that would be awesome.

<target name="map2exportmap">
    <dirname property="dita.temp.dir.fullpath" file="${dita.temp.dir}${file.separator}dummy.file"/>
    <xslt in="${dita.temp.dir.fullpath}${file.separator}.job.xml"
      out="${dita.temp.dir.fullpath}${file.separator}allResources.out"
      style="${dita.plugin.com.myplugin.dir}/xsl/generateAllResources.xsl" 
      force="true"/>
    <mkdir dir="${dita.map.output.dir}/temp"/>

    <fileset id="global" dir="${user.input.dir}/" includesfile="${dita.temp.dir.fullpath}${file.separator}allResources.out" />
    <union id="globalAddendum">
      <fileset id="ditaGeneration" dir="${user.input.dir}/" includesfile="${dita.temp.dir.fullpath}${file.separator}allResources.out"/>
      <fileset id="additionalFile" dir="${user.input.dir}/" includesfile="${add-File}"/>
    </union>
    
<condition property="withAddedFile" refid="globalAddendum" else="global">
        <isset property="add-file"/>
    </condition>
    <copy todir="${dita.map.output.dir}/temp">
      <fileset dir="${user.input.dir}/" includesfile="${withAddedFile}"/>
    </copy>

    <zip destfile="${dita.map.output.dir}/${dita.map.filename.root}.zip">
      <fileset dir="${dita.map.output.dir}/temp"/>
    </zip>
    <delete dir="${dita.map.output.dir}/temp"/>
  </target>

Upvotes: 1

Views: 60

Answers (1)

Badiou30120
Badiou30120

Reputation: 73

everyone! I found the solution!

Here is the code if it can help anyone.

<target name="map2exportmap">
<dirname property="dita.temp.dir.fullpath" file="${dita.temp.dir}${file.separator}dummy.file"/>
<xslt in="${dita.temp.dir.fullpath}${file.separator}.job.xml"
  out="${dita.temp.dir.fullpath}${file.separator}allResources.out"
  style="${dita.plugin.com.xxxxx.xxxxxxx.dir}/xsl/generateAllResources.xsl" 
  force="true"/>
<mkdir dir="${dita.map.output.dir}/temp"/>
<!-- Create two filesets depending on the argument `add-file` sent in the command line -->
<fileset id="base" dir="${user.input.dir}/" includesfile="${dita.temp.dir.fullpath}${file.separator}allResources.out" />
<fileset id="addedFile" file="${add-file}"/>
<!-- this is the core of the condition. It tests if there was an argument for `add-file, then ii sets the property `with.or.without.added.file`-->
<condition property="with.or.without.added.file" value="addedFile" else="base">
  <isset property="add-file"/>
</condition>
<echo>${with.or.without.added.file}</echo>
<echo>${add-file}</echo>
<!-- Process the copy of content in the tempoerary folder-->
<copy todir="${dita.map.output.dir}/temp">
  <fileset refid="${with.or.without.added.file}"/>
  <fileset id="base" dir="${user.input.dir}/" includesfile="${dita.temp.dir.fullpath}${file.separator}allResources.out" />
</copy>
<!-- Execute the zip packaging -->
<zip destfile="${dita.map.output.dir}/${dita.map.filename.root}.zip">
  <fileset dir="${dita.map.output.dir}/temp"/>
</zip>
<delete dir="${dita.map.output.dir}/temp"/>

Upvotes: 0

Related Questions