<?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>1.2.0</version>
  </parent>

  <name>Apache Syncope Common</name>
  <description>Apache Syncope Common</description>
  <groupId>org.apache.syncope</groupId>
  <artifactId>syncope-common</artifactId>
  <packaging>bundle</packaging>

  <distributionManagement>
    <site>
      <id>syncope.website</id>
      <name>Apache Syncope website</name>
      <url>${site.deploymentBaseUrl}/${project.artifactId}</url>
    </site>
  </distributionManagement>
  
  <dependencies>
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
    </dependency>      

    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-extension-search</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description</artifactId>
    </dependency>
          
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
    </dependency>
    
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
    </dependency>
    
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
      
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
    </dependency>
    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Generating javadoc JAR artifact for usage with CXF's WADL generator (for core) -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>      
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-Name>${project.name}</Bundle-Name>
            <Bundle-SymbolicName>org.apache.syncope.common</Bundle-SymbolicName>
            <Bundle-Version>${project.version}</Bundle-Version>
            <Export-Package>
              org.apache.syncope.common*;version=${project.version};-split-package:=merge-first
            </Export-Package>
            <Import-Package>
              org.apache.commons.lang3;version="[3.1,3.2)",
              com.fasterxml.jackson.annotation;version="[2.2.2,2.3)",
              org.springframework*;version="[3,4)",
              org.apache.logging.log4j*;resolution:=optional,
              org.slf4j;resolution:=optional,
              *
            </Import-Package>
          </instructions>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
      </plugin>
    </plugins>
    
    <resources>
      <resource>
        <directory>..</directory>
        <targetPath>META-INF</targetPath>
        <includes>
          <include>LICENSE</include>
          <include>NOTICE</include>
        </includes>
      </resource>
    </resources>
  </build>
  
  <profiles>
    <profile>
      <id>offline-doc</id>
      
      <build>
        <defaultGoal>clean verify</defaultGoal>
        
        <plugins>
          <!-- 1. Generate offline WADL -->
          <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-java2wadl-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <id>parsejavadoc</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>parsejavadoc</goal>
                </goals>
              </execution>
              <execution>
                <id>process-classes</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>java2wadl</goal>
                </goals>
                <configuration>
                  <applicationTitle>Apache Syncope ${project.version}</applicationTitle>
                  <namespacePrefix>syncope</namespacePrefix>
                  <addResourceAndMethodIds>true</addResourceAndMethodIds>
                  <linkAnyMediaTypeToXmlSchema>true</linkAnyMediaTypeToXmlSchema>
                  <classResourceNames />
                  <basePackages>org.apache.syncope.common.services</basePackages>
                  <docProvider>org.apache.cxf.maven_plugin.javatowadl.ResourceMapJavaDocProvider</docProvider>
                  <attachWadl>true</attachWadl>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- 2. Transform WADL into 2 HTML pages -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <transformationSets>
                <transformationSet>
                  <dir>${project.build.directory}/generated/wadl/</dir>
                  <includes>
                    <include>application.wadl</include>
                  </includes>
                  <outputDir>${project.build.directory}/generated/wadl</outputDir>
                  <stylesheet>${basedir}/../core/src/main/resources/wadl2html/index.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>contextPath</name>
                      <value>/restdocs/${project.version}</value>
                    </parameter>
                  </parameters>
                  <outputProperties>
                    <outputProperty>
                      <name>indent</name>
                      <value>yes</value>
                    </outputProperty>
                  </outputProperties>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^.*$</pattern>
                      <replacement>index.html</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
                <transformationSet>
                  <dir>${project.build.directory}/generated/wadl/</dir>
                  <includes>
                    <include>application.wadl</include>
                  </includes>
                  <outputDir>${project.build.directory}/generated/wadl</outputDir>
                  <stylesheet>${basedir}/../core/src/main/resources/wadl2html/schema.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>contextPath</name>
                      <value>/restdocs/${project.version}</value>
                    </parameter>
                    <parameter>
                      <name>schema-position</name>
                      <value>1</value>
                    </parameter>
                    <parameter>
                      <name>schema-prefix</name>
                      <value>syncope1</value>
                    </parameter>
                  </parameters>
                  <outputProperties>
                    <outputProperty>
                      <name>indent</name>
                      <value>yes</value>
                    </outputProperty>
                  </outputProperties>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^.*$</pattern>
                      <replacement>schema_1_syncope1.html</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
              </transformationSets>
            </configuration>
          </plugin>   
          <!-- 3. Replace CSS and JS local includes with hosted -->
          <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <inherited>true</inherited>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>replace</goal>
                </goals>                   
              </execution>
            </executions>
            <configuration>
              <regex>false</regex>
              <includes>
                <include>${project.build.directory}/generated/wadl/*.html</include>
              </includes>              
              <replacements>
                <replacement>
                  <token>/restdocs/${project.version}/webjars/highlightjs/$/styles/default.min.css</token>
                  <value>http://yandex.st/highlightjs/${highlightjs.version}/styles/default.min.css</value>
                </replacement>         
                <replacement>
                  <token>/restdocs/${project.version}/webjars/highlightjs/$/highlight.min.js</token>
                  <value>http://yandex.st/highlightjs/${highlightjs.version}/highlight.min.js"</value>
                </replacement>         
                <replacement>
                  <token>/restdocs/${project.version}/webjars/jquery-ui/$/themes/base/minified/jquery-ui.min.css</token>
                  <value>http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css</value>
                </replacement>  
                <replacement>
                  <token>/restdocs/${project.version}/webjars/jquery-ui/$/ui/minified/jquery-ui.min.js</token>
                  <value>http://ajax.googleapis.com/ajax/libs/jqueryui/${jquery-ui.version}/jquery-ui.min.js</value>
                </replacement>  
                <replacement>
                  <token>/restdocs/${project.version}/webjars/jquery/$/jquery.min.js</token>
                  <value>http://ajax.googleapis.com/ajax/libs/jquery/${jquery.version}/jquery.min.js</value>
                </replacement>  
              </replacements>
            </configuration>
          </plugin>                 
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
