<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>dspace-saml2</artifactId>
    <packaging>jar</packaging>
    <name>DSpace SAML 2</name>
    <description>DSpace SAML 2 Extension</description>

    <parent>
        <groupId>org.dspace</groupId>
        <artifactId>dspace-parent</artifactId>
        <version>9.2</version>
        <relativePath>..</relativePath>
    </parent>

    <properties>
        <!-- This is the path to the root [dspace-src] directory. -->
        <root.basedir>${basedir}/..</root.basedir>
    </properties>

    <build>
        <plugins>
            <!-- This plugin allows us to run a Groovy script in our Maven POM
                 (see: https://groovy.github.io/gmaven/groovy-maven-plugin/execute.html )
                 We are generating a OS-agnostic version (agnostic.build.dir) of
                 the ${project.build.directory} property (full path of target dir).
                 This is needed by the Surefire & Failsafe plugins (see below)
                 to initialize the Unit Test environment's dspace.cfg file.
                 Otherwise, the Unit Test Framework will not work on Windows OS.
                 This Groovy code was mostly borrowed from:
                 http://stackoverflow.com/questions/3872355/how-to-convert-file-separator-in-maven
            -->
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <executions>
                    <execution>
                    <id>setproperty</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            project.properties['agnostic.build.dir'] = project.build.directory.replace(File.separator, '/');
                            log.info("Initializing Maven property 'agnostic.build.dir' to: {}", project.properties['agnostic.build.dir']);
                        </source>
                    </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
     </build>

     <profiles>
        <!-- Setup the Unit Test Environment (when -DskipUnitTests=false) -->
        <profile>
            <id>unit-test-environment</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>skipUnitTests</name>
                    <value>false</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- Unit Testing setup: This plugin unzips the
                         'testEnvironment.zip' file (created by dspace-parent POM), into
                         the 'target/testing/' folder, to essentially create a test
                         install of DSpace, against which Tests can be run. -->
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <configuration>
                            <outputDirectory>${project.build.directory}/testing</outputDirectory>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.dspace</groupId>
                                    <artifactId>dspace-parent</artifactId>
                                    <version>${project.version}</version>
                                    <type>zip</type>
                                    <classifier>testEnvironment</classifier>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                        <executions>
                            <execution>
                                <id>setupUnitTestEnvironment</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Run Unit Testing! This plugin just kicks off the tests (when enabled). -->
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <systemPropertyVariables>
                                <!-- Specify the dspace.dir to use for test environment -->
                                <!-- This system property is loaded by AbstractDSpaceTest to initialize the test environment -->
                                <dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
                                <!-- Turn off any DSpace logging -->
                                <dspace.log.init.disable>true</dspace.log.init.disable>
                                <solr.install.dir>${agnostic.build.dir}/testing/dspace/solr/</solr.install.dir>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <!-- When running tests, also include test classes from dspace-api
                     (this test-jar is only built when tests are enabled). -->
                <dependency>
                    <groupId>org.dspace</groupId>
                    <artifactId>dspace-api</artifactId>
                    <type>test-jar</type>
                    <scope>test</scope>
                </dependency>
            </dependencies>
        </profile>

        <!-- Setup the Integration Test Environment (when -DskipIntegrationTests=false) -->
        <profile>
            <id>integration-test-environment</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>skipIntegrationTests</name>
                    <value>false</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- Integration Testing setup: This plugin unzips the
                         'testEnvironment.zip' file (created by dspace-parent POM), into
                         the 'target/testing/' folder, to essentially create a test
                         install of DSpace, against which Tests can be run. -->
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <configuration>
                            <outputDirectory>${project.build.directory}/testing</outputDirectory>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.dspace</groupId>
                                    <artifactId>dspace-parent</artifactId>
                                    <version>${project.version}</version>
                                    <type>zip</type>
                                    <classifier>testEnvironment</classifier>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                        <executions>
                            <execution>
                                <id>setupIntegrationTestEnvironment</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Run Integration Testing! This plugin just kicks off the tests (when enabled). -->
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                        <systemPropertyVariables>
                            <!-- Specify the dspace.dir to use for test environment -->
                            <dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
                            <!-- Turn off any DSpace logging -->
                            <dspace.log.init.disable>true</dspace.log.init.disable>
                            <solr.install.dir>${agnostic.build.dir}/testing/dspace/solr/</solr.install.dir>
                        </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
           <dependencies>
                <!-- When running tests, also include test classes from dspace-api
                     (this test-jar is only built when tests are enabled). -->
                <dependency>
                    <groupId>org.dspace</groupId>
                    <artifactId>dspace-api</artifactId>
                    <type>test-jar</type>
                    <scope>test</scope>
                </dependency>
           </dependencies>
        </profile>
     </profiles>

    <dependencies>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.dspace</groupId>
            <artifactId>dspace-services</artifactId>
        </dependency>
        <!-- Needed to support Spring @Configuration classes (to register servlets/beans with Spring Boot webapp) -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>${spring-boot.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
            <version>${spring-boot.version}</version>
            <exclusions>
                <!-- Later version brought in by dspace-services above -->
                <exclusion>
                    <groupId>io.micrometer</groupId>
                    <artifactId>micrometer-observation</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-saml2-service-provider</artifactId>
            <version>${spring-security.version}</version>
            <exclusions>
                <!-- Later version brought in by dspace-api -->
                <exclusion>
                    <groupId>org.apache.velocity</groupId>
                    <artifactId>velocity-engine-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Test dependencies -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.dspace</groupId>
            <artifactId>dspace-api</artifactId>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-inline</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <!--
            Shibboleth repo is needed for opensaml 4.3 libraries that are transitive dependencies of
            spring-security-saml2-service-provider.
        -->
        <repository>
            <id>shibboleth</id>
            <name>Shibboleth Maven Repository</name>
            <url>https://build.shibboleth.net/maven/releases/</url>
        </repository>
    </repositories>
</project>
