<?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">
  <parent>
    <artifactId>yauaa-parent</artifactId>
    <groupId>nl.basjes.parse.useragent</groupId>
    <version>5.21</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>yauaa</artifactId>
  <name>Yauaa : Analyzer</name>
  <description>A parsing and analyzing library to get information from a useragent string.</description>
  <url>https://yauaa.basjes.nl</url>
  <developers>
    <developer>
      <name>Niels Basjes</name>
      <email>niels@basjes.nl</email>
      <roles>
        <role>Architect</role>
        <role>Developer</role>
      </roles>
      <timezone>Europe/Amsterdam</timezone>
    </developer>
  </developers>
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <scm>
    <connection>scm:git:https://github.com/nielsbasjes/yauaa.git</connection>
    <developerConnection>scm:git:.</developerConnection>
    <url>https://yauaa.basjes.nl</url>
  </scm>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>UserAgents/*.sh</exclude>
            <exclude>UserAgents/**/*.sh</exclude>
            <exclude>UserAgents/**/*.csv</exclude>
            <exclude>UserAgents/**/*.txt</exclude>
            <exclude>UserAgents/**/*.tab</exclude>
            <exclude>UserAgents/**/*.md</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <id>inject-problematic-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <artifactSet>
                <includes>
                  <include>org.antlr:antlr4-runtime</include>
                  <include>org.springframework:spring-core</include>
                  <include>org.yaml:snakeyaml</include>
                </includes>
              </artifactSet>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <minimizeJar>true</minimizeJar>
          <createDependencyReducedPom>true</createDependencyReducedPom>
          <filters>
            <filter>
              <artifact>org.springframework:spring-core</artifact>
              <excludes>
                <exclude>META-INF/services/**</exclude>
              </excludes>
            </filter>
          </filters>
          <relocations>
            <relocation>
              <pattern>org.springframework</pattern>
              <shadedPattern>nl.basjes.shaded.org.springframework</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.antlr</pattern>
              <shadedPattern>nl.basjes.shaded.org.antlr</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.yaml.snakeyaml</pattern>
              <shadedPattern>nl.basjes.shaded.org.yaml.snakeyaml</shadedPattern>
            </relocation>
          </relocations>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.alexecollins.maven.plugin</groupId>
        <artifactId>script-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
            <id>Verify jar contents to ensure the shading of dependencies went right</id>
            <phase>verify</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <language>beanshell</language>
              <script>import java.io.*;
                import java.util.jar.*;
                import java.util.Arrays;
                import org.codehaus.plexus.util.*;

                System.out.println("Verifying if the shading went correctly");

                String[] libraryWanted = {
                  "nl/basjes/parse/useragent/utils/YauaaVersion.class",
                  "nl/basjes/shaded/org/antlr/v4/runtime/Parser.class",
                  "nl/basjes/shaded/org/springframework/core/io/support/PathMatchingResourcePatternResolver.class",
                };

                String[] libraryUnwanted = {
                  "org/antlr/v4/runtime/Parser.class",
                  "org/springframework/core/io/support/PathMatchingResourcePatternResolver.class",
                  "org/slf4j/LoggerFactory.class",
                };

                JarFile libraryJarFile = new JarFile( new File( "${project.basedir}/target", "yauaa-${project.version}.jar" ) );

                for ( String path : libraryWanted ) {
                  if ( libraryJarFile.getEntry( path ) == null ) {
                    throw new IllegalStateException( "Library: wanted path is missing: " + path );
                  }
                }

                for ( String path : libraryUnwanted ) {
                  if ( libraryJarFile.getEntry( path ) != null ) {
                    throw new IllegalStateException( "Library: unwanted path is present: " + path );
                  }
                }</script>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache-extras.beanshell</groupId>
            <artifactId>bsh</artifactId>
            <version>2.0b6</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>Generate Matchers and Lookups</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>./regen-all.sh</executable>
            </configuration>
          </execution>
          <execution>
            <id>Inject dependency-reduced-pom.xml to the final jar file</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>./inject-dependency-reduced-pom-into-jar.sh</executable>
              <arguments>
                <argument>${project.groupId}</argument>
                <argument>${project.artifactId}</argument>
                <argument>${project.version}</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <version>${antlr.version}</version>
        <executions>
          <execution>
            <id>antlr</id>
            <goals>
              <goal>antlr4</goal>
            </goals>
            <configuration>
              <visitor>true</visitor>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.github.spotbugs</groupId>
        <artifactId>spotbugs-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>nl/basjes/parse/useragent/Version.class</exclude>
            <exclude>nl/basjes/parse/useragent/PackagedRules.class</exclude>
            <exclude>nl/basjes/parse/useragent/parser/*.class</exclude>
            <exclude>nl/basjes/parse/useragent/debug/*.class</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <fileset />
                <pathconvert>
                  <map />
                </pathconvert>
                <echo>${my-file-list}</echo>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.3</version>
        <executions>
          <execution>
            <id>Generate Version YAML</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <file>${basedir}/src/main/code-gen/version/Version.yaml.template</file>
              <outputFile>${basedir}/target/classes/UserAgents/__Version__.yaml</outputFile>
            </configuration>
          </execution>
          <execution>
            <id>Generate Version Java</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <file>${basedir}/src/main/code-gen/version/Version.java.template</file>
              <outputFile>${basedir}/target/generated-sources/java/nl/basjes/parse/useragent/Version.java</outputFile>
            </configuration>
          </execution>
          <execution>
            <id>Generate Yaml List Java</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
            <configuration>
              <file>${basedir}/src/main/code-gen/UserAgents/PackagedRules.java.template</file>
              <outputFile>${basedir}/target/generated-sources/java/nl/basjes/parse/useragent/PackagedRules.java</outputFile>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <replacements>
            <replacement>
              <token>@git.commit.id.describe-short@</token>
              <value>${git.commit.id.describe-short}</value>
            </replacement>
            <replacement>
              <token>@maven.build.timestamp@</token>
              <value>${maven.build.timestamp}</value>
            </replacement>
            <replacement>
              <token>@project.version@</token>
              <value>${project.version}</value>
            </replacement>
            <replacement>
              <token>@version.copyright@</token>
              <value>${version.copyright}</value>
            </replacement>
            <replacement>
              <token>@version.license@</token>
              <value>${version.license}</value>
            </replacement>
            <replacement>
              <token>@version.url@</token>
              <value>${version.url}</value>
            </replacement>
            <replacement>
              <token>@java.version@</token>
              <value>${java.version}</value>
            </replacement>
            <replacement>
              <token>@target.java.version@</token>
              <value>${target.java.version}</value>
            </replacement>
            <replacement>
              <token>###file-list###</token>
              <valueFile>${basedir}/target/temp-yaml-list.txt</valueFile>
            </replacement>
          </replacements>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-sources/java/</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.pitest</groupId>
        <artifactId>pitest-maven</artifactId>
        <version>1.5.2</version>
        <configuration>
          <threads>4</threads>
          <reportsDirectory>${project.basedir}/pitest/pit-reports</reportsDirectory>
          <historyInputFile>${project.basedir}/pitest/yauaa_pitest_history.bin</historyInputFile>
          <historyOutputFile>${project.basedir}/pitest/yauaa_pitest_history.bin</historyOutputFile>
          <timestampedReports>true</timestampedReports>
          <excludedMethods>
            <excludedMethod>toString</excludedMethod>
          </excludedMethods>
          <excludedClasses>
            <excludedClass>nl.basjes.parse.useragent.Version</excludedClass>
            <excludedGroup>nl.basjes.parse.useragent.parser.*</excludedGroup>
            <excludedGroup>nl.basjes.parse.useragent.debug.*</excludedGroup>
          </excludedClasses>
          <avoidCallsTo>
            <avoidCallsTo>java.util.logging</avoidCallsTo>
            <avoidCallsTo>org.apache.log4j</avoidCallsTo>
            <avoidCallsTo>org.slf4j</avoidCallsTo>
            <avoidCallsTo>org.apache.commons.logging</avoidCallsTo>
          </avoidCallsTo>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.apache.httpcomponents.client5</groupId>
      <artifactId>httpclient5</artifactId>
      <version>5.0.3</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>slf4j-api</artifactId>
          <groupId>org.slf4j</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-text</artifactId>
      <version>1.9</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-collections4</artifactId>
      <version>4.4</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>nl.basjes.collections</groupId>
      <artifactId>prefixmap</artifactId>
      <version>2.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.30</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.30</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <artifactId>log4j</artifactId>
          <groupId>log4j</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.esotericsoftware</groupId>
      <artifactId>kryo</artifactId>
      <version>5.0.2</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.7.0</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <artifactId>hamcrest-core</artifactId>
          <groupId>org.hamcrest</groupId>
        </exclusion>
        <exclusion>
          <artifactId>apiguardian-api</artifactId>
          <groupId>org.apiguardian</groupId>
        </exclusion>
        <exclusion>
          <artifactId>junit-platform-engine</artifactId>
          <groupId>org.junit.platform</groupId>
        </exclusion>
        <exclusion>
          <artifactId>junit-jupiter-api</artifactId>
          <groupId>org.junit.jupiter</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <version>5.7.0</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <artifactId>apiguardian-api</artifactId>
          <groupId>org.apiguardian</groupId>
        </exclusion>
        <exclusion>
          <artifactId>junit-jupiter-api</artifactId>
          <groupId>org.junit.jupiter</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-core</artifactId>
      <version>2.2</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <artifactId>hamcrest</artifactId>
          <groupId>org.hamcrest</groupId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>
