<?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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.eclipse.jetty.documentation</groupId>
    <artifactId>documentation</artifactId>
    <version>12.0.33</version>
  </parent>
  <artifactId>jetty</artifactId>
  <packaging>pom</packaging>
  <name>Documentation :: Asciidoc</name>

  <modules>
    <module>modules/code/examples</module>
  </modules>

  <properties>
    <!-- build cache must be disabled for antora goal to work and for run.jetty.classpath value to be computed properly -->
    <maven.build.cache.enabled>false</maven.build.cache.enabled>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.antora</groupId>
        <artifactId>antora-maven-plugin</artifactId>
        <version>1.0.0-alpha.5</version>
        <extensions>true</extensions>
        <configuration>
          <options>
            <option>attribute[] jetty-home=${project.build.directory}/jetty-home-${project.version}</option>
            <option>attribute[] jetty-version=${project.version}</option>
          </options>
          <playbookProvider>
            <repository>jetty/jetty.website</repository>
            <path>main:lib/playbook-templates/per-branch-antora-playbook.yml</path>
          </playbookProvider>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>collector</id>
      <activation>
        <property>
          <name>collector</name>
        </property>
      </activation>
      <properties>
        <jetty.home>${project.build.directory}/jetty-home-${project.version}</jetty.home>
        <jetty.home.output.directory>${project.build.directory}</jetty.home.output.directory>
        <maven.test.skip>true</maven.test.skip>
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-home</artifactId>
          <version>${project.version}</version>
          <type>zip</type>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>org.eclipse.jetty.tests</groupId>
          <artifactId>jetty-testers</artifactId>
          <scope>runtime</scope>
        </dependency>
        <dependency>
          <groupId>org.eclipse.jetty.toolchain</groupId>
          <artifactId>jetty-test-helper</artifactId>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>build-jetty-home</id>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.eclipse.jetty</groupId>
                      <artifactId>jetty-home</artifactId>
                      <version>${project.version}</version>
                      <type>zip</type>
                    </artifactItem>
                  </artifactItems>
                  <outputDirectory>${jetty.home.output.directory}</outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>capture-run-jetty-classpath</id>
                <goals>
                  <goal>build-classpath</goal>
                </goals>
                <phase>generate-resources</phase>
                <configuration>
                  <outputProperty>run.jetty.classpath</outputProperty>
                  <includeScope>runtime</includeScope>
                  <!-- when mvn is run from project root, this jar gets resolved to build dir instead of local Maven repo -->
                  <excludeArtifactIds>jetty-testers</excludeArtifactIds>
                  <silent>true</silent>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>pass-jetty-home</id>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <phase>process-resources</phase>
                <configuration>
                  <outputDirectory>${project.build.directory}/collector</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${basedir}</directory>
                      <includes>
                        <include>antora.yml</include>
                      </includes>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>collector-with-antora-cache-dir</id>
      <activation>
        <property>
          <name>env.ANTORA_CACHE_DIR</name>
        </property>
      </activation>
      <properties>
        <jetty.home>${env.ANTORA_CACHE_DIR}/jetty/jetty-home-${project.version}</jetty.home>
        <jetty.home.output.directory>${env.ANTORA_CACHE_DIR}/jetty</jetty.home.output.directory>
      </properties>
    </profile>
  </profiles>
</project>
