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

	<parent>
		<groupId>org.squashtest.tm.plugin</groupId>
		<artifactId>api.rest</artifactId>
		<version>15.0.0-springboot4.IT1</version>
	</parent>

	<name>squash-rest-api-services</name>
	<artifactId>api.rest.services</artifactId>
	<packaging>jar</packaging>

	<description>The actual services exposed by the API</description>


	<dependencies>

		<!-- squash dependencies -->
		<dependency>
			<groupId>org.squashtest.tm</groupId>
			<artifactId>tm.domain</artifactId>
		</dependency>

		<dependency>
			<groupId>org.squashtest.tm</groupId>
			<artifactId>tm.service</artifactId>
		</dependency>

    <dependency>
      <groupId>org.squashtest.tm</groupId>
      <artifactId>core.archunit</artifactId>
    </dependency>

		<dependency>
			<groupId>org.squashtest.tm.plugin</groupId>
			<artifactId>api.rest.core</artifactId>
			<version>${project.version}</version>
		</dependency>

		<!-- /squash dependencies -->

		<!-- support dependencies -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-hateoas</artifactId>
			<scope>provided</scope>
		</dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-webmvc-test</artifactId>
      <scope>provided</scope>
    </dependency>
		<!-- /support dependencies -->


		<!-- test dependencies -->
		<dependency>
			<groupId>org.squashtest.tm.plugin</groupId>
			<artifactId>domainbuilder</artifactId>
			<version>${project.version}</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.squashtest.tm</groupId>
			<artifactId>spock-test-dependencies</artifactId>
			<type>pom</type>
		</dependency>

		<dependency>
			<groupId>org.springframework.restdocs</groupId>
			<artifactId>spring-restdocs-mockmvc</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.spockframework</groupId>
			<artifactId>spock-junit4</artifactId>
			<version>${spock-junit.version}</version>
			<scope>test</scope>
		</dependency>


		<dependency>
			<groupId>jakarta.xml.bind</groupId>
			<artifactId>jakarta.xml.bind-api</artifactId>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>org.squashtest.tm</groupId>
			<artifactId>tm.web</artifactId>
			<scope>test</scope>
			<classifier>classes</classifier>
		</dependency>

		<dependency>
			<groupId>tools.jackson.datatype</groupId>
			<artifactId>jackson-datatype-hibernate7</artifactId>
			<scope>test</scope>
		</dependency>

		<!-- /test dependencies -->

	</dependencies>


	<!--
		The main build :
			- do the default stuff at their default phases (compile, test-compile, package)
			- run the unit tests
			- generates the documentation

		The integration tests are not part of the default build because they are time consuming.
		This choice has consequences (see the note on documentation).

		The documentation is generated at phase 'prepare-package', right before the jar is created.
		However, since most of it is generated by spring-restdocs, it remains half-built unless the
		integration tests are run (see profile 'integration-tests').
	-->
	<build>
		<plugins>
			<!-- ================ setup ================== -->

			<!--
				create a new variable with the project version, that knows only the major.minor.micro version
			 	(ommitting the RELEASE/RC/SNAPSHOT qualifier
			 -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>${build-helper-maven-plugin.version}</version>
				<executions>
					<execution>
						<id>regex-property</id>
						<goals>
							<goal>regex-property</goal>
						</goals>
						<configuration>
							<name>api.version</name>
							<value>${project.version}</value>
							<regex>^([0-9]+)\.([0-9]+)\.([0-9]+).*$</regex>
							<replacement>$1.$2.$3</replacement>
							<failIfNoMatch>true</failIfNoMatch>
						</configuration>
					</execution>
				</executions>
			</plugin>


			<!-- =================== Unit tests ================== -->

			<!-- run the unit tests. For integration tests, see profile 'integration-tests' -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>${maven-failsafe-surefire-plugin.version}</version>
			</plugin>

			<!-- =================== /Unit Tests ================== -->

			<!-- =================== Documentation ================== -->

			<!-- copy and filter the documentation with the version number generated above -->
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<executions>
					<execution>
						<id>filter-documentation</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${asciidoc.filtered-directory}</outputDirectory>
							<resources>
								<resource>
									<include>*.adoc</include>
									<directory>src/main/asciidoc</directory>
									<filtering>true</filtering>
								</resource>
								<resource>
									<exclude>*.adoc</exclude>
									<directory>src/main/asciidoc</directory>
									<filtering>false</filtering>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>


			<!-- generate the documentation documentation -->
			<plugin>
				<groupId>org.asciidoctor</groupId>
				<artifactId>asciidoctor-maven-plugin</artifactId>
				<version>${asciidoc.version}</version>
				<executions>
					<execution>
						<id>generate-docs</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>process-asciidoc</goal>
						</goals>
						<configuration>
							<backend>html</backend>
							<doctype>book</doctype>
							<sourceDirectory>${asciidoc.filtered-directory}</sourceDirectory>
							<attributes>
								<snippets>${project.build.directory}/generated-snippets</snippets>
							</attributes>
						</configuration>
					</execution>
				</executions>
				<dependencies>
					<dependency>
						<groupId>org.springframework.restdocs</groupId>
						<artifactId>spring-restdocs-asciidoctor</artifactId>
						<version>${spring-asciidoc.version}</version>
					</dependency>
				</dependencies>
			</plugin>

			<!-- package the documentation -->
			<!--
				Postponed the packaging of the documentation because it would trigger before it was generated.
				It seems that, when building the whole project (as a multimodule project), maven regroups executions of
				'filter-documentation' and 'package-documentation' together because both are executions of maven-resources-plugin,
				thus generate-docs arrives too late
			-->
			<plugin>
				<artifactId>maven-resources-plugin</artifactId>
				<version>${maven-resources-plugin.version}</version>
				<executions>
					<execution>
						<id>package-documentation</id>
						<phase>package</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<!--
                                The doc will be served as a static content. In effect
                                the url where it will be found is /api/rest/latest/docs/api-documentation.html :
                                the root path '/static' will be implicitly appended by
                                one of the native Squash resource resolver.
                            -->
							<outputDirectory>${asciidoc.packaging.jar-path}</outputDirectory>
							<resources>
								<resource>
									<directory>
										${project.build.directory}/generated-docs
									</directory>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- =================== /Documentation ================== -->

			<!-- ================== Creating the jar ================= -->

			<!--
				Postponed the jar to pre-integration-test to make sure the documentation is
				ready before creating the jar (see comments on 'package-documentation')
			-->

			<plugin>
				<artifactId>maven-jar-plugin</artifactId>
				<version>${maven-jar-plugin.version}</version>

				<configuration>
					<!--
						It turns out that maven-jar-plugin already runs as part of the main build,
						under the id 'default-jar'. Here we ask it to run again. Under normal
						circumstances it would run because it should detects that the target/classes
						has been modified (see package-documentation above).

						Problem is, on some systems (like our CI server for instance) the mojo
						doesn't detect the change and thus skips the jar. Hence the force flag below.

						Note : the alternate solution would be to abort the default execution of maven-jar-plugin,
						 but this solution is simpler and does not involve significant penalty.
                    -->
					<forceCreation>true</forceCreation>
				</configuration>

				<executions>
					<execution>
						<id>default-jar</id>
						<phase>none</phase>
						<configuration>
							<finalName>unwanted</finalName>
							<classifier>unwanted</classifier>
						</configuration>
					</execution>
					<execution>
						<id>pre-integration-test-jar</id>
						<phase>pre-integration-test</phase>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

		</plugins>
	</build>


	<profiles>

		<!--
			Profile : integration-tests. We made the IT run in a profile to make them optional. This eases
			the life of the developper (ITs are time consuming), but be careful to enable them in your IT server.

			Since the integration tests are essential in the creation of the documentation, we have to schedule the ITs
			at the same time than the regular unit tests to make sure the doc will be available for the package phase.

			Note that creating a distribution using the profile 'distro', defined in the umbrella module, enforces
			the usage of this profile.
		-->
		<profile>
			<id>integration-tests</id>
			<activation>
				<activeByDefault>false</activeByDefault>
			</activation>

			<build>

				<!-- ============== ITs ===================== -->

				<!--
					copy IT tests sources into the test directory
					(maven wont see them otherwise)
				-->
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>build-helper-maven-plugin</artifactId>
						<executions>
							<!-- Adds more source directories to the pom -->
							<execution>
								<id>add-integration-test-source</id>
								<goals>
									<goal>add-test-source</goal>
								</goals>
								<phase>generate-test-sources</phase>
								<configuration>
									<sources>
										<source>src/it/groovy</source>
									</sources>
								</configuration>
							</execution>

							<execution>
								<id>add-integration-test-resource</id>
								<goals>
									<goal>add-test-resource</goal>
								</goals>
								<phase>generate-test-resources</phase>
								<configuration>
									<resources>
										<resource>
											<directory>src/it/resources</directory>
										</resource>
									</resources>
								</configuration>
							</execution>
						</executions>
					</plugin>

					<!-- run -->
					<plugin>
						<!--<groupId>org.apache.maven.plugins</groupId>-->
						<!--<artifactId>maven-failsafe-plugin</artifactId>-->
						<!--<configuration>-->
							<!--&lt;!&ndash; We can run ITs and skip unit tests with -DskipTests=true &ndash;&gt;-->
							<!--<skipTests>${skipITs}</skipTests>-->
						<!--</configuration>-->
							<groupId>org.apache.maven.plugins</groupId>
							<artifactId>maven-failsafe-plugin</artifactId>

						<executions>
							<execution>
								<id>integration-tests</id>
								<goals>
									<goal>integration-test</goal>
									<goal>verify</goal>
								</goals>
								<phase>test</phase>
							</execution>
						</executions>
					</plugin>

					<!-- ============== /ITs ===================== -->

				</plugins>

			</build>
		</profile>

	</profiles>

</project>
