<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>share-docker</artifactId>
    <name>Alfresco Share Docker image builder</name>
    <packaging>pom</packaging>

    <parent>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-share-packaging</artifactId>
        <version>6.2.0-RC3</version>
    </parent>

    <properties>
        <dependency.alfresco-mmt.version>6.0</dependency.alfresco-mmt.version>
        <!-- Alfresco GoogleDocs integration version -->
        <alfresco.googledocs.version>3.1.0</alfresco.googledocs.version>

        <image.registry>quay.io</image.registry>
        <image.name>alfresco/alfresco-share</image.name>
        <image.tag>latest</image.tag>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>share</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-mmt</artifactId>
            <version>${dependency.alfresco-mmt.version}</version>
        </dependency>
        <dependency>
            <groupId>org.alfresco.integrations</groupId>
            <artifactId>alfresco-googledocs-share-community</artifactId>
            <version>${alfresco.googledocs.version}</version>
            <type>amp</type>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-resources</id>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/licenses</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>../licenses</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>unpack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.alfresco</groupId>
                                    <artifactId>share</artifactId>
                                    <version>${project.version}</version>
                                    <type>war</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/war/share</outputDirectory>
                                    <destFileName>share.war</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.alfresco</groupId>
                                    <artifactId>alfresco-mmt</artifactId>
                                    <version>${dependency.alfresco-mmt.version}</version>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/alfresco-mmt</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.alfresco.integrations</groupId>
                                    <artifactId>alfresco-googledocs-share-community</artifactId>
                                    <version>${alfresco.googledocs.version}</version>
                                    <type>amp</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/amps_share</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>fabric8-maven-plugin</artifactId>
                    <configuration>
                        <verbose>true</verbose>
                        <skipBuildPom>false</skipBuildPom>
                        <images>
                            <!-- Default image configuration - used by the *local* and *intenal* profiles -->
                            <image>
                                <name>${image.name}:${image.tag}</name>
                                <registry>${image.registry}</registry>
                                <build>
                                    <dockerFileDir>${project.basedir}</dockerFileDir>
                                </build>
                            </image>
                        </images>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>local</id>
            <!-- Builds local image for development & testing only -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>fabric8-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build-image</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>internal</id>
            <!-- Builds and publishes image to Quay -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>fabric8-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>build-push-image</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>build</goal>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>release</id>
            <!-- Builds and publishes release image to Quay -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>fabric8-maven-plugin</artifactId>
                        <configuration combine.self="override">
                            <verbose>true</verbose>
                            <skipBuildPom>false</skipBuildPom>
                            <images>
                                <image>
                                    <name>${image.name}:${project.version}</name>
                                    <registry>${image.registry}</registry>
                                    <build>
                                        <dockerFileDir>${project.basedir}</dockerFileDir>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>build-push-image</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>build</goal>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>