0

I have to create an ant target that will add component .jar to a zip. The problem is that I do not have the version of component always defined. For example:

    <zip destfile="${dist.dir}\result-${result-version}.zip">
       <fileset dir="${dist.dir}" includes="maincomponent-${maincomponenet-version}*.jar"/>
       <fileset dir="${second-componenet-folder}" includes="${second-component-version}.jar" />
   </zip>

How can I add some condition that will create the zip with the main component if the second-component-version property is not defined?

Alex
  • 10,470
  • 8
  • 40
  • 62
Radu D
  • 3,505
  • 9
  • 42
  • 69

1 Answers1

2

Using Condition and isset (conditions):

<target name="zip">
    <fileset id="main" dir="${dist.dir}" includes="maincomponent-${maincomponenet-version}.jar" />
    <fileset id="component" dir="${second-componenet-folder}" includes="${second-component-version}.jar" />
    <condition property="jar.file" value="component" else="main">
        <isset property="second-component-version"/>
    </condition>
    <zip destfile="${dist.dir}/result-${result-version}.zip">
        <fileset refid="${jar.file}" />
    </zip>
</target>
Alex
  • 10,470
  • 8
  • 40
  • 62
  • will this add both files if the second-component-version is supplied? – Radu D Apr 03 '13 at 09:14
  • is it easy changeable to include both if second component is defined and only the main if the second variable is not set? I have many components to add in this way – Radu D Apr 03 '13 at 12:16
  • 1
    You can either create a third combined `fileset` element from the parent directory to include both files, or use [`union`](http://ant.apache.org/manual/Types/resources.html#union) to combined the two original `fileset`s – Alex Apr 03 '13 at 13:44