<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>hibernate-extension</artifactId>
    <version>5.6.15.15-RC</version>
    <packaging>jar</packaging>
    <name>Hibernate Extension</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
        <build.timestamp>${maven.build.timestamp}</build.timestamp>
        <bundlename>org.lucee.hibernate.extension</bundlename>
        <release.url>https://central.sonatype.com/api/v1/publisher/deployments/download/</release.url>
        <snapshot.url>https://central.sonatype.com/repository/maven-snapshots/</snapshot.url>
    </properties>

    <scm>
        <url>https://github.com/lucee/extension-hibernate</url>
        <connection>scm:git:git://github.com/lucee/extension-hibernate.git</connection>
        <developerConnection>scm:git:git@github.com:lucee/extension-hibernate.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>Hibernate ORM (Hibernate in short) is an object-relational mapping library for the Java language,
 providing a framework for mapping an object-oriented domain model to a traditional relational database.
 Hibernate solves object-relational impedance mismatch problems by replacing direct persistence-related
 database accesses with high-level object handling functions.</description>
    <url>https://github.com/lucee/extension-hibernate</url>

    <!-- ============================== Dependencies ============================== -->

    <dependencies>
        <!-- Lucee (provided — not bundled) -->
        <dependency>
            <groupId>org.lucee</groupId>
            <artifactId>lucee</artifactId>
            <version>5.4.6.9</version>
            <scope>provided</scope>
        </dependency>

        <!-- Hibernate core (pulls antlr, dom4j, hibernate-commons-annotations transitively) -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.6.15.Final</version>
            <exclusions>
                <!-- Use simple JTA, not JBoss spec (needs javax.interceptor) -->
                <exclusion>
                    <groupId>org.jboss.spec.javax.transaction</groupId>
                    <artifactId>jboss-transaction-api_1.2_spec</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Simple JTA (no javax.interceptor dependency) -->
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- Hibernate EHCache integration -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>5.6.15.Final</version>
            <exclusions>
                <exclusion>
                    <groupId>net.sf.ehcache</groupId>
                    <artifactId>ehcache</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- EHCache (Lucee repackaged — specific package structure required) -->
        <dependency>
            <groupId>net.sf.ehcache.internal</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.10.9.2</version>
        </dependency>

        <!-- SLF4J API (Hibernate depends on it) -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.36</version>
        </dependency>

        <!-- Bean Validation API (Hibernate 5.6's TypeSafeActivator has hard javax.validation
             imports — Lucee 7+ exposes jakarta.validation via boot delegation, Hibernate
             thinks BV is available, then fails loading the javax classes) -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>

        <!-- JAXB (needed for Hibernate XML mapping) -->
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.9</version>
        </dependency>
    </dependencies>

    <!-- ============================== Repositories ============================== -->

    <repositories>
        <repository>
            <id>terracotta</id>
            <url>https://repo.terracotta.org/maven2/</url>
        </repository>
        <repository>
            <id>sonatype-central-snapshots</id>
            <name>Sonatype Central Snapshots</name>
            <url>https://central.sonatype.com/repository/maven-snapshots</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

    <!-- ============================== Build ============================== -->

    <build>
        <sourceDirectory>source/java/src</sourceDirectory>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <targetPath>${project.build.directory}/extension-resources</targetPath>
            </resource>
            <!-- Include META-INF/services in the compiled jar -->
            <resource>
                <directory>source/java/src</directory>
                <includes>
                    <include>META-INF/services/*</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <!-- 1. Read build.properties -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>read-project-properties</goal>
                        </goals>
                        <configuration>
                            <files>
                                <file>${project.basedir}/build.properties</file>
                            </files>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 2. Compile -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
            </plugin>

            <!-- 3. Rename manifest, copy FLD -->
            <plugin>
                <groupId>com.coderplus.maven.plugins</groupId>
                <artifactId>copy-rename-maven-plugin</artifactId>
                <version>1.0.1</version>
                <executions>
                    <execution>
                        <id>rename-manifest</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>rename</goal>
                        </goals>
                        <configuration>
                            <sourceFile>${project.build.directory}/extension-resources/extension-manifest.txt</sourceFile>
                            <destinationFile>${project.build.directory}/extension-resources/META-INF/MANIFEST.MF</destinationFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-fld</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <sourceFile>${project.basedir}/source/fld/ormFunctions.fld</sourceFile>
                            <destinationFile>${project.build.directory}/extension-resources/flds/ormFunctions.fld</destinationFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>rename-lex</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>rename</goal>
                        </goals>
                        <configuration>
                            <sourceFile>${project.build.directory}/${project.artifactId}-${project.version}.zip</sourceFile>
                            <destinationFile>${project.build.directory}/${project.artifactId}-${project.version}.lex</destinationFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 4. Create extension jar with OSGi manifest -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.4.2</version>
                <configuration>
                    <archive>
                        <manifestFile>source/java/src/META-INF/MANIFEST.MF</manifestFile>
                        <manifestEntries>
                            <Bundle-SymbolicName>${bundlename}</Bundle-SymbolicName>
                            <Bundle-Version>${project.version}</Bundle-Version>
                            <Built-Date>${build.timestamp}</Built-Date>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <!-- 5. Shade ALL deps into one fat jar (same approach as Ortus) -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Bundle-SymbolicName>${bundlename}</Bundle-SymbolicName>
                                        <Bundle-Version>${project.version}</Bundle-Version>
                                        <Built-Date>${build.timestamp}</Built-Date>
                                        <!-- Required: Hibernate's Version.getVersionString() reads this at runtime.
                                             Without it, the shaded jar reports [WORKING] instead of the real version. -->
                                        <Implementation-Version>5.6.15.Final</Implementation-Version>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                            <!-- Relocate ehcache classes to a private namespace so they never
                                 conflict with the ehcache Lucee extension's OSGi-exported copy.
                                 Without this, both bundles have net.sf.ehcache.* classes loaded by
                                 different BundleClassLoaders → ClassCastException. -->
                            <relocations>
                                <relocation>
                                    <pattern>net.sf.ehcache</pattern>
                                    <shadedPattern>org.lucee.extension.orm.hibernate.shaded.net.sf.ehcache</shadedPattern>
                                </relocation>
                            </relocations>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 6. Copy fat jar to target/jars/ with bundle name -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>copy-extension-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}/jars"/>
                                <copy file="${project.build.directory}/${project.artifactId}-${project.version}.jar"
                                      tofile="${project.build.directory}/jars/${bundlename}-${project.version}.jar"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 6. Assemble .lex -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.7.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/lex.xml</descriptor>
                    </descriptors>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                    <attach>false</attach>
                </configuration>
            </plugin>

            <!-- 7. Attach .lex as artifact -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>attach-lex</id>
                        <phase>verify</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>

            <!-- Central Publishing -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.10.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>ossrh</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- ============================== Profiles ============================== -->

    <profiles>
        <profile>
            <id>release-sign-artifacts</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <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>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
