<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.devonfw</groupId>
    <artifactId>maven-parent</artifactId>
    <version>12</version>
  </parent>
  <groupId>com.devonfw.tools</groupId>
  <artifactId>devonfw-docgen</artifactId>
  <version>2023.04.001</version>
  <packaging>pom</packaging>
  <name>${project.artifactId}</name>
  <description>Generates documentation as PDF, ePub or HTML from AsciiDoc wiki pages.</description>
  <licenses>
    <license>
      <name>Apache Software License, Version 2.0</name>
      <url>https://github.com/devonfw/devon-docgen/blob/master/LICENSE</url>
      <distribution>repro</distribution>
      <comments></comments>
    </license>
  </licenses>
  <developers>
    <developer>
      <name>Malte Brunnlieb</name>
      <organization>Capgemini</organization>
    </developer>
    <developer>
      <name>Jörg Hohwiller</name>
      <organization>Capgemini</organization>
    </developer>
    <developer>
      <name>Jaime Diaz Gonzalez</name>
      <organization>Capgemini</organization>
    </developer>
    <developer>
      <name>Jorge Dacal Cantos</name>
      <organization>Capgemini</organization>
    </developer>
  </developers>
  <contributors>
    <contributor>
      <name>Simon Röger</name>
      <organization>Capgemini</organization>
    </contributor>
  </contributors>
  <modules>
    <module>init</module>
    <module>pdf</module>
    <module>html</module>
    <module>all</module>
  </modules>
  <properties>
    <github.repository>devon-docgen</github.repository>
    <asciidoctor.skip>false</asciidoctor.skip>
    <docgen.preserveDirectories>true</docgen.preserveDirectories>
    <docgen.idseparator>-</docgen.idseparator>
    <docgen.highlighter>coderay</docgen.highlighter>
    <docgen.asciidoc.page>documentation/master</docgen.asciidoc.page>
    <maven.build.timestamp.format>yyyy-MM-dd_HH.mm.ss</maven.build.timestamp.format>
    <docgen.asciidoc.target>${basedir}/target/asciidoc</docgen.asciidoc.target>
    <asciidoctor.maven.plugin.version>1.6.0</asciidoctor.maven.plugin.version>
    <docgen.asciidoc.source>${basedir}</docgen.asciidoc.source>
    <docgen.toc>right</docgen.toc>
    <docgen.docsource>${docgen.asciidoc.page}.${docgen.asciidoc.extension}</docgen.docsource>
    <docgen.images.dir>images</docgen.images.dir>
    <asciidoctorj.pdf.version>1.5.0-alpha.18</asciidoctorj.pdf.version>
    <docgen.generated.docs>${basedir}/target/generated-docs</docgen.generated.docs>
    <flatten.mode>resolveCiFriendliesOnly</flatten.mode>
    <docgen.eruby>erb</docgen.eruby>
    <jruby.version>9.2.6.0</jruby.version>
    <docgen.headerFooter>true</docgen.headerFooter>
    <docgen.backend>pdf</docgen.backend>
    <docgen.icons>font</docgen.icons>
    <buildtime>${maven.build.timestamp}</buildtime>
    <docgen.output.format>pdf</docgen.output.format>
    <docgen.asciidoc.extension>asciidoc</docgen.asciidoc.extension>
    <docgen.linkcss>true</docgen.linkcss>
    <asciidoctorj.epub.version>1.5.0-alpha.9</asciidoctorj.epub.version>
  </properties>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-release-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>flatten-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>flatten</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>flatten</goal>
            </goals>
          </execution>
          <execution>
            <id>flatten.clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <flattenMode>${flatten.mode}</flattenMode>
          <updatePomFile>true</updatePomFile>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>pre-process-asciidoc</id>
            <phase>process-resources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <skip>${asciidoctor.skip}</skip>
              <target>
                <taskdef resource="net/sf/antcontrib/antlib.xml" />
                <for param="asciidoc-file">
                  <path>
                    <fileset casesensitive="yes" dir="${docgen.asciidoc.source}">
                      <exclude name="**/target/**" />
                      <include name="**/*.${docgen.asciidoc.extension}" />
                    </fileset>
                  </path>
                  <sequential>
                    <var name="path_to_copy_to" unset="true" />
                    <var name="path_id_prefix" unset="true" />
                    <property name="path_id_prefix" value="" />
                    <var name="file_path" unset="true" />
                    <property name="path_to_copy_to" value="" />
                    <dirname file="@{asciidoc-file}" property="file_path" />
                    <var name="filename" unset="true" />
                    <basename file="@{asciidoc-file}" property="filename" />
                    <var name="norm_prefix" unset="true" />
                    <property name="norm_prefix" value="" />
                    <script language="beanshell">String path = project.getProperty("file_path").replace("\\", "/");
                      String source = project.getProperty("docgen.asciidoc.source").replace("\\", "/");
                      path = path.replace(source, "");
                      if(path.startsWith("/")) {
                        path = path.replaceFirst("/", "");
                      }
                      project.setProperty("path_to_copy_to", path);
                      if(!path.isEmpty()) {
                      project.setProperty("path_id_prefix", path + "_");
                      } else {
                        project.setProperty("path_id_prefix", "");
                      }

                      String filename = project.getProperty("filename");
                      String normalizedPrefix = (path + "/" + filename).replace("/", "_");
                      if( normalizedPrefix.startsWith("_")) normalizedPrefix=normalizedPrefix.substring(1);
                      project.setProperty("norm_prefix", normalizedPrefix);</script>
                    <copy file="@{asciidoc-file}" todir="${docgen.asciidoc.target}/${path_to_copy_to}" encoding="${project.build.sourceEncoding}" outputencoding="${project.reporting.outputEncoding}" verbose="true">
                      <filterchain>
                        <tokenfilter>
                          <linetokenizer />
                          <replaceregex pattern="\[\[" replace="[[${norm_prefix}_" flags="g" />
                          <replaceregex pattern="^(==+) (.*)" replace="[[${norm_prefix}_\2]]${line.separator}\1 \2" flags="g" />
                          <replaceregex pattern="include\:\:(.*/)?(?!.*\.)(.*)\[" replace="include::\1\2.asciidoc[" flags="g" />
                          <replaceregex pattern="include\:\:(.*)((\.adoc)|(\.asc)|(\.asciidoc))(\.asciidoc)\[" replace="include::\1\2[" flags="g" />
                          <replaceregex pattern="xref:([^#\[]+)\[" replace="xref:${norm_prefix}_\1[" flags="g" />
                          <replaceregex pattern="link:([^#:.]+)#([^\[]*)\[" replace="xref:${path_id_prefix}\1.asciidoc_\2[" flags="g" />
                          <replaceregex pattern="link:([^#:.\[]+)(#|\[)" replace="xref:${path_id_prefix}\1.asciidoc\2" flags="g" />
                          <replaceregex pattern="link:([^\]]+)(#|\[)" replace="xref:${path_id_prefix}\1\2" flags="g" />
                          <replaceregex pattern="xref:([^\[]*)\[\]" replace="xref:\1[\1]" flags="g" />
                          <replaceregex pattern="xref:([^#:/]+)/([^#:/]+)/([^#:/]+)\[" replace="xref:\1_\2_\3[" flags="g" />
                          <replaceregex pattern="xref:([^#:/]+)/([^#:/]+)\[" replace="xref:\1_\2[" flags="g" />
                          <replaceregex pattern="xref:([^#:/]+)\[" replace="xref:\1[" flags="g" />
                          <replaceregex pattern="xref:([^#:/]+)/([^#:/]+)/([^#:/]+)#([^\[]*)\[\]" replace="xref:\1_\2_\3_\4[\1_\2_\3#\4]" flags="g" />
                          <replaceregex pattern="xref:([^#:/]+)/([^#:/]+)#([^\[]*)\[\]" replace="xref:\1_\2_\3[\1_\2#\3]" flags="g" />
                          <replaceregex pattern="xref:([^#:/]+)#([^\[]*)\[\]" replace="xref:\1_\2[\1#\2]" flags="g" />
                          <scriptfilter setbeans="true" language="beanshell" byline="true">String text = self.getToken();
                            if (text.startsWith("[[")) {
                              int end = text.indexOf("]]");
                              if (end > 0) {
                                String content = text.substring(2, end).trim().toLowerCase().replaceAll("[?¿!¡':()&amp;/“”`\"\\[\\]#]", "").replace(' ', '-');
                                self.setToken("[[" + content + "]]" + text.substring(end + 2));
                              }
                            }</scriptfilter>
                          <replaceregex pattern="^(=) " replace="[[${norm_prefix}]]${line.separator}\1 " flags="g" />
                          <replaceregex pattern="\$\{project\.version\}" replace="${project.version}" flags="g" />
                          <replaceregex pattern="\$\{project\.artifactId\}" replace="${project.artifactId}" flags="g" />
                          <replaceregex pattern="\$\{buildtime\}" replace="${buildtime}" flags="g" />
                        </tokenfilter>
                      </filterchain>
                    </copy>
                  </sequential>
                </for>
                <copy todir="${docgen.asciidoc.target}" encoding="${project.build.sourceEncoding}">
                  <path>
                    <fileset dir="${docgen.asciidoc.source}">
                      <exclude name="**/*.${docgen.asciidoc.extension}" />
                      <exclude name="**/target/**" />
                      <exclude name="**/pom.xml" />
                      <exclude name="**/${docgen.images.dir}/**/*" />
                      <exclude name="**/.repository/**" />
                    </fileset>
                  </path>
                </copy>
                <for param="receiveddir" list="${docgen.images.dir}">
                  <sequential>
                    <for param="imagesdir">
                      <path>
                        <dirset casesensitive="yes" dir="${docgen.asciidoc.source}">
                          <include name="**/@{receiveddir}/**" />
                        </dirset>
                      </path>
                      <sequential>
                        <copy todir="${docgen.asciidoc.target}/@{receiveddir}">
                          <path>
                            <fileset dir="@{imagesdir}">
                              <include name="**/*" />
                            </fileset>
                          </path>
                        </copy>
                      </sequential>
                    </for>
                  </sequential>
                </for>
              </target>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
            <exclusions>
              <exclusion>
                <groupId>ant</groupId>
                <artifactId>ant</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-nodeps</artifactId>
            <version>1.8.1</version>
          </dependency>
          <dependency>
            <groupId>org.beanshell</groupId>
            <artifactId>bsh</artifactId>
            <version>2.0b5</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.asciidoctor</groupId>
        <artifactId>asciidoctor-maven-plugin</artifactId>
        <version>${asciidoctor.maven.plugin.version}</version>
        <executions>
          <execution>
            <id>generate-doc</id>
            <phase>compile</phase>
            <goals>
              <goal>process-asciidoc</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-pdf</artifactId>
            <version>${asciidoctorj.pdf.version}</version>
          </dependency>
          <dependency>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctorj-epub3</artifactId>
            <version>${asciidoctorj.epub.version}</version>
          </dependency>
          <dependency>
            <groupId>org.jruby</groupId>
            <artifactId>jruby-complete</artifactId>
            <version>${jruby.version}</version>
          </dependency>
        </dependencies>
        <configuration>
          <skip>${asciidoctor.skip}</skip>
          <sourceDirectory>${docgen.asciidoc.target}</sourceDirectory>
          <sourceDocumentName>${docgen.docsource}</sourceDocumentName>
          <imagesDir>${docgen.generated.docs}</imagesDir>
          <backend>${docgen.backend}</backend>
          <outputDirectory>${docgen.generated.docs}</outputDirectory>
          <sourceHighlighter>${docgen.highlighter}</sourceHighlighter>
          <headerFooter>${docgen.headerFooter}</headerFooter>
          <preserveDirectories>${docgen.preserveDirectories}</preserveDirectories>
          <eruby>${docgen.eruby}</eruby>
          <attributes>
            <allow-uri-read />
            <icons>${docgen.icons}</icons>
            <pagenums />
            <experimental />
            <toc>${docgen.toc}</toc>
            <baseDir>./</baseDir>
            <linkcss>${docgen.linkcss}</linkcss>
            <idprefix />
            <idseparator>${docgen.idseparator}</idseparator>
          </attributes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>custom-style</id>
      <activation>
        <file>
          <exists>./theme/custom-theme.yml</exists>
        </file>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <configuration>
              <attributes>
                <pdf-stylesdir>${basedir}/theme</pdf-stylesdir>
                <pdf-style>custom</pdf-style>
              </attributes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
