<?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>

    <parent>
        <groupId>fr.gouv.vitam</groupId>
        <artifactId>parent</artifactId>
        <relativePath>../../sources/pom.xml</relativePath>
        <version>8.0.3</version>
    </parent>

    <artifactId>library-server</artifactId>
    <properties>
        <unix.name>library</unix.name>
        <unix.user>vitam</unix.user>
        <unix.group>vitam</unix.group>
        <jib.skip>true</jib.skip>
    </properties>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <!-- Include static resources (from technical-doc) -->
            <resource>
                <directory>target/doc</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <configuration>
                    <to>
                        <image>${env.SERVICE_DOCKER_PUSH_URL}/vitam/libray</image>
                        <tags>
                            <tag>${git.commit.id.describe-short}</tag>
                            <tag>${project.version}</tag>
                        </tags>
                    </to>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <!-- Extract doc into target/doc/static folder -->
                    <execution>
                        <id>unpack-technical-doc</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/doc/static</outputDirectory>
                            <includeGroupIds>fr.gouv.vitam.doc</includeGroupIds>
                            <includeArtifactIds>technical-doc</includeArtifactIds>
                            <includeTypes>zip</includeTypes>
                        </configuration>
                    </execution>
                    <!-- Dependency manipulation (copy, unpack) and analysis. -->
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                            <includeTypes>jar</includeTypes>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-config-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/conf/sysconfig</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/conf</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <!-- Debian -->
                    <execution>
                        <id>copy-debian-controlFiles</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/control</outputDirectory>
                            <overwrite>true</overwrite>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/deb/control</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>fr.gouv.vitam.library.LibraryMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.version}</version>
            </plugin>


            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <configuration>
                    <disabled>false</disabled>
                    <license>CeCILL 2.1</license>
                    <distribution>Vitam Project</distribution>
                    <group>Application/Archiving</group>
                    <packager>Vitam Package Team</packager>
                    <defineStatements/>
                    <targetOS>linux</targetOS>
                    <requires>
                        <require>systemd</require>
                        <require>${jdk.version.rpm}</require>
                        <require>vitam-user-${unix.user}</require>
                    </requires>
                    <defaultDirmode>750</defaultDirmode>
                    <defaultFilemode>640</defaultFilemode>
                    <defaultUsername>${unix.user}</defaultUsername>
                    <defaultGroupname>${unix.group}</defaultGroupname>
                    <mappings>
                        <mapping>
                            <!-- Caution : keep the artifact & dependency copy in the first mapping element ; or else they will be copied in every mapping before... -->
                            <directory>/vitam/lib/${unix.name}</directory>
                            <!-- Special marker to exclude non-default artefacts (we only need the jar to be packaged) -->
                            <artifact>
                                <classifiers>
                                    <classifier/>
                                </classifiers>
                            </artifact>
                            <!-- Exclude technical-doc zip artefact-->
                            <dependency>
                                <excludes>
                                    <exclude>fr.gouv.vitam.doc:technical-doc:zip</exclude>
                                </excludes>
                            </dependency>
                        </mapping>

                        <mapping>
                            <directory>/vitam/conf/${unix.name}</directory>
                            <sources>
                                <source>
                                    <location>${project.build.directory}/conf</location>
                                </source>
                            </sources>
                        </mapping>
                    </mappings>

                </configuration>
            </plugin>
            <plugin>
                <artifactId>jdeb</artifactId>
                <groupId>org.vafer</groupId>
                <version>1.4</version>
                <configuration>
                    <snapshotExpand>true</snapshotExpand>
                    <skip>false</skip>
                    <controlDir>${project.build.directory}/control</controlDir>
                    <dataSet>

                        <!-- Artifacts -->
                        <data>
                            <src>${project.build.directory}/${project.build.finalName}.jar</src>
                            <type>file</type>
                            <mapper>
                                <type>perm</type>
                                <user>${unix.user}</user>
                                <group>${unix.group}</group>
                                <filemode>0644</filemode>
                                <prefix>/vitam/lib/${unix.name}/</prefix>
                            </mapper>
                        </data>
                        <data>
                            <src>${project.build.directory}/dependencies</src>
                            <type>directory</type>
                            <missingSrc>ignore</missingSrc>
                            <mapper>
                                <type>perm</type>
                                <user>${unix.user}</user>
                                <group>${unix.group}</group>
                                <filemode>0644</filemode>
                                <prefix>/vitam/lib/${unix.name}</prefix>
                            </mapper>
                        </data>
                        <data>
                            <src>${project.build.directory}/conf</src>
                            <type>directory</type>
                            <missingSrc>ignore</missingSrc>
                            <mapper>
                                <type>perm</type>
                                <user>${unix.user}</user>
                                <group>${unix.group}</group>
                                <filemode>0750</filemode>
                                <prefix>/vitam/conf/${unix.name}</prefix>
                            </mapper>
                        </data>
                        <!-- Additional templates -->
                        <data>
                            <type>template</type>
                            <paths>
                                <path>/vitam/tmp/${unix.name}</path>
                                <path>/vitam/log/${unix.name}</path>
                            </paths>
                            <mapper>
                                <type>perm</type>
                                <user>${unix.user}</user>
                                <group>${unix.group}</group>
                            </mapper>
                        </data>

                    </dataSet>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Doc dependency - in a multi-module build, ensure that the documentation is built first -->
        <dependency>
            <groupId>fr.gouv.vitam.doc</groupId>
            <artifactId>technical-doc</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
        </dependency>
        <!-- Server dependencies -->
        <dependency>
            <groupId>fr.gouv.vitam</groupId>
            <artifactId>common-private</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Doc dependencies -->

    </dependencies>
</project>
