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

    <groupId>org.dizitart</groupId>
    <artifactId>dbinspect-bridge</artifactId>
    <version>0.1.0</version>
    <packaging>jar</packaging>

    <name>dbinspect-bridge</name>
    <description>
        The engine-neutral dbinspect bridge core for the JVM: wire protocol, pairing, transport
        and the release guard. It knows about no database. Adapters live in their own artifacts
        so that using one never drags in the dependencies of the others.
    </description>
    <url>https://github.com/nitrite/dbinspect</url>

    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <!-- Maven Central requires both of these blocks on every artifact it
         accepts, and rejects the bundle at validation rather than at upload.
         They are here rather than in the release profile below so that a POM
         which is missing them fails nobody's build at the last minute. -->
    <developers>
        <developer>
            <name>Anindya Chatterjee</name>
            <email>anidotnet@gmail.com</email>
            <organization>Dizitart</organization>
            <organizationUrl>https://nitrite.dizitart.com</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:https://github.com/nitrite/dbinspect.git</connection>
        <developerConnection>scm:git:https://github.com/nitrite/dbinspect.git</developerConnection>
        <url>https://github.com/nitrite/dbinspect</url>
        <tag>HEAD</tag>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Java 11 floor, per PLAN.md M3. Also the language level an Android
             application reaches through desugaring. -->
        <maven.compiler.release>11</maven.compiler.release>
        <gson.version>2.11.0</gson.version>
        <java-websocket.version>1.6.0</java-websocket.version>
        <slf4j.version>2.0.18</slf4j.version>
        <junit.version>4.13.2</junit.version>
    </properties>

    <dependencies>
        <!-- A JSON tree, not a binder: every frame is untrusted input from a
             socket and is read as Map/List rather than into a type. Gson has no
             transitive dependencies and runs on Android, which the two obvious
             alternatives do not both do. -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>${gson.version}</version>
        </dependency>

        <!-- The "minimal embedded WebSocket server" PLAN.md M3 asks for: RFC 6455
             framing and nothing else, no servlet container, and it runs on
             Android. Writing the framing by hand is several hundred lines of
             masking and fragmentation handling on bytes from a socket. -->
        <dependency>
            <groupId>org.java-websocket</groupId>
            <artifactId>Java-WebSocket</artifactId>
            <version>${java-websocket.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <compilerArgs>
                        <arg>-Xlint:all</arg>
                        <arg>-Werror</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.2.5</version>
            </plugin>
        </plugins>
    </build>

    <!--
        Maven Central, and nothing that runs on an ordinary build.

        Everything a release needs and a developer does not is in this profile:
        the sources and javadoc jars Central rejects a bundle without, the GPG
        signature it rejects it without, and the Portal upload itself. `mvn
        verify` stays a compile-and-test on a machine with no signing key, which
        is the same "opt-in by ordering" rule the desktop signing follows — a
        fork's CI is green without credentials it can never have.

        The version was `-SNAPSHOT` until 0.1.0 reached Central, because three
        repositories consume `org.dizitart:dbinspect-bridge` by that exact
        coordinate — `fanlight/sidecar-jvm`, `nitrite-java/nitrite-bridge` and
        their CI — and a release version committed before the upload existed
        would have broken all of them. 0.1.0 is on Central now, those three are
        on the released coordinate, and this POM carries a plain version; see
        docs/RELEASING.md.
    -->
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!--
                        `-Werror -Xlint:all` on the compiler is this module's
                        standard and it stays. Javadoc's own doclint is a
                        different checker with a different opinion — it fails on
                        an undocumented parameter of a package-private class —
                        and turning it into a release blocker would mean the
                        first release is the day the whole module gets javadoc
                        it does not have. `none` here, and the honest statement
                        is that the jar exists because Central requires one.
                    -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.12.0</version>
                        <configuration>
                            <doclint>none</doclint>
                            <quiet>true</quiet>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <!--
                        Loopback pinentry: there is no tty on a runner, and
                        without it gpg blocks forever on a passphrase prompt
                        rather than reading `gpg.passphrase`.
                    -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.8</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <gpgArguments>
                                        <arg>--pinentry-mode</arg>
                                        <arg>loopback</arg>
                                    </gpgArguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!--
                        `autoPublish` false: the bundle is validated and left in
                        the Portal for a human to release. A first publish under
                        a namespace is not the moment to discover that the
                        automatic path has no undo.
                    -->
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.11.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>central</publishingServerId>
                            <autoPublish>false</autoPublish>
                            <waitUntil>validated</waitUntil>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
