<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>se.swedenconnect.iam</groupId>
    <artifactId>iam-admin-app</artifactId>
    <version>0.9.1</version>
  </parent>

  <artifactId>admin-app-backend</artifactId>
  <packaging>jar</packaging>

  <name>Sweden Connect :: IAM :: Admin Application :: Backend</name>
  <description>Backend for the IAM Admin Application</description>
  <url>https://www.swedenconnect.se</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>

  <properties>
    <!-- Architecture for jib:dockerBuild@local. Override with -Djib.local.architecture=arm64 on Apple Silicon. -->
    <jib.local.architecture>amd64</jib.local.architecture>
  </properties>

  <dependencies>

    <dependency>
      <groupId>se.swedenconnect.iam</groupId>
      <artifactId>iam-commons</artifactId>
    </dependency>

    <dependency>
      <groupId>se.swedenconnect.iam</groupId>
      <artifactId>iam-security-spring-boot-starter</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security-oauth2-client</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
    </dependency>

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

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

    <dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>3.0.3</version>
    </dependency>

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

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

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>

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

  </dependencies>

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerArgs>
            <arg>-parameters</arg>
          </compilerArgs>
          <annotationProcessorPaths>
            <path>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-configuration-processor</artifactId>
            </path>
            <path>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.7.0</version>
        <executions>
          <execution>
            <id>unpack-frontend</id>
            <phase>process-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>se.swedenconnect.iam</groupId>
                  <artifactId>admin-app-frontend</artifactId>
                  <version>${project.version}</version>
                  <classifier>dist</classifier>
                  <type>zip</type>
                  <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
                  <overWrite>true</overWrite>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <configuration>
          <from>
            <image>eclipse-temurin:21-jre-alpine</image>
          </from>
          <to>
            <image>${DOCKER_REPO}/swedenconnect/iam-admin-app</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/organizations-iam-app
              </org.opencontainers.image.source>
              <org.opencontainers.image.description>Sweden Connect Organizations and Users IAM Application</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>
              <from>
                <!-- Override with -Djib.local.architecture=arm64 on Apple Silicon -->
                <platforms>
                  <platform>
                    <os>linux</os>
                    <architecture>${jib.local.architecture}</architecture>
                  </platform>
                </platforms>
              </from>
              <to>
                <image>iam-admin-app</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>
  </build>

</project>
