<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
 
  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<project name="ivy">
  <description>Targets for ivy.xml creation/handling</description>

  <dirname property="common.basedir" file="${ant.file.ivy}"/>
  <import file="${common.basedir}/common-tasks.xml"/>

  <!-- ========================================================== -->
  <!-- init all the Ivy support   -->
  <!-- ========================================================== -->
  <target name="ivy-init"
          depends="setup">
    <property name="ivy.organization" value="org/apache"/>
    <property name="target.ivy.xml"
              location="${build.lib}/${artifact.stub}-ivy.xml"/>
    <tstamp>
      <format property="publication.datetime" pattern="yyyyMMddHHmmss"/>
    </tstamp> 

    <!--look for a template Ivy file -->
    <property name="project.ivy.xml" location="project-template.ivy.xml"/>
    <available property="project.has-ivy.xml?" file="${project.ivy.xml}"/>
  </target>


  <!-- ========================================================== -->
  <!-- ivy.xml creation/copy, depending on whether it exists or not   -->
  <!-- ========================================================== -->

  <!--copy an existing template-->
  <target name="copy-ivy.xml" depends="ivy-init" if="project.has-ivy.xml?">
    <expandingcopy file="${project.ivy.xml}" tofile="${target.ivy.xml}"/>
  </target>


  <!-- inline creation of a zero dependency ivy.xml.
    We don't even declare a dependency on ant!
  -->
  <target name="make-ivy.xml" depends="ivy-init" unless="project.has-ivy.xml?">
    <echo message="Creating ivy.xml ${target.ivy.xml}" level="verbose"/>
    <echoxml file="${target.ivy.xml}">
      <ivy-module version="2.0">
        <info organisation="${ivy.organization}"
              module="ant"
              revision="${artifact.version}"
              publication="${publication.datetime}">
          <license name="Apache Software License 2.0"
                   url="http://www.apache.org/licenses/LICENSE-2.0"/>
          <ivyauthor name="Apache Ant Development Team"
                     url="http://ant.apache.org/"/>
        </info>
        <publications xmlns:e="urn:ant.apache.org:ivy-extras">
          <artifact name="${artifact.name}" type="pom" ext="pom"/>
          <artifact name="${artifact.name}" type="pom.asc" ext="pom.asc"/>
          <artifact name="${artifact.name}" type="jar" ext="jar"/>
          <artifact name="${artifact.name}" type="jar.asc" ext="jar.asc"/>
          <artifact name="${artifact.name}" type="source" ext="jar"
                    e:classifier="sources"/>
          <artifact name="${artifact.name}" type="source.asc" ext="jar.asc"
                    e:classifier="sources"/>
          <artifact name="${artifact.name}" type="javadoc" ext="jar"
                    e:classifier="javadoc"/>
          <artifact name="${artifact.name}" type="javadoc.asc" ext="jar.asc"
                    e:classifier="javadoc"/>
          <artifact name="${artifact.name}" type="ivy" ext="xml"
                    e:classifier="ivy"/>
          <artifact name="${artifact.name}" type="ivy.asc" ext="xml.asc"
                    e:classifier="ivy"/>
        </publications>
      </ivy-module>
    </echoxml>
  </target>

  <target name="ivy.xml" depends="copy-ivy.xml,make-ivy.xml">
    <checksums>
      <file file="${target.ivy.xml}"/>
    </checksums>
  </target>

</project>

