<!--
   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="org.apache.easyant.plugins#source-jar" xmlns:ea="antlib:org.apache.easyant">
    <ea:core-version requiredrevision="[0.9,+]" />
    <ea:plugin module="abstract-package" revision="0.9" />

    <target name="source-jar:init" depends="abstract-package:init,abstract-compile:compile-ready">
    	<ea:parameter property="main.sources" required="true" description="directory where sources to be compiled are. This property should be reused by other plugins to locate sources."/>
        <ea:parameter property="test.sources" required="true" description="directory where test sources to be compiled are. This property should be reused by other plugins to locate sources."/>
    	
    	<ea:parameter property="target.artifacts.main.source.jar.name" default="${module.name}-sources.jar"
            description="main source artifact file name" />

        <ea:parameter property="target.artifacts.test.source.jar.name" default="${module.name}-test-sources.jar"
            description="test source artifact file name" />

        <ea:parameter property="src.main.resources" default="${basedir}/src/main/resources"
            description="directory where main resources files are stored" />
        <ea:parameter property="src.test.resources" default="${basedir}/src/test/resources"
            description="directory where test resources files are stored" />
        <ea:parameter property="src.publish.conf" default="source" description="default configuration for source artifacts" />

        <condition property="has.src.main">
            <or>
                <available file="${main.sources}" />
                <available file="${src.main.resources}" />
            </or>
        </condition>

        <condition property="has.src.test">
            <or>
                <available file="${test.sources}" />
                <available file="${src.test.resources}" />
            </or>
        </condition>
    </target>

    <!-- Main Sources -->

    <target name="source-jar:main" depends="source-jar:init" description="package main source as a JAR" if="has.src.main"
        unless="skip.source">
        <mkdir dir="${target.artifacts}" />
        <jar destfile="${target.artifacts}/${target.artifacts.main.source.jar.name}">
            <fileset dir="${src.main.resources}" erroronmissingdir="false" />
            <fileset dir="${main.sources}" erroronmissingdir="false" />
        </jar>
        <ea:registerartifact type="source" ext="jar" classifier="sources" settingsRef="${project.ivy.instance}"
            confs="${src.publish.conf}" />
    </target>

    <!-- Test sources -->

    <target name="source-jar:test" depends="source-jar:init" description="package test source as a JAR" if="has.src.test"
        unless="skip.source">
        <mkdir dir="${target.artifacts}" />
        <jar destfile="${target.artifacts}/${target.artifacts.test.source.jar.name}">
            <fileset dir="${src.test.resources}" erroronmissingdir="false" />
            <fileset dir="${test.sources}" erroronmissingdir="false" />
        </jar>
        <ea:registerartifact type="test-source" ext="jar" classifier="test-sources" settingsRef="${project.ivy.instance}"
            confs="${src.publish.conf}" />
    </target>
</project>