<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <!-- Parent reference -->
  <parent>
    <groupId>se.alipsa.groovy</groupId>
    <artifactId>gsvg-parent</artifactId>
    <version>1.0.0</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <!-- CRITICAL: Artifact ID remains 'gsvg' for backward compatibility -->
  <artifactId>gsvg</artifactId>
  <packaging>jar</packaging>

  <name>gsvg</name>
  <description>A Groovy object model for SVG (Scalable Vector Graphics)</description>

  <!-- Dependencies (versions managed by parent) -->
  <dependencies>
    <dependency>
      <groupId>org.dom4j</groupId>
      <artifactId>dom4j</artifactId>
    </dependency>
    <dependency>
      <groupId>jaxen</groupId>
      <artifactId>jaxen</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.groovy</groupId>
      <artifactId>groovy</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.helger</groupId>
      <artifactId>ph-css</artifactId>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.openjdk.jmh</groupId>
      <artifactId>jmh-generator-annprocess</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Groovy compilation -->
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>compileTests</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <targetBytecode>${java.version}</targetBytecode>
        </configuration>
      </plugin>

      <!-- Add Groovy source directories -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-groovy-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/main/groovy</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>add-groovy-test-sources</id>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/test/groovy</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Java compilation -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>${java.version}</source>
          <target>${java.version}</target>
        </configuration>
      </plugin>

      <!-- Testing -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <useModulePath>false</useModulePath>
        </configuration>
      </plugin>

      <!-- Source JAR -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <includes>
            <include>**/*.java</include>
            <include>**/*.groovy</include>
          </includes>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <!-- A) Generate GroovyDoc for package/deploy -->
          <execution>
            <id>groovydoc-generate</id>
            <phase>prepare-package</phase>
            <goals><goal>run</goal></goals>
            <configuration>
              <target name="groovydoc-generate">
                <taskdef name="groovydoc"
                         classname="org.codehaus.groovy.ant.Groovydoc"
                         classpathref="maven.plugin.classpath"/>

                <mkdir dir="${project.build.directory}/groovydoc"/>

                <groovydoc
                    destdir="${project.build.directory}/groovydoc"
                    use="true"
                    private="false"
                    windowtitle="${project.name} ${project.version} API"
                    doctitle="${project.name} ${project.version} API"
                    sourcepath="${project.basedir}/src/main/groovy${path.separator}${project.basedir}/src/main/java"
                />
              </target>
            </configuration>
          </execution>

          <!-- B) Copy GroovyDoc into the site output for mvn site -->
          <execution>
            <id>groovydoc-copy-to-site</id>
            <phase>pre-site</phase>
            <goals><goal>run</goal></goals>
            <configuration>
              <target name="groovydoc-copy-to-site">
                <mkdir dir="${project.reporting.outputDirectory}/groovydoc"/>
                <copy todir="${project.reporting.outputDirectory}/groovydoc" overwrite="true">
                  <fileset dir="${project.build.directory}/groovydoc"/>
                </copy>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Groovydoc JAR (javadoc classifier for Maven Central) -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>groovydoc-jar</id>
            <phase>package</phase>
            <goals><goal>jar</goal></goals>
            <configuration>
              <classifier>javadoc</classifier>
              <classesDirectory>${project.build.directory}/groovydoc</classesDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Code coverage -->
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-agent</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <excludes>
                <exclude>com/helger/**</exclude>
              </excludes>
            </configuration>
          </execution>
          <execution>
            <id>report</id>
            <phase>test</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Bytecode version enforcement -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>enforce-bytecode</id>
            <phase>validate</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <enforceBytecodeVersion>
                  <!-- Cap dependencies at JDK 17 -->
                  <maxJdkVersion>${java.version}</maxJdkVersion>
                  <!-- Optional: ignore test scope -->
                  <ignoredScopes>
                    <ignoredScope>test</ignoredScope>
                  </ignoredScopes>
                </enforceBytecodeVersion>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <configuration>
          <rulesUri>file://${project.parent.basedir}/version-plugin-rules.xml</rulesUri>
        </configuration>
      </plugin>

      <!-- Site plugin with fluido skin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.skins</groupId>
            <artifactId>maven-fluido-skin</artifactId>
            <version>${maven-fluido-skin.version}</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <!-- Reporting (same as before) -->
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <reportSets>
          <reportSet>
            <reports>
              <report>report</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
</project>
