<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>io.github.amilasaad</groupId>
  <artifactId>dw-mask-library</artifactId>
  <version>0.0.1</version>
  <packaging>dw-library</packaging>

  <name>DataWeave Masking Library</name>
  <description>A lightweight, reusable DataWeave 2.0 utility library for masking sensitive PII data.</description>
  <url>https://github.com/amilasaad/dw-mask-library</url>

  <licenses>
    <license>
      <name>MIT License</name>
      <url>https://opensource.org/licenses/MIT</url>
    </license>
  </licenses>

  <developers>
    <developer>
      <name>Amilasaad</name>
      <url>https://github.com/amilasaad</url>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:git://github.com/amilasaad/dw-mask-library.git</connection>
    <developerConnection>scm:git:ssh://github.com:amilasaad/dw-mask-library.git</developerConnection>
    <url>https://github.com/amilasaad/dw-mask-library/tree/main</url>
  </scm>

  <distributionManagement>
    <repository>
      <id>central</id>
      <name>Sonatype Central Portal</name>
      <url>https://central.sonatype.com</url>
    </repository>
  </distributionManagement>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <data.weave.version>2.5.0</data.weave.version>
    <data.weave.testing.framework.version>1.2.2</data.weave.testing.framework.version>
    <data.weave.maven.plugin.version>0.3.5</data.weave.maven.plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.mule.weave</groupId>
      <artifactId>runtime</artifactId>
      <version>${data.weave.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.mule.weave</groupId>
      <artifactId>core-modules</artifactId>
      <version>${data.weave.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.mule.weave</groupId>
      <artifactId>data-weave-testing-framework</artifactId>
      <version>${data.weave.testing.framework.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>mulesoft-public</id>
      <name>MuleSoft Public Repository</name>
      <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
    </repository>
    <repository>
      <id>mule-releases</id>
      <name>MuleSoft Releases Repository</name>
      <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>mulesoft-public</id>
      <name>MuleSoft Public Repository</name>
      <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
    </pluginRepository>
    <pluginRepository>
      <id>mule-releases</id>
      <name>MuleSoft Releases Repository</name>
      <url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
    </pluginRepository>
  </pluginRepositories>

  <build>
    <resources>
      <resource>
        <directory>src/main/dw</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/dw</directory>
      </testResource>
    </testResources>
    <plugins>
      <plugin>
        <groupId>org.mule.weave</groupId>
        <artifactId>data-weave-maven-plugin</artifactId>
        <version>${data.weave.maven.plugin.version}</version>
        <extensions>true</extensions>
      </plugin>

      <!-- Step 1: Copy dw-library jar to unclassified primary jar -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-primary-jar</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>cp</executable>
              <arguments>
                <argument>${project.build.directory}/${project.artifactId}-${project.version}-dw-library.jar</argument>
                <argument>${project.build.directory}/${project.artifactId}-${project.version}.jar</argument>
              </arguments>
            </configuration>
          </execution>
          <!-- Sign custom dw-library jar directly with GPG -->
          <execution>
            <id>gpg-sign-dw-library</id>
            <phase>verify</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>gpg</executable>
              <arguments>
                <argument>--batch</argument>
                <argument>--yes</argument>
                <argument>--pinentry-mode</argument>
                <argument>loopback</argument>
                <argument>--detach-sign</argument>
                <argument>--armor</argument>
                <argument>${project.build.directory}/${project.artifactId}-${project.version}-dw-library.jar</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Step 2: Attach primary jar AND the dw-library signature -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.5.0</version>
        <executions>
          <execution>
            <id>attach-primary-jar</id>
            <phase>package</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${project.artifactId}-${project.version}.jar</file>
                  <type>jar</type>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
          <execution>
            <id>attach-dw-library-asc</id>
            <phase>verify</phase>
            <goals>
              <goal>attach-artifact</goal>
            </goals>
            <configuration>
              <artifacts>
                <artifact>
                  <file>${project.build.directory}/${project.artifactId}-${project.version}-dw-library.jar.asc</file>
                  <type>jar.asc</type>
                  <classifier>dw-library</classifier>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Step 3: Attach Sources -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.3.1</version>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>package</phase>
            <goals>
              <goal>jar-no-fork</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Step 4: Attach Javadoc -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.6.3</version>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <failOnError>false</failOnError>
        </configuration>
      </plugin>

      <!-- Step 5: Central Publishing Plugin -->
      <plugin>
        <groupId>org.sonatype.central</groupId>
        <artifactId>central-publishing-maven-plugin</artifactId>
        <version>0.11.0</version>
        <extensions>true</extensions>
        <configuration>
          <publishingServerId>central</publishingServerId>
        </configuration>
      </plugin>

      <!-- Step 6: Standard GPG Sign Plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-gpg-plugin</artifactId>
        <version>3.2.4</version>
        <executions>
          <execution>
            <id>sign-artifacts</id>
            <phase>verify</phase>
            <goals>
              <goal>sign</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>