<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.06.04</version>
    </parent>
    <artifactId>jcardengine</artifactId>
    <name>JCardEngine - JavaCard Simulator</name>

    <properties>
        <javacard.version>3.0.5</javacard.version>
        <globalplatform.version>1.8</globalplatform.version>
        <globalplatform.contactless.version>1.4</globalplatform.contactless.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>
        <dependency>
            <groupId>org.globalplatform</groupId>
            <artifactId>contactless</artifactId>
            <version>${globalplatform.contactless.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.10.1</version>
        </dependency>
        <!-- Global Platform support -->
        <dependency>
            <groupId>com.github.martinpaljak</groupId>
            <artifactId>globalplatformpro</artifactId>
            <version>${gppro.version}</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.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
            <version>2.21.4</version>
        </dependency>
        <!-- unit tests -->
        <!-- transport adapters: only the JSONAdapter integration test needs them (main engine does not) -->
        <dependency>
            <groupId>com.github.martinpaljak</groupId>
            <artifactId>apdu4j-remote</artifactId>
            <version>${apdu4j.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>6.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>6.1.0</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/jc320v26.0_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_${globalplatform.version}.jar</file>
                        </configuration>
                    </execution>
                    <execution>
                        <id>globalplatform-contactless</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>org.globalplatform</groupId>
                            <artifactId>contactless</artifactId>
                            <version>${globalplatform.contactless.version}</version>
                            <packaging>jar</packaging>
                            <file>gpapi-contactless_${globalplatform.contactless.version}.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>
                    <execution>
                        <id>globalplatform-contactless</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.globalplatform</groupId>
                                    <artifactId>contactless</artifactId>
                                    <version>${globalplatform.contactless.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>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <!-- Build the test applet CAPs -->
                    <execution>
                        <id>build-caps</id>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <ant antfile="build.xml" inheritAll="false"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </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>
                        <!-- Test applets run in the reloader with rewritten bytecode; instrumenting
                             their application-loader copies too would clash in the dump report. They
                             are test fixtures, not the engine under test. -->
                        <exclude>com/licel/jcardsim/samples/**</exclude>
                        <exclude>pro/javacard/engine/testapplets/**</exclude>
                        <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>
                            <!-- Instrument the engine host code and the simulated platform it
                                 provides. Applet packages are reloaded with rewritten bytecode by
                                 IsolatingClassReloader and are excluded below to avoid clashing with
                                 their application-loader copies; the JC API is loaded once, so it is
                                 measured normally. -->
                            <includes>
                                <include>com/licel/jcardsim/**</include>
                                <include>pro/javacard/engine/**</include>
                                <include>javacard/**</include>
                                <include>javacardx/**</include>
                                <include>org/globalplatform/**</include>
                            </includes>
                        </configuration>
                    </execution>
                    <!-- Engine host coverage: pro.javacard.engine.* and the com.licel.jcardsim
                         simulator core, excluding the test-applet fixtures and the reloaded JC-API
                         facades (measured, if at all, only inside the reloader). -->
                    <execution>
                        <id>host-report</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/site/jacoco</outputDirectory>
                            <includes>
                                <include>pro/javacard/engine/**</include>
                                <include>com/licel/jcardsim/**</include>
                                <include>javacard/**</include>
                                <include>javacardx/**</include>
                                <include>org/globalplatform/**</include>
                            </includes>
                            <excludes>
                                <exclude>com/licel/jcardsim/samples/**</exclude>
                                <exclude>pro/javacard/engine/testapplets/**</exclude>
                                <!-- Build-time bytecode tool, runs at process-classes not under test. -->
                                <exclude>com/licel/jcardsim/utils/JavaCardApiProcessor*</exclude>
                            </excludes>
                        </configuration>
                    </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>
            <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>

