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

  <artifactId>bankid-idp</artifactId>
  <packaging>jar</packaging>

  <parent>
    <groupId>se.swedenconnect.bankid</groupId>
    <artifactId>saml-bankid-idp-parent</artifactId>
    <version>1.2.2</version>
  </parent>

  <name>Sweden Connect :: BankID :: SAML Identity Provider</name>
  <description>BankID SAML Identity Provider</description>
  <url>https://docs.swedenconnect.se/bankid-saml-idp</url>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <scm>
    <connection>scm:git:https://github.com/swedenconnect/bankid-saml-idp.git</connection>
    <developerConnection>scm:git:https://github.com/swedenconnect/bankid-saml-idp.git</developerConnection>
    <url>https://github.com/swedenconnect/bankid-saml-idp/tree/main</url>
  </scm>

  <organization>
    <name>Sweden Connect</name>
    <url>https://www.swedenconnect.se</url>
  </organization>

  <developers>
    <developer>
      <name>Martin Lindström</name>
      <email>martin@idsec.se</email>
      <organization>IDsec Solutions AB</organization>
      <organizationUrl>https://www.idsec.se</organizationUrl>
    </developer>

    <developer>
      <name>Felix Hellman</name>
      <email>felix@idsec.se</email>
      <organization>Helagon AB</organization>
      <organizationUrl>https://www.idsec.se</organizationUrl>
    </developer>
  </developers>

  <properties>
    <resilience4j.version>2.3.0</resilience4j.version>
    <logstash-logback-encoder.version>8.0</logstash-logback-encoder.version>
  </properties>

  <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>org.testcontainers</groupId>
        <artifactId>testcontainers-bom</artifactId>
        <version>1.20.5</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

    </dependencies>

  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>se.swedenconnect.bankid</groupId>
      <artifactId>bankid-rp-api</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- QR support -->
    <dependency>
      <groupId>com.google.zxing</groupId>
      <artifactId>core</artifactId>
      <version>${zxing.version}</version>
    </dependency>

    <dependency>
      <groupId>com.google.zxing</groupId>
      <artifactId>javase</artifactId>
      <version>${zxing.version}</version>
    </dependency>

    <dependency>
      <groupId>se.swedenconnect.spring.saml.idp</groupId>
      <artifactId>saml-idp-spring-boot-starter</artifactId>
      <version>2.3.6</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>

    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
    </dependency>

    <dependency>
      <groupId>org.redisson</groupId>
      <artifactId>redisson-spring-boot-starter</artifactId>
      <version>3.45.0</version>
    </dependency>

    <!--
    <dependency>
      <groupId>org.redisson</groupId>
      <artifactId>redisson</artifactId>
      <version>3.45.0</version>
    </dependency>
    -->

    <dependency>
      <groupId>org.springframework.session</groupId>
      <artifactId>spring-session-data-redis</artifactId>
    </dependency>

    <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>

    <dependency>
      <groupId>io.github.resilience4j</groupId>
      <artifactId>resilience4j-circuitbreaker</artifactId>
      <version>${resilience4j.version}</version>
    </dependency>

    <dependency>
      <groupId>io.github.resilience4j</groupId>
      <artifactId>resilience4j-reactor</artifactId>
      <version>${resilience4j.version}</version>
    </dependency>

    <dependency>
      <groupId>io.github.resilience4j</groupId>
      <artifactId>resilience4j-micrometer</artifactId>
      <version>${resilience4j.version}</version>
    </dependency>

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>${logstash-logback-encoder.version}</version>
    </dependency>

    <!-- Test -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jsoup</groupId>
      <artifactId>jsoup</artifactId>
      <version>1.18.3</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.wiremock</groupId>
      <artifactId>wiremock-standalone</artifactId>
      <version>3.12.0</version>
      <scope>test</scope>
    </dependency>


    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-test</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.projectreactor</groupId>
      <artifactId>reactor-test</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>

    <plugins>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring.boot.version}</version>
        <executions>
          <execution>
            <id>repackage</id>
            <goals>
              <goal>repackage</goal>
            </goals>
            <configuration>
              <classifier>exec</classifier>
            </configuration>
          </execution>
          <execution>
            <goals>
              <goal>build-info</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>3.4.4</version>
        <configuration>
          <from>
            <image>openjdk:18.0.2.1-slim</image>
          </from>
          <to>
            <image>${DOCKER_REPO}/swedenconnect/bankid-saml-idp</image>
            <tags>
              <tag>${project.version}</tag>
            </tags>
          </to>
          <container>
            <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
            <jvmFlags>
              <jvmFlag>-Djava.net.preferIPv4Stack=true</jvmFlag>
              <jvmFlag>-Dorg.apache.xml.security.ignoreLineBreaks=true</jvmFlag>
            </jvmFlags>
            <labels>
              <org.opencontainers.image.source>https://github.com/swedenconnect/bankid-saml-idp
              </org.opencontainers.image.source>
              <org.opencontainers.image.description>BankID SAML IdP</org.opencontainers.image.description>
              <org.opencontainers.image.licenses>Apache-2.0</org.opencontainers.image.licenses>
            </labels>
          </container>
        </configuration>
        <executions>
          <execution>
            <phase>none</phase>
            <id>local</id>
            <goals>
              <goal>dockerBuild</goal>
            </goals>
            <configuration>
              <to>
                <image>bankid-saml-idp</image>
              </to>
            </configuration>
          </execution>
          <execution>
            <id>default-cli</id>
            <phase>none</phase>
            <goals>
              <goal>build</goal>
            </goals>
            <configuration>
              <from>
                <platforms>
                  <platform>
                    <os>linux</os>
                    <architecture>amd64</architecture>
                  </platform>
                  <platform>
                    <os>linux</os>
                    <architecture>arm64</architecture>
                  </platform>
                </platforms>
              </from>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>

    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>**/*.properties</include>
        </includes>
      </testResource>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
      </testResource>
    </testResources>

  </build>

  <profiles>

    <profile>
      <id>with-frontend</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <property>
          <name>!backend-only</name>
        </property>
      </activation>

      <build>
        <plugins>

          <!-- Unpack the frontend zip -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack-frontend</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>${project.groupId}</groupId>
                      <artifactId>bankid-idp-frontend</artifactId>
                      <version>${project.version}</version>
                      <type>zip</type>
                      <outputDirectory>${project.build.directory}</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.3.1</version>
            <executions>
              <execution>
                <id>copy-resource-templates</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.outputDirectory}/templates/</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.build.directory}/frontend/dist</directory>
                      <includes>
                        <include>index.html</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <id>copy-resources-assets</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.outputDirectory}/static/assets/</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${project.build.directory}/frontend/dist/assets/</directory>
                      <includes>
                        <include>**/*.*</include>
                      </includes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>

    </profile>

    <!--
      Build backend only: mvn clean install -Dbackend-only
    -->
    <profile>

      <id>backend-only-profile</id>
      <activation>
        <property>
          <name>backend-only</name>
        </property>
      </activation>

      <build>
        <finalName>bankid-idp-backend-${project.version}</finalName>
      </build>

    </profile>

  </profiles>

</project>
