<?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>software.xdev</groupId>
	<artifactId>sessionize-java-client</artifactId>
	<version>1.2.1</version>
	<packaging>jar</packaging>

	<name>sessionize-java-client</name>
	<description>sessionize-java-client</description>
	<url>https://github.com/xdev-software/sessionize-java-client</url>

	<scm>
		<url>https://github.com/xdev-software/sessionize-java-client</url>
		<connection>https://github.com/xdev-software/sessionize-java-client.git</connection>
	</scm>

	<inceptionYear>2023</inceptionYear>

	<organization>
		<name>XDEV Software</name>
		<url>https://xdev.software</url>
	</organization>

	<developers>
		<developer>
			<name>XDEV Software</name>
			<organization>XDEV Software</organization>
			<url>https://xdev.software</url>
		</developer>
	</developers>

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

	<properties>
		<javaVersion>17</javaVersion>
		<maven.compiler.release>${javaVersion}</maven.compiler.release>

		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

		<generatedDirRelative>src/generated/java</generatedDirRelative>

		<!-- Ignore generated code -->
		<sonar.exclusions>
			src/generated/**
		</sonar.exclusions>
	</properties>

	<repositories>
		<!-- The order of definitions matters. Explicitly defining central here 
			to make sure it has the highest priority. -->
		<repository>
			<id>central</id>
			<url>https://repo.maven.apache.org/maven2</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>

	<pluginRepositories>
		<!-- The order of definitions matters. Explicitly defining central here 
			to make sure it has the highest priority. -->
		<pluginRepository>
			<id>central</id>
			<url>https://repo.maven.apache.org/maven2</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

	<distributionManagement>
		<snapshotRepository>
			<id>ossrh</id>
			<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
		</snapshotRepository>
		<repository>
			<id>ossrh</id>
			<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
		</repository>
	</distributionManagement>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>com.fasterxml.jackson</groupId>
				<artifactId>jackson-bom</artifactId>
				<version>2.16.1</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<!-- HTTP client: apache client -->
		<dependency>
			<groupId>org.apache.httpcomponents.client5</groupId>
			<artifactId>httpclient5</artifactId>
			<version>5.3</version>
		</dependency>

		<!-- JSON processing: jackson -->
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-annotations</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.datatype</groupId>
			<artifactId>jackson-datatype-jsr310</artifactId>
		</dependency>
		<dependency>
			<groupId>org.openapitools</groupId>
			<artifactId>jackson-databind-nullable</artifactId>
			<version>0.2.6</version>
		</dependency>

		<dependency>
			<groupId>jakarta.annotation</groupId>
			<artifactId>jakarta.annotation-api</artifactId>
			<version>2.1.1</version>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>com.mycila</groupId>
				<artifactId>license-maven-plugin</artifactId>
				<version>4.3</version>
				<configuration>
					<properties>
						<email>${project.organization.url}</email>
					</properties>
					<licenseSets>
						<licenseSet>
							<header>com/mycila/maven/plugin/license/templates/APACHE-2.txt</header>
							<includes>
								<include>src/main/java/**</include>
								<include>src/test/java/**</include>
							</includes>
						</licenseSet>
					</licenseSets>
				</configuration>
				<executions>
					<execution>
						<id>first</id>
						<goals>
							<goal>format</goal>
						</goals>
						<phase>process-sources</phase>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.12.1</version>
				<configuration>
					<release>${maven.compiler.release}</release>
					<compilerArgs>
						<arg>-proc:none</arg>
					</compilerArgs>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<version>3.6.3</version>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<phase>verify</phase>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<quiet>true</quiet>
					<doclint>none</doclint>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-source-plugin</artifactId>
				<version>3.3.0</version>
				<executions>
					<execution>
						<id>attach-sources</id>
						<phase>verify</phase>
						<goals>
							<goal>jar-no-fork</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>3.5.0</version>
				<executions>
					<execution>
						<phase>generate-sources</phase>
						<goals>
							<goal>add-source</goal>
						</goals>
						<configuration>
							<sources>
								<source>${generatedDirRelative}</source>
							</sources>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	<profiles>
		<profile>
			<id>ossrh</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-gpg-plugin</artifactId>
						<version>3.1.0</version>
						<executions>
							<execution>
								<id>sign-artifacts</id>
								<phase>verify</phase>
								<goals>
									<goal>sign</goal>
								</goals>
								<configuration>
									<!-- Fixes "gpg: signing failed: Inappropriate ioctl for device" -->
									<!-- Prevent `gpg` from using pinentry programs -->
									<gpgArguments>
										<arg>--pinentry-mode</arg>
										<arg>loopback</arg>
									</gpgArguments>
								</configuration>
							</execution>
						</executions>
					</plugin>
					
					<plugin>
						<groupId>org.sonatype.plugins</groupId>
						<artifactId>nexus-staging-maven-plugin</artifactId>
						<version>1.6.13</version>
						<extensions>true</extensions>
						<configuration>
							<serverId>ossrh</serverId>
							<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
							<!-- Sometimes OSSRH is really slow -->
							<stagingProgressTimeoutMinutes>30</stagingProgressTimeoutMinutes>
							<autoReleaseAfterClose>true</autoReleaseAfterClose>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>openapi-generator</id>
			<properties>
				<componentName>sessionize</componentName>

				<generatedDir>${project.basedir}/${generatedDirRelative}</generatedDir>
				<openApiRelativeGeneratorDir>src/gen</openApiRelativeGeneratorDir>
				<openApiGeneratorDir>
					${project.basedir}/target/generated-sources/openapi/${openApiRelativeGeneratorDir}
				</openApiGeneratorDir>
			</properties>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-clean-plugin</artifactId>
						<version>3.3.2</version>
						<executions>
							<execution>
								<id>pre-generation-clean</id>
								<phase>initialize</phase>
								<goals>
									<goal>clean</goal>
								</goals>
								<configuration>
									<excludeDefaultDirectories>true</excludeDefaultDirectories>
									<filesets>
										<fileset>
											<directory>${generatedDir}</directory>
										</fileset>
									</filesets>
								</configuration>
							</execution>
							<execution>
								<id>post-generation-clean</id>
								<phase>process-resources</phase>
								<goals>
									<goal>clean</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.openapitools</groupId>
						<artifactId>openapi-generator-maven-plugin</artifactId>
						<version>7.2.0</version>
						<executions>
							<execution>
								<goals>
									<goal>generate</goal>
								</goals>
								<configuration>
									<inputSpec>${project.basedir}/../openapi/openapi.yml</inputSpec>
									<generatorName>java</generatorName>
									<configOptions>
										<sourceFolder>${openApiRelativeGeneratorDir}</sourceFolder>
										<library>apache-httpclient</library>
										<apiPackage>software.xdev.${componentName}.api</apiPackage>
										<modelPackage>software.xdev.${componentName}.model</modelPackage>
										<invokerPackage>software.xdev.${componentName}.client</invokerPackage>
										<!-- Otherwise throw and catch everywhere -->
										<useRuntimeException>true</useRuntimeException>
										<!-- Some fields of API have been ignored because they are unused -->
										<disallowAdditionalPropertiesIfNotPresent>false
										</disallowAdditionalPropertiesIfNotPresent>
										<!-- Use newer Jakarta EE instead of Javax -->
										<useJakartaEe>true</useJakartaEe>
										<hideGenerationTimestamp>true</hideGenerationTimestamp>
										<!-- No tests and documentation because we don't use that -->
										<generateModelTests>false</generateModelTests>
										<generateApiTests>false</generateApiTests>
										<generateModelDocumentation>false</generateModelDocumentation>
										<generateApiDocumentation>false</generateApiDocumentation>
									</configOptions>
								</configuration>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-resources-plugin</artifactId>
						<version>3.3.1</version>
						<executions>
							<execution>
								<id>copy-generated-resources</id>
								<phase>process-sources</phase>
								<goals>
									<goal>copy-resources</goal>
								</goals>
								<configuration>
									<outputDirectory>${generatedDir}</outputDirectory>
									<resources>
										<resource>
											<directory>${openApiGeneratorDir}</directory>
										</resource>
									</resources>
								</configuration>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>io.github.floverfelt</groupId>
						<artifactId>find-and-replace-maven-plugin</artifactId>
						<version>1.1.0</version>
						<executions>
							<execution>
								<id>remove-unused-import-com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider</id>
								<phase>process-sources</phase>
								<goals>
									<goal>find-and-replace</goal>
								</goals>
								<configuration>
									<replacementType>file-contents</replacementType>
									<baseDir>${generatedDirRelative}/software/xdev/${componentName}/client/</baseDir>
									<fileMask>ApiClient.java</fileMask>
									<!-- @formatter:off DO NOT INTRODUCE LINE BREAK -->
									<findRegex>^(import com\.fasterxml\.jackson\.jaxrs\.json\.JacksonJsonProvider;)$</findRegex>
									<!-- Can't be removed as the plugin isn't supporting empty values -->
									<replaceValue>// $1</replaceValue>
									<!-- @formatter:on -->
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>checkstyle</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-checkstyle-plugin</artifactId>
						<version>3.3.1</version>
						<dependencies>
							<dependency>
								<groupId>com.puppycrawl.tools</groupId>
								<artifactId>checkstyle</artifactId>
								<version>10.12.7</version>
							</dependency>
						</dependencies>
						<configuration>
							<configLocation>../.config/checkstyle/checkstyle.xml</configLocation>
						</configuration>
						<executions>
							<execution>
								<goals>
									<goal>check</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>
</project>
