<?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>
    <groupId>se.alipsa.groovy</groupId>
    <artifactId>gsvg-parent</artifactId>
    <version>1.0.0</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <artifactId>gsvg-export</artifactId>
  <packaging>jar</packaging>

  <name>gsvg-export</name>
  <description>SVG rendering, optimization, and export capabilities (Phase 6)</description>

  <dependencies>
    <!-- Dependency on core module -->
    <dependency>
      <groupId>se.alipsa.groovy</groupId>
      <artifactId>gsvg</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- jsvg for SVG rendering -->
    <dependency>
      <groupId>com.github.weisj</groupId>
      <artifactId>jsvg</artifactId>
      <version>2.0.0</version>
    </dependency>

    <!-- Groovy (provided scope) -->
    <dependency>
      <groupId>org.apache.groovy</groupId>
      <artifactId>groovy</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</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>

      <!-- Testing -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <useModulePath>false</useModulePath>
          <argLine>-Djava.awt.headless=true</argLine>
        </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>

      <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>

      <!-- Version 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>
    </plugins>
  </build>
</project>
