<?xml version="1.0"?>
<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>
  <groupId>io.github.joht.search.example.servlet</groupId>
  <artifactId>search-example-servlet</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <properties>
    <compiler-plugin.version>3.15.0</compiler-plugin.version>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <maven.compiler.source>25</maven.compiler.source>
    <maven.compiler.target>25</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus-plugin.version>3.34.2</quarkus-plugin.version>
    <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
    <quarkus.platform.version>3.34.1</quarkus.platform.version>
    <json-sanitizer.version>1.2.3</json-sanitizer.version>
    <surefire-plugin.version>3.5.5</surefire-plugin.version>
    <jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>
    <mockito-core.version>5.23.0</mockito-core.version>
    <hamcrest.version>3.0</hamcrest.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-undertow</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-elasticsearch-rest-client</artifactId>
    </dependency>
    <!-- Main dependency for the elasticsearch REST client that itself mainly depends on the apache http client -->
    <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-client</artifactId>
    </dependency>
    <!--  OWASP JSON Sanatizer (XSS Security Protection) -->
    <dependency>
      <groupId>com.mikesamuel</groupId>
      <artifactId>json-sanitizer</artifactId>
      <version>${json-sanitizer.version}</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-junit-jupiter</artifactId>
      <version>${mockito-core.version}</version>
      <scope>test</scope>
  </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
      <version>${mockito-core.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest</artifactId>
      <version>${hamcrest.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-maven-plugin</artifactId>
        <version>${quarkus-plugin.version}</version>
        <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>build</goal>
              <goal>generate-code</goal>
              <goal>generate-code-tests</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${compiler-plugin.version}</version>
        <configuration>
          <parameters>${maven.compiler.parameters}</parameters>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
            <maven.home>${maven.home}</maven.home>
          </systemPropertyVariables>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco-maven-plugin.version}</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>report</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
      <plugin>
				<groupId>net.alchim31.maven</groupId>
				<artifactId>yuicompressor-maven-plugin</artifactId>
				<version>1.5.1</version>
        <executions>
          <execution>
            <id>aggregate_js_css</id>
            <phase>process-resources</phase>
            <goals>
              <goal>compress</goal>
            </goals>
          </execution>
        </executions>
				<configuration>
          <!-- Gathers JavaScript, CSS and images from the upper dir example. -->
          <!-- Aggregates all JavaScript files into one application.js -->
					<preProcessAggregates>true</preProcessAggregates>
					<aggregations>
						<aggregation>
							<insertNewLine>true</insertNewLine>
							<inputDir>${project.basedir}/..</inputDir>
							<output>${project.build.directory}/aggregated/application.js</output>
							<!-- <output>${project.build.directory}/classes/META-INF/resources/application.js</output> -->
							<includes>
								<include>**/src/js/polyfills/*.js</include>
								<include>**/src/js/ponyfills/*.js</include>
                <!-- 
                  TODO could gather JavaScript dependencies via npm
                  For now, the modules of the main directory (../../) are included directly 
                  while developing this example. This should be changed to "node_modules" or
                  maybe directly loaded from npm using a separate maven plugin.
                -->
                <include>**/node_modules/data-restructor/devdist/datarestructor-ie-global-all.js</include>
                <include>../devdist/search-menu-ui-ie-global-all.js</include>
								<include>**/src/js/*.js</include>
							</includes>
						</aggregation>
						<aggregation>
							<insertNewLine>true</insertNewLine>
							<inputDir>${project.basedir}/../styles</inputDir>
							<output>${project.build.directory}/aggregated/application.css</output>
							<!-- <output>${project.build.directory}/classes/META-INF/resources/application.css</output> -->
							<includes>
								<include>*.css</include>
							</includes>
						</aggregation>
						<aggregation>
							<insertNewLine>true</insertNewLine>
							<inputDir>${project.basedir}/../images</inputDir>
							<output>${project.build.directory}/classes/META-INF/resources/images/searchicon-small.png</output>
							<includes>
								<include>searchicon-small.png</include>
							</includes>
						</aggregation>
					</aggregations>
          <!-- skip minification and anything else that makes it hard to read the example -->
          <!-- For production code it would make sense to use minification etc.-->
					<nosuffix>true</nosuffix>
					<jswarn>false</jswarn>
					<nomunge>true</nomunge>
					<nocompress>true</nocompress>
          <disableOptimizations>true</disableOptimizations>
					<sourceDirectory>${project.build.directory}/aggregated</sourceDirectory>
					<outputDirectory>${project.build.directory}/classes/META-INF/resources</outputDirectory>
				</configuration>
			</plugin>
      <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.3</version>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <!-- Replace hardcoded elasticsearch port number in example javascript -->
          <!-- with the local port. The servlet will delegate the call to elasticsearch -->
          <basedir>${project.build.directory}/classes/META-INF/resources</basedir>
          <includes>
            <include>application.js</include>
          </includes>
          <replacements>
            <replacement>
              <token>:9200/</token>
              <value>:8080/</value>
            </replacement>
          </replacements>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>native</id>
      <activation>
        <property>
          <name>native</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>${surefire-plugin.version}</version>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
                <configuration>
                  <systemPropertyVariables>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <maven.home>${maven.home}</maven.home>
                  </systemPropertyVariables>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      <properties>
        <quarkus.package.type>native</quarkus.package.type>
      </properties>
    </profile>
  </profiles>
</project>
