<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<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>org.apache.syncope</groupId>
    <artifactId>syncope</artifactId>
    <version>3.0.3</version>
  </parent>

  <name>Apache Syncope Standalone Distribution</name>
  <description>Apache Syncope Standalone Distribution</description>
  <groupId>org.apache.syncope</groupId>
  <artifactId>syncope-standalone</artifactId>
  <packaging>jar</packaging>
  
  <properties>
    <rootpom.basedir>${basedir}/..</rootpom.basedir>

    <test.csvdir.path>./test-csvdir</test.csvdir.path>

    <work.dir>${project.build.directory}/standalone</work.dir>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-build-tools</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-core-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-console-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-enduser-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.syncope.fit</groupId>
      <artifactId>syncope-fit-wa-reference</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>

    <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven3-plugin</artifactId>
        <inherited>true</inherited>
        <configuration>
          <container>
            <containerId>tomcat9x</containerId>
            <zipUrlInstaller>
              <url>https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/${tomcat.version}/tomcat-${tomcat.version}.zip</url>
              <downloadDir>${settings.localRepository}/org/codehaus/cargo/cargo-container-archives</downloadDir>
              <extractDir>${project.build.directory}/cargo/extract</extractDir>
            </zipUrlInstaller>
            <timeout>300000</timeout>
          </container>
        </configuration>
        <executions>
          <execution>
            <id>install-tomcat</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
          
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-standalone</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
              <target>
                <mkdir dir="${work.dir}"/>

                <!-- legal stuff -->
                <copy file="${project.build.outputDirectory}/README" todir="${work.dir}"/>
                <copy file="LICENSE" todir="${work.dir}"/>
                <copy file="NOTICE" todir="${work.dir}"/>

                <!-- Unzip Tomcat and remove docs and examples from webapps (space saving) -->
                <unzip src="${settings.localRepository}/org/codehaus/cargo/cargo-container-archives/tomcat-${tomcat.version}.zip" dest="${work.dir}"/>
                <delete dir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/docs"/>
                <delete dir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/examples"/>

                <!-- Syncope core -->
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope">
                  <fileset dir="../fit/core-reference/target/syncope-fit-core-reference-${project.version}" includes="**/*"/>
                </copy>
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope/WEB-INF/classes" overwrite="true">
                  <fileset dir="${project.build.outputDirectory}/core"/>
                </copy>
                <copy file="../fit/core-reference/target/test-classes/saml.keystore.jks" todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope/WEB-INF/classes" overwrite="true"/>

                <!-- Syncope console -->
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-console">
                  <fileset dir="../fit/console-reference/target/syncope-fit-console-reference-${project.version}" includes="**/*"/>
                </copy>
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-console/WEB-INF/classes" overwrite="true">
                  <fileset dir="${project.build.outputDirectory}/console"/>
                </copy>

                <!-- Syncope enduser -->
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-enduser">
                  <fileset dir="../fit/enduser-reference/target/syncope-fit-enduser-reference-${project.version}" includes="**/*"/>
                </copy>
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-enduser/WEB-INF/classes" overwrite="true">
                  <fileset dir="${project.build.outputDirectory}/enduser"/>
                </copy>f

                <!-- Syncope wa -->
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-wa">
                  <fileset dir="../fit/wa-reference/target/syncope-fit-wa-reference-${project.version}" includes="**/*"/>
                </copy>
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-wa/WEB-INF/classes" overwrite="true">
                  <fileset dir="${project.build.outputDirectory}/wa"/>
                </copy>
                <copy file="../fit/wa-reference/src/test/resources/keystore.jks" todir="${work.dir}/apache-tomcat-${tomcat.version}/conf" overwrite="true"/>

                <mkdir dir="${work.dir}/apache-tomcat-${tomcat.version}/${test.csvdir.path}"/>
                <copy file="../fit/core-reference/src/test/resources/test.csv" todir="${work.dir}/apache-tomcat-${tomcat.version}/${test.csvdir.path}"/>

                <!-- Syncope build tools (provide H2, LDAP and REST / SOAP resources + ConnId connector server) -->
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-fit-build-tools">
                  <fileset dir="../fit/build-tools/target/syncope-fit-build-tools-${project.version}" includes="**/*"/>
                </copy>
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope-fit-build-tools/WEB-INF/lib">
                  <fileset dir="../fit/core-reference/target/bundles/" includes="**/*"/>
                </copy>

                <!-- Tomcat shared libraries: StAX2 API, Woodstox -->
                <copy todir="${work.dir}/apache-tomcat-${tomcat.version}/lib">
                  <fileset dir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope/WEB-INF/lib" includes="stax2-api-*.jar"/>
                  <fileset dir="${work.dir}/apache-tomcat-${tomcat.version}/webapps/syncope/WEB-INF/lib" includes="woodstox-core-asl-*.jar"/>
                </copy>

                <!-- Other custom Tomcat resources -->
                <copy file="${project.build.outputDirectory}/context.xml" todir="${work.dir}/apache-tomcat-${tomcat.version}/conf" overwrite="true"/>
                <copy file="${project.build.outputDirectory}/setenv.sh" todir="${work.dir}/apache-tomcat-${tomcat.version}/bin"/>
                <copy file="${project.build.outputDirectory}/setenv.bat" todir="${work.dir}/apache-tomcat-${tomcat.version}/bin"/>
                <replace file="${work.dir}/apache-tomcat-${tomcat.version}/conf/server.xml" token="8080" value="${cargo.servlet.port}"/>
                <replace file="${work.dir}/apache-tomcat-${tomcat.version}/conf/server.xml" token="8443" value="9443"/>
                <replace file="${work.dir}/apache-tomcat-${tomcat.version}/conf/server.xml">
                  <replacetoken><![CDATA[redirectPort="9443" />]]></replacetoken>
                  <replacevalue><![CDATA[redirectPort="9443" />
<Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="9443" maxThreads="200"
scheme="https" secure="true" SSLEnabled="true" keystoreFile="conf/keystore.jks" keystorePass="password"
keystoreType="JKS" clientAuth="false" sslProtocol="TLS"/>]]></replacevalue>
                </replace>
                <replace file="${work.dir}/apache-tomcat-${tomcat.version}/conf/server.xml" token="8009" value="${cargo.tomcat.ajp.port}"/>
                <replace file="${work.dir}/apache-tomcat-${tomcat.version}/conf/server.xml" token="8005" value="${cargo.rmi.port}"/>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/assemble/standalone-zip.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>make-standalone-zip</id>
            <phase>verify</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <configuration>
          <resourceIncludes>src/main/resources/**/*.*</resourceIncludes>
        </configuration>
      </plugin>
    </plugins>

    <resources>
      <resource>
        <directory>../core/persistence-jpa/src/main/resources</directory>
        <includes>
          <include>persistence.properties</include>
        </includes>
        <targetPath>core</targetPath>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>../core/persistence-jpa/src/test/resources/domains</directory>
        <targetPath>core/domains</targetPath>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>../fit/core-reference/src/main/resources</directory>
        <includes>
          <include>*.xml</include>
          <include>*.properties</include>
        </includes>
        <targetPath>core</targetPath>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>../fit/core-reference/src/main/resources/all</directory>
        <includes>
          <include>*.xml</include>
          <include>*.properties</include>
        </includes>
        <targetPath>core</targetPath>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>../fit/core-reference/src/test/resources</directory>
        <includes>
          <include>mail.properties</include>
        </includes>
        <targetPath>core</targetPath>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>../fit/core-reference/src/test/resources/scriptedsql</directory>
        <targetPath>core/scriptedsql</targetPath>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>../fit/core-reference/src/test/resources/rest</directory>
        <targetPath>core/rest</targetPath>
        <filtering>true</filtering>
      </resource>

      <resource>
        <directory>../fit/console-reference/src/main/resources</directory>
        <targetPath>console</targetPath>
        <filtering>true</filtering>
      </resource>
      
      <resource>
        <directory>../fit/enduser-reference/src/main/resources</directory>
        <targetPath>enduser</targetPath>
        <filtering>true</filtering>
      </resource>

      <resource>
        <directory>../fit/wa-reference/src/main/resources</directory>
        <targetPath>wa</targetPath>
        <filtering>true</filtering>
      </resource>

      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>setenv.*</include>
        </includes>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <excludes>
          <exclude>setenv.*</exclude>
        </excludes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/assemble</directory>
      </resource>
    </resources>
  </build>

  <profiles>
    <profile>
      <id>site</id>

      <build>
        <plugins>
          <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <inherited>false</inherited>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
              <skip>true</skip>
              <skipDeploy>true</skipDeploy>
              <generateReports>false</generateReports>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-docs-to-site</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    
    <profile>
      <id>apache-release</id>

      <build>
        <plugins>      
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
              <skip>true</skip>
            </configuration>
          </plugin>           
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <inherited>false</inherited>
            <configuration>
              <skipSource>true</skipSource>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
