<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.ibm.jbatch.tck</groupId>
        <artifactId>tck-parent</artifactId>
        <version>1.1-b02</version>
    </parent>

    <groupId>com.ibm.jbatch.tck</groupId>
    <artifactId>com.ibm.jbatch.tck</artifactId>
    <packaging>jar</packaging>
    <version>1.1-b02</version>
    <name>JSR 352 TCK Core Test Artifacts</name>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.batch</groupId>
            <artifactId>javax.batch-api</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.ibm.jbatch</groupId>
            <artifactId>com.ibm.jbatch.spi</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.ibm.jbatch.tck</groupId>
            <artifactId>com.ibm.jbatch.tck.spi</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
        </dependency>
        <dependency>
            <groupId>xmlunit</groupId>
            <artifactId>xmlunit</artifactId>
        </dependency>
    </dependencies>

    <pluginRepositories>
        <pluginRepository>
            <id>maven2-repository.dev.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/glassfish/</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>filter-build.xml</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>none</phase>
                            <configuration>
                                <target>
                                    <copy file="${project.basedir}/testng/build.xml"
                                          tofile="${project.basedir}/testng/filtered.build.xml"
                                          filtering="true"
                                          overwrite="true">
                                        <filterset>
                                            <filter token="project.version" value="${project.version}" />
                                            <filter token="version.org.testng.testng" value="${version.org.testng.testng}" />
                                        </filterset>
                                    </copy>
                                </target>
                            </configuration>
                        </execution>
                        <!-- By failing when the newly-generated batch.xml changes, we force someone to review
                             the changes.   We purposely don't want to make it too easy to introduce a change here, 
                             since this will ultimately affect the pass/failing of implementations' runs against the TCK.
                             This will add as a guard that the person who would make the update knows what they're doing. -->
                        <execution>
                            <id>generate-batch.xml</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>none</phase>
                            <configuration>
                                <target>
                                    <property name="original.batch.xml" value="${project.basedir}${fs}src${fs}main${fs}resources${fs}META-INF${fs}batch.xml"/>
                                    <property name="generate.batch.xml.dir" value="${project.basedir}${fs}target${fs}generate-tck"/>
                                    <mkdir dir="${generate.batch.xml.dir}"/>
                                    <echo message="building ${generate.batch.xml.dir}/batch.xml"/>
                                    <java classname="com.ibm.jbatch.tck.utils.BatchXMLGenerator">
                                        <arg value="${project.build.outputDirectory}"/>
                                        <arg value="com${fs}ibm${fs}jbatch${fs}tck${fs}artifacts"/>
                                        <arg value="${generate.batch.xml.dir}"/>
                                        <classpath refid="maven.compile.classpath"/>
                                        <classpath>
                                            <dirset dir="${project.build.outputDirectory}/com/ibm/jbatch/tck">
                                                <include name="artifacts utils"/>
                                            </dirset>
                                        </classpath>
                                    </java>
                                    <!-- See comment above <execution> -->
                                    <fail message="Newly-generated ${generate.batch.xml.dir}${fs}batch.xml does not exactly match previous batch.xml at location: ${original.batch.xml}.  Review carefully and if this is correct, then overwrite the old ${original.batch.xml} file with the newly-generated copy of batch.xml">
                                        <condition>
                                            <not>
                                                <filesmatch file1="${original.batch.xml}" file2="${generate.batch.xml.dir}${fs}batch.xml" textfile="true"/>
                                            </not>
                                        </condition>
                                    </fail>
                                </target>
                            </configuration>
                        </execution>
                        <!-- Updating the signature files should not be done lightly.  This changes the specified, public API. 
                             We purposely make this fail by default when a signature is changed, to ensure
                             that the person who would make the update knows what they're doing. -->
                        <execution>
                            <id>generate-sigtest</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>none</phase>
                            <configuration>
                                <target>
                                    <!-- Note this simply uses the JRE level of the JRE executing Maven and generates the correspondng .sig file.
                                         So to generate the Java 6, 7, 8 .sig files you have to actually run Maven using Java 6, 7, 8, respectively, 
                                         once for each.  You can't just generate them all at once. -->
                                    <condition property="jdk" value="6">
                                        <contains string="${ant.java.version}" substring="1.6"/>
                                    </condition>
                                    <condition property="jdk" value="7">
                                        <contains string="${ant.java.version}" substring="1.7"/>
                                    </condition>
                                    <condition property="jdk" value="8">
                                        <contains string="${ant.java.version}" substring="1.8"/>
                                    </condition>
                                    <property name="old.sig.file" value="${project.basedir}${fs}sigtest${fs}jsr352-api-sigtest-java${jdk}.sig"/>
                                    <property name="new.sig.file" value="${project.basedir}${fs}generate-sigtest${fs}jsr352-api-sigtest-java${jdk}.sig"/>
                                    <mkdir dir="${project.basedir}${fs}generate-sigtest"/>
                                    <taskdef name="setup" classname="com.sun.tdk.signaturetest.ant.ASetup" classpathref="maven.plugin.classpath"/>
                                    <echo message="Generating Java ${jdk} SigTest files for batch"/>
                                    <setup failonerror="true" filename="${new.sig.file}"
                                           package="javax.batch">
                                        <classpath refid="maven.compile.classpath"/>
                                        <classpath refid="maven.plugin.classpath"/>
                                        <classpath>
                                            <pathelement location="${java.home}${fs}lib${fs}rt.jar"/>
                                        </classpath>
                                    </setup>
                                    <!-- See comment above <execution> -->
                                    <fail message="Fail on purpose to ensure that any changes to the public API signature are truly intended.  They should not be done just to get the Maven build to complete.  Newly-generated ${new.sig.file} does not exactly match previous sig test file at location: ${old.sig.file}.  Review carefully and if this is correct, then overwrite the old ${old.sig.file} file with the newly-generated copy of the sig test file">
                                        <condition>
                                            <not>
                                                <filesmatch file1="${old.sig.file}" file2="${new.sig.file}" textfile="true"/>
                                            </not>
                                        </condition>
                                    </fail>
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>javax.enterprise</groupId>
                            <artifactId>cdi-api</artifactId>
                            <version>${version.javax.enterprise.cdi-api}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>filter-build.xml</id>
                        <phase>generate-resources</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                      <skipTests>true</skipTests>
                </configuration>
              </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>jdk8</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <jdk>[1.8,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <configuration>
                            <!-- xjc uses > rather than &gt for closing tags in a generated classes javadoc -->
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>batchXML</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property><name>batchXML</name></property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate-batch.xml</id>
                                <phase>process-classes</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>        
        <profile>
            <id>sigtest</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property><name>sigtest</name></property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate-sigtest</id>
                                <phase>generate-resources</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
