<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (C) 2010 eXo Platform SAS.

    This is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation; either version 2.1 of
    the License, or (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this software; if not, write to the Free
    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA, or see the FSF site: http://www.fsf.org.

-->
<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>
  <parent>
    <groupId>org.exoplatform.platform</groupId>
    <artifactId>exo.platform.doc</artifactId>
    <version>3.5.7</version>
  </parent>
  <artifactId>exo.platform.doc.refguide</artifactId>
  <packaging>pom</packaging>
  <name>eXo Platform - Reference Guides</name>

  <profiles>
    <profile>
      <id>distrib</id>
      <properties>
        <docbook.source>${project.build.directory}/docbook-src</docbook.source>
        <jcr.source>${project.build.directory}/docbook-src/org.exoplatform.jcr</jcr.source>
        <!-- Override version of JCR to get the new structure and so the artifact from platform-documentation -->
	    <org.exoplatform.jcr.version>3.5.7-SNAPSHOT</org.exoplatform.jcr.version>
      </properties>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${maven-dependency-plugin.version}</version>
            <executions>
              <!--
				1) Download the Ref guides of products and unpack them in target
			  -->
              <execution>
                <id>a-unpack</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <!-- JCR -->
                    <artifactItem>
                      <groupId>com.exoplatform.platform.documentation</groupId>
                      <artifactId>platform-documentation-refguide-jcr</artifactId>
                      <version>${org.exoplatform.jcr.version}</version>
                      <type>jar</type>
                      <classifier>sources</classifier>
                      <outputDirectory>${docbook.source}/org.exoplatform.jcr</outputDirectory>
                      <includes>**</includes>
                    </artifactItem>
                    <!-- GateIn -->
                    <artifactItem>
                      <groupId>org.gatein.doc</groupId>
                      <artifactId>gatein-reference-guide-en</artifactId>
                      <version>${org.exoplatform.portal.version}</version>
                      <classifier>sources</classifier>
                      <type>zip</type>
                      <outputDirectory>${docbook.source}</outputDirectory>
                      <includes>**</includes>
                    </artifactItem>
                    <!-- Content -->
                    <artifactItem>
                      <groupId>org.exoplatform.ecms</groupId>
                      <artifactId>exo-ecms-docs-refguide</artifactId>
                      <version>${org.exoplatform.ecms.version}</version>
                      <classifier>html-docs</classifier>
                      <type>zip</type>
                      <outputDirectory>${docbook.source}</outputDirectory>
                      <includes>**</includes>
                    </artifactItem>
                    <!-- Collaboration -->
                    <artifactItem>
                      <groupId>org.exoplatform.cs</groupId>
                      <artifactId>exo.cs.docs.refguide</artifactId>
                      <version>${org.exoplatform.cs.version}</version>
                      <classifier>html-zip</classifier>
                      <type>zip</type>
                      <outputDirectory>${docbook.source}</outputDirectory>
                      <includes>**</includes>
                    </artifactItem>
                    <!-- Knowledge -->
                    <artifactItem>
                      <groupId>org.exoplatform.ks</groupId>
                      <artifactId>exo.ks.docs.refguide</artifactId>
                      <version>${org.exoplatform.ks.version}</version>
                      <classifier>html-zip</classifier>
                      <type>zip</type>
                      <outputDirectory>${docbook.source}</outputDirectory>
                      <includes>**</includes>
                    </artifactItem>
                    <!-- Social -->
                    <artifactItem>
                      <groupId>org.exoplatform.social</groupId>
                      <artifactId>exo.social.docs.refguide</artifactId>
                      <version>${org.exoplatform.social.version}</version>
                      <classifier>html-zip</classifier>
                      <type>zip</type>
                      <outputDirectory>${docbook.source}</outputDirectory>
                      <includes>**</includes>
                    </artifactItem>
                    <!-- Common style -->
                    <artifactItem>
                      <groupId>org.exoplatform.doc</groupId>
                      <artifactId>doc-style</artifactId>
                      <version>${org.exoplatform.doc.doc-style.version}</version>
                      <outputDirectory>${docbook.source}</outputDirectory>
                      <includes>**</includes>
                      <excludes>META-INF/**</excludes>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!--
          2) Copy resources (images, background, docbook-src) to target
          -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${maven-resources-plugin.version}</version>
            <executions>
              <execution>
                <id>b-copy-resources</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                        <exclude>background/**</exclude>
                      </excludes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <id>c-copy-images</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${docbook.source}/images</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${docbook.source}/org.exoplatform.social/images</directory>
                    </resource>
                    <resource>
                      <directory>${docbook.source}/org.exoplatform.ecms/images</directory>
                    </resource>
                    <resource>
                      <directory>${docbook.source}/org.exoplatform.ks/images</directory>
                    </resource>
                    <resource>
                      <directory>${docbook.source}/org.exoplatform.cs/images</directory>
                    </resource>
                    <resource>
                      <directory>${docbook.source}/org.exoplatform.jcr/resources/images</directory>
                    </resource>
                    <resource>
                      <directory>${docbook.source}/org.gatein.doc/images</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <id>d-copy-background</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${docbook.source}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/main/resources</directory>
                      <excludes>
                        <exclude>docbook-src/**</exclude>
                      </excludes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Make the links between reference guides work -->
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>j-update-links</id>
                <phase>process-classes</phase>
                <configuration>
                  <target>
                    <replaceregexp match="(../../../reference/html/)" replace="" flags="g" byline="true">
                      <fileset dir="${project.build.directory}/docbook/publish/en-US/html" includes="**/*.html" />
                    </replaceregexp>
                    <replaceregexp match="(../../reference/html/)" replace="" flags="g" byline="true">
                      <fileset dir="${project.build.directory}/docbook/publish/en-US/html" includes="**/*.html" />
                    </replaceregexp>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>

            </executions>
          </plugin>
		<!--
          3) Process all the XML files to generate HTML and PDF formats
        -->
          <plugin>
            <groupId>org.jboss.maven.plugins</groupId>
            <artifactId>maven-jdocbook-plugin</artifactId>
            <version>${maven-jdocbook-plugin.version}</version>
            <executions>
              <execution>
                <id>f-jdocbook-resources</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>resources</goal>
                </goals>
              </execution>
              <execution>
                <id>g-jdocbook-generate</id>
                <phase>compile</phase>
                <goals>
                  <goal>generate</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <sourceDirectory>${docbook.source}</sourceDirectory>
              <sourceDocumentName>index.xml</sourceDocumentName>
              <cssResource>
                <directory>${docbook.source}</directory>
                <includes>
                  <include>css/**</include>
                </includes>
              </cssResource>
              <imageResource>
                <directory>${docbook.source}</directory>
                <includes>
                  <include>background/**</include>
                  <include>images/**</include>
                </includes>
              </imageResource>
              <formats>
                <format>
                  <formatName>html</formatName>
                  <stylesheetResource>file:${docbook.source}/xsl/xhtml.xsl</stylesheetResource>
                  <finalName>index.html</finalName>
                </format>
                <format>
                  <formatName>pdf</formatName>
                  <stylesheetResource>file:${docbook.source}/xsl/pdf.xsl</stylesheetResource>
                  <finalName>${project.artifactId}-${project.version}.pdf</finalName>
                </format>
              </formats>
              <options>
                <xincludeSupported>true</xincludeSupported>
                <xmlTransformerType>saxon</xmlTransformerType>
                <docbookVersion>${docbook.version}</docbookVersion>
              </options>
            </configuration>
            <extensions>true</extensions>
            <dependencies>
              <dependency>
                <groupId>org.exoplatform.doc</groupId>
                <artifactId>exo-docbook-xslt</artifactId>
                <version>${docbook-xslt.version}</version>
              </dependency>
            </dependencies>
          </plugin>

          <!-- 4) Assemble and attach the final artifacts (HTML, Docbook, PDF) -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>h-assemble-archives</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>src/main/assembly/docbook.xml</descriptor>
                    <descriptor>src/main/assembly/html.xml</descriptor>
                  </descriptors>
                  <appendAssemblyId>true</appendAssemblyId>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>${helper-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>i-attach-pdf</id>
                <phase>package</phase>
                <goals>
                  <goal>attach-artifact</goal>
                </goals>
                <configuration>
                  <artifacts>
                    <artifact>
                      <file>
                        ${project.build.directory}/docbook/publish/en-US/pdf/${project.artifactId}-${project.version}.pdf
                      </file>
                      <type>pdf</type>
                    </artifact>
                  </artifacts>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
