<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>

    <parent>
        <groupId>com.github.martinpaljak</groupId>
        <artifactId>jcardengine-package</artifactId>
        <version>26.04.20</version>
    </parent>
    <artifactId>jcardengine</artifactId>
    <name>JCardEngine - JavaCard Simulator</name>

    <properties>
        <javacard.version>3.0.5</javacard.version>
        <globalplatform.version>1.6</globalplatform.version>
    </properties>

    <dependencies>
        <!-- The base JC API -->
        <dependency>
            <groupId>oracle.javacard</groupId>
            <artifactId>api_classic</artifactId>
            <version>${javacard.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.globalplatform</groupId>
            <artifactId>api</artifactId>
            <version>${globalplatform.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
        <!-- Mandatory deps -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.17</version>
        </dependency>
        <!-- Instance proxy for Applets -->
        <dependency>
            <groupId>net.bytebuddy</groupId>
            <artifactId>byte-buddy</artifactId>
            <version>1.18.8</version>
        </dependency>
        <!-- ASM for bytecode processing -->
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-commons</artifactId>
            <version>9.9.1</version>
        </dependency>
        <!-- Global Platform support -->
        <dependency>
            <groupId>com.github.martinpaljak</groupId>
            <artifactId>globalplatformpro</artifactId>
            <version>26.04.20.1</version>
        </dependency>
        <!-- apdu4j: explicit core to override transitive version from globalplatformpro -->
        <dependency>
            <groupId>com.github.martinpaljak</groupId>
            <artifactId>apdu4j-core</artifactId>
            <version>${apdu4j.version}</version>
        </dependency>
        <!-- apdu4j pcsc-sim (transitively brings apdu4j-prefs) -->
        <dependency>
            <groupId>com.github.martinpaljak</groupId>
            <artifactId>apdu4j-pcsc-sim</artifactId>
            <version>${apdu4j.version}</version>
        </dependency>
        <!-- Faulty config parser -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.21.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.21.2</version>
        </dependency>
        <!-- unit tests -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>6.0.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>6.0.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.17</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Install the JC API JAR as an addressable Maven dependency -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <executions>
                    <execution>
                        <id>javacard-api</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>oracle.javacard</groupId>
                            <artifactId>api_classic</artifactId>
                            <version>${javacard.version}</version>
                            <packaging>jar</packaging>
                            <file>sdks/jc320v25.1_kit/lib/api_classic-${javacard.version}.jar</file>
                        </configuration>
                    </execution>
                    <execution>
                        <id>globalplatform-api</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>org.globalplatform</groupId>
                            <artifactId>api</artifactId>
                            <version>${globalplatform.version}</version>
                            <packaging>jar</packaging>
                            <file>gpapi-globalplatform.jar</file>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Extract java card API classes -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>javacard-api</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>oracle.javacard</groupId>
                                    <artifactId>api_classic</artifactId>
                                    <version>${javacard.version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                    <includes>**/*.class</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>globalplatform-api</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.globalplatform</groupId>
                                    <artifactId>api</artifactId>
                                    <version>${globalplatform.version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                    <includes>**/*.class</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Now compile -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <!-- Run the ASM based proxy code injector -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>inject-implementation</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>com.licel.jcardsim.utils.JavaCardApiProcessor</mainClass>
                            <arguments>
                                <argument>${project.build.directory}/classes</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <includePluginDependencies>true</includePluginDependencies>
                </configuration>
            </plugin>
            <!-- Make Jacoco report -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>java/lang/**</exclude>
                        <exclude>java/rmi/**</exclude>
                        <exclude>java/io/**</exclude>
                        <exclude>javacard/framework/service/**</exclude>
                        <exclude>javacardx/biometry/**</exclude>
                        <exclude>javacardx/biometry1toN/**</exclude>
                        <exclude>javacardx/external/**</exclude>
                        <exclude>javacardx/apdu/util/**</exclude>
                        <exclude>javacardx/framework/util/**</exclude>
                        <exclude>javacardx/framework/math/**</exclude>
                        <exclude>javacardx/framework/string/**</exclude>
                        <exclude>javacardx/framework/tlv/**</exclude>
                        <exclude>com/licel/jcardsim/utils/JavaCardApiProcessor*</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>agent</id>
                        <!-- NOTE: the phase binding here is hacky, set to test-compile to make sure test has the agent -->
                        <phase>test-compile</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <classDumpDir>${project.build.directory}/jacoco-dump</classDumpDir>
                            <exclClassLoaders>*AppClassLoader:*PlatformClassLoader</exclClassLoaders>
                        </configuration>
                    </execution>
                    <!--execution>
                        <id>report</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution-->
                    <!-- Set current baseline for minimums -->
                    <!--execution>
                        <id>check</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>LINE</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.50</minimum>
                                        </limit>
                                        <limit>
                                            <counter>INSTRUCTION</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.50</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution-->
                </executions>
            </plugin>
            <!-- Run tests, so that the classes have already been processed with proxy code -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
            <!-- Use Ant to run the modified variant of jacoco execution dump gatherer -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.2.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.jacoco</groupId>
                        <artifactId>org.jacoco.ant</artifactId>
                        <!--classifier>nodeps</classifier-->
                        <version>0.8.14</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>jacoco-report</id>
                        <phase>verify</phase>
                        <configuration>
                            <target>
                                <typedef resource="org/jacoco/ant/antlib.xml"/>
                                <report>
                                    <executiondata>
                                        <fileset dir="target" includes="jacoco*.exec"/>
                                    </executiondata>
                                    <structure name="${project.name}">
                                        <group name="oink">
                                            <classfiles>
                                                <fileset dir="${basedir}/target/jacoco-dump"/>
                                            </classfiles>
                                            <sourcefiles>
                                                <fileset dir="${basedir}/src/main/java"/>
                                            </sourcefiles>
                                        </group>
                                    </structure>
                                    <html destdir="${basedir}/target/site/jacoco"/>
                                    <xml destfile="${basedir}/target/site/jacoco/jacoco.xml"/>
                                </report>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <links>
                        <link>https://docs.oracle.com/javase/8/docs/api/</link>
                        <link>https://docs.oracle.com/javase/8/docs/jre/api/security/smartcardio/spec/</link>
                    </links>
                    <author>false</author>
                    <source>8</source>
                </configuration>
            </plugin>
            <!-- Source jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>install</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

