<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright (c) 2021-2022 - Yupiik SAS - https://www.yupiik.com
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
<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/xsd/maven-4.0.0.xsd">
  <parent>
    <artifactId>bundlebee</artifactId>
    <groupId>io.yupiik</groupId>
    <version>1.0.18</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>bundlebee-core</artifactId>
  <name>BundleBee :: Core</name>

  <dependencies>
    <dependency> <!-- todo: replace it by something lighter without the mapping feature? -->
      <groupId>org.yaml</groupId>
      <artifactId>snakeyaml</artifactId>
      <version>1.32</version>
    </dependency>

    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-jcdi_2.0_spec</artifactId>
      <version>1.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-annotation_1.3_spec</artifactId>
      <version>1.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-atinject_1.0_spec</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-interceptor_1.2_spec</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>org.eclipse.microprofile.config</groupId>
      <artifactId>microprofile-config-api</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-json_1.1_spec</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-jsonb_1.0_spec</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.openwebbeans</groupId>
      <artifactId>openwebbeans-se</artifactId>
      <version>${owb.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.geronimo.config</groupId>
      <artifactId>geronimo-config-impl</artifactId>
      <version>1.2.3</version>
    </dependency>
    <dependency>
      <groupId>org.apache.johnzon</groupId>
      <artifactId>johnzon-jsonb</artifactId>
    </dependency>
    <dependency>
      <groupId>io.yupiik.logging</groupId>
      <artifactId>yupiik-logging-jul</artifactId>
      <version>${yupiik-logging.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.openwebbeans</groupId>
      <artifactId>openwebbeans-junit5</artifactId>
      <version>${owb.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.talend.sdk.component</groupId>
      <artifactId>component-runtime-http-junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency> <!-- for talend mock http server -->
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>templating-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
            <id>filter-src</id>
            <goals>
              <goal>filter-sources</goal>
            </goals>
            <configuration>
              <encoding>UTF-8</encoding>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.4</version>
        <executions>
          <execution>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <shadedClassifierName>fat</shadedClassifierName>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <dependencyReducedPomLocation>${project.build.directory}/reduced-pom.xml</dependencyReducedPomLocation>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>io.yupiik.bundlebee.core.BundleBee</mainClass>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
                <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                  <resource>META-INF/beans.xml</resource>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.properties.OpenWebBeansPropertiesTransformer" />
              </transformers>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                    <exclude>META-INF/LICENSE.txt</exclude>
                    <exclude>META-INF/LICENSE</exclude>
                    <exclude>META-INF/NOTICE.txt</exclude>
                    <exclude>META-INF/NOTICE</exclude>
                    <exclude>META-INF/MANIFEST.MF</exclude>
                    <exclude>META-INF/DEPENDENCIES</exclude>
                  </excludes>
                </filter>
              </filters>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>native</id>

      <build>
        <finalName>${project.artifactId}</finalName>

        <plugins>
          <plugin> <!-- mvn package -Pnative -DskipTests  -->
            <groupId>org.apache.geronimo.arthur</groupId>
            <artifactId>arthur-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>native</id>
                <phase>package</phase>
                <goals>
                  <goal>native-image</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <main>io.yupiik.bundlebee.core.BundleBee</main>
            </configuration>
          </plugin>

          <!-- enable to work with krew kubectl plugin manager (zip + manifest filtering) -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
              <execution>
                <id>kubectl-bundlebee-zip</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>${project.basedir}/src/main/assembly/kubectl-bundlebee.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>net.nicoulaj.maven.plugins</groupId>
            <artifactId>checksum-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>krew-sha256</id>
                <phase>package</phase>
                <goals>
                  <goal>files</goal>
                </goals>
                <configuration>
                  <csvSummary>false</csvSummary>
                  <fileSets>
                    <fileSet>
                      <directory>${project.build.directory}</directory>
                      <includes>
                        <include>${project.build.finalName}-kubectl-bundlebee.zip</include>
                      </includes>
                    </fileSet>
                  </fileSets>
                  <algorithms>
                    <algorithm>SHA-256</algorithm>
                  </algorithms>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.honton.chas</groupId>
            <artifactId>readfiles-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>read-kubectl-bundlebee-sha256</id>
                <phase>package</phase>
                <goals>
                  <goal>readfiles</goal>
                </goals>
                <configuration>
                  <files>
                    <file>${project.build.directory}/${project.build.finalName}-kubectl-bundlebee.zip.sha256</file>
                  </files>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
              <execution>
                <id>copy-krew-manifest</id>
                <phase>verify</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${project.basedir}/target/krew</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/main/krew</directory>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>add-krew</id>
                <phase>verify</phase>
                <goals>
                  <goal>attach-artifact</goal>
                </goals>
                <configuration>
                  <artifacts>
                    <artifact>
                      <file>${project.basedir}/target/krew/manifest.yaml</file>
                      <type>yaml</type>
                      <classifier>krew.manifest</classifier>
                    </artifact>
                  </artifacts>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
