<?xml version="1.0" encoding="UTF-8"?>
<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.exoplatform.social</groupId>
    <artifactId>exo.social.docs</artifactId>
    <version>1.2.9</version>
  </parent>
  <artifactId>exo.social.docs.refguide</artifactId>
  <packaging>jar</packaging>

  <name>eXo Social Reference Guide</name>

  <properties>
    <wikbook.sourceDirectory>${project.build.directory}/wikbook/tmp</wikbook.sourceDirectory>
    <wikbook.syntaxId>confluence/1.0</wikbook.syntaxId><!-- xwiki/2.0 -->
    <wikbook.validationMode>strict</wikbook.validationMode> <!-- lax/strick -->
    <docbook.sourceDirectory>${project.build.directory}/wikbook/src</docbook.sourceDirectory>
    <docbook.targetDirectory>${project.build.directory}/wikbook/output</docbook.targetDirectory>
  </properties>


  <dependencies>
    <dependency>
      <groupId>org.exoplatform.social</groupId>
      <artifactId>exo.social.component.service</artifactId>
      <classifier>doc-jaxrs</classifier>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.social</groupId>
      <artifactId>exo.social.component.core</artifactId>
      <classifier>doc-chromattic</classifier>
    </dependency>
    <dependency>
      <groupId>org.wikbook</groupId>
      <artifactId>wikbook.docbkxstyle</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Copy resources filtering with maven properties -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare</id>
            <phase>compile</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${wikbook.sourceDirectory}</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/resources/wikbook</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!--
        The wikbook maven plugin generates the docbook document from the
        wiki source
      -->
      <plugin>
        <groupId>org.wikbook</groupId>
        <artifactId>wikbook.maven</artifactId>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>transform</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <bookId>SocialReferenceGuide</bookId>
          <sourceDirectory>${wikbook.sourceDirectory}/en/en-US</sourceDirectory>
          <sourceFileName>book.wiki</sourceFileName>
          <destinationDirectory>${docbook.sourceDirectory}</destinationDirectory>
          <destinationFileName>${project.artifactId}.xml</destinationFileName>
          <beforeBookBodyXML><![CDATA[
                 <xi:include href="bookinfo.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
                 <!--xi:include href="acknowledgements.xml" xmlns:xi="http://www.w3.org/2001/XInclude" /-->
           ]]></beforeBookBodyXML>
          <validationMode>${wikbook.validationMode}</validationMode>
          <syntaxId>${wikbook.syntaxId}</syntaxId>
        </configuration>
      </plugin>

      <!-- Unpacks the docbook style resources for the docbkx plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>a</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeGroupIds>org.wikbook</includeGroupIds>
              <includeArtifactIds>wikbook.docbkxstyle</includeArtifactIds>
              <excludes>META-INF/**</excludes>
              <outputDirectory>${docbook.sourceDirectory}/resources</outputDirectory>
            </configuration>
          </execution>
           <execution>
             <id>unpack-jaxrs</id>
             <phase>compile</phase>
             <goals>
               <goal>unpack-dependencies</goal>
             </goals>
             <configuration>
               <includeGroupIds>org.exoplatform.social</includeGroupIds>
               <includeArtifactIds>exo.social.component.service</includeArtifactIds>
               <includeClassifiers>doc-jaxrs</includeClassifiers>
               <excludes>META-INF/**</excludes>
               <outputDirectory>${project.build.directory}/wikbook/tmp/en/en-US/DeveloperReference/jaxrs</outputDirectory>
            </configuration>
           </execution>
           <execution>
             <id>unpack-chromattic</id>
             <phase>compile</phase>
             <goals>
               <goal>unpack-dependencies</goal>
             </goals>
             <configuration>
               <includeGroupIds>org.exoplatform.social</includeGroupIds>
               <includeArtifactIds>exo.social.component.core</includeArtifactIds>
               <includeClassifiers>doc-chromattic</includeClassifiers>
               <excludes>META-INF/**</excludes>
               <outputDirectory>${project.build.directory}/wikbook/tmp/en/en-US/chromattic</outputDirectory>
            </configuration>
           </execution>
        </executions>
      </plugin>

      <!-- Dockbx plugin that generates content -->
      <plugin>
        <groupId>com.agilejava.docbkx</groupId>
        <artifactId>docbkx-maven-plugin</artifactId>
        <version>${version.docbkx.plugin}</version>
        <!--
          not last generation due to incompatibilities with last docbook
          format
        -->
        <executions>
          <execution>
            <id>generate-html</id>
            <goals>
              <goal>generate-html</goal>
            </goals>
            <phase>package</phase>
            <configuration>

              <!-- Output -->
              <targetDirectory>${project.build.directory}/wikbook/output/html</targetDirectory>

              <!-- Stylesheets -->
              <htmlCustomization>${docbook.sourceDirectory}/resources/xsl/bootstrap/html.xsl</htmlCustomization>

              <!-- Copy the image -->
              <postProcess>
                <copy todir="${project.build.directory}/wikbook/output/html/images">
                  <fileset dir="${pom.basedir}/src/main/resources/wikbook/images">
                    <include name="**" />
                  </fileset>
                </copy>
                <copy todir="${project.build.directory}/wikbook/output/html">
                  <fileset dir="${project.build.directory}/wikbook/src/resources">
                    <include name="**/*.css" />
                    <include name="**/*.js" />
                    <include name="**/*.png" />
                    <include name="**/*.gif" />
                    <include name="**/*.jpg" />
                  </fileset>
                </copy>
              </postProcess>
            </configuration>
          </execution>
          <execution>
            <id>generate-xhtml</id>
            <goals>
              <goal>generate-xhtml</goal>
            </goals>
            <phase>package</phase>
            <configuration>

              <!-- Output -->
              <targetDirectory>${project.build.directory}/wikbook/output/xhtml</targetDirectory>
              <targetFileExtension>html</targetFileExtension>

              <!-- Stylesheets -->
              <xhtmlCustomization>${docbook.sourceDirectory}/resources/xsl/simple/pdf.xsl</xhtmlCustomization>

              <!-- Copy the image -->
              <postProcess>
                <copy todir="${project.build.directory}/wikbook/output/xhtml/images">
                  <fileset dir="${pom.basedir}/src/main/resources/wikbook/images">
                    <include name="**" />
                  </fileset>
                </copy>
                <copy todir="${project.build.directory}/wikbook/output/xhtml">
                  <fileset dir="${project.build.directory}/wikbook/src/resources">
                    <include name="**/*.css" />
                    <include name="**/*.png" />
                    <include name="**/*.gif" />
                    <include name="**/*.jpg" />
                  </fileset>
                </copy>
              </postProcess>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <sourceDirectory>${docbook.sourceDirectory}</sourceDirectory>
          <targetDirectory>${docbook.targetDirectory}</targetDirectory>
          <includes>${project.artifactId}.xml</includes>

          <!-- Highlight source code -->
          <highlightSource>1</highlightSource>

          <!-- We need to support xinclude -->
          <xincludeSupported>true</xincludeSupported>

          <!--
            | See
            http://www.sagehill.net/docbookxsl/AnnotateListing.html |
            Callouts on imported text
          -->
          <useExtensions>1</useExtensions>
          <calloutsExtension>1</calloutsExtension>

          <!-- Copy any docbook XML -->
          <preProcess>
            <copy todir="${docbook.sourceDirectory}">
              <fileset dir="${wikbook.sourceDirectory}/en/en-US">
                <include name="**/*.xml" />
              </fileset>
            </copy>
          </preProcess>

        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.docbook</groupId>
            <artifactId>docbook-xml</artifactId>
            <version>4.4</version>
            <scope>runtime</scope>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <groupId>org.wikbook</groupId>
        <artifactId>wikbook.html2pdf</artifactId>
        <version>${org.wikbook.version}</version>
	<executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>transform</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <sourceDirectory>${project.build.directory}/wikbook/output/xhtml</sourceDirectory>
          <sourceFileName>exo.social.docs.refguide.html</sourceFileName>
          <destinationDirectory>${project.build.directory}/wikbook/output/pdf</destinationDirectory>
          <destinationFileName>exo.social.docs.refguide.pdf</destinationFileName>
        </configuration>
      </plugin>

      <!-- html-zip packaging -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/html-zip.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Attach the doc to the pom in maven repo -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/main/resources</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${docbook.targetDirectory}/pdf/${project.artifactId}.pdf</file>
                  <type>pdf</type>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

