<?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>com.irurueta</groupId>
    <artifactId>irurueta-numerical</artifactId>
    <version>1.3.2</version>
    <packaging>jar</packaging>

    <name>${project.groupId}:${project.artifactId}</name>
    <description>Numerical utilities</description>
    <url>https://github.com/albertoirurueta/irurueta-numerical</url>
    <inceptionYear>2017</inceptionYear>
    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <name>Alberto Irurueta Carro</name>
            <email>alberto@irurueta.com</email>
            <organizationUrl>https://github.com/albertoirurueta</organizationUrl>
        </developer>
    </developers>
    <scm>
        <connection>scm:git@github.com:albertoirurueta/irurueta-numerical.git</connection>
        <developerConnection>scm:git@github.com:albertoirurueta/irurueta-numerical.git</developerConnection>
        <url>git@github.com:albertoirurueta/irurueta-numerical.git</url>
    </scm>

    <dependencies>
        <!-- dependencies for unit tests -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.13.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.irurueta</groupId>
            <artifactId>irurueta-statistics</artifactId>
            <version>1.3.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.irurueta</groupId>
            <artifactId>irurueta-sorting</artifactId>
            <version>1.3.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.irurueta</groupId>
            <artifactId>irurueta-algebra</artifactId>
            <version>1.3.2</version>
            <scope>compile</scope>
        </dependency>        
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <github.global.server>github</github.global.server>
        <github.global.oauth2Token>${env.GITHUB_OAUTH_TOKEN}</github.global.oauth2Token>
    </properties>

    <profiles>
        <profile>
            <id>sign</id>
            <build>
                <plugins>
                    <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>
                </plugins>
            </build>
        </profile>        
        <profile>
            <id>extras</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.3.1</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.11.3</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>                    
                </plugins>
            </build>
        </profile>        
    </profiles>
    
    <!-- default profile -->
    <build>
        <plugins>
            <!-- unit tests plugins -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.5.4</version>
            </plugin>                 
            <!-- code coverage plugin -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.13</version>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>    
            <!-- code quality plugins -->
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.9.6.0</version>
            </plugin>
            <!-- maven site -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.21.0</version>
            </plugin>
            <!-- save build info into generated package -->
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <version>2.1.1</version>
                    <executions>
                        <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <source>
                                <![CDATA[
                                    import java.util.Date
                                    import java.util.Properties
                                    import java.text.SimpleDateFormat
                                    import java.io.File
                                    import java.io.FileWriter
                                    
                                    println("Saving build info...")
                                    def dateFormatter = new SimpleDateFormat("yy-MM-dd HH:mm:ss")
                                    def buildTimestamp = dateFormatter.format(new Date())
                                    
                                    String groupId = "${project.groupId}"
                                    String artifactId = "${project.artifactId}"
                                    String version = "${project.version}"
                                    
                                    //JENKINS
                                    def buildNumber = System.getenv("BUILD_NUMBER")
                                    def commit = System.getenv("GIT_COMMIT")
                                    def branch = System.getenv("GIT_BRANCH")
                                    
                                    //TRAVIS CI
                                    if (buildNumber == null) {
                                        buildNumber = System.getenv("TRAVIS_BUILD_NUMBER")
                                    }
                                    if (commit == null) {
                                        commit = System.getenv("TRAVIS_COMMIT")
                                    }
                                    if (branch == null) {
                                        branch = System.getenv("TRAVIS_BRANCH")
                                    }

                                    //GITLAB
                                    if (buildNumber == null) {
                                        buildNumber = System.getenv("CI_JOB_ID")
                                    }
                                    if (commit == null) {
                                        commit = System.getenv("CI_COMMIT_SHA")
                                    }
                                    if (branch == null) {
                                        branch = System.getenv("CI_COMMIT_REF_NAME")
                                    }
                                    
                                    def props = new Properties()
                                    props.setProperty("BUILD_TIMESTAMP", buildTimestamp)
                                    props.setProperty("GROUP_ID", groupId)
                                    props.setProperty("ARTIFACT_ID", artifactId)
                                    props.setProperty("VERSION", version)
                                    if (buildNumber != null) {
                                        props.setProperty("BUILD_NUMBER", buildNumber)
                                    }
                                    if (commit != null) {
                                        props.setProperty("COMMIT", commit)
                                    }
                                    if (branch != null) {
                                        props.setProperty("BRANCH", branch)
                                    }
                                    
                                    File dir = new File("src/main/resources/com/irurueta/numerical")
                                    dir.mkdirs()
                                    File file = new File(dir, "build-info.properties")
                                    FileWriter writer = new FileWriter(file)
                                    props.store(writer, null)
                                    writer.close()
                                    println("Build info saved at " + file)
                                ]]>
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- deploys artifact to snapshots repository -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.8.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
        </plugins>
    </build>
   
    <reporting>
        <plugins>
            <!-- add javadoc report into site -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.11.3</version>
                <configuration>
                    <show>private</show>
                    <nohelp>true</nohelp>
                    <detectJavaApiLink>true</detectJavaApiLink>
                </configuration>
            </plugin>
            <!-- adds unit tests report into site -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>3.5.4</version>
            </plugin> 
            <!-- adds code coverage report into site -->  
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.13</version>
            </plugin>     
            <!-- adds code quality reports into site -->               
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                </configuration>                
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>checkstyle</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>

            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>4.9.6.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.27.0</version>
            </plugin>
            <!-- 
            adds cross-reference into source for easier navigation of source in
            reports 
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>3.6.0</version>
            </plugin>
        </plugins>
    </reporting>         
</project>