<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>com.danhaywood.mavenmixin</groupId>
    <artifactId>docker</artifactId>
    <version>0.0.3</version>

    <packaging>pom</packaging>
    
    <name>${project.groupId}:${project.artifactId}</name>
    <description>
        Maven mixin providing the ability to build, tag and deploy Docker images
    </description>
    
    <url>https://github.com/danhaywood/java-mavenmixin-docker</url>
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <scm>
        <connection>scm:git:git@github.com:danhaywood/java-mavenmixin-docker.git</connection>
        <developerConnection>scm:git:git@github.com:danhaywood/java-mavenmixin-docker.git</developerConnection>
        <url>git@github.com:danhaywood/java-mavenmixin-docker.git</url>
    </scm>
    <developers>
        <developer>
            <id>danhaywood</id>
            <name>Dan Haywood</name>
            <email>dan@haywood-associates.co.uk</email>
        </developer>
    </developers>    

    <profiles>
        <profile>
            <id>mavenmixin-docker-install</id>
            <activation>
                <property>
                    <name>mavenmixin-docker</name>
                </property>
            </activation>

            <properties>
                <maven-deploy-plugin.version>2.8.1</maven-deploy-plugin.version>
                <docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
                <gmavenplus-plugin.version>1.5</gmavenplus-plugin.version>
                <groovy-all.version>2.4.7</groovy-all.version>

                <docker-plugin.imageName>XXX/${project.parent.artifactId}</docker-plugin.imageName>
                <docker-plugin.resource.include>${project.parent.artifactId}.war</docker-plugin.resource.include>
                <docker-plugin.releaseServerId>docker-hub</docker-plugin.releaseServerId>
                <docker-plugin.releaseRegistryUrl>https://index.docker.io/v1/</docker-plugin.releaseRegistryUrl>
                <docker-plugin.snapshotServerId>docker-hub</docker-plugin.snapshotServerId>
                <docker-plugin.snapshotRegistryUrl>https://index.docker.io/v1/</docker-plugin.snapshotRegistryUrl>
            </properties>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.gmavenplus</groupId>
                        <artifactId>gmavenplus-plugin</artifactId>
                        <version>${gmavenplus-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>infer-serverId-and-registryUrl</id>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <phase>initialize</phase>
                                <configuration>
                                    <scripts>
                                        <script><![CDATA[//
                                        project.properties['docker-plugin.serverId'] = project.version.endsWith('-SNAPSHOT') 
                                            ? project.properties['docker-plugin.snapshotServerId']
                                            : project.properties['docker-plugin.releaseServerId']
                                        project.properties['docker-plugin.registryUrl'] = project.version.endsWith('-SNAPSHOT') 
                                            ? project.properties['docker-plugin.snapshotRegistryUrl']
                                            : project.properties['docker-plugin.releaseRegistryUrl']
                                        project.properties['_docker-plugin.deployType'] = project.version.endsWith('-SNAPSHOT') 
                                            ? 'snapshot'
                                            : 'release'
                                        println ""
                                        println "deployType               : " + project.properties['_docker-plugin.deployType']
                                        println "docker-plugin.serverId   : " + project.properties['docker-plugin.serverId']
                                        println "docker-plugin.registryUrl: " + project.properties['docker-plugin.registryUrl']
                                        println ""
                                        ]]></script>
                                    </scripts>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                        <dependency>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-all</artifactId>
                            <version>${groovy-all.version}</version>
                            <scope>runtime</scope>
                            </dependency>
                        </dependencies>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>${maven-deploy-plugin.version}</version>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${docker-maven-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>build-image</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>tag-image</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>tag</goal>
                                </goals>
                                <configuration>
                                    <image>${docker-plugin.imageName}</image>
                                    <newName>${docker-plugin.imageName}:${project.version}</newName>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>${docker-plugin.imageName}</imageName>
                            <dockerDirectory>${build.outputDirectory}/docker</dockerDirectory>
                            <resources>
                                <resource>
                                    <targetPath>.</targetPath>
                                    <directory>${project.build.directory}</directory>
                                    <include>${docker-plugin.resource.include}</include>
                                </resource>
                            </resources>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.spotify</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${docker-maven-plugin.version}</version>
                        <executions>
                            <execution>
                                <id>push-image-tagged</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                                <configuration>
                                    <imageName>${docker-plugin.imageName}:${project.version}</imageName>
                                </configuration>
                            </execution>
                            <execution>
                                <id>push-image-latest</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                                <configuration>
                                    <imageName>${docker-plugin.imageName}:latest</imageName>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>${docker-plugin.imageName}</imageName>
                            <serverId>${docker-plugin.serverId}</serverId>
                            <registryUrl>${docker-plugin.registryUrl}</registryUrl>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>danhaywood-mavenmixin-sonatyperelease</id>
            <!-- 
            this profile is not part of the mixin, but is required to be defined as a profile
            in order to release this mixin pom.xml to Maven Central repo
            -->
            <build>
                <plugins>
                    <!-- http://central.sonatype.org/pages/apache-maven.html -->
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.2</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <!-- http://kohsuke.org/pgp-maven-plugin/secretkey.html instead of maven-gpg-plugin -->
                    <plugin>
                        <groupId>org.kohsuke</groupId>
                        <artifactId>pgp-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
            </distributionManagement>
        </profile>


    </profiles>


    
</project>
