<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.jboss.tools.integration-stack</groupId>
  <artifactId>target-platform</artifactId>
  <version>4.3.2.Final</version>

  <name>JBoss Tools Integration Stack Target Platform</name>
  <description>
    Create the JBTIS target platform files and optionally a mirrored repository.

    JBoss Tools integration stack component target dependencies + JBoss Tools core target dependencies +
    JBoss Tools multiple core target dependencies forming an 'aggregate-base.target' and an 
    'aggregate-base-ea.target' combined target.

    Then add any leftover community dependencies to the aggregate forming an 'aggregate-full.target'/
    'aggregate-full-ea.target'.

    Build -P mirror to get:
       target-platform-ea.target.repo
       target-platform.target.repo
  </description>

  <packaging>pom</packaging>

  <!-- JBoss parent POM required for nexus deployment. -->
  <parent>
    <groupId>org.jboss</groupId>
    <artifactId>jboss-parent</artifactId>
    <version>17</version>
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <tychoVersion>0.23.1</tychoVersion>
    <tychoExtrasVersion>${tychoVersion}</tychoExtrasVersion>
    <jboss-tycho-version>0.23.1</jboss-tycho-version>
    <JBTCoreTPVersion>4.52.0.Final</JBTCoreTPVersion>
  </properties>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>2.5.1</version><!-- same version as build plugin -->
        <reportSets>
          <reportSet>
            <reports>
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

  <build>

    <plugins>

      <plugin>
	<groupId>org.eclipse.tycho</groupId>
	<artifactId>tycho-maven-plugin</artifactId>
	<version>${tychoVersion}</version>
	<extensions>true</extensions>
      </plugin>

      <plugin>
	<groupId>org.jboss.tools.tycho-plugins</groupId>
	<artifactId>target-platform-utils</artifactId>
        <version>${jboss-tycho-version}</version>

	<!-- Merge:
	     1. released integration-stack specific target dependencies:   integration-stack-base.target
	     2. the JBoss Tools core target dependencies:                + core-base.target
	     3. the JBoss Tools multiple core target dependencies:       + jbosstools-multiple.target
                                                                           =============================
	     to generate an aggregate base target dependencies file:       aggregate-base.target
        -->
	<executions>

	  <!-- aggregate-base.target -->
	  <execution>

	    <id>merge-base</id>
	    <phase>generate-resources</phase>
	    <goals>
	      <goal>merge-targets</goal>
	    </goals>

	    <configuration>

	      <sourceTargetArtifacts>
		<item>
		  <groupId>org.jboss.tools.targetplatforms</groupId>
		  <artifactId>jbosstools-multiple</artifactId>
		  <version>${JBTCoreTPVersion}</version>
		  <classifier>jbosstools-multiple</classifier>
		</item>
	      </sourceTargetArtifacts>

	      <sourceTargetFiles>
		<item>${basedir}/src/targets/integration-stack-base.target</item>
		<item>${basedir}/src/targets/core-base.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/aggregate-base.target</outputFile>

	    </configuration>
	  </execution>

	  <!-- aggregate-full.target

	       Merge:
	       1. the previously generated aggregate base target file:    aggregate-base.target
	       2. the community-specific target dependencies:           + community.target
                                                                          ====================
	       to generate the full community target dependencies file:   aggregate-full.target
	    -->
	  <execution>

	    <id>merge-community-full</id>
	    <phase>generate-resources</phase>
	    <goals>
	      <goal>merge-targets</goal>
	    </goals>

	    <configuration>

	      <sourceTargetFiles>
		<item>${basedir}/src/targets/community.target</item>
		<item>${project.build.directory}/aggregate-base.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/aggregate-full.target</outputFile>

	    </configuration>
	  </execution>

	  <!-- integration-stack-community.target

	       Merge:
	       1. the integration-stack specific target dependencies:     integration-stack-base.target
	       2. the community-specific target dependencies:           + community.target
                                                                          =================================
	       to generate the full community target dependencies file:   integration-stack-community.target

               This target file will be mirrored to create the JBTIS target platform repository.
	    -->
	  <execution>

	    <id>merge-community</id>
	    <phase>generate-resources</phase>
	    <goals>
	      <goal>merge-targets</goal>
	    </goals>

	    <configuration>

	      <sourceTargetFiles>
		<item>${basedir}/src/targets/integration-stack-base.target</item>
		<item>${basedir}/src/targets/community.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/integration-stack-community.target</outputFile>

	    </configuration>
	  </execution>

	  <!-- Merge:
	       1. integration-stack specific target dependencies:                    integration-stack-base.target
	       2. early access integration-stack specific target dependencies:     + integration-stack-base-ea.target
	       3. the JBoss Tools core target dependencies:                        + core-base.target
	       4. the JBoss Tools multiple core target dependencies:               + jbosstools-multiple.target
                                                                                     =============================
	       to generate an early access aggregate base target dependencies file:  aggregate-base-ea.target
          -->
	  <execution>

	    <id>merge-base-ea</id>
	    <phase>generate-resources</phase>
	    <goals>
	      <goal>merge-targets</goal>
	    </goals>

	    <configuration>

	      <sourceTargetArtifacts>
		<item>
		  <groupId>org.jboss.tools.targetplatforms</groupId>
		  <artifactId>jbosstools-multiple</artifactId>
		  <version>${JBTCoreTPVersion}</version>
		  <classifier>jbosstools-multiple</classifier>
		</item>
	      </sourceTargetArtifacts>

	      <sourceTargetFiles>
		<item>${basedir}/src/targets/integration-stack-base.target</item>
		<item>${basedir}/src/targets/integration-stack-base-ea.target</item>
		<item>${basedir}/src/targets/core-base.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/aggregate-base-ea.target</outputFile>

	    </configuration>
	  </execution>

	  <!-- Merge:
	       1. the previously generated aggregate base EA target file:    aggregate-base-ea.target
	       2. the community-specific target dependencies:              + community.target
                                                                             ========================
	       to generate the full community target dependencies file:      aggregate-full-ea.target
	    -->
	  <execution>
	    <id>merge-community-full-ea</id>
	    <phase>generate-resources</phase>
	    <goals>
	      <goal>merge-targets</goal>
	    </goals>

	    <configuration>

	      <sourceTargetFiles>
		<item>${basedir}/src/targets/community.target</item>
		<item>${project.build.directory}/aggregate-base-ea.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/aggregate-full-ea.target</outputFile>

	    </configuration>
	  </execution>

	  <!-- Merge:
	       1. the integration-stack specific target dependencies:     integration-stack-base-ea.target
	       2. the community-specific target dependencies:           + community.target
                                                                          ==================================
	       to generate the full community target dependencies file:   integration-stack-community-ea.target

               This target file will be mirrored to create the JBTIS target platform early access repository.
	    -->
	  <execution>
	    <id>merge-community-ea</id>
	    <phase>generate-resources</phase>
	    <goals>
	      <goal>merge-targets</goal>
	    </goals>

	    <configuration>

	      <sourceTargetFiles>
		<item>${basedir}/src/targets/integration-stack-base-ea.target</item>
		<item>${basedir}/src/targets/community.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/integration-stack-community-ea.target</outputFile>

	    </configuration>
	  </execution>

	</executions>
      </plugin>

      <plugin>
	<groupId>org.eclipse.tycho.extras</groupId>
	<artifactId>target-platform-validation-plugin</artifactId>
	<version>${tychoExtrasVersion}</version>

	<executions>
	  <execution>

	    <!--Validate the aggregated target dependencies. -->
	    <phase>verify</phase>
	    <goals>
	      <goal>validate-target-platform</goal>
	    </goals>

	    <configuration>

	      <targetFiles>
		<param>${project.build.directory}/aggregate-base.target</param>
		<param>${project.build.directory}/aggregate-full.target</param>
		<param>${project.build.directory}/aggregate-base-ea.target</param>
		<param>${project.build.directory}/aggregate-full-ea.target</param>
	      </targetFiles>
	      <failOnError>true</failOnError>

	    </configuration>
	  </execution>
	</executions>
      </plugin>

      <!-- Use the codehaus mojo to package the aggegated target dependencies (base and community). -->
      <plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>build-helper-maven-plugin</artifactId>
	<version>1.3</version>

	<executions>

	  <execution>
	    <id>attach-artifacts-base</id>
	    <phase>package</phase>
	    <goals>
	      <goal>attach-artifact</goal>
	    </goals>

	    <configuration>

	      <tasks>
		<echo>Packaging the aggregated base target dependencies.</echo>
	      </tasks>

	      <artifacts>
		<artifact>
		  <file>${project.build.directory}/aggregate-base.target</file>
		  <type>target</type>
		  <classifier>base</classifier>
		</artifact>
	      </artifacts>

	    </configuration>
	  </execution>

	  <execution>
	    <id>attach-artifacts-full</id>
	    <phase>package</phase>
	    <goals>
	      <goal>attach-artifact</goal>
	    </goals>

	    <configuration>

	      <tasks>
		<echo>Packaging the aggregated full target dependencies (base + community).</echo>
	      </tasks>

	      <artifacts>
		<artifact>
		  <file>${project.build.directory}/aggregate-full.target</file>
		  <type>target</type>
		  <classifier>full</classifier>
		</artifact>
	      </artifacts>

	    </configuration>
	  </execution>

	  <execution>
	    <id>attach-artifacts-target-platform-base</id>
	    <phase>package</phase>
	    <goals>
	      <goal>attach-artifact</goal>
	    </goals>
	    <configuration>
	      <artifacts>
		<artifact>
		  <file>src/targets/integration-stack-base.target</file>
		  <type>target</type>
		  <classifier>integration-stack-base</classifier>
		</artifact>
	      </artifacts>
	    </configuration>
	  </execution>

	  <execution>
	    <id>attach-artifacts-base-ea</id>
	    <phase>package</phase>
	    <goals>
	      <goal>attach-artifact</goal>
	    </goals>

	    <configuration>

	      <tasks>
		<echo>Packaging the aggregated early access base target dependencies.</echo>
	      </tasks>

	      <artifacts>
		<artifact>
		  <file>${project.build.directory}/aggregate-base-ea.target</file>
		  <type>target</type>
		  <classifier>base-ea</classifier>
		</artifact>
	      </artifacts>

	    </configuration>
	  </execution>

	  <execution>
	    <id>attach-artifacts-full-ea</id>
	    <phase>package</phase>
	    <goals>
	      <goal>attach-artifact</goal>
	    </goals>

	    <configuration>

	      <tasks>
		<echo>Packaging the aggregated early access full target dependencies (base + community).</echo>
	      </tasks>

	      <artifacts>
		<artifact>
		  <file>${project.build.directory}/aggregate-full-ea.target</file>
		  <type>target</type>
		  <classifier>full-ea</classifier>
		</artifact>
	      </artifacts>

	    </configuration>
	  </execution>

	  <execution>
	    <id>attach-artifacts-target-platform-base-ea</id>
	    <phase>package</phase>
	    <goals>
	      <goal>attach-artifact</goal>
	    </goals>
	    <configuration>
	      <artifacts>
		<artifact>
		  <file>src/targets/integration-stack-base-ea.target</file>
		  <type>target</type>
		  <classifier>integration-stack-base-ea</classifier>
		</artifact>
	      </artifacts>
	    </configuration>
	  </execution>

	</executions>
      </plugin>

    </plugins>
  </build>

  <!-- Mirror the integration stack target dependencies (release/ early access) for both community (jbtis) and
       production (jbdsis).  These will be used by the jbosstools and devstudio poms as an extra repo for resolving 
       the contents of the .target files into a repository. -->
  <profiles>

    <profile>
      <id>mirror</id>
      <activation>
	<activeByDefault>false</activeByDefault>
      </activation>

      <build>
	<plugins>

	  <plugin>
	    <groupId>org.jboss.tools.tycho-plugins</groupId>
	    <artifactId>target-platform-utils</artifactId>
            <version>${jboss-tycho-version}</version>

	    <executions>

	      <!-- Mirror the integration stack community target dependencies to a repository. -->
	      <execution>
		<id>mirror-target-platform-repo</id>
		<phase>package</phase>
		<goals>
		  <goal>mirror-target-to-repo</goal>
		</goals>
		<configuration>
		  <sourceTargetFile>${project.build.directory}/integration-stack-community.target</sourceTargetFile>
		  <outputRepository>${project.build.directory}/${project.artifactId}.target.repo</outputRepository>
		</configuration>
	      </execution>

	      <!-- Mirror the integration stack community early access target dependencies to a repository. -->
	      <execution>
		<id>mirror-target-platform-repo-ea</id>
		<phase>package</phase>
		<goals>
		  <goal>mirror-target-to-repo</goal>
		</goals>
		<configuration>
		  <sourceTargetFile>${project.build.directory}/integration-stack-community-ea.target</sourceTargetFile>
		  <outputRepository>${project.build.directory}/${project.artifactId}-ea.target.repo</outputRepository>
		</configuration>
	      </execution>

	      <!-- Mirror the jbdsis integration stack target dependencies to a repository. -->
	      <execution>
		<id>mirror-target-platform-jbdsis-repo</id>
		<phase>package</phase>
		<goals>
		  <goal>mirror-target-to-repo</goal>
		</goals>
		<configuration>
		  <sourceTargetFile>${basedir}/src/targets/integration-stack-base.target</sourceTargetFile>
		  <outputRepository>${project.build.directory}/${project.artifactId}-jbdsis.target.repo</outputRepository>
		</configuration>
	      </execution>

	      <!-- Mirror the jdbsis integration stack early access target dependencies to a repository. -->
	      <execution>
		<id>mirror-target-platform-jbdsis-repo-ea</id>
		<phase>package</phase>
		<goals>
		  <goal>mirror-target-to-repo</goal>
		</goals>
		<configuration>
		  <sourceTargetFile>${basedir}/src/targets/integration-stack-base-ea.target</sourceTargetFile>
		  <outputRepository>${project.build.directory}/${project.artifactId}-jbdsis-ea.target.repo</outputRepository>
		</configuration>
	      </execution>

	    </executions>
	  </plugin>

	  <plugin>
	    <groupId>org.apache.maven.plugins</groupId>
	    <artifactId>maven-antrun-plugin</artifactId>
	    <version>1.7</version>

	    <executions>

	      <execution>
		<id>package-target-platform-repo</id>
		<phase>package</phase>

		<configuration>
		  <quiet>true</quiet>
		  <target>
		    <!-- ANT script to remove the <references> section from the mirror repo content.xml. -->
		    <ant antfile="../scripts/remove.references.xml" dir=".">
		      <property name="workDir" value="./target/target-platform.target.repo" />
		    </ant>
		  </target>
		</configuration>
		<goals>
		  <goal>run</goal>
		</goals>
	      </execution>

	      <execution>
		<id>package-target-platform-repo-ea</id>
		<phase>package</phase>

		<configuration>
		  <quiet>true</quiet>
		  <target>
		    <!-- ANT script to remove the <references> section from the mirror repo content.xml. -->
		    <ant antfile="../scripts/remove.references.xml" dir=".">
		      <property name="workDir" value="./target/target-platform-ea.target.repo" />
		    </ant>
		  </target>
		</configuration>
		<goals>
		  <goal>run</goal>
		</goals>
	      </execution>

	      <execution>
		<id>package-target-platform-jbdsis-repo</id>
		<phase>package</phase>

		<configuration>
		  <quiet>true</quiet>
		  <target>
		    <!-- ANT script to remove the <references> section from the mirror repo content.xml. -->
		    <ant antfile="../scripts/remove.references.xml" dir=".">
		      <property name="workDir" value="./target/target-platform-jbdsis.target.repo" />
		    </ant>
		  </target>
		</configuration>
		<goals>
		  <goal>run</goal>
		</goals>
	      </execution>

	      <execution>
		<id>package-target-platform-jbdsis-repo-ea</id>
		<phase>package</phase>

		<configuration>
		  <quiet>true</quiet>
		  <target>
		    <!-- ANT script to remove the <references> section from the mirror repo content.xml. -->
		    <ant antfile="../scripts/remove.references.xml" dir=".">
		      <property name="workDir" value="./target/target-platform-jbdsis-ea.target.repo" />
		    </ant>
		  </target>
		</configuration>
		<goals>
		  <goal>run</goal>
		</goals>
	      </execution>

	    </executions>

	    <dependencies>
	      <dependency>
		<groupId>commons-net</groupId>
		<artifactId>commons-net</artifactId>
		<version>1.4.1</version>
	      </dependency>
	      <dependency>
		<groupId>org.apache.ant</groupId>
		<artifactId>ant</artifactId>
		<version>1.8.2</version>
	      </dependency>
	      <dependency>
		<groupId>org.apache.ant</groupId>
		<artifactId>ant-nodeps</artifactId>
		<version>1.8.1</version>
	      </dependency>
	      <dependency>
		<groupId>org.apache.ant</groupId>
		<artifactId>ant-trax</artifactId>
		<version>1.8.0</version>
	      </dependency>
	      <dependency>
		<groupId>org.apache.ant</groupId>
		<artifactId>ant-commons-net</artifactId>
		<version>1.8.2</version>
	      </dependency>
	      <dependency>
		<groupId>org.apache.ant</groupId>
		<artifactId>ant-apache-regexp</artifactId>
		<version>1.8.2</version>
	      </dependency>
	      <dependency>
		<groupId>ant-contrib</groupId>
		<artifactId>ant-contrib</artifactId>
		<version>1.0b3</version>
	      </dependency>
	    </dependencies>

	  </plugin>

          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
               <descriptors>
                 <descriptor>src/assemblies/publish-jbtis-tp-assembly.xml</descriptor>
                 <descriptor>src/assemblies/publish-jbtis-ea-tp-assembly.xml</descriptor>
               </descriptors>
              <finalName>${project.artifactId}-${project.version}</finalName>
            </configuration>
          </plugin>
	</plugins>

      </build>
    </profile>
  </profiles>

</project>
