<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.cibseven.webapp</groupId>
		<artifactId>cibseven-webclient</artifactId>
		<version>3.0.0</version>
	</parent>
	<artifactId>cibseven-webclient-web</artifactId>
	<packaging>war</packaging>
	<name>CIB seven webclient web</name>
	<description>Web application module for the CIB seven webclient platform (Spring Boot 4.x).</description>

	<properties>
		<!-- jacoco:check floors; measured 32.0% line / 0.0% branch. See the root pom for the rules. -->
		<jacoco.line.coverage.floor>0.30</jacoco.line.coverage.floor>
		<jacoco.branch.coverage.floor>0.00</jacoco.branch.coverage.floor>
	</properties>

	<dependencies>

		<dependency>
			<groupId>org.cibseven.webapp</groupId>
			<artifactId>cibseven-webclient-core</artifactId>
			<version>${project.version}</version>
		</dependency>

		<!--
			Spring Boot 4 renamed spring-boot-starter-web to spring-boot-starter-webmvc.
			Also pulls in tools.jackson (Jackson 3) for the wire layer.
		-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-webmvc</artifactId>
		</dependency>
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>

		<!-- New in SB4: replaces RestTemplate idiom -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-restclient</artifactId>
		</dependency>

		<!--
			The webclient reads and writes JSON with Jackson 3 (tools.jackson.*), see SevenWebclientContext.
			Jackson 2 still reaches the war through springdoc (swagger-core, YAML); nothing of the
			webclient's own JSON goes through it.
		-->
		<dependency>
			<groupId>tools.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
			<version>${version.openapi-starter-webmvc-ui}</version>
			<exclusions>
				<exclusion>
					<groupId>org.apache.commons</groupId>
        			<artifactId>commons-lang3</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!--
			Declared directly, not only in the root pom's dependencyManagement, so the patched
			swagger-ui (${version.swagger-ui}) also reaches consumers of this module's classes jar,
			such as the Spring Boot starter and the Run distro in cibseven. A dependencyManagement
			entry doesn't apply there, so they would otherwise get springdoc's own swagger-ui
			(5.32.11 with springdoc 3.1.0, which bundles a vulnerable DOMPurify).
		-->
		<dependency>
			<groupId>org.webjars</groupId>
			<artifactId>swagger-ui</artifactId>
			<version>${version.swagger-ui}</version>
		</dependency>
		
		<!-- Override common transitive dependencies to ensure consistent versions -->
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-lang3</artifactId>
			<version>${version.commons-lang3}</version>
		</dependency>

		<!-- Without this, any controller method with parameters annotated with some jakarta.validation.* annotations, 
		such as jakarta.validation.constraints.NotNull, throws the described exception. 
		The exception is thrown by Spring and the method is not even called at all. -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>

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

		<!-- The JPA wiring of the modeler lives in this module, so it is tested here. JPA itself and
		     the H2 driver already come from cibseven-webclient-core; re-declaring them here would
		     narrow their scope to test and drop them from the war. -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>com.tngtech.archunit</groupId>
			<artifactId>archunit-junit5</artifactId>
			<version>${version.archunit}</version>
			<scope>test</scope>
		</dependency>

	</dependencies>

	<build>
		<finalName>webapp</finalName>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>false</filtering>
				<includes>
					<include>*.jpg</include>
					<include>*.txt</include>
					<!-- <include>*.xml</include> -->
					<include>*.txt</include>
					<include>**/*.scss</include>
					<include>META-INF/**</include>
				</includes>
			</resource>
		</resources>

		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<executions>
					<execution>
						<id>create-jar</id>
						<goals>
							<goal>jar</goal>
						</goals>
						<phase>package</phase>
						<configuration>
							<classifier>classes</classifier>
							<excludes>
							    <!-- Do not pack the public/ folder into the classes jar, as that causes trouble when embedding the engine. -->
								<exclude>public/**</exclude>
							</excludes>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- Clean webapp folder to have a clean copy of resources in the root of WAR (copy-frontend-resources) -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>clean-webapp-folder</id>
						<phase>validate</phase>
						<goals>
							<goal>run</goal>
						</goals>
						<configuration>
							<target>
								<delete includeemptydirs="true">
									<fileset dir="${project.basedir}/src/main/webapp">
										<exclude name="README.md"/>
									</fileset>
								</delete>
							</target>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- Index.html contain projectVersion variable which needs to be
			replace by the current version of the project -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>${maven-resources-plugin.version}</version>
				<executions>
					<execution>
						<id>replace-data-banner</id>
						<phase>validate</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<overwrite>true</overwrite>
							<outputDirectory>
								${project.basedir}/src/main/resources</outputDirectory>
							<resources>
								<resource>
									<directory>${project.parent.basedir}/banner</directory>
									<filtering>true</filtering>
									<includes>
										<include>banner.txt</include>
									</includes>
									<targetPath>.</targetPath>
								</resource>
							</resources>
						</configuration>
					</execution>
					<!-- Add new execution for frontend resources to project root -->
					<execution>
						<id>copy-frontend-resources</id>
						<phase>validate</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<!-- This puts content at the root of the WAR -->
							<outputDirectory>src/main/webapp</outputDirectory>
							<resources>
								<resource>
									<directory>../frontend/dist</directory>
									<includes>
										<include>**/*</include>
									</includes>
									<targetPath>.</targetPath>
								</resource>
							</resources>
						</configuration>
					</execution>
					<execution>
						<id>copy-cibseven-webclient-npm-resources</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.build.directory}/classes/public</outputDirectory>
							<overwrite>true</overwrite>
							<resources>
								<resource>
									<directory>
										${project.parent.basedir}/frontend/dist</directory>
									<includes>
										<include>**/*</include>
									</includes>
									<targetPath>.</targetPath>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<warSourceExcludes>**/README.md</warSourceExcludes>
				</configuration>
			</plugin>

			<plugin>
				<groupId>io.github.git-commit-id</groupId>
				<artifactId>git-commit-id-maven-plugin</artifactId>
				<version>${git-commit-id-maven-plugin.version}</version>
				<configuration>
					<skip>false</skip>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<version>${version.spring.boot}</version>
				<configuration>
					<mainClass>org.cibseven.webapp.SevenWebclientApplication</mainClass>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
							<!-- Build info for actuator info endpoint-->
							<goal>build-info</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>com.google.cloud.tools</groupId>
				<artifactId>jib-maven-plugin</artifactId>
				<configuration>
					<skip>false</skip>
					<container>
						<appRoot>/usr/local/tomcat/webapps/seven</appRoot>
					</container>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<executions>
					<execution>
						<id>wildfly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
						<configuration>
							<descriptors>
								<descriptor>assembly-war-wildfly.xml</descriptor>
							</descriptors>
							<attach>true</attach>
							<outputDirectory>target/</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>

	</build>
</project>
