<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2011 JBoss, by Red Hat, Inc
  ~
  ~ Licensed 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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <name>Errai::Reference::Guide</name>
    <artifactId>errai-reference-guide</artifactId>
    <packaging>jdocbook</packaging>

    <!-- Parent -->
    <parent>
        <groupId>org.jboss.errai</groupId>
        <artifactId>errai-parent</artifactId>
        <version>2.3.2.Final-redhat-1</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <properties>
        <translation>en</translation>
        <docname>Reference_Guide</docname>
        <bookname>Reference Guide</bookname>
    </properties>

    <dependencies>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jboss.maven.plugins</groupId>
                    <artifactId>maven-jdocbook-plugin</artifactId>
                    <version>2.3.5</version>
                    <extensions>true</extensions>

                    <dependencies>
                        <dependency>
                            <groupId>org.jboss.pressgang</groupId>
                            <!--Non-namespaced version for DocBook 4.5 compatibility. For XSD namespaced version, use pressgang-xslt-ns-->
                            <artifactId>pressgang-xslt</artifactId>
                            <version>2.0.0</version>
                        </dependency>

                        <dependency>
                            <groupId>org.jboss.pressgang</groupId>
                            <artifactId>pressgang-jdocbook-style</artifactId>
                            <type>jdocbook-style</type>
                            <version>2.0.0</version>
                        </dependency>
                    </dependencies>

                    <configuration>
                        <sourceDocumentName>Reference_Guide.xml</sourceDocumentName>
                        <masterTranslation>en</masterTranslation>
                        <imageResource>
                            <directory>${basedir}/src/main/docbook/en</directory>
                            <includes>
                                <include>images/*.png</include>
                            </includes>
                        </imageResource>

                        <formats>
                            <format>
                                <formatName>pdf</formatName>
                                <stylesheetResource>classpath:/xslt/org/jboss/pdf.xsl</stylesheetResource>
                                <finalName>${docname}.pdf</finalName>
                            </format>

                            <format>
                                <formatName>html</formatName>
                                <stylesheetResource>classpath:/xslt/org/jboss/xhtml.xsl</stylesheetResource>
                                <finalName>index.html</finalName>
                            </format>

                            <format>
                                <formatName>html_single</formatName>
                                <stylesheetResource>classpath:/xslt/org/jboss/xhtml-single.xsl</stylesheetResource>
                                <finalName>index.html</finalName>
                            </format>
                        </formats>

                        <options>
                            <xmlTransformerType>saxon</xmlTransformerType>
                            <xincludeSupported>true</xincludeSupported>
                            <docbookVersion>1.72.0</docbookVersion>
                            <useRelativeImageUris>true</useRelativeImageUris>
                        </options>

                    </configuration>

                </plugin>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                  <groupId>org.eclipse.m2e</groupId>
                  <artifactId>lifecycle-mapping</artifactId>
                  <version>1.0.0</version>
                  <configuration>
                    <lifecycleMappingMetadata>
                      <pluginExecutions>
                        <pluginExecution>
                          <pluginExecutionFilter>
                            <groupId>org.jboss.maven.plugins</groupId>
                            <artifactId>maven-jdocbook-plugin</artifactId>
                            <versionRange>[2.3.5,)</versionRange>
                            <goals>
                              <goal>generate</goal>
                              <goal>resources</goal>
                            </goals>
                          </pluginExecutionFilter>
                          <action>
                            <ignore></ignore>
                          </action>
                        </pluginExecution>
                        <pluginExecution>
                          <pluginExecutionFilter>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>xml-maven-plugin</artifactId>
                            <versionRange>[1.0,)</versionRange>
                            <goals>
                              <goal>transform</goal>
                            </goals>
                          </pluginExecutionFilter>
                          <action>
                            <ignore></ignore>
                          </action>
                        </pluginExecution>
                        <pluginExecution>
                          <pluginExecutionFilter>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-antrun-plugin</artifactId>
                            <versionRange>[1.3,)</versionRange>
                            <goals>
                              <goal>run</goal>
                            </goals>
                          </pluginExecutionFilter>
                          <action>
                            <ignore></ignore>
                          </action>
                        </pluginExecution>
                      </pluginExecutions>
                    </lifecycleMappingMetadata>
                  </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <!-- Entry needed to enable jdocbook packaging -->
                <groupId>org.jboss.maven.plugins</groupId>
                <artifactId>maven-jdocbook-plugin</artifactId>
            </plugin>
        </plugins>

    </build>

    <profiles>
      <profile>
        <id>updateDocs</id>

        <!-- the download will fail unless jboss-credentials.properties contains jboss.username and jboss.password entries -->
        <activation>
          <file>
            <exists>jboss-credentials.properties</exists>
          </file>
        </activation>

        <dependencies>
          <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>Saxon-HE</artifactId>
            <version>9.4.0.6</version>
          </dependency>
        </dependencies>

        <build>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-antrun-plugin</artifactId>
              <version>1.7</version>
              <executions>
                <execution>
                  <id>fetch-docs</id>
                  <phase>generate-resources</phase>
                  <goals>
                    <goal>run</goal>
                  </goals>
                  <inherited>false</inherited>
                  <configuration>
                    <tasks>
                      <property file="jboss-credentials.properties" />
                      <get
                        src="https://docs.jboss.org/author/rpc/jboss_docbook_tools/export.action?os_authType=basic&amp;spaceKey=ERRAI&amp;pageId=5833085&amp;singleBook=true"
                        dest="target/exported-reference-guide.zip"
                        username="${jboss.username}"
                        password="${jboss.password}" />
                      <delete quiet="true">
                        <fileset dir="target/exported-reference-guide" includes="**"/>
                      </delete>
                      <mkdir dir="target/exported-reference-guide"/>
                      <unzip src="target/exported-reference-guide.zip"
                        dest="target/exported-reference-guide"
                        stripAbsolutePathSpec="true" />
                      <delete>
                        <fileset dir="src/main/docbook/en/" includes="chapter-*"/>
                      </delete>
                      
                      <!-- Preprocess the documents and add language attribtues to programlistings. -->
                      <!-- This can be removed once ORG-1337 is resolved (language attributes should be included in docbook export in the first place!) -->
                      <xslt basedir="target/exported-reference-guide"
                        includes="*.xml"
                        destdir="src/main/docbook/en"
                        extension=".xml"
                        style="set-language-attributes.xsl"
                        processor="trax">
                        <factory name="net.sf.saxon.TransformerFactoryImpl"/>
                        <classpath refid="maven.compile.classpath"/>
                        <xmlcatalog>
                          <dtd 
                            publicId="-//OASIS//DTD DocBook XML V4.5//EN"
                            location="src/main/dtd/docbook/xml/4.5/docbookx.dtd"/>
                        </xmlcatalog>
                      </xslt>
                    </tasks>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
	  </build>
     </profile>
    </profiles>
</project>
