<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">
  <parent>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-project</artifactId>
    <version>9.4.44.v20210927</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>jetty-distribution</artifactId>
  <name>Jetty :: Distribution Assemblies</name>
  <packaging>pom</packaging>

  <properties>
    <assembly-directory>${basedir}/target/distribution</assembly-directory>
    <home-directory>${basedir}/target/home</home-directory>
    <spotbugs.skip>true</spotbugs.skip>
  </properties>

  <build>
    <plugins>
      <!--
      Copies the additional distribution content over the unpacked jetty-home
      artifact contents, after the antrun execution that initially populates
      the jetty-distribution directory
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-base-assembly-tree</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <useBuildFilters>false</useBuildFilters>
              <includeEmptyDirs>true</includeEmptyDirs>
              <outputDirectory>${assembly-directory}</outputDirectory>
              <resources>
                <resource>
                  <directory>${basedir}/src/main/resources</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!--
          The jetty-home artifact is the starting point for the jetty-distribution
          and must happen early in the build process
          -->
          <execution>
            <id>unpack-jetty-home</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>jetty-home</artifactId>
                  <version>${project.version}</version>
                  <type>zip</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${home-directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
              <excludes>META-INF/**</excludes>
            </configuration>
          </execution>
          <execution>
            <id>copy</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>test-jetty-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <overWrite>true</overWrite>
                  <includes>**</includes>
                  <outputDirectory>${assembly-directory}/demo-base/webapps</outputDirectory>
                  <destFileName>test.war</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>org.eclipse.jetty.tests</groupId>
                  <artifactId>test-jaas-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <overWrite>true</overWrite>
                  <includes>**</includes>
                  <outputDirectory>${assembly-directory}/demo-base/webapps</outputDirectory>
                  <destFileName>test-jaas.war</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>org.eclipse.jetty.tests</groupId>
                  <artifactId>test-jndi-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <overWrite>true</overWrite>
                  <includes>**</includes>
                  <outputDirectory>${assembly-directory}/demo-base/webapps</outputDirectory>
                  <destFileName>test-jndi.war</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>org.eclipse.jetty.tests</groupId>
                  <artifactId>test-spec-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <overWrite>true</overWrite>
                  <includes>**</includes>
                  <outputDirectory>${assembly-directory}/demo-base/webapps</outputDirectory>
                  <destFileName>test-spec.war</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>test-proxy-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <overWrite>true</overWrite>
                  <includes>**</includes>
                  <outputDirectory>${assembly-directory}/demo-base/webapps</outputDirectory>
                  <destFileName>javadoc-proxy.war</destFileName>
                </artifactItem>
                <artifactItem>
                  <groupId>org.eclipse.jetty.example-async-rest</groupId>
                  <artifactId>example-async-rest-webapp</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                  <overWrite>true</overWrite>
                  <includes>**</includes>
                  <outputDirectory>${assembly-directory}/demo-base/webapps</outputDirectory>
                  <destFileName>async-rest.war</destFileName>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>

          <execution>
            <id>unpack-test-webapp-config</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>test-jetty-webapp</artifactId>
                  <version>${project.version}</version>
                  <classifier>config</classifier>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${assembly-directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
              <excludes>META-INF/**</excludes>
            </configuration>
          </execution>

          <execution>
            <id>unpack-test-jaas-config</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty.tests</groupId>
                  <artifactId>test-jaas-webapp</artifactId>
                  <version>${project.version}</version>
                  <classifier>config</classifier>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${assembly-directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
              <excludes>META-INF/**</excludes>
            </configuration>
          </execution>

          <execution>
            <id>unpack-test-jndi-config</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty.tests</groupId>
                  <artifactId>test-jndi-webapp</artifactId>
                  <version>${project.version}</version>
                  <classifier>config</classifier>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${assembly-directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
              <excludes>META-INF/**</excludes>
            </configuration>
          </execution>

          <execution>
            <id>unpack-test-spec-config</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty.tests</groupId>
                  <artifactId>test-spec-webapp</artifactId>
                  <version>${project.version}</version>
                  <classifier>config</classifier>
                  <type>jar</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${assembly-directory}</outputDirectory>
                </artifactItem>
              </artifactItems>
              <excludes>META-INF/**</excludes>
            </configuration>
          </execution>
          <execution>
            <id>unpack-documentation</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.eclipse.jetty</groupId>
                  <artifactId>jetty-documentation</artifactId>
                  <version>${project.version}</version>
                  <classifier>html</classifier>
                  <type>zip</type>
                  <overWrite>true</overWrite>
                  <outputDirectory>${assembly-directory}/demo-base/webapps/doc</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>populate distribution from home</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <copy todir="${assembly-directory}">
                  <fileset dir="${home-directory}/jetty-home-${project.version}/" />
                </copy>
              </target>
            </configuration>
          </execution>
          <execution>
            <id>set jetty.sh</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <chmod dir="${assembly-directory}/bin" perm="755" includes="**/*.sh" />
              </target>
            </configuration>
          </execution>
          <execution>
            <id>removeKeystore</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <delete file="${assembly-directory}/etc/keystore" />
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>process</goal>
            </goals>
            <configuration>
              <resourceBundles>
                <resourceBundle>org.eclipse.jetty.toolchain:jetty-distribution-remote-resources:1.2</resourceBundle>
              </resourceBundles>
              <outputDirectory>${assembly-directory}</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <!--
          Setup the jetty distribution as a jetty.home/jetty.base combo using start.ini configuration mechanism
          -->
          <execution>
            <id>setup home</id>
            <phase>package</phase>
            <configuration>
              <mainClass>org.eclipse.jetty.start.Main</mainClass>
              <arguments>
                <argument>jetty.home=${assembly-directory}</argument>
                <argument>jetty.base=${assembly-directory}</argument>
                <argument>--add-to-start=server,deploy,websocket,ext,resources,jsp,jstl,http</argument>
              </arguments>
            </configuration>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
          <!--
          Setup the demo-base using the start.d configuration mechanism
          -->
          <execution>
            <id>setup demo-base-startd</id>
            <phase>package</phase>
            <configuration>
              <mainClass>org.eclipse.jetty.start.Main</mainClass>
              <arguments>
                <argument>jetty.home=${assembly-directory}</argument>
                <argument>jetty.base=${assembly-directory}/demo-base</argument>
                <argument>--add-to-startd=server,continuation,deploy,websocket,ext,resources,client,annotations,jndi,servlets,jsp,jstl,http,https,threadpool</argument>
              </arguments>
            </configuration>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/jetty-assembly.xml</descriptor>
          </descriptors>
          <tarLongFileMode>posix</tarLongFileMode>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- For users of jetty-distribution via maven, none of the following
         dependencies should be mandatory to function.
         These only exist to make the reactor sane during the build
         of jetty-distribution itself -->
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-home</artifactId>
      <version>${project.version}</version>
      <type>pom</type>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>test-jetty-webapp</artifactId>
      <type>war</type>
      <version>${project.version}</version>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>test-proxy-webapp</artifactId>
      <type>war</type>
      <version>${project.version}</version>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty.example-async-rest</groupId>
      <artifactId>example-async-rest-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty.tests</groupId>
      <artifactId>test-jaas-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty.tests</groupId>
      <artifactId>test-jndi-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty.tests</groupId>
      <artifactId>test-spec-webapp</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-documentation</artifactId>
      <version>${project.version}</version>
      <classifier>html</classifier>
      <type>zip</type>
      <optional>true</optional>
    </dependency>
  </dependencies>
</project>
