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

    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <name>Mojave: JSON Schema Tools</name>
    <description>Provides tools to work with JSON schemas.</description>
    <url>https://github.com/rcsb/rcsb-mojave-tools</url>

    <groupId>org.rcsb</groupId>
    <artifactId>rcsb-mojave-tools</artifactId>
    <version>1.9.0</version>

    <!-- https://central.sonatype.org/pages/apache-maven.html -->
    <!-- https://github.com/chhh/sonatype-ossrh-parent/blob/master/pom.xml -->
    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <organization>
        <name>RCSB PDB</name>
        <url>https://www.rcsb.org/</url>
    </organization>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/license/mit/</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Yana Rose</name>
            <email>yana.rose@rcsb.org</email>
            <organization>RCSB PDB</organization>
            <organizationUrl>https://www.rcsb.org</organizationUrl>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/rcsb/rcsb-mojave-tools</url>
        <connection>scm:git:git://github.com/rcsb/rcsb-mojave-tools.git</connection>
        <developerConnection>scm:git:git@github.com:rcsb/rcsb-mojave-tools.git</developerConnection>
      <tag>1.9.0</tag>
  </scm>

    <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.build.targetEncoding>UTF-8</project.build.targetEncoding>

        <!-- Configure package name for automatically generated models -->
        <uniprot.auto.package>org.rcsb.uniprot.auto</uniprot.auto.package>
        <ncbi.auto.package>org.rcsb.ncbi.auto</ncbi.auto.package>
        <mesh.auto.package>org.rcsb.mesh.auto</mesh.auto.package>

        <!-- DEPENDENCY VERSIONS -->

        <jdk.version>11</jdk.version>
        <junit.version>4.13.2</junit.version>
        <slf4j.version>2.0.12</slf4j.version>
        <log4j.version>2.23.1</log4j.version>

        <jackson.version>2.13.3</jackson.version>
        <swagger.version>2.2.0</swagger.version>

        <jsonschema2pojo.version>1.1.2</jsonschema2pojo.version>
        <pojo2jsonschema.version>1.16</pojo2jsonschema.version>
        <bean.validation.api.version>2.0.1.Final</bean.validation.api.version>

        <!-- SOURCES OF SCHEMAS FOR EXTERNAL DATA -->

        <!-- uniprot -->
        <uniprot.xsd.schema.source.url>https://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/complete/</uniprot.xsd.schema.source.url>
        <uniprot.xsd.schema.name>uniprot.xsd</uniprot.xsd.schema.name>

        <!-- NCBI esummary.fcgi xsd schema location -->
        <ncbi.xsd.esummary.schema.file>src/main/resources/xsd-schemas/ncbi-esummary.xsd</ncbi.xsd.esummary.schema.file>
        <ncbi.xsd.efetch.schema.file>src/main/resources/xsd-schemas/ncbi-efetch.xsd</ncbi.xsd.efetch.schema.file>

        <!-- where we store downloaded XSD schema for uniprot -->
        <uniprot.xsd.schema.download.location>generated-sources/xsd/uniprot</uniprot.xsd.schema.download.location>

        <!-- where we store auto generated classes from XSD schema for uniprot -->
        <uniprot.auto.gen.classes.location>generated-sources/xjc/uniprot</uniprot.auto.gen.classes.location>
        <!-- where we store auto generated classes from XSD schema for NCBI esummary.fcgi -->
        <ncbi.auto.gen.classes.location>generated-sources/xjc/ncbi</ncbi.auto.gen.classes.location>
        <!-- where we store auto generated classes from DTD schema for MeSH terminology -->
        <mesh.auto.gen.classes.location>generated-sources/xjc/mesh</mesh.auto.gen.classes.location>

    </properties>

    <dependencies>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Used by jsonschema2pojo -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Used by jsonschema2pojo -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Used by jsonschema2pojo -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>33.1.0-jre</version>
        </dependency>

        <!-- Since java 11 JRE, this is needed at runtime (not in JRE anymore) -->
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>4.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>4.0.5</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.openjdk.nashorn</groupId>
            <artifactId>nashorn-core</artifactId>
            <version>15.4</version>
        </dependency>

        <!-- Tool to generate DTO style Java classes from JSON schema -->
        <dependency>
            <groupId>org.jsonschema2pojo</groupId>
            <artifactId>jsonschema2pojo-core</artifactId>
            <version>${jsonschema2pojo.version}</version>
        </dependency>

        <!-- API annotations -->
        <dependency>
            <groupId>io.swagger.core.v3</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>${swagger.version}</version>
        </dependency>

        <!-- The validation api v2. Used to decorate generated POJOs so that annotations like @NotNull
            work well with graphql-spqr. See TestGraphQLSchemaGenMojave in rcsb-yosemite -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${bean.validation.api.version}</version>
        </dependency>

        <!-- API for Log4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <!-- Binding for Log4J, purely used for tests and for the CLI apps in this project: thus runtime scope -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>${log4j.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Log4j API and Core implementation required for binding -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Testing dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                    http://sonarqube.rcsb.org
                </sonar.host.url>
            </properties>
        </profile>
        <profile>
            <!-- A profile only to be used when releasing-->
            <id>release</id>
            <build>
                <plugins>
                    <!-- handles propagating the build to the staging repository -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>

                    <!-- signing of content to be published -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <!-- This is necessary for gpg to not try to use the pinentry programs -->
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- create source -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.0</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- create javadoc -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.6.3</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <!-- so that javadoc generator is not so strict about missing docs -->
                            <!-- https://stackoverflow.com/questions/15886209/maven-is-not-working-in-java-8-when-javadoc-tags-are-incomplete -->
                            <doclint>none</doclint>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

            <!-- https://mvnrepository.com/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin -->
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.2</version>
            </plugin>

            <!-- Write project properties file at build time -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0.0</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>write-project-properties</goal>
                        </goals>
                        <configuration>
                            <outputFile>${basedir}/src/main/resources/tools.module.properties</outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Downloads files in part of maven build -->
            <plugin>

                <groupId>com.googlecode.maven-download-plugin</groupId>
                <artifactId>download-maven-plugin</artifactId>
                <version>1.3.0</version>

                <configuration>
                    <!-- plugin is caching the downloaded file, getting it from .m2 folder. When skipping cache
                            the file will be downloaded every time maven runs (needed because the file may change) -->
                    <skipCache>true</skipCache>
                </configuration>

                <executions>

                    <!-- UniProt KB -->
                    <execution>
                        <!-- the wget goal actually binds itself to this phase by default -->
                        <phase>initialize</phase>
                        <id>download-uniprot-schema</id>
                        <goals>
                            <goal>wget</goal>
                        </goals>
                        <configuration>
                            <url>${uniprot.xsd.schema.source.url}/${uniprot.xsd.schema.name}</url>
                            <outputFileName>${uniprot.xsd.schema.name}</outputFileName>
                            <outputDirectory>${project.build.directory}/${uniprot.xsd.schema.download.location}</outputDirectory>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <!-- Build Java classes from schema files (XSD, DTD) using XJC tool -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>

                    <!-- UNIPROT KB -->
                    <execution>
                        <id>uniprot-schema-generate</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/${uniprot.auto.gen.classes.location}</outputDirectory>
                            <packageName>${uniprot.auto.package}</packageName>
                            <extension>true</extension>
                            <sources>
                                <source>${project.build.directory}/${uniprot.xsd.schema.download.location}/${uniprot.xsd.schema.name}</source>
                            </sources>
                            <xjbSources>
                                <xjbSource>src/main/resources/jaxb-bindings/uniprot.xjb</xjbSource>
                            </xjbSources>
                        </configuration>
                    </execution>

                    <!-- NCBI esummary.fcgi -->
                    <execution>
                        <id>ncbi-schema-generate</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/${ncbi.auto.gen.classes.location}</outputDirectory>
                            <packageName>${ncbi.auto.package}</packageName>
                            <extension>true</extension>
                            <sources>
                                <source>${ncbi.xsd.esummary.schema.file}</source>
                                <source>${ncbi.xsd.efetch.schema.file}</source>
                            </sources>
                        </configuration>
                    </execution>

                    <!-- MeSH Descriptor Record -->
                    <execution>
                        <id>mesh-schema-generate</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/${mesh.auto.gen.classes.location}</outputDirectory>
                            <packageName>${mesh.auto.package}</packageName>
                            <externalEntityProcessing>true</externalEntityProcessing>
                            <!-- Indicate that we should use DTD input instead of XSDs -->
                            <sourceType>dtd</sourceType>
                            <!-- Define the directory where we should find the DTD file -->
                            <sources>
                                <source>src/main/resources/dtd-mesh</source>
                            </sources>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>3.0.1</version>
            </plugin>

        </plugins>
    </build>

</project>
