<?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.souther-lang</groupId>
    <artifactId>souther-parent</artifactId>
    <version>0.1.0-rc5</version>
    <packaging>pom</packaging>

    <name>Souther</name>
    <description>Souther: a JVM language that turns SMDD spec models into implementation models.</description>
    <url>https://github.com/souther-lang/souther</url>

    <licenses>
        <license>
            <name>Eclipse Public License - v 2.0</name>
            <url>https://www.eclipse.org/legal/epl-2.0/</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>kawasima</id>
            <name>kawasima</name>
            <url>https://github.com/kawasima</url>
        </developer>
    </developers>

    <modules>
        <module>souther-runtime</module>
        <module>souther-syntax</module>
        <module>souther-compiler</module>
        <module>souther-build-driver</module>
        <module>souther-fmt</module>
        <module>souther-lsp</module>
        <module>souther-cli</module>
        <module>souther-bench</module>
    </modules>

    <scm>
        <connection>scm:git:https://github.com/souther-lang/souther.git</connection>
        <developerConnection>scm:git:git@github.com:souther-lang/souther.git</developerConnection>
        <url>https://github.com/souther-lang/souther</url>
        <tag>HEAD</tag>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>25</maven.compiler.release>
        <raoh.version>0.7.2</raoh.version>
        <jspecify.version>1.0.0</jspecify.version>
        <!-- Where compiled classes go, named so the `m2e` profile below can send the editor's
             somewhere else. A build outside the editor uses the Maven defaults. -->
        <build.classes>${project.basedir}/target/classes</build.classes>
        <build.test.classes>${project.basedir}/target/test-classes</build.test.classes>
        <errorprone.version>2.50.0</errorprone.version>
        <nullaway.version>0.13.8</nullaway.version>
        <!-- Which Error Prone checks a build runs. Measured on `clean test-compile`, whole
             reactor, one run each: 8.7s with no Error Prone at all, 12.0s with NullAway alone,
             38.0s with the default checks as well. The nullness gate is the rule this repository
             holds itself to, and it costs three seconds; the other five hundred checks cost
             twenty-six, which is too much to spend on every compile while writing code. So a
             development build runs the gate, and the `lint` profile below runs the rest. -->
        <errorprone.checks>-XepDisableAllChecks</errorprone.checks>
        <!-- The build protocol souther-build-driver implements. Not this project's version and not
             tracked to it: it moves when the interface between a build plugin and a driver moves,
             which is why it is released from souther-lang/souther-build-api and named here like any
             other outside dependency. -->
        <souther.build.api.version>1.0.0</souther.build.api.version>
        <junit.version>6.1.2</junit.version>
        <!-- Named rather than written where it is used: `souther init` writes a project that runs
             its tests, and what it hands that project is this number. -->
        <surefire.version>3.5.6</surefire.version>
        <!-- A JVM per two cores. Named here so -DforkCount=N reaches it: a literal in the plugin's
             configuration outranks the property surefire declares, so the override the comment
             below offers was not one, and a fork count could not be measured until it was.
             Measured on sixteen cores, whole build, three runs each: 59s at one per core, 53s at
             this. A fork brings its own compiler and collector threads, and one per core leaves
             nothing for them but the cores the tests are on. -->
        <forkCount>0.5C</forkCount>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>net.unit8.raoh</groupId>
                <artifactId>raoh</artifactId>
                <version>${raoh.version}</version>
            </dependency>
            <dependency>
                <groupId>net.unit8.raoh</groupId>
                <artifactId>raoh-json</artifactId>
                <version>${raoh.version}</version>
            </dependency>
            <dependency>
                <groupId>net.unit8.raoh</groupId>
                <artifactId>raoh-jooq</artifactId>
                <version>${raoh.version}</version>
            </dependency>
            <dependency>
                <groupId>org.jspecify</groupId>
                <artifactId>jspecify</artifactId>
                <version>${jspecify.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-build-api</artifactId>
                <version>${souther.build.api.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-runtime</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-syntax</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-compiler</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-build-driver</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-fmt</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-lsp</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.souther-lang</groupId>
                <artifactId>souther-cli</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>${junit.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <outputDirectory>${build.classes}</outputDirectory>
        <testOutputDirectory>${build.test.classes}</testOutputDirectory>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${surefire.version}</version>
                    <configuration>
                        <!-- Whole test classes run to completion in a fork. Forks
                             rather than threads: four classes capture `System.out` to read what the
                             CLI printed, and a stream is one per JVM however many threads share it.
                             A fork also settles the rest of it — a class loaded per fork, a static
                             initialiser run per fork — so nothing here depends on what another test
                             did first. Override with -DforkCount=N; 1 is one JVM for everything. -->
                        <forkCount>${forkCount}</forkCount>
                        <reuseForks>true</reuseForks>
                        <!-- Classes go to the forks by what they took last time, which is recorded
                             in a `.surefire-*` file beside the module. Handed out in file order
                             instead, one fork draws the longest class and a share of the rest, and
                             the build waits on that fork: the compiler's suite is 156s of tests
                             over sixteen forks, and it came to 28s rather than the 14s its longest
                             class alone would cost. A checkout with no record behaves as before. -->
                        <runOrder>balanced</runOrder>
                        <!-- C1 only, and a collector that runs no threads of its own. A test class
                             is a few seconds of work, over well before C2 has finished compiling
                             what it profiled, and with a JVM per core the compiler and collector
                             threads of every fork are competing for the cores the tests are on.
                             Measured on the compiler's suite, whole build, eight forks: 49s without
                             these, 27s with them. -->
                        <!-- -Xss4m is the stack this compiler is supported on, and the tests are
                             held to the same one: a source at the structural bound needs about a
                             megabyte, and what is checked here has to be checked on the stack the
                             bound was set for. A test that wants a smaller one makes its own
                             thread. -->
                        <argLine>-XX:TieredStopAtLevel=1 -XX:+UseSerialGC -Xss4m</argLine>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <!-- The null analysis runs here, in javac, rather than in an editor: a rule only some
                 checkouts enforce is not a rule. NullAway reads the JSpecify annotations
                 souther-runtime already carries, and `OnlyNullMarked` is what decides where it
                 looks — the packages that declare `@NullMarked`, and no others. Adopting a package
                 is then one line in its `package-info.java`, and the packages that have not adopted
                 it compile as they did. Declaring the whole of souther-compiler annotated instead
                 reports 1024 findings at once, which is a migration and not a check.

                 The `compilePolicy` and `should-stop` arguments below are Error Prone's, not ours:
                 its checks read the flow graph, and javac builds one per class only under that
                 policy. The exports the plugin needs to reach javac's internals are in
                 `.mvn/jvm.config`, because the compiler runs in the Maven JVM; without them the
                 build stops at `IllegalAccessError` before any source is read. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.15.0</version>
                <configuration>
                    <compilerArgs>
                        <!-- javac prints a hundred warnings per compilation and stops counting, and
                             a hundred errors likewise. A report that stops at a round number reads
                             as the whole of what was found — a change that breaks two hundred call
                             sites is read as breaking a hundred — so both limits are raised past
                             anything this build produces. -->
                        <arg>-Xmaxwarns</arg>
                        <arg>100000</arg>
                        <arg>-Xmaxerrs</arg>
                        <arg>100000</arg>
                        <arg>-XDcompilePolicy=simple</arg>
                        <arg>--should-stop=ifError=FLOW</arg>
                        <!-- UnicodeInCode is off for good. It reads a non-ASCII identifier as a
                             thing that confuses a reader, and this compiler's tests call methods
                             the language named in Japanese: the check would be asking the tests to
                             stop covering what Souther supports. -->
                        <arg>-Xplugin:ErrorProne ${errorprone.checks} -Xep:UnicodeInCode:OFF -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:JSpecifyMode=true</arg>
                    </compilerArgs>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>com.google.errorprone</groupId>
                            <artifactId>error_prone_core</artifactId>
                            <version>${errorprone.version}</version>
                        </path>
                        <path>
                            <groupId>com.uber.nullaway</groupId>
                            <artifactId>nullaway</artifactId>
                            <version>${nullaway.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <!-- Implementation-Version in every jar's manifest. A compiled Souther module records
                 the compiler that produced it, and this is where that string comes from: Maven
                 fills it from the project version, so the root pom stays the one place the version
                 is written. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- Error Prone's own checks, on top of the nullness gate every build runs. On in CI,
             which sets `CI` in the environment, and available anywhere as `mvn -Plint verify`.
             What this buys is the checks that are errors by default — the first run of it found a
             `String` handed to a `Map<NumericTerm, ...>`, which had left two tests asserting
             something about a domain they were never given. What it costs is three times the
             compile, which is why it is not what a build runs while code is being written. A
             finding can therefore reach CI without having been seen locally; `mvn -Plint` on the
             module in hand is the way to answer it. -->
        <profile>
            <id>lint</id>
            <activation>
                <property>
                    <name>env.CI</name>
                </property>
            </activation>
            <properties>
                <errorprone.checks/>
            </properties>
        </profile>
        <!-- An editor's Java support builds these modules through m2e, and m2e points an Eclipse
             project's output at whatever the pom names: ECJ then writes into target/classes, which
             is where maven-compiler-plugin reads staleness from. A class file newer than its source
             is indistinguishable from an up-to-date build, so javac is skipped and whatever ECJ
             left is what runs — including the classes it writes under proceedOnError, whose bodies
             throw `Unresolved compilation problem` at run time. Sending the editor's output
             somewhere else leaves target/classes with one writer.

             m2e sets the `m2e.version` property while it resolves a pom and a command-line build
             never does, so this profile is on in the editor and off everywhere else. The editor
             settings that would otherwise carry this are in `.vscode/`, which is not in the
             repository: a rule that has to hold for every checkout belongs here. -->
        <profile>
            <id>m2e</id>
            <activation>
                <property>
                    <name>m2e.version</name>
                </property>
            </activation>
            <properties>
                <build.classes>${project.basedir}/target/jdt-classes</build.classes>
                <build.test.classes>${project.basedir}/target/jdt-test-classes</build.test.classes>
            </properties>
        </profile>
        <!-- Activate for a Central release: `mvn -Prelease deploy`. Attaches sources and
             javadoc, GPG-signs every artifact, and publishes the reactor to the Sonatype
             Central Portal (autoPublish=false, so the bundle is reviewed in the Portal before
             release). Normal build/test is untouched. -->
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.4.0</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>3.12.0</version>
                        <configuration>
                            <doclint>none</doclint>
                            <failOnError>false</failOnError>
                            <quiet>true</quiet>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <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>
                            </execution>
                        </executions>
                    </plugin>
                    <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>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
