<?xml version="1.0"?>
<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>
    <parent>
        <groupId>com.taobao.arthas</groupId>
        <artifactId>arthas-all</artifactId>
        <version>3.4.3</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>arthas-packaging</artifactId>
    <name>arthas-packaging</name>

    <dependencies>
        <dependency>
            <groupId>com.taobao.arthas</groupId>
            <artifactId>arthas-core</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.taobao.arthas</groupId>
            <artifactId>arthas-site</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <finalName>arthas</finalName>
        <plugins>
            <!-- Assembly plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bin</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/main/assembly/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- add binary files in jar -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <zip update="true" destfile="${project.build.directory}/${project.build.finalName}.${project.packaging}" basedir="${project.build.directory}" includes="arthas-bin.zip">
                                </zip>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>deb</id>
            <activation>
                <jdk>[1.8,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>jdeb</artifactId>
                        <groupId>org.vafer</groupId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jdeb</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <skipPOMs>false</skipPOMs>
                            <deb>${project.build.directory}/arthas-${project.version}.deb</deb>
                            <dataSet>
                                <data>
                                    <src>${project.build.directory}/arthas-bin</src>
                                    <type>directory</type>

                                    <mapper>
                                        <type>perm</type>
                                        <strip>1</strip>
                                        <prefix>/usr/share/arthas</prefix>
                                        <user>root</user>
                                        <group>root</group>
                                    </mapper>
                                </data>

                                <data>
                                    <src>${project.build.directory}/arthas-bin/as.sh </src>
                                    <type>file</type>
                                    <mapper>
                                        <type>perm</type>
                                        <strip>1</strip>
                                        <prefix>/usr/bin</prefix>
                                        <filemode>755</filemode>
                                        <user>root</user>
                                        <group>root</group>
                                    </mapper>
                                </data>
                                <data>
                                    <src>../packaging/src/deb/man1/arthas.1</src>
                                    <type>file</type>
                                    <mapper>
                                        <type>perm</type>
                                        <strip>1</strip>
                                        <prefix>/usr/share/man/man1</prefix>
                                        <filemode>755</filemode>
                                        <user>root</user>
                                        <group>root</group>
                                    </mapper>
                                </data>
                                <data>
                                    <src>../packaging/src/deb/copyright/copyright.1</src>
                                    <type>file</type>
                                    <mapper>
                                        <type>perm</type>
                                        <strip>1</strip>
                                        <prefix>/usr/share/doc/arthas</prefix>
                                        <filemode>755</filemode>
                                        <user>root</user>
                                        <group>root</group>
                                    </mapper>
                                </data>
                            </dataSet>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>rpm</id>
            <activation>
                <os>
                    <family>linux</family>
                </os>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>rpm-maven-plugin</artifactId>
                        <version>2.2.0</version>
                        <executions>
                            <execution>
                                <id>generate-rpm</id>
                                <goals>
                                    <goal>rpm</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <license>(c) Alibaba, Apache-2.0</license>
                            <distribution>Arthas</distribution>
                            <group>Development/tools</group>
                            <packager>Alibaba</packager>
                            <prefix>/usr/share</prefix>
                            <autoProvides>false</autoProvides>
                            <autoRequires>false</autoRequires>
                            <defineStatements>
                                <defineStatement>_unpackaged_files_terminate_build 0</defineStatement>
                            </defineStatements>
                            <mappings>
                                <mapping>
                                    <directory>/usr/share/arthas</directory>
                                    <filemode>755</filemode>
                                    <username>root</username>
                                    <groupname>root</groupname>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/arthas-bin</location>
                                        </source>
                                    </sources>
                                </mapping>
                                <mapping>
                                    <directory>/usr/local/bin</directory>
                                    <filemode>755</filemode>
                                    <username>root</username>
                                    <groupname>root</groupname>
                                    <sources>
                                        <softlinkSource>
                                            <location>/usr/share/arthas/as.sh</location>
                                        </softlinkSource>
                                    </sources>
                                </mapping>
                                <mapping>
                                    <directory>/usr/share/man/man1</directory>
                                    <filemode>755</filemode>
                                    <username>root</username>
                                    <groupname>root</groupname>
                                    <sources>
                                        <source>
                                            <location>../packaging/src/deb/man1/arthas.1</location>
                                        </source>
                                    </sources>
                                </mapping>
                            </mappings>
                            <requires>
                                <require>curl</require>
                                <require>telnet</require>
                                <require>unzip</require>
                            </requires>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>full</id>
            <build>
                <plugins>
                    <!-- Assembly plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>doc</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <descriptors>
                                        <descriptor>src/main/assembly/assembly-doc.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
