<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.sistcoop</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>1.0.5</version>

    <name>Elasticsearch</name>
    <description>Elasticsearch Shaded</description>
    <packaging>pom</packaging>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Versions -->
        <elasticsearch.version>5.6.4</elasticsearch.version>
        <shade-plugin.version>3.1.0</shade-plugin.version>

        <!-- Configuration -->
        <elasticsearch.package>org.elasticsearch.shaded</elasticsearch.package>
        <install.dir>${project.build.directory}/distribution</install.dir>
    </properties>

    <url>http://openfact.org</url>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>carlosthe19916</id>
            <name>Carlos Esteban Feria Vila</name>
            <email>carlosthe19916@gmail.com</email>
            <organization>SistCoop</organization>
            <roles>
                <role>project-owner</role>
            </roles>
            <timezone>-5</timezone>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/openfact/elasticsearch.git</connection>
        <developerConnection>scm:git:git@github.com:openfact/elasticsearch.git</developerConnection>
        <url>https://github.com/openfact/elasticsearch/tree/master/</url>
    </scm>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <modules>
        <module>elasticsearch-shaded</module>
        <module>elasticsearch-test-shaded</module>
    </modules>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.6.8</version>
                    <extensions>true</extensions>
                    <configuration>
                        <serverId>ossrh</serverId>
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                        <autoReleaseAfterClose>true</autoReleaseAfterClose>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                    <configuration>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <useReleaseProfile>false</useReleaseProfile>
                        <releaseProfiles>release</releaseProfiles>
                        <tagNameFormat>@{project.version}</tagNameFormat>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <source>${maven.compiler.source}</source>
                        <target>${maven.compiler.target}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.2.1</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.9.1</version>
                    <executions>
                        <execution>
                            <id>attach-javadocs</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>1.6</version>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>sign</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${shade-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createSourcesJar>true</createSourcesJar>
                            <shadeSourcesContent>true</shadeSourcesContent>
                            <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <!-- Elasticsearch relies on these entries to verify build correctness -->
                                    <manifestEntries>
                                        <Change>GIT commit ID</Change>
                                        <Build-Date>${maven.build.timestamp}</Build-Date>
                                    </manifestEntries>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                            <relocations>
                                <!-- elasticsearch-shade relocations -->
                                <relocation>
                                    <pattern>com.fasterxml.jackson</pattern>
                                    <shadedPattern>${elasticsearch.package}.jackson</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>io.netty</pattern>
                                    <shadedPattern>${elasticsearch.package}.netty</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.jboss.netty</pattern>
                                    <shadedPattern>${elasticsearch.package}.jboss.netty</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.yaml</pattern>
                                    <shadedPattern>${elasticsearch.package}.yaml</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.apache.lucene</pattern>
                                    <shadedPattern>${elasticsearch.package}.apache.lucene</shadedPattern>
                                </relocation>

                                <!-- elasticsearch-test-shade relocations -->
                                <relocation>
                                    <pattern>org.objectweb.asm</pattern>
                                    <shadedPattern>${elasticsearch.package}.objectweb.asm</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.antlr</pattern>
                                    <shadedPattern>${elasticsearch.package}.antlr</shadedPattern>
                                </relocation>

                                <!-- common relocations -->
                                <relocation>
                                    <pattern>org.apache.http</pattern>
                                    <shadedPattern>${elasticsearch.package}.apache.http</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.apache.commons.codec</pattern>
                                    <shadedPattern>${elasticsearch.package}.apache.commons.codec</shadedPattern>
                                </relocation>
                            </relocations>

                            <!-- Include only Elasticsearch and relocated dependencies. Promote everything else as transitive dependencies -->
                            <artifactSet>
                                <includes>
                                    <include>org.sistcoop:*</include>
                                    <include>org.elasticsearch:*</include>
                                    <include>org.elasticsearch.client:*</include>
                                    <include>org.elasticsearch.plugin:*</include>
                                    <include>org.elasticsearch.test:*</include>
                                    <include>com.fasterxml.jackson.core:*</include>
                                    <include>com.fasterxml.jackson.dataformat:*</include>
                                    <include>io.netty:*</include>
                                    <include>org.yaml:*</include>
                                    <include>org.apache.httpcomponents:*</include>
                                    <include>commons-codec:*</include>
                                    <include>org.jboss.netty:*</include>
                                    <include>org.apache.lucene:*</include>
                                </includes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/license/**</exclude>
                                        <exclude>META-INF/*</exclude>
                                        <exclude>META-INF/maven/**</exclude>
                                        <exclude>LICENSE</exclude>
                                        <exclude>NOTICE</exclude>
                                        <exclude>/*.txt</exclude>
                                        <exclude>build.properties</exclude>
                                    </excludes>
                                </filter>

                                <!-- Ensure the custom JarHell is included -->
                                <filter>
                                    <artifact>org.elasticsearch:elasticsearch</artifact>
                                    <excludes>
                                        <exclude>org/elasticsearch/bootstrap/JarHell.class</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.7</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>doclint-java8-disable</id>
            <activation>
                <jdk>[1.8,)</jdk>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <configuration>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>nexus-staging</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
