<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">
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You 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.
-->

  <parent>
    <groupId>org.apache.felix.karaf</groupId>
    <artifactId>karaf</artifactId>
    <version>1.6.0</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.felix.karaf</groupId>
  <artifactId>manual</artifactId>
  <version>1.6.0</version>
  <packaging>pom</packaging>
  <name>Apache Felix Karaf :: Manual</name>
  <description>The Karaf Manual which generates a HTML and PDF representation of the manual.</description>

  <properties>
      <must-succeed>false</must-succeed>
      
      <manual.dir>${project.build.directory}/manual</manual.dir>
      <manual>${manual.dir}/manual-${project.version}</manual>
      <svn.root>${project.scm.connection}</svn.root>
  </properties>

  <build>
    <plugins>
        
    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.2</version>
        <executions>
            <execution>
                <id>preprocess</id>
                <configuration>
                    <tasks>
                        <taskdef name="if" classname="net.sf.antcontrib.logic.IfTask" classpathref="maven.plugin.classpath" />
                        <taskdef name="for" classname="net.sf.antcontrib.logic.ForTask" classpathref="maven.plugin.classpath" />
                        <taskdef name="trycatch" classname="net.sf.antcontrib.logic.TryCatchTask" classpathref="maven.plugin.classpath" />
                        <property name="ant.regexp.regexpimpl" value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp" />
                        <mkdir dir="${manual.dir}" />
                        <trycatch property="error">
                            <try>
                                <get src="https://cwiki.apache.org/confluence/display/FELIX/Karaf+Users'+Guide+in+one+page" dest="${manual}.temp" />
                                <for list="1,2,3,4,5,6,7,8,9,10" param="letter">
                                    <sequential>
                                        <replaceregexp file="${manual}.temp" flags="g" match="&quot;/confluence/display/FELIX/([^&quot;]*)\+([^&quot;+]*)&quot;" replace="&quot;/confluence/display/FELIX/\1\2&quot;" />
                                    </sequential>
                                </for>
                                <replaceregexp file="${manual}.temp" flags="g" match="&quot;/confluence/display/FELIX/([^&quot;]*)&quot;" replace="&quot;#KarafUsers%27Guideinonepage-\1&quot;" />
                                <replaceregexp file="${manual}.temp" flags="g" match="&quot;/confluence/([^&quot;]*)&quot;" replace="&quot;http://cwiki.apache.org/confluence/\1&quot;" />
                                <replaceregexp file="${manual}.temp" flags="g" match="&gt;top&lt;/a&gt;" replace="&gt;&lt;/a&gt;" />
                                <java classname="org.ccil.cowan.tagsoup.CommandLine" classpathref="maven.plugin.classpath" fork="true" output="${manual}.temp2" logError="true">
                                    <arg value="${manual}.temp" />
                                </java>
                                <xslt in="${manual}.temp2" out="${manual}.html" style="${basedir}/src/xslt/extract.xsl">
                                    <param name="stylesheet" expression="${basedir}/src/styles/print.css" />
                                </xslt>
                                <exec executable="prince">
                                    <arg value="${manual}.html" />
                                    <arg value="${manual}.pdf" />
                                </exec>
                                <replace file="${manual}.html" token="${basedir}/src/styles/print.css" value="${svn.root}/src/styles/print.css" />
                                <replace file="${manual}.html" token="scm:svn:" value="" />
                            </try>
                            <catch>
                                <if>
                                    <equals arg1="${must-succeed}" arg2="true" />
                                    <then>
                                        <echo>ERROR: ${error}</echo>
                                        <fail>${error}</fail>
                                    </then>
                                    <else>
                                        <echo>ERROR: ${error}</echo>
                                        <echo>Falling back to dummy manuals</echo>
                                        <copy file="src/fallback/manual.html" tofile="${manual}.html" />
                                        <copy file="src/fallback/manual.pdf" tofile="${manual}.pdf" />
                                    </else>
                                </if>
                            </catch>
                        </trycatch>
                    </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
                <phase>generate-resources</phase>
            </execution>
         </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${manual}.html</file>
                  <type>html</type>
                </artifact>
                <artifact>
                  <file>${manual}.pdf</file>
                  <type>pdf</type>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>      
    </plugins>
  </build>

  <profiles>
      <profile>
          <id>release</id>
          <properties>
              <must-succeed>true</must-succeed>
          </properties>
      </profile>
  </profiles>

</project>
