<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2009-2013 Roland Huss
  ~
  ~ 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">
  <modelVersion>4.0.0</modelVersion>

  <artifactId>jolokia-agent-jvm</artifactId>
  <version>2.2.1</version>
  <packaging>jar</packaging>

  <name>jolokia-agent-jvm</name>
  <description>Jolokia :: JVM :: Agent</description>

  <parent>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-parent</artifactId>
    <version>2.2.1</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>

  <url>https://jolokia.org/</url>

  <dependencies>

    <!-- Jolokia own artifacts -->

    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-tools-test</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-json</artifactId>
    </dependency>

    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-server-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-server-core</artifactId>
      <classifier>tests</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-server-detector</artifactId>
    </dependency>

    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-serializer</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-jmx</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-discovery</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-history</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-jsr160</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-notif-pull</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jolokia</groupId>
      <artifactId>jolokia-service-notif-sse</artifactId>
    </dependency>

    <!-- JakartaEE dependencies -->

    <dependency>
      <groupId>jakarta.servlet</groupId>
      <artifactId>jakarta.servlet-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Other -->

    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-server</artifactId>
      <version>${version.org.eclipse.jetty}</version>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.eclipse.jetty.toolchain</groupId>
          <artifactId>jetty-jakarta-servlet-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-servlet</artifactId>
      <version>${version.org.eclipse.jetty}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerArgs>
            <arg>--add-modules=jdk.attach</arg>
          </compilerArgs>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <minimizeJar>false</minimizeJar>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <shadedClassifierName>javaagent</shadedClassifierName>
              <shadedArtifactAttached>true</shadedArtifactAttached>
              <artifactSet>
                <includes>
                  <include>org.jolokia:jolokia-json</include>
                  <include>org.jolokia:jolokia-server-core</include>
                  <include>org.jolokia:jolokia-server-detector</include>
                  <include>org.jolokia:jolokia-service-serializer</include>
                  <include>org.jolokia:jolokia-service-jmx</include>
                  <include>org.jolokia:jolokia-service-discovery</include>
                  <include>org.jolokia:jolokia-service-history</include>
                  <include>org.jolokia:jolokia-service-jsr160</include>
                  <include>org.jolokia:jolokia-service-notif-pull</include>
                  <include>org.jolokia:jolokia-service-notif-sse</include>
                </includes>
              </artifactSet>
              <filters>
                <filter>
                  <artifact>org.jolokia:jolokia-json</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-server-core</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/server/core/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-server-detector</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/server/detector/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-serializer</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/serializer/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-jmx</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/jmx/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-discovery</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/discovery/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-history</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/history/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-jsr160</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/jsr160/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-notif-pull</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/notif/pull/osgi/**</exclude>
                  </excludes>
                </filter>
                <filter>
                  <artifact>org.jolokia:jolokia-service-notif-sse</artifact>
                  <excludes>
                    <exclude>META-INF/*.MF</exclude>
                    <exclude>org/jolokia/service/notif/sse/osgi/**</exclude>
                  </excludes>
                </filter>
              </filters>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/jolokia/services-default</resource>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Premain-Class>org.jolokia.jvmagent.JvmAgent</Premain-Class>
                    <Agent-Class>org.jolokia.jvmagent.JvmAgent</Agent-Class>
                    <Main-Class>org.jolokia.jvmagent.client.AgentLauncher</Main-Class>
                    <Can-Redefine-Classes>false</Can-Redefine-Classes>
                    <Can-Retransform-Classes>false</Can-Retransform-Classes>
                    <Can-Set-Native-Method-Prefix>false</Can-Set-Native-Method-Prefix>
                  </manifestEntries>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <reuseForks>false</reuseForks>
          <forkCount>1</forkCount>
          <!--<argLine>-Djava.security.debug=certpath,Provider</argLine>-->
        </configuration>
      </plugin>
    </plugins>
  </build>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <reportSets>
          <reportSet>
            <reports>
              <report>dependencies</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

  <profiles>
    <profile>
      <id>dist</id>
      <build>
        <plugins>

          <plugin>
            <groupId>org.vafer</groupId>
            <artifactId>jdeb</artifactId>
            <version>${plugin.org.vafer.jdeb}</version>

            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>jdeb</goal>
                </goals>
                <configuration>
                  <dataSet>

                    <data>
                      <src>${project.build.directory}/${project.build.finalName}.jar</src>
                      <type>file</type>
                      <mapper>
                        <type>perm</type>
                        <prefix>/usr/share/jolokia</prefix>
                        <filemode>644</filemode>
                      </mapper>
                    </data>

                    <data>
                      <type>link</type>
                      <symlink>true</symlink>
                      <linkName>/usr/share/jolokia/jolokia-jvm.jar</linkName>
                      <linkTarget>/usr/share/jolokia/${project.build.finalName}.jar</linkTarget>
                    </data>

                  </dataSet>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
