<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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <artifactId>shibboleth-base</artifactId>
  <packaging>pom</packaging>  

  <parent>
    <groupId>se.litsec.sweid.idp</groupId>
    <artifactId>shibboleth-base-parent</artifactId>
    <version>1.8.0</version>
  </parent>

  <name>Swedish eID :: Base packaging of Shibboleth IdP 3.X</name>
  <description>Base packaging of Shibboleth IdP 3.X for the Swedish eID Framework</description>
  <url>https://github.com/litsec/swedish-eid-shibboleth-base</url>

  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  
  <scm>
    <connection>scm:https://github.com/litsec/swedish-eid-shibboleth-base.git</connection>
    <developerConnection>scm:https://github.com/litsec/swedish-eid-shibboleth-base.git</developerConnection>
    <url>https://github.com/litsec/swedish-eid-shibboleth-base/tree/master</url>
  </scm>

  <developers>
    <developer>
      <name>Martin Lindström</name>
      <email>martin.lindstrom@litsec.se</email>
      <organization>Litsec AB</organization>
      <organizationUrl>http://www.litsec.se</organizationUrl>
    </developer>
  </developers>
  
  <organization>
    <name>Litsec AB</name>
    <url>http://www.litsec.se</url>
  </organization>  

  <properties>
  </properties>

  <dependencyManagement>
    <dependencies>

    </dependencies>
  </dependencyManagement>

  <dependencies>
  
    <!-- Include newer version of Guava -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <scope>compile</scope>
    </dependency>
    
    <!-- Include spring-web 4.3.20 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <scope>compile</scope>    
    </dependency>
    
    <!-- Include newer version of Bouncy Castle --> 
    <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcprov-jdk15on</artifactId>        
      <scope>compile</scope>
    </dependency>
    
    <!-- We don't want to use dom4j:dom4j:jar:1.6.1 from opensaml-storage-impl. -->   
    <dependency>
      <groupId>org.dom4j</groupId>
      <artifactId>dom4j</artifactId>
    </dependency>    
    
    <!-- Make sure to copy valid Jackson dependencies -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <scope>compile</scope>
    </dependency>
    
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <scope>compile</scope>
    </dependency>
    
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <scope>compile</scope>
    </dependency>
    
    <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-joda</artifactId>
      <scope>compile</scope>
    </dependency>
    
    <dependency>
      <groupId>se.swedenconnect.opensaml</groupId>
      <artifactId>opensaml-security-ext</artifactId>
      <scope>compile</scope>
    </dependency> 
 
    <dependency>
      <groupId>se.litsec.opensaml</groupId>
      <artifactId>opensaml3-ext</artifactId>
      <scope>compile</scope>
    </dependency>
     
    <dependency>
      <groupId>se.litsec.opensaml.sweid</groupId>
      <artifactId>swedish-eid-opensaml3</artifactId>
      <scope>compile</scope>
    </dependency>    
    
    <dependency>
      <groupId>se.litsec.sweid.idp</groupId>
      <artifactId>shibboleth-sweid-extensions</artifactId>
      <version>${project.version}</version>
      <scope>compile</scope>
    </dependency>

    <!-- For mobile device support -->
    <dependency>
      <groupId>org.springframework.mobile</groupId>
      <artifactId>spring-mobile-device</artifactId>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
        </exclusion>
      </exclusions>      
    </dependency>    

  </dependencies>

  <build>

    <plugins>

      <!-- Unpacks the Shibboleth zip to target. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>net.shibboleth.idp</groupId>
                  <artifactId>idp-distribution</artifactId>
                  <version>${shibboleth.version}</version>
                  <type>zip</type>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
           
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib</outputDirectory>
            </configuration>
          </execution>

        </executions>
      </plugin>

      <!-- Copies our extensions into the Shibboleth distribution -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}</outputDirectory>
              <overwrite>true</overwrite>
              <includeEmptyDirs>true</includeEmptyDirs>
              <resources>
                <resource>
                  <directory>${basedir}/src/main/resources</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Copy additional files -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <!-- Remove Shibboleth dependencies that are too old (we have included versions with no vulnerabilities ourselves) -->
          <execution>
            <id>clean-shib-deps</id>
            <phase>process-resources</phase>
            <configuration>
              <target name="clean-shib-deps">              
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/guava-20.0.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/bcprov-jdk15on-1.59.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/spring-web-4.3.19.RELEASE.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/jackson-annotations-2.8.3.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/jackson-core-2.8.3.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/jackson-databind-2.8.3.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/jackson-datatype-joda-2.8.3.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/jsr305-3.0.1.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/dom4j-1.6.1.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/httpclient-4.5.3.jar" />
                <delete file="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp/WEB-INF/lib/httpcore-4.4.8.jar" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>            
          </execution>
        
          <!-- Copy the modifications we made to the files in the webapp directory -->
          <execution>
            <id>copy-webapp</id>
            <phase>process-resources</phase>
            <configuration>
              <target name="copy-webapp">
                <copy todir="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/webapp" overwrite="true">
                  <fileset dir="${project.basedir}/src/main/webapp" />
                </copy>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
          <!-- Copy the changed files into the dist directory (so that Shib install works correctly). -->
          <execution>
            <id>copy-to-dist</id>
            <phase>process-resources</phase>
            <configuration>
              <target name="copy-to-dist">
                <copy todir="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/dist/conf" overwrite="true" force="true">
                  <fileset dir="${basedir}/src/main/resources/conf" includes="**/*">
                    <type type="file" />
                  </fileset>
                  <mapper type="glob" from="*" to="*.dist" />
                </copy>
                <copy todir="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/dist/messages" overwrite="true" force="true">
                  <fileset dir="${basedir}/src/main/resources/messages" includes="**/*">
                    <type type="file" />
                  </fileset>
                  <mapper type="glob" from="*" to="*.dist" />
                </copy>
                <copy todir="${project.build.directory}/shibboleth-identity-provider-${shibboleth.version}/dist/flows" overwrite="true" force="true">
                  <fileset dir="${basedir}/src/main/resources/flows" includes="**/*">
                    <type type="file" />
                  </fileset>
                  <mapper type="glob" from="*" to="*.dist" />
                </copy>
                <!-- TODO: add views later on -->
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Build the distribution zip -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>${basedir}/src/assembly/shibboleth.xml</descriptor>
          </descriptors>
          <finalName>${project.artifactId}-${project.version}</finalName>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>build-shibboleth</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Attach the zip file as an artifact of this build to get it installed and deployed -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${project.artifactId}-${project.version}.zip</file>
                  <type>zip</type>
                  <!-- <classifier></classifier> -->
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>

  </build>

</project>
