<?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.ecms</groupId>
    <artifactId>exo-ecms-docs</artifactId>
    <version>2.3.3-CP01</version>
  </parent>
  <artifactId>exo-ecms-docs-refguide</artifactId>
  <packaging>jar</packaging>

  <name>ECMS documentation reference guide</name>

  <properties>
    <wikbook.source>${project.build.directory}/wikbook-src</wikbook.source>
    <wikbook.resources>${project.basedir}/src/main/resources/wikbook/images</wikbook.resources>
    <wikbook.target>${project.build.directory}/wikbook</wikbook.target>
    <wikbook.version>0.9.30</wikbook.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.wikbook</groupId>
      <artifactId>wikbook.docbkxstyle</artifactId>
      <version>${wikbook.version}</version>
    </dependency>
    
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
	    <artifactId>exo-ecms-core-services</artifactId>
  	  <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.ecms</groupId>
      <artifactId>exo-ecms-core-services</artifactId>
      <version>${project.version}</version>
      <classifier>sources</classifier>
    </dependency>   
  </dependencies>

  <build>
    <plugins>
      <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.source}</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/resources/wikbook</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
     <id>docs</id>
     <activation>
       <property>
         <name>!skip.doc</name>
       </property>
     </activation>
     <build>
       <plugins> 
          <!-- The wikbook maven plugin generates the docbook document from the wiki source -->
	      <plugin>
	         <groupId>org.wikbook</groupId>
	         <artifactId>wikbook.maven</artifactId>
	         <version>${wikbook.version}</version>
	         <executions>
	           <execution>
	             <phase>prepare-package</phase>
	             <goals>
	               <goal>transform</goal>
	             </goals>
	           </execution>
	         </executions>
	         <configuration>
	           <sourceDirectory>${wikbook.source}/en/en-US</sourceDirectory>
	      	  <sourceFileName>wcm-ref.wiki</sourceFileName>
	           <destinationDirectory>${wikbook.target}/src</destinationDirectory>
	           <destinationFileName>${project.artifactId}.xml</destinationFileName>
	             <emitDoctype>false</emitDoctype>
	           <beforeBookBodyXML><![CDATA[<xi:include href="bookinfo.ext" xmlns:xi="http://www.w3.org/2001/XInclude" />]]></beforeBookBodyXML>
	           <validationMode>lax</validationMode>
	           <syntaxId>confluence/1.0</syntaxId>
	         </configuration>
	       </plugin>
	
	       <!-- Unpacks the docbook style resources for the docbkx plugin -->
	       <plugin>
	         <groupId>org.apache.maven.plugins</groupId>
	         <artifactId>maven-dependency-plugin</artifactId>
	         <version>2.1</version>
	         <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>${wikbook.target}/src/resources</outputDirectory>
	             </configuration>
	           </execution>
	         </executions>
	       </plugin>
	
	       <!-- Dockbx plugin that generates content -->
	       <plugin>
	         <groupId>com.agilejava.docbkx</groupId>
	         <artifactId>docbkx-maven-plugin</artifactId>
	         <version>2.0.7</version>
	         <executions>
	           <execution>
	             <goals>
	               <goal>generate-pdf</goal>
	               <goal>generate-html</goal>
	             </goals>
	             <phase>package</phase>
	             <configuration>
	               <sourceDirectory>${wikbook.target}/src</sourceDirectory>
	               <targetDirectory>${wikbook.target}/output</targetDirectory>
	
	               <!-- HTML -->
	               <htmlCustomization>${wikbook.target}/src/resources/xsl/html.xsl</htmlCustomization>
	               <htmlStylesheet>css/ecms.css</htmlStylesheet>
	
	               <!-- PDF -->
	               <foCustomization>${wikbook.target}/src/resources/xsl/fopdf.xsl</foCustomization>
	               <imgSrcPath />
	               <admonGraphicsPath>images/admons/</admonGraphicsPath>
	
	               <!-- Highlight source code -->
	               <highlightSource>1</highlightSource>
	               <xincludeSupported>true</xincludeSupported>
	
	               <!--
	                 |  See http://www.sagehill.net/docbookxsl/AnnotateListing.html
	                 |  Callouts on imported text
	                 -->
	               <useExtensions>1</useExtensions>
	               <calloutsExtension>1</calloutsExtension>
	 
	            <!-- Copy the bookinfo.xml -->
	            <preProcess>
	              <copy todir="${wikbook.target}/src">
	                <fileset dir="${wikbook.source}/en/en-US">
	                  <include name="**/*.ext" />
	                </fileset>
	              </copy>
	                 <!-- Images from the Stylesheets -->
	                 <copy todir="${wikbook.target}/output">
	                   <fileset dir="${wikbook.target}/src/resources">
	                     <include name="**/*.css" />
	                     <include name="**/*.png" />
	                     <include name="**/*.gif" />
	                     <include name="**/*.jpg" />
	                   </fileset>
	                 </copy>
	            </preProcess>
	
	            <!-- Copy the css -->
	            <postProcess>
	              <copy todir="${wikbook.target}/output/css">
									<fileset dir="${wikbook.source}/css">
	                  <include name="**/*.css" />
	                </fileset>
	              </copy>
	              <copy todir="${wikbook.target}/output/images">
	                  <fileset dir="${wikbook.source}/images">
										<include name="**/*.gif" />
										<include name="**/*.png" />
										<include name="**/*.jpg" />
	                </fileset>
	              </copy>                
	            </postProcess>
	
	             </configuration>
	           </execution>
	         </executions>
	         <dependencies>
	           <dependency>
	             <groupId>org.docbook</groupId>
	             <artifactId>docbook-xml</artifactId>
	             <version>4.4</version>
	             <scope>runtime</scope>
	           </dependency>
	         </dependencies>
	       </plugin>
	
		   <!-- html-zip packaging -->
		   <plugin>
		     <artifactId>maven-assembly-plugin</artifactId>
		     <configuration>
		       <descriptors>
		         <descriptor>src/main/assembly/html-zip.xml</descriptor>
		       </descriptors>
		       <appendAssemblyId>false</appendAssemblyId>
		     </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>target/wikbook/output/${project.artifactId}.pdf</file>
	                  <type>pdf</type>
	                </artifact>
	                <artifact>
	                  <file>target/${project.artifactId}-${project.version}.zip</file>
	                  <type>zip</type>
	                </artifact>
	              </artifacts>
	            </configuration>
	          </execution>
	        </executions>
	      </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
  
</project>
