<?xml version="1.0" encoding="UTF-8"?>
<project name="generate-poms" xmlns:ivy="antlib:org.apache.ivy.ant">

  <property file="${basedir}/../build.properties"/>
  <import file="${basedir}/../spring-build/multi-bundle/default.xml"/>


  <path id="modules-to-process">
          <pathelement location="../org.springframework.instrument"/>
          <pathelement location="../org.springframework.instrument.classloading"/>
          <pathelement location="../org.springframework.asm"/>
          <pathelement location="../org.springframework.core"/>
          <pathelement location="../org.springframework.expression"/>
          <pathelement location="../org.springframework.beans"/>
          <pathelement location="../org.springframework.aop"/>
          <pathelement location="../org.springframework.context"/>
          <pathelement location="../org.springframework.transaction"/>
          <pathelement location="../org.springframework.oxm"/>
          <pathelement location="../org.springframework.jms"/>
          <pathelement location="../org.springframework.aspects"/>
          <pathelement location="../org.springframework.jdbc"/>
          <pathelement location="../org.springframework.web"/>
          <pathelement location="../org.springframework.orm"/>
          <pathelement location="../org.springframework.context.support"/>
          <pathelement location="../org.springframework.web.servlet"/>
          <pathelement location="../org.springframework.web.portlet"/>
          <pathelement location="../org.springframework.test"/>
  </path>

  <condition property="maven.extension" value=".bat" else="">
    <os family="windows"/>
  </condition>
  <property name="mvn.exe" value="mvn${maven.extension}"/>


  <target name="test">
    <echo message="pom version = ${project.version}"/>
  </target>

  <target name="generate-pom" depends="ivy.init">
     <all-bundles target="do-generate-pom" buildpathRef="modules-to-process"/>
  </target>

  <target name="generate-pom-test">
     <all-bundles target="do-generate-pom-test"  buildpathRef="modules-to-process"/>
  </target>


  <target name="do-generate-pom" depends="ivy.init">


    <delete file="pom.xml" quiet="true"/>
    <delete file="central-pom.xml" quiet="true"/>

    <ivy:makepom ivyfile="ivy.xml" pomfile="pom.xml">
     <mapping conf="compile" scope="compile"/>
     <mapping conf="test" scope="test"/>
     <mapping conf="provided" scope="provided"/>
     <mapping conf="runtime" scope="runtime"/>
    </ivy:makepom>

    <xmlproperty file="../org.springframework.spring-library/pom.xml"/>

    <replaceregexp file="pom.xml" 
	           match="&lt;version>.*?&lt;/version>"
                   replace="&lt;version>@project-version@&lt;/version>" />


    <exec executable="${mvn.exe}" failonerror="true">
      <arg line="org.springframework.build.repository:org.springframework.build.repository.maven:create-central"/>
    </exec>

    <move file="pom.xml" tofile="pom-bundle.xml"/>
    <move file="central-pom.xml" tofile="pom.xml"/>

    <replace file="pom.xml">
         <replacetoken><![CDATA[  <version>@project-version@</version>]]></replacetoken>
	 <replacevalue><![CDATA[  <version>@project-version@</version>
  <parent>
    <groupId>org.springframework</groupId>
    <artifactId>spring-parent</artifactId>
    <relativePath>../org.springframework.spring-parent</relativePath>
    <version>@project-version@</version>
  </parent>
]]></replacevalue>
    </replace>

    <replace file="pom.xml" token="@project-version@" value="${project.version}"/>
    <replace file="pom.xml" token="latest.integration" value="${project.version}"/>


    <fixcrlf srcDir="."  
             eol="lf"
             eof="remove"
             includes="pom.xml"/>
    
  </target>

  <target name="remove-unresolved-references">
    <!-- TODO in spring-context these are only found in S2 bundle repo, not maven central -->

    <replace file="pom.xml">
         <replacetoken><![CDATA[<dependency>
      <groupId>com.oracle.oc4j</groupId>
      <artifactId>oracle.classloader</artifactId>
      <version>10.1.3.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.enterprise</groupId>
      <artifactId>com.sun.enterprise.loader</artifactId>
      <version>1.0</version>
      <scope>provided</scope>
    </dependency>
]]></replacetoken>
	 <replacevalue><![CDATA[]]></replacevalue>
    </replace>
    

  </target>

  <target name="do-generate-pom-test">
    <exec executable="${mvn.exe}" failonerror="true">
      <env key="MAVEN_TERMINATE_CMD" value="on" />
      <arg line="-P stage,fast install"/>
    </exec>
  </target>


</project>