<?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.ks</groupId>
    <artifactId>exo.ks.docs</artifactId>
    <version>2.2.15</version>
  </parent>

  <artifactId>exo.ks.docs.refguide</artifactId>
  <packaging>pom</packaging>


  <name>Knowledge Reference Guide</name>
  <profiles>
    <profile>
      <id>distrib</id>
      <activation>
        <property>
          <name>!skip.doc</name>
        </property>
      </activation>      
      <properties>
        <wikbook.source>${project.basedir}/src/main/resources/wikbook/en/en-US</wikbook.source>
        <docbook.source>${project.build.directory}/docbook-src</docbook.source>
        <wikbook.jaxrs.source>${project.basedir}/target/wikbook-src</wikbook.jaxrs.source>
      </properties>


      <dependencies>
				<dependency>
					<groupId>org.wikbook</groupId>
					<artifactId>wikbook.docbkxstyle</artifactId>
					<version>${version.wikbook.plugin}</version>
				</dependency>
				<dependency>
					<groupId>org.exoplatform.ks</groupId>
					<artifactId>exo.ks.eXoApplication.poll.service</artifactId>
					<version>${project.version}</version>
					<classifier>doc-jaxrs</classifier>
				</dependency>
				<dependency>
					<groupId>org.exoplatform.ks</groupId>
					<artifactId>exo.ks.eXoApplication.faq.service</artifactId>
					<version>${project.version}</version>
					<classifier>doc-jaxrs</classifier>
				</dependency>
				<dependency>
					<groupId>org.exoplatform.ks</groupId>
					<artifactId>exo.ks.eXoApplication.forum.service</artifactId>
					<version>${project.version}</version>
					<classifier>doc-jaxrs</classifier>
				</dependency>
        <dependency>
          <groupId>org.exoplatform.doc</groupId>
          <artifactId>doc-style</artifactId>
          <version>${org.exoplatform.doc.doc-style.version}</version>
          <type>jar</type>
        </dependency>
      </dependencies>

      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
              <!--
             1a) Copy the Wikbook sources to target
             -->
              <execution>
                <id>b-copy-resources</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/wikbook-src</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${wikbook.source}</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <!--
                1b) Copy the images to the Docbook sources directory
              -->
              <execution>
                <id>c-copy-images</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${docbook.source}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/main/resources/wikbook</directory>
                      <excludes>
                        <exclude>en/**</exclude>
                      </excludes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <!--
               1c) Copy the "docbook" folder to the Docbook sources directory
             -->
              <execution>
                <id>d-copy-docbksource</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${docbook.source}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/main/resources/docbook</directory>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!--  2) Unpack the Common style resources -->

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
							<execution>
								<id>unpack-jaxrs</id>
								<phase>generate-sources</phase>
								<goals>
									<goal>unpack-dependencies</goal>
								</goals>
								<configuration>
									<includeGroupIds>org.exoplatform.ks</includeGroupIds>
									<includeArtifactIds>exo.ks.eXoApplication.poll.service,exo.ks.eXoApplication.faq.service,exo.ks.eXoApplication.forum.service</includeArtifactIds>
									<includeClassifiers>doc-jaxrs</includeClassifiers>
									<excludes>META-INF/**</excludes>
									<outputDirectory>${wikbook.jaxrs.source}/DeveloperReference/jaxrs</outputDirectory>
								</configuration>
							</execution>
              <execution>
                <id>a-unpack</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <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>

          <!--
3) The Wikbook Maven plugin generates the Docbook document from the Wiki source -->
          <plugin>
            <groupId>org.wikbook</groupId>
            <artifactId>wikbook.maven</artifactId>
            <version>${version.wikbook.plugin}</version>
            <executions>
              <execution>
                <id>d-generate-docbook</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <bookId>KnowledgeReferenceGuide</bookId>
              <sourceDirectory>${project.build.directory}/wikbook-src</sourceDirectory>
              <sourceFileName>book.wiki</sourceFileName>
              <destinationDirectory>${docbook.source}</destinationDirectory>
              <destinationFileName>${project.artifactId}.xml</destinationFileName>
              <beforeBookBodyXML><![CDATA[
                 <xi:include href="bookinfo.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
                 <xi:include href="Preface.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
           ]]></beforeBookBodyXML>
              <syntaxId>confluence/1.0</syntaxId>
            </configuration>
          </plugin>

          <!-- Use ANT run to replace RoleNotInToc -->
          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <id>add-role</id>
                <phase>generate-sources</phase>
                <configuration>
                  <target>
                    <replace file="${docbook.source}/${project.artifactId}.xml">
                      <replacetoken><![CDATA[RoleNotInToc"]]></replacetoken>
                      <replacevalue><![CDATA[" role="NotInToc"]]></replacevalue>
                    </replace>
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- 4) Process all the XML files to generate HTML and PDF formats -->
          <plugin>
            <groupId>org.jboss.maven.plugins</groupId>
            <artifactId>maven-jdocbook-plugin</artifactId>
            <version>2.1.1</version>
            <extensions>true</extensions>
            <dependencies>
              <dependency>
                <groupId>org.exoplatform.doc</groupId>
                <artifactId>exo-docbook-xslt</artifactId>
                <version>1</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <id>e-jdocbook-resources</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>resources</goal>
                </goals>
              </execution>
              <execution>
                <id>f-generate-docs</id>
                <goals>
                  <goal>generate</goal>
                </goals>
                <phase>compile</phase>
              </execution>
            </executions>
            <configuration>
              <sourceDirectory>${docbook.source}</sourceDirectory>
              <sourceDocumentName>${project.artifactId}.xml</sourceDocumentName>
              <imageResource>
                <directory>${docbook.source}</directory>
                <includes>
                  <include>images/**</include>
                  <include>background/**</include>
                </includes>
              </imageResource>
              <cssResource>
                <directory>${docbook.source}</directory>
                <includes>
                  <include>css/**</include>
                </includes>
              </cssResource>
              <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>1.76.1</docbookVersion>
              </options>
            </configuration>
          </plugin>

          <!-- 5) Assemble and attach the final artifacts (HTML, Docbook, PDF) -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>g-assemble-archives</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>src/main/assembly/html-zip.xml</descriptor>
                  </descriptors>
                  <appendAssemblyId>true</appendAssemblyId>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- Attach the doc to the pom in maven repo -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
            <executions>
              <execution>
                <id>h-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>
