<?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.4.3.Final</version>

  <name>JBoss Tools Integration Stack Target Platform</name>
  <description>
    Create the JBTIS and DevstudioIS 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 form an 'aggregate-base.target' and an 
    'aggregate-base-ea.target' combined target.

    Add any leftover community dependencies to the aggregate forming an 'aggregate-full.target' and an
    'aggregate-full-ea.target'.

    Build -P mirror to get:
       target-platform-ea.target.repo
       target-platform.target.repo

    Build -D p2diff.skip to turn off p2 differentiation.
    Build -P jboss-release to push to the nexus release repo, push to nexus staging repo otherwise
  </description>

  <packaging>pom</packaging>

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

  <properties>
    <!-- For p2diff comparison -->
    <baseRepositoryUrl>http://download.jboss.org/jbosstools/targetplatforms/jbtistarget/4.4.3.Final-SNAPSHOT/jbtis/</baseRepositoryUrl>
    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <tychoVersion>0.26.0</tychoVersion>
    <tychoExtrasVersion>${tychoVersion}</tychoExtrasVersion>
    <jbossTychoPluginsVersion>0.26.0</jbossTychoPluginsVersion>
    <JBTCoreTPVersion>4.63.0.Final</JBTCoreTPVersion>
    <p2diff.skip>false</p2diff.skip>
    <jbossNexus>origin-repository.jboss.org</jbossNexus>
    <!-- hudson doesn't have write permissions to the releases repo below - build -P jboss-release manually to push to nexus -->
    <nexusRepo>https://${jbossNexus}/nexus/content/repositories/releases/</nexusRepo>
    <!-- <nexusRepo>https://${jbossNexus}/nexus/service/local/staging/deploy/maven2/</nexusRepo> -->
  </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.sonatype.plugins</groupId>
        <artifactId>nexus-staging-maven-plugin</artifactId>
        <version>1.6.7</version>
        <extensions>true</extensions>
        <configuration>
          <nexusUrl>https://${jbossNexus}/nexus/</nexusUrl>
          <serverId>jboss-releases-repository</serverId>
        </configuration>
      </plugin>
      -->
      <plugin>
	<groupId>org.jboss.tools.tycho-plugins</groupId>
	<artifactId>target-platform-utils</artifactId>
        <version>${jbossTychoPluginsVersion}</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. integration-stack specific target dependencies:                    integration-stack-base.target
	       2. early access integration-stack specific target dependencies:     + integration-stack-base-ea.target
                                                                                     =============================
	       to generate an IS-only EA aggregate base target dependencies file:    aggregate-base-is-ea.target
          -->
	  <execution>

	    <id>merge-base-is-ea</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/integration-stack-base-ea.target</item>
	      </sourceTargetFiles>

	      <outputFile>${project.build.directory}/aggregate-base-is-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-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>

	</executions>
      </plugin>

    </plugins>
  </build>

  <!-- Mirror the integration stack target dependencies (release/ early access) for both community (jbtis) and
       production (devstudiois).  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.

       Note that we don't enable 'includeSources' since we're mirroring the IS dependencies only - not the full
       aggregated set of dependencies (too large).  Component developers should mirror the generated nexus .target
       file (classifier base or base-ea) locally to their projects if they want source debugging.
  -->
  <profiles>

    <profile>
      <id>jboss-release</id>
      <activation>
       <activeByDefault>false</activeByDefault>
      </activation>
      <properties>      
          <nexusRepo>https://${jbossNexus}/nexus/content/repositories/releases/</nexusRepo>
      </properties>
    </profile>

    <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>${jbossTychoPluginsVersion}</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}/aggregate-base-is-ea.target</sourceTargetFile>
		  <outputRepository>${project.build.directory}/${project.artifactId}-ea.target.repo</outputRepository>
		</configuration>
	      </execution>

	      <!-- Mirror the devstudiois integration stack target dependencies to a repository. -->
	      <execution>
		<id>mirror-target-platform-devstudiois-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}-devstudiois.target.repo</outputRepository>
		</configuration>
	      </execution>

	      <!-- Mirror the jdbsis integration stack early access target dependencies to a repository. -->
	      <execution>
		<id>mirror-target-platform-devstudiois-repo-ea</id>
		<phase>package</phase>
		<goals>
		  <goal>mirror-target-to-repo</goal>
		</goals>
		<configuration>
		  <sourceTargetFile>${project.build.directory}/aggregate-base-is-ea.target</sourceTargetFile>
		  <outputRepository>${project.build.directory}/${project.artifactId}-devstudiois-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-devstudiois-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-devstudiois.target.repo" />
		    </ant>
		  </target>
		</configuration>
		<goals>
		  <goal>run</goal>
		</goals>
	      </execution>

	      <execution>
		<id>package-target-platform-devstudiois-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-devstudiois-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>

          <plugin>
            <groupId>org.eclipse.tycho.extras</groupId>
            <artifactId>tycho-eclipserun-plugin</artifactId>
            <version>${tychoVersion}</version>
            <configuration>
              <repositories>
                <repository>
                  <id>p2diff</id>
                  <layout>p2</layout>
                  <url>http://download.jboss.org/jbosstools/updates/requirements/p2diff/20160508-2315/</url>
                </repository>
                <repository>
                  <id>neon</id>
                  <layout>p2</layout>
                  <url>http://download.jboss.org/jbosstools/updates/requirements/neon/</url>
                </repository>
              </repositories>

              <dependencies>
                <dependency>
                  <type>eclipse-plugin</type>
                  <artifactId>org.eclipse.equinox.p2.example.p2diff</artifactId>
                  <version>0.0.0</version>
                </dependency>
                <dependency>
                  <type>eclipse-feature</type>
                  <artifactId>org.eclipse.rcp</artifactId>
                  <version>0.0.0</version>
                </dependency>
                <dependency>
                  <type>eclipse-plugin</type>
                  <artifactId>org.eclipse.equinox.p2.transport.ecf</artifactId>
                  <version>0.0.0</version>
                </dependency>
              </dependencies>
              <skip>${p2diff.skip}</skip>
            </configuration>
            <executions>
              <execution>
                <id>generate-p2diff</id>
                <phase>verify</phase>
                <goals>
                  <goal>eclipse-run</goal>
                </goals>
                <configuration>
                  <appArgLine>-application org.eclipse.equinox.p2.example.p2diff.application -outputFile=${project.build.directory}/${project.artifactId}.p2diff -mode=ignoreVersions ${baseRepositoryUrl}/REPO file:${project.build.directory}/${project.artifactId}.target.repo</appArgLine>
                </configuration>
              </execution>
              <execution>
                <id>generate-p2diff-ea</id>
                <phase>verify</phase>
                <goals>
                  <goal>eclipse-run</goal>
                </goals>
                <configuration>
                  <appArgLine>-application org.eclipse.equinox.p2.example.p2diff.application -outputFile=${project.build.directory}/${project.artifactId}-ea.p2diff -mode=ignoreVersions ${baseRepositoryUrl}/earlyaccess/REPO file:${project.build.directory}/${project.artifactId}-ea.target.repo</appArgLine>
                </configuration>
              </execution>
            </executions>
          </plugin>

	</plugins>

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

  <distributionManagement>
    <repository>
      <id>jboss-releases-repository</id>
      <name>JBoss Releases Repository</name>
      <uniqueVersion>false</uniqueVersion>
      <url>${nexusRepo}</url>
      <layout>default</layout>
    </repository>
    <snapshotRepository>
      <id>jboss-snapshots-repository</id>
      <name>JBoss Snapshot Repository</name>
      <uniqueVersion>false</uniqueVersion>
      <url>https://${jbossNexus}/nexus/content/repositories/snapshots/</url>
      <layout>default</layout>
    </snapshotRepository>
  </distributionManagement>
  
</project>
