<?xml version="1.0"?>
<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>
    <artifactId>annis-all</artifactId>
    <groupId>de.hu-berlin.german.korpling.annis</groupId>
    <version>3.7.1</version>
    <relativePath>../pom.xml</relativePath>
  </parent>
  <name>annis-doc</name>
  <packaging>pom</packaging>
  <artifactId>annis-docs</artifactId>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <site.path>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}-develop</site.path>
    <!-- override in your settings -->
    <siteMainDirectory>${user.home}</siteMainDirectory>
    <scmPubCheckoutDirectory>\${siteMainDirectory}/annis-content-scm</scmPubCheckoutDirectory>
  </properties>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-scm-publish-plugin</artifactId>
          <version>3.0.0</version>
          <extensions>true</extensions>
          <configuration>
            <pubScmUrl>scm:git:ssh://git@github.com/korpling/ANNIS.git</pubScmUrl>
            <scmBranch>gh-pages</scmBranch>
            <content>${project.build.directory}/mdbook/</content>
            <skipDeletedFiles>true</skipDeletedFiles>
            <ignorePathsToDelete>
              <path>doc</path>
              <path>index.html</path>
              <path>.gitignore</path>
            </ignorePathsToDelete>
            <tryUpdate>true</tryUpdate>
            <checkoutDirectory>${scmPubCheckoutDirectory}</checkoutDirectory>
            <checkinComment>update documentation for version ${project.version} (${site.path})
              
Original revision is ${buildNumber}.</checkinComment>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>parse-version</id>
            <goals>
              <goal>parse-version</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>release</id>
      <properties>
        <!-- set the site.path variable to "major.minor" version -->
        <site.path>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</site.path>
      </properties>
    </profile>
    <!-- preview releases still push their documentation to doc-develop -->
    <profile>
      <id>preview</id>
      <properties>
        <site.path>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}-develop</site.path>
      </properties>
    </profile>
    <profile>
      <id>mdbook</id>
      <build>
        <plugins>
          <!-- make sure all paths are correct by replacing the properties -->
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>copy-mdbook-to-generated</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/mdbook-generated</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/mdbook/</directory>
                      <filtering>true</filtering>
                      <excludes>
                        <exclude>user-guide/book/</exclude>
                        <exclude>developer-guide/book/</exclude>
                        <exclude>online-help/book/</exclude>
                      </excludes>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <id>copy-index-html</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.build.directory}/mdbook/${site.path}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/html</directory>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- use the filtered source files to actually generate the mdbook output -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
              <execution>
                <id>compile-user-guide</id>
                <phase>compile</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>mdbook</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>build</argument>
                    <argument>-d</argument>
                    <argument>${project.build.directory}/mdbook/${site.path}/user-guide/</argument>
                    <argument>mdbook-generated/user-guide/</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>compile-developer-guide</id>
                <phase>compile</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>mdbook</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>build</argument>
                    <argument>-d</argument>
                    <argument>${project.build.directory}/mdbook/${site.path}/developer-guide/</argument>
                    <argument>mdbook-generated/developer-guide/</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>compile-online-help</id>
                <phase>compile</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>mdbook</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>build</argument>
                    <argument>-d</argument>
                    <argument>${project.basedir}/../annis-gui/src/main/webapp/VAADIN/help/</argument>
                    <argument>mdbook-generated/online-help/</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <!-- the online help directory should be cleaned as well -->
          <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
              <filesets>
                <fileset>
                  <directory>${project.basedir}/../annis-gui/src/main/webapp/VAADIN/help/</directory>
                  <followSymlinks>false</followSymlinks>
                </fileset>
              </filesets>
            </configuration>
          </plugin>
          <!-- upload the generated documentation to GitHub -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-publish-plugin</artifactId>
            <executions>
              <execution>
                <id>scm-publish</id>
                <phase>deploy</phase>
                <goals>
                  <goal>publish-scm</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>