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

  <parent>
    <groupId>org.opennms</groupId>
    <artifactId>org.opennms.features</artifactId>
    <version>19.0.0-SNAPSHOT</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <groupId>org.opennms.plugins</groupId>
  <artifactId>internal-plugins-descriptor</artifactId>
  <description>Module to generate list of internal plugins which can be installed</description>
  <packaging>bundle</packaging>

  <properties>
    <!-- these properties define the productSpec.xml variables -->
    <!-- <productFeatureRepository>mvn:${groupId}/${productName}/${project.version}/xml/features</productFeatureRepository> -->
    <productFeatureRepository>mvn:org.opennms.karaf/opennms/${project.version}/xml/features</productFeatureRepository>
    <productName>${project.artifactId}</productName>
    <productId>${productName}/${project.version}</productId>

  </properties>

  <build>

    <plugins>


      <!-- copy and process the productSpec for this project -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>filter-resources</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/filtered-resources</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/filtered-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>


      <!-- used to generate available plugins / kar descriptor -->
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>features-maven-plugin</artifactId>
        <version>${karafVersion}</version>
        <executions>

          <!-- generates repo which we can traverse to find product descriptor files -->
          <execution>
            <id>add-features-to-repo</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>add-features-to-repo</goal>
            </goals>
            <configuration>
              <!-- this unknown karaf version prevents copying any karaf descriptors into kar - which we do not want -->
              <karafVersion>99999</karafVersion>
              <descriptors>

                <!-- Please define the features containing the plugin product descriptors which -->
                <!-- you want to include in the 'available plugins' list here -->
                <!-- <descriptor>mvn:${project.groupId}/${productName}/${project.version}/xml/features</descriptor> -->
                <descriptor>mvn:org.opennms.plugins/alarm-change-notifier/${project.version}/xml/features</descriptor>
                <descriptor>mvn:org.opennms.plugins/opennms-es-rest/${project.version}/xml/features</descriptor>

              </descriptors>
              <features>
                <!-- <feature>${productName}/${project.version}</feature> -->
                <feature>alarm-change-notifier/${project.version}</feature>
                <feature>opennms-es-rest/${project.version}</feature>
              </features>
              <repository>${project.build.directory}/temp-features-repo</repository>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-http</artifactId>
            <version>2.8</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>create-temp-features-repo</id>
            <phase>initialize</phase>
            <configuration>
              <target>
                <delete dir="${project.build.directory}/temp-features-repo" />
                <mkdir dir="${project.build.directory}/temp-features-repo" />
                <echo>PLEASE NOTE The exec-maven-plugin runs ProductSpecListGenerator twice. The second time generates useful output.</echo>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- used to generate product specification list -->
      <!-- NOTE due to a bug in maven this will run twice. The first time with an error in output log. This is not a problem -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>org.opennms.karaf.licencemanager.generate.ProductSpecListGenerator</mainClass>
              <includePluginDependencies>true</includePluginDependencies>
              <arguments>
                <!-- ProductSpecListGenerator(String searchDirectory, String outputFile, String packagingDescriptor) -->
                <argument>${project.build.directory}/temp-features-repo</argument>
                <argument>${project.build.directory}/generated-code/resources/productSpecList.xml</argument>
                <argument>Internal Repo OpenNMS ${project.version} (${productName})</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.opennms.plugins</groupId>
            <artifactId>org.opennms.plugin.licencemanager</artifactId>
            <version>${licencemanagerVersion}</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${project.build.directory}/generated-code/java</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>add-resource</id>
            <phase>process-resources</phase>
            <goals>
              <goal>add-resource</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>${project.build.directory}/generated-code/resources</directory>
                </resource>
                <resource>
                  <directory>${project.build.directory}/filtered-resources</directory>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <target>1.8</target>
          <source>1.8</source>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-Version>${project.version}</Bundle-Version>
            <Import-Package>
              *
            </Import-Package>
            <!-- <Import-Package> -->
            <!-- org.apache.felix.service.command, -->
            <!-- * -->
            <!-- </Import-Package> -->
          </instructions>
        </configuration>
      </plugin>

      <!-- used to generate opennms style features.xml for this plugin -->
      <plugin>
        <groupId>org.opennms.maven.plugins</groupId>
        <artifactId>features-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>features.xml</id>
            <phase>process-resources</phase>
            <goals>
              <goal>generate-features-xml</goal>
            </goals>
            <configuration>
              <!-- so that licence manager feature starts before this module -->
              <repositories>
                <repository>mvn:org.opennms.plugins/org.opennms.plugin.licencemanager/${licencemanagerVersion}/xml/features</repository>
              </repositories>
              <features>
                <feature>org.opennms.plugin.licencemanager</feature>
              </features>
              <bundles>
                <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
              </bundles>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

  </build>

  <dependencies>
    <dependency>
      <groupId>org.opennms.core.ipc.sink</groupId>
      <artifactId>org.opennms.core.ipc.sink.xml</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.opennms.plugins</groupId>
      <artifactId>alarm-change-notifier</artifactId>
      <version>${project.version}</version>
      <type>xml</type>
      <classifier>features</classifier>
    </dependency>
    <dependency>
      <groupId>org.opennms.plugins</groupId>
      <artifactId>opennms-es-rest</artifactId>
      <version>${project.version}</version>
      <type>xml</type>
      <classifier>features</classifier>
    </dependency>
  </dependencies>

</project>
