<?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">
    <parent>
        <groupId>org.mock-server</groupId>
        <artifactId>mockserver</artifactId>
        <version>7.6.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>mockserver-maven-plugin</artifactId>
    <packaging>maven-plugin</packaging>

    <name>MockServer Maven Plugin</name>
    <description>A maven plugin to start and stop the MockServer</description>
    <url>https://www.mock-server.com</url>

    <scm>
        <url>https://github.com/mock-server/mockserver-monorepo.git</url>
        <connection>scm:git:https://github.com/mock-server/mockserver-monorepo.git</connection>
        <developerConnection>scm:git:git@github.com:mock-server/mockserver-monorepo.git</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <properties>
        <module.name>org.mockserver.maven</module.name>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
        <maven-invoker-parallel-threads>1</maven-invoker-parallel-threads>
        <maven-plugin.version>3.9.16</maven-plugin.version>
    </properties>

    <!--
        NOTE: deliberately NO <repositories>/<pluginRepositories> here.

        Every org.mock-server dependency of this plugin is a sibling module built by
        the same reactor (or installed into the local repository by the preceding
        `mvn install`), so a remote snapshot repository only adds a network dependency
        on our own artifacts and lets a previously published snapshot win whenever the
        locally installed one is older.

        It also leaked: <repositories> is copied into the POM published to Maven
        Central, so every consumer of a released mockserver-maven-plugin inherited
        central-portal-snapshots with <releases><enabled>true</enabled> — a
        third-party repository their Maven would query for RELEASE artifacts too.
        Already-published POMs are immutable, so this stops the injection from here on.
    -->

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.maven.resolver</groupId>
                <artifactId>maven-resolver-util</artifactId>
                <!-- version 2.0.21 appears to brake build -->
                <version>2.0.21</version>
            </dependency>
            <dependency>
                <groupId>org.apache.maven.resolver</groupId>
                <artifactId>maven-resolver-api</artifactId>
                <!-- version 2.0.21 appears to brake build -->
                <version>2.0.21</version>
            </dependency>
            <dependency>
                <groupId>org.apache.maven.shared</groupId>
                <artifactId>maven-shared-utils</artifactId>
                <version>3.4.2</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-component-annotations</artifactId>
                <version>2.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-utils</artifactId>
                <version>4.0.3</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-classworlds</artifactId>
                <version>2.12.0</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.sisu</groupId>
                <artifactId>org.eclipse.sisu.inject</artifactId>
                <version>1.1.0</version>
            </dependency>
            <dependency>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
                <version>7.6.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- mockserver -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>mockserver-netty</artifactId>
            <version>${project.version}</version>
            <classifier>jar-with-dependencies</classifier>
            <scope>compile</scope>
        </dependency>

        <!-- maven plugin -->
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.google.inject</groupId>
                    <artifactId>guice</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-model</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-settings</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-settings-builder</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-repository-metadata</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-model-builder</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-artifact</artifactId>
            <version>${maven-plugin.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.shared</groupId>
            <artifactId>maven-artifact-transfer</artifactId>
            <version>0.13.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-model</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-settings</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-settings-builder</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-repository-metadata</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-plugin-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-model-builder</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.maven</groupId>
                    <artifactId>maven-artifact</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.15.2</version>
            <scope>provided</scope>
        </dependency>

        <!-- test -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>mockserver-integration-testing</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>kill_mockserver_instances</id>
            <activation>
                <file>
                    <exists>/usr/bin/env</exists>
                </file>
            </activation>

            <build>
                <plugins>
                    <!-- ensure no existing mock server instances running -->
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>3.6.3</version>
                        <inherited>false</inherited>
                        <configuration>
                            <workingDirectory>${basedir}</workingDirectory>
                        </configuration>
                        <executions>
                            <execution>
                                <id>kill_mockserver_instances</id>
                                <phase>clean</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <!-- single canonical copy at the repo root (basedir is this module dir) -->
                                    <executable>../../scripts/stop_MockServer.sh</executable>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <!-- clean up additional artifacts not generated by this build -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.5.0</version>
                <configuration>
                    <verbose>true</verbose>
                    <filesets>
                        <fileset>
                            <directory>src/integration-tests/mockserver-initializer-main-classpath/target</directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-initializer-test-classpath/target</directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-run-from-command-line/target</directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-run-stop-forked-from-command-line/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-start-using-plugin-stops-using-listener/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>
                                src/integration-tests/mockserver-start-using-plugin-stops-using-listener-and-plugin/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-starts-stops-forked-server-from-pom/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-starts-stops-server-from-pom-explicitly/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/proxy-run-from-command-line/target</directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/proxy-run-stop-forked-from-command-line/target</directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/mockserver-start-using-plugin-stop-using-listener/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/proxy-starts-stops-forked-server-from-pom/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/proxy-starts-stops-server-from-pom-explicitly/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/proxy-starts-using-plugins-stops-using-listener/target
                            </directory>
                        </fileset>
                        <fileset>
                            <directory>src/integration-tests/skip/target</directory>
                        </fileset>
                        <fileset>
                            <directory>${basedir}</directory>
                            <includes>
                                <include>**/*.log</include>
                                <include>**/keystore.jks</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <!-- generate plugin documentation -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.15.2</version>
                <configuration>
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>descriptor</goal>
                            <!-- 'report' goal moved to maven-plugin-report-plugin in
                                 maven-plugin-plugin 3.15+; the project does not run
                                 'mvn site' so the report output is unused — drop it. -->
                            <goal>addPluginArtifactMetadata</goal>
                            <goal>helpmojo</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- plugin integration tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-invoker-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <skipInvocation>${skipTests}</skipInvocation>
                    <debug>false</debug>
                    <!-- only stream the invoked child Maven build log on
                         failure (invoker 3.3+) — passing builds stay quiet so
                         the CI log is not flooded with per-invoker child output. -->
                    <streamLogs>false</streamLogs>
                    <streamLogsOnFailures>true</streamLogsOnFailures>
                    <showErrors>false</showErrors>
                    <showVersion>true</showVersion>
                    <disableReports>true</disableReports>
                    <parallelThreads>${maven-invoker-parallel-threads}</parallelThreads>
                    <projectsDirectory>${basedir}/src/integration-tests/</projectsDirectory>
                    <cloneProjectsTo>${project.build.directory}/integration-tests/</cloneProjectsTo>
                    <reportsDirectory>${project.build.directory}</reportsDirectory>
                    <cloneClean>true</cloneClean>
                    <ignoreFailures>false</ignoreFailures>
                    <addTestClassPath>true</addTestClassPath>
                    <properties>
                        <property>
                            <name>mockserver.version</name>
                            <value>${project.version}</value>
                        </property>
                    </properties>
                    <environmentVariables>
                        <mockserver.logLevel>DEBUG</mockserver.logLevel>
                    </environmentVariables>
                    <filterProperties>
                        <mockserver.version>${project.version}</mockserver.version>
                    </filterProperties>
                    <settingsFile>src/integration-tests/settings.xml</settingsFile>
                    <!--<mavenOpts>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005</mavenOpts>-->
                    <pomIncludes>
                        <pomInclude>**/pom.xml</pomInclude>
                        <!--<pomInclude>mockserver-run-stop-forked-from-pom/pom.xml</pomInclude>-->
                    </pomIncludes>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>install</goal>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
