<?xml version="1.0"?>
<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed 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 
  xmlns:j="jelly:core"
  xmlns:d="jelly:define"
  xmlns:pom="pom"
  xmlns:util="jelly:util"
  xmlns:ant="jelly:ant"
  xmlns:artifact="artifact">

  <!-- set up pom tag library -->
  <d:taglib uri="pom">
    <d:jellybean
        name="contentvalidator"
        className="org.apache.maven.ContentValidator"
        method="execute"/>
  </d:taglib>

  <!-- default goal -->
  <goal name="pom" description="Validate the Maven XML project descriptor"
      prereqs="pom:validate"/>

  <!--
     ========================================================================
       Verify validity of <pomVersion> element.
     ========================================================================
  -->
  <goal name="pom:verify-version">

    <j:if test="${not(pom.pomVersion == '3' or pom.pomVersion == '4')}">
      <ant:fail>POM version should be either "3" or "4", found "${pom.pomVersion}".</ant:fail>
    </j:if>
    
  </goal>

  <!-- ================================================================== -->
  <!-- V A L I D A T E  P O M                                             -->
  <!-- ================================================================== -->
  <goal name="pom:validate" prereqs="pom:verify-version"
      description="Validate the Maven XML project descriptor">

    <path id="validate.path">
      <pathelement path="${plugin.getDependencyPath('isorelax')}"/>
      <pathelement path="${plugin.getDependencyPath('thaiopensource:jing')}"/>
      <pathelement path="${plugin.getDependencyPath('xml-apis')}"/>
      <pathelement path="${plugin.getDependencyPath('xerces')}"/>
    </path>

    <!-- Support Maven 1.0 rc1 and before which only had a single XSD file. -->
    <j:set var="xsd" 
        value="${maven.home}/maven-project-${pom.pomVersion}.xsd"/>
    <util:file var="xsdAsFile" name="${xsd}"/>
    <j:if test="${not(xsdAsFile.exists())}">
      <j:set var="xsd" 
          value="${maven.home}/maven-project.xsd"/>
    </j:if>
    
    <java classname="com.thaiopensource.relaxng.util.Driver" fork="true">
      <classpath refid="validate.path"/>
      <arg value="${xsd}"/>
      <arg value="${pom.file.canonicalPath}"/>
    </java>

  </goal>
  
  <goal name="pom:contentvalidate"
      description="Validate the content of the Maven POM">

    <j:new className="org.apache.maven.ContentValidator" var="contentvalidator"/>
    <j:setProperties object="${contentvalidator}" project="${pom}"/>
    
    <j:set var="notices" value="${contentvalidator.execute()}"/>
     
    <j:forEach var="notice" items="${notices}">
      <echo>${notice.Level} : ${notice.Section} : ${notice.Message}</echo>
    </j:forEach>

  </goal>

  <!-- ========================================================================== -->
  <!-- I N S T A L L  P O M                                                       -->
  <!-- ========================================================================== -->

  <goal name="pom:install"
      description="Install POM in the local repository.">

    <artifact:install
        artifact="project.xml"
        type="pom"
        project="${pom}"/> 
        
  </goal>

  <!-- ========================================================================== -->
  <!-- D E P L O Y  P O M                                                         -->
  <!-- ========================================================================== -->
  <!-- POMs are deployed in the form ${pom.artifactId}-${pom.currentVersion}.pom  -->
  <!-- to match the same versioning convention as JARs. Having the POMs           -->
  <!-- deployed during each release will allow someone to build any               -->
  <!-- version of a project reliably.                                             -->
  <!-- ========================================================================== -->

  <goal name="pom:deploy"
      description="Deploy POM to the central repository.">
        
    <artifact:deploy
        artifact="project.xml"
        type="pom"
        project="${pom}"/>     

  </goal>
    
  <!--==================================================================-->
  <!-- Install the snapshot version of the war in the local repository  -->
  <!--==================================================================-->      
  <goal name="pom:install-snapshot"
      description="Install the snapshot version of the POM in the local repository">
        
    <artifact:install-snapshot
        artifact="project.xml"
        type="pom"
        project="${pom}"/> 
        
  </goal>
        
  <!--==================================================================-->
  <!-- Deploys the snapshot of the war to the remote repository         -->
  <!--==================================================================-->      
  <goal name="pom:deploy-snapshot" 
      description="Deploys the snapshot version of the POM to remote repository">  

    <artifact:deploy-snapshot
        artifact="project.xml"
        type="pom"
        project="${pom}"/>    
        
  </goal>

</project>
