<?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: RCSB Meta Models</name>
    <description>Meta models (JSON schema extensions) for RCSB schemas</description>
    <groupId>org.rcsb</groupId>
    <artifactId>rcsb-mojave-meta</artifactId>
    <version>1.5.1</version>
    <url>https://github.com/rcsb/rcsb-mojave-meta</url>

    <!-- 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>

    <!-- Maven will use the information embedded in the scm configuration to determine the command
        mapping for the scm command. -->
    <scm>
        <url>https://github.com/rcsb/rcsb-mojave-meta</url>
        <connection>scm:git:git://github.com/rcsb/rcsb-mojave-meta.git</connection>
        <developerConnection>scm:git:git@github.com:rcsb/rcsb-mojave-meta.git</developerConnection>
      <tag>v1.5.1</tag>
  </scm>


    <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>

    <properties>

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

        <jdk.version>11</jdk.version>

        <schema.spec.directory>json-schema-spec</schema.spec.directory>
        <schema.spec.source>${project.basedir}/src/main/resources/${schema.spec.directory}</schema.spec.source>
        <schema.spec.draft7>json-schema-draft-07.json</schema.spec.draft7>
        <schema.spec.rcsb.extensions>json-schema-rcsb-extensions.json</schema.spec.rcsb.extensions>

        <schema.spec.target>${project.build.directory}/generated-sources/${schema.spec.directory}</schema.spec.target>
        <schema.spec.target.name>json-schema-spec-rcsb-extensions.json</schema.spec.target.name>
        <project.meta.package>org.rcsb.mojave.meta</project.meta.package>
        <mojave.tools.version>1.7.3</mojave.tools.version>

    </properties>

    <dependencies>

        <dependency>
            <groupId>org.rcsb</groupId>
            <artifactId>rcsb-mojave-tools</artifactId>
            <version>${mojave.tools.version}</version>
        </dependency>

    </dependencies>

    <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>

            <!-- Executes Java programs -->
            <plugin>

                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <includeProjectDependencies>true</includeProjectDependencies>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>

                <!-- executes the supplied java class in the current VM with the enclosing project's dependencies as classpath -->
                <executions>

                    <!-- GENERATE META SCHEMA -->
                    <execution>
                        <id>build-meta-schema</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <!-- execute Java programs in the same VM -->
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.rcsb.mojave.tools.core.GenerateCombinedJsonSchema</mainClass>
                            <arguments>
                                <!-- where to put final schema -->
                                <argument>-o</argument>
                                <argument>${schema.spec.target}/${schema.spec.target.name}</argument>
                                <!-- list of schemas to stitch -->
                                <argument>-i</argument>
                                <argument>file:${schema.spec.source}/${schema.spec.draft7}</argument>
                                <argument>file:${schema.spec.source}/${schema.spec.rcsb.extensions}</argument>
                                <!-- overrides $id property with this value-->
                                <argument>-s</argument>
                                <argument>${schema.spec.directory}/${schema.spec.target.name}</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <!-- GENERATE META CONSTANTS -->
                    <execution>
                        <id>generate-meta-constants</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <!-- execute Java programs in the same VM -->
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.rcsb.mojave.tools.core.GenerateSchemaConstants</mainClass>
                            <arguments>
                                <!-- Location of the JSON Schema file(s). -->
                                <argument>-i</argument>
                                <argument>${schema.spec.target}/${schema.spec.target.name}</argument>
                                <!-- Target directory for generated Java source files. -->
                                <argument>-o</argument>
                                <argument>${project.build.directory}/generated-sources/classes</argument>
                                <!-- Target fully qualified class name used for generated Java class. -->
                                <argument>-t</argument>
                                <argument>${project.meta.package}.MetaSchemaConstants</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <!-- GENERATE ENUMS FROM META SCHEMA -->
                    <execution>
                        <id>generate-meta-enums</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <!-- execute Java programs in the same VM -->
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.rcsb.mojave.tools.core.GenerateSchemaEnums</mainClass>
                            <arguments>
                                <!-- Location of the JSON Schema file(s). -->
                                <argument>-i</argument>
                                <argument>${schema.spec.target}</argument>
                                <!-- Target directory for generated Java source files. -->
                                <argument>-o</argument>
                                <argument>${project.build.directory}/generated-sources/classes</argument>
                                <!-- Package name used for generated Java classes (for types where a fully qualified name
                                    has not been supplied in the schema using the 'javaType' property). -->
                                <argument>-t</argument>
                                <argument>${project.meta.package}.enums</argument>
                                <!-- Whether to add a suffix to generated classes. -->
                                <argument>-s</argument>
                                <argument>Enum</argument>
                                <!-- Dynamically resolve references -->
                                <argument>-d</argument>
                                <argument>true</argument>
                            </arguments>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>add-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/classes</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>

    </build>

    <profiles>
        <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>


</project>
