<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>de.adorsys.opba</groupId>
        <artifactId>opba-protocols</artifactId>
        <version>0.20.0.2</version>
    </parent>

    <!-- BPMN based engine to talk to XS2A-compliant banks -->
    <artifactId>xs2a-sandbox-protocol</artifactId>
    <name>opba-protocols/xs2a-sandbox-protocol</name>

    <properties>
      <!-- Hard reference to root directory. Used to reference pmd and checkstyle files from root.
      Change this if depth changes. Current: /open-banking-gateway/opba-protocols/xs2a-protocol -->
      <main.basedir>${project.parent.parent.basedir}</main.basedir>
    </properties>

    <dependencies>
        <dependency>
            <groupId>de.adorsys.opba</groupId>
            <artifactId>xs2a-protocol</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>de.adorsys.opba</groupId>
            <artifactId>xs2a-bdd-tests-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>de.adorsys.opba</groupId>
            <artifactId>xs2a-bdd-wiremock</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <version>${wiremock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>postgresql</artifactId>
            <version>${testcontainers.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${testcontainers.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <plugins>
            <!-- FLOW CUSTOMIZATION BEGIN (import remote, rename beans, remove processed original resources)-->
            <!-- Importing XS2A flows: -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-remote-resources-plugin</artifactId>
                <version>${maven-remote-resources-plugin.version}</version>
                <executions>
                    <execution>
                        <!-- Imports XS2a process definition to override bean names-->
                        <id>processes</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>process</goal>
                            <goal>bundle</goal>
                        </goals>
                        <configuration>
                            <resourceBundles>
                                <resourceBundle>de.adorsys.opba:xs2a-protocol:${project.version}</resourceBundle>
                            </resourceBundles>
                            <outputDirectory>${project.build.directory}/shared-processes</outputDirectory>
                            <attachToMain>false</attachToMain>
                            <attachToTest>false</attachToTest>
                        </configuration>
                    </execution>
                    <!-- Tests support import - to make tests run -->
                    <execution>
                        <!-- Imports test profiles and fixtures-->
                        <id>tests</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <resourceBundles>
                                <resourceBundle>de.adorsys.opba:xs2a-bdd-tests-common:${project.version}</resourceBundle>
                                <resourceBundle>de.adorsys.opba:xs2a-bdd-wiremock:${project.version}</resourceBundle>
                            </resourceBundles>
                            <outputDirectory>${project.build.directory}/shared-test-resources</outputDirectory>
                            <attachToMain>false</attachToMain>
                            <attachToTest>false</attachToTest>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Include only necessary test resources -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/shared-test-resources</directory>
                                    <excludes>
                                        <exclude>**/*.xml</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Protocol customization: -->
            <!--
            This plugin performs replacement of flowable-called beans with protocol customary ones.
            We customize only 'xs2a-list-transactions.bpmn20.xml' flow as it is the only one that needs custom beans.
            -->
            <plugin>
                <groupId>com.google.code.maven-replacer-plugin</groupId>
                <artifactId>replacer</artifactId>
                <version>${maven.replacer.version}</version>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>replace</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filesToInclude>${project.build.directory}/shared-processes/processes/xs2a/accounts/xs2a-list-transactions.bpmn20.xml</filesToInclude>
                    <tokenValueMap>${project.basedir}/src/main/resources/context.properties</tokenValueMap>
                    <inputFilePattern>${project.build.directory}/shared-processes/processes/(.*)/([A-Za-z0-9\.\-]+)$</inputFilePattern>
                    <outputFilePattern>${project.build.directory}/classes/processes/$1/sandbox-$2</outputFilePattern>
                </configuration>
            </plugin>
            <!-- FLOW CUSTOMIZATION END -->
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${maven.dependency.plugin.version}</version>
                <executions>
                    <execution>
                        <id>analyze</id>
                        <goals>
                            <goal>analyze-only</goal>
                        </goals>
                        <configuration>
                            <failOnWarning>false</failOnWarning>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

