<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://www.w3.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.lucee</groupId>
    <artifactId>mssql-jdbc-extension</artifactId>
    <version>13.2.1</version>
    <packaging>pom</packaging>
    <name>MSSQL JDBC</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <id>99A4EF8D-F2FD-40C8-8FB8C2E67A4EEEB6</id>
        <luceeCoreVersion>5.3.2.63-SNAPSHOT</luceeCoreVersion>
        <connstr>jdbc:sqlserver://{host}:{port}</connstr>
        <jdbcid>mssql</jdbcid>
        <label>Microsoft SQL Server (Vendor Microsoft)</label>
        <releaseType>server</releaseType>
        <release.url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</release.url>
        <snapshot.url>https://oss.sonatype.org/content/repositories/snapshots/</snapshot.url>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjdk.nashorn</groupId>
            <artifactId>nashorn-core</artifactId>
            <version>15.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.lucee</groupId>
            <artifactId>mssql</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <scm>
        <url>https://github.com/lucee/extension-jdbc-mssql</url>
        <connection>scm:git:git://github.com/lucee/extension-jdbc-mssql.git</connection>
        <developerConnection>scm:git:git@github.com:lucee/extension-jdbc-mssql.git</developerConnection>
        <tag>${project.version}</tag>
    </scm>

    <licenses>
        <license>
            <name>The GNU Lesser General Public License, Version 2.1</name>
            <url>http://www.gnu.org/licenses/lgpl-2.1.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>micstriit</id>
            <name>Michael Offner</name>
            <email>michael@lucee.org</email>
            <organization>Lucee Association Switzerland</organization>
            <organizationUrl>http://lucee.org</organizationUrl>
            <roles>
                <role>Project-Administrator</role>
                <role>Developer</role>
            </roles>
            <timezone>+1</timezone>
        </developer>
    </developers>

    <description>JDBC Driver from Microsoft for SQL Server, SQL Server is a relational database management system developed by Microsoft.</description>
    <url>https://github.com/lucee/extension-jdbc-mssql</url>

    <profiles>
        <profile>
            <id>release-sign-artifacts</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <!-- GPG sign -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <files>
                                        <file>${project.build.directory}/${project.artifactId}-${project.version}.lex</file>
                                    </files>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-release-plugin</artifactId>
                      <version>3.0.0</version>
                      <configuration>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <useReleaseProfile>false</useReleaseProfile>
                        <releaseProfiles>release</releaseProfiles>
                        <goals>deploy</goals>
                      </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>copy-mssql-jar</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>org.lucee</includeGroupIds>
                            <includeArtifactIds>mssql</includeArtifactIds>
                            <includeVersion>${project.version}</includeVersion> 
                            <outputDirectory>${project.basedir}</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Antrun plugin to execute the Ant build -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.0.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.openjdk.nashorn</groupId>
                        <artifactId>nashorn-core</artifactId>
                        <version>15.4</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <ant antfile="build.xml" target="clean">
                                    <property name="id" value="${id}"/>
                                    <property name="label" value="${label}"/>
                                    <property name="description" value="${project.description}"/>
                                    <property name="filename" value="${project.artifactId}"/>
                                    <property name="jdbcid" value="${jdbcid}"/>
                                    <property name="connstr" value="${connstr}"/>
                                </ant>
                                
                                <!-- Clean up the copied MSSQL JAR after ant build -->
                                <delete>
                                    <fileset dir="${project.basedir}">
                                        <include name="mssql-*.jar"/>
                                    </fileset>
                                </delete>

                                <condition property="isSnapshot" value="true" else="false">
                                    <matches string="${project.version}" pattern=".*-SNAPSHOT"/>
                                </condition>
                                <condition property="deploy.url" value="${snapshot.url}">
                                    <istrue value="${isSnapshot}"/>
                                </condition>
                                <condition property="deploy.url" value="${release.url}">
                                    <isfalse value="${isSnapshot}"/>
                                </condition>
                                <echo message="Deploying to URL: ${deploy.url}" />
                            </target>
                            <exportAntProperties>true</exportAntProperties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

           

            <!-- Build Helper Plugin to attach additional artifacts -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-${project.version}.lex</file>
                                    <type>lex</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Clean plugin to remove extra folders -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>cleanup</id>
                        <phase>post-package</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>${project.build.directory}/antrun</directory>
                                    <includes>
                                        <include>**/*</include>
                                    </includes>
                                </fileset>
                                <fileset>
                                    <directory>${project.build.directory}/archive-tmp</directory>
                                    <includes>
                                        <include>**/*</include>
                                    </includes>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Maven Deploy Plugin to deploy the .lex file -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>3.0.0-M1</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <file>${project.build.directory}/${project.artifactId}-${project.version}.lex</file>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>${project.artifactId}</artifactId>
                            <version>${project.version}</version>
                            <repositoryId>ossrh</repositoryId>
                            <url>${deploy.url}</url>
                            <packaging>lex</packaging>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Nexus Staging Maven Plugin to automate the release process -->
            <plugin>
              <groupId>org.sonatype.central</groupId>
              <artifactId>central-publishing-maven-plugin</artifactId>
              <version>0.8.0</version>
              <extensions>true</extensions>
              <configuration>
                <publishingServerId>ossrh</publishingServerId>
                <autoPublish>true</autoPublish>
              </configuration>
            </plugin>
        </plugins>
    </build>
</project>
