<?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>
        <artifactId>jikkou</artifactId>
        <groupId>io.streamthoughts</groupId>
        <version>0.14.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>jikkou-cli</artifactId>
    <name>jikkou</name>

    <description>A command-line tool to help you automate the management of the configurations that live on your Apache Kafka platform.</description>
    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <app.distribution.directory>${project.basedir}/../dist</app.distribution.directory>
        <license.header.file>${project.parent.basedir}/license-header</license.header.file>
    </properties>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jikkou-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jikkou-template-jinja</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jikkou-extension-kafka</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe</groupId>
            <artifactId>config</artifactId>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
        </dependency>
        <!-- START dependencies for test -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- END dependencies for test -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <finalName>jikkou-runner</finalName>
                            <minimizeJar>false</minimizeJar>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>runner</shadedClassifierName>
                            <filters>
                                <filter>
                                    <artifact>io.streamthoughts:jikkou-extension-kafka</artifact>
                                    <includes>
                                        <include>**</include>
                                    </includes>
                                </filter>
                                <filter>
                                    <artifact>com.fasterxml.jackson*:*</artifact>
                                    <includes>
                                        <include>**</include>
                                    </includes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>io.streamthoughts.jikkou.client.Jikkou</mainClass>
                                    <manifestEntries>
                                        <Implementation-Title>Jikkou</Implementation-Title>
                                        <Implementation-Version>${project.version}</Implementation-Version>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <attach>false</attach>
                    <appendAssemblyId>false</appendAssemblyId>
                    <finalName>jikkou-${project.version}-runner</finalName>
                    <outputDirectory>${app.distribution.directory}</outputDirectory>
                    <skipAssembly>true</skipAssembly>
                </configuration>
                <executions>
                    <execution>
                        <id>make-distribution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>dist</id>
            <activation>
                <property>
                    <name>dist</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>${exec-maven-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>generate-autocompletion-script</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-Dpicocli.autocomplete.systemExitOnError</argument>
                                <argument>-cp</argument>
                                <classpath/>
                                <argument>picocli.AutoComplete</argument>
                                <argument>--force</argument><!-- overwrite if exists -->
                                <argument>--completionScript</argument>
                                <argument>${project.basedir}/../jikkou_completion</argument>
                                <argument>io.streamthoughts.jikkou.client.Jikkou</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration combine.self="append">
                            <skipAssembly>false</skipAssembly>
                            <descriptors>
                                <descriptor>${project.basedir}/src/main/assembly/assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.vafer</groupId>
                        <artifactId>jdeb</artifactId>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jdeb</goal>
                                </goals>
                                <configuration>
                                    <installDir>/opt/jikkou</installDir>
                                    <deb>${app.distribution.directory}/jikkou.deb</deb>
                                    <verbose>true</verbose>
                                    <snapshotExpand>true</snapshotExpand>
                                    <!-- expand "SNAPSHOT" to what is in the "USER" env variable -->
                                    <snapshotEnv>USER</snapshotEnv>
                                    <verbose>true</verbose>
                                    <controlDir>${project.basedir}/src/deb/control</controlDir>
                                    <dataSet>
                                        <data>
                                            <src>${project.basedir}/target/jikkou-runner.jar</src>
                                            <type>file</type>
                                            <mapper>
                                                <type>perm</type>
                                                <prefix>/opt/jikkou/lib</prefix>
                                                <filemode>444</filemode>
                                            </mapper>
                                        </data>

                                        <data>
                                            <src>${project.basedir}/src/main/bin/jikkou</src>
                                            <type>file</type>
                                            <mapper>
                                                <type>perm</type>
                                                <prefix>/opt/jikkou/bin</prefix>
                                                <filemode>755</filemode>
                                            </mapper>
                                        </data>

                                        <data>
                                            <src>${project.basedir}/src/main/conf/</src>
                                            <type>directory</type>
                                            <mapper>
                                                <type>perm</type>
                                                <prefix>/opt/jikkou/etc</prefix>
                                                <filemode>755</filemode>
                                            </mapper>
                                        </data>

                                        <data>
                                            <src>${project.basedir}/../jikkou_completion</src>
                                            <type>file</type>
                                            <mapper>
                                                <type>perm</type>
                                                <prefix>/opt/jikkou/</prefix>
                                                <filemode>444</filemode>
                                            </mapper>
                                        </data>
                                    </dataSet>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>rpm</id>
            <activation>
                <file>
                    <exists>/usr/bin/rpmbuild</exists>
                </file>
            </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>attached-rpm</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <name>jikkou</name>
                            <version>${project.version}</version>
                            <license>Apache License Version 2.0</license>
                            <group>Applications/Programming</group>
                            <needarch>noarch</needarch>
                            <defaultFilemode>644</defaultFilemode>
                            <defaultUsername>root</defaultUsername>
                            <defaultGroupname>root</defaultGroupname>
                            <defaultDirmode>755</defaultDirmode>
                            <packager>Streamthoughts</packager>
                            <prefix>/opt/jikkou</prefix>
                            <requires>
                                <require>java</require>
                            </requires>
                            <mappings>
                                <mapping>
                                    <directory>/opt/jikkou/lib/</directory>
                                    <filemode>444</filemode>
                                    <sources>
                                        <source>
                                            <location>${project.basedir}/target/jikkou-runner.jar</location>
                                        </source>
                                    </sources>
                                </mapping>
                                <mapping>
                                    <directory>/opt/jikkou/bin/</directory>
                                    <filemode>755</filemode>
                                    <sources>
                                        <source>
                                            <location>${project.basedir}/src/main/bin/jikkou</location>
                                        </source>
                                    </sources>
                                </mapping>
                                <mapping>
                                    <directory>/opt/jikkou/etc/</directory>
                                    <filemode>640</filemode>
                                    <configuration>noreplace</configuration>
                                    <sources>
                                        <source>
                                            <location>${project.basedir}/src/main/conf/</location>
                                        </source>
                                    </sources>
                                </mapping>
                                <mapping>
                                    <directory>/opt/jikkou/</directory>
                                    <filemode>640</filemode>
                                    <sources>
                                        <source>
                                            <location>${project.basedir}/../jikkou_completion</location>
                                        </source>
                                    </sources>
                                </mapping>
                            </mappings>
                            <preinstallScriptlet>
                                <scriptFile>src/rpm/scripts/preinstall</scriptFile>
                                <fileEncoding>utf-8</fileEncoding>
                                <filter>true</filter>
                            </preinstallScriptlet>
                            <postinstallScriptlet>
                                <scriptFile>src/rpm/scripts/postinstall</scriptFile>
                                <fileEncoding>utf-8</fileEncoding>
                                <filter>true</filter>
                            </postinstallScriptlet>
                            <preremoveScriptlet>
                                <scriptFile>src/rpm/scripts/preremove</scriptFile>
                                <fileEncoding>utf-8</fileEncoding>
                            </preremoveScriptlet>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>