/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.opencord.gradle.rules.*
import org.yaml.snakeyaml.Yaml

allprojects {
    apply plugin: 'base'
    apply plugin: 'de.gesellix.docker'
    //apply plugin: 'com.tmiyamon.config'

    docker {
        // dockerHost = System.env.DOCKER_HOST ?: 'unix:///var/run/docker.sock'
        // dockerHost = System.env.DOCKER_HOST ?: 'https://192.168.99.100:2376'
        // certPath = System.getProperty('docker.cert.path') ?: "${System.getProperty('user.home')}/.docker/machine/machines/default"
        // authConfigPlain = [
        //   "username"       : "joe",
        //   "password"       : "some-pw-as-needed",
        //   "email"          : "joe@acme.com",
        //   "serveraddress"  : "https://index.docker.io/v1/"
        //  ]
    }
}

ext {

    appVersion = null

    // Upstream registry to simplify filling out the comps table below
    upstreamReg = project.hasProperty('upstreamReg') ? project.getProperty('upstreamReg') : 'docker.io'

    // Target registry to be used to publish docker images needed for deployment
    targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000'

    // The tag used to tag the docker images push to the target registry
    targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate'

    comps = [
            'aaa' : [
                    'type':     'gitmodule',
                    'upstream': 'https://gerrit.opencord.org/aaa',
                    'branch' : 'master',
                    'tag' : appVersion,
                    'componentDir': './apps/aaa'
            ],
            'vtn' : [
                    'type':     'gitmodule',
                    'upstream': 'https://gerrit.opencord.org/vtn',
                    'branch' : 'master',
                    'tag' : appVersion,
                    'componentDir': './apps/vtn'
            ],
            'mcast' : [
                    'type':     'gitmodule',
                    'upstream': 'https://gerrit.opencord.org/mcast',
                    'branch' : 'master',
                    'tag' : appVersion,
                    'componentDir': './apps/mcast'
            ],
            'igmp' : [
                    'type':     'gitmodule',
                    'upstream': 'https://gerrit.opencord.org/igmp',
                    'branch' : 'master',
                    'tag' : appVersion,
                    'componentDir': './apps/igmp'
            ],
            'olt' : [
                    'type':     'gitmodule',
                    'upstream': 'https://gerrit.opencord.org/olt',
                    'branch' : 'master',
                    'tag' : appVersion,
                    'componentDir': './apps/olt'
            ],
            'config' : [
                    'type':     'gitmodule',
                    'upstream': 'https://gerrit.opencord.org/config',
                    'branch' : 'master',
                    'tag' : appVersion,
                    'componentDir': './apps/config'
            ]
    ]
}


task fetchGitSubmodules {
    comps.each { name, spec -> if (spec.type == 'gitmodule') { dependsOn "gitupdate" + name } }
}

task buildOnosApps (type: Exec) {
    workingDir './apps'
    commandLine 'mvn', 'clean', 'install'
}

task copyLocalRepo (dependsOn: buildOnosApps, type: Exec) {
    workingDir './'
    commandLine 'cp', '-R', System.env.HOME + '/.m2/repository', 'repository'
}

task buildRepoImage (dependsOn: copyLocalRepo, type: Exec) {
    commandLine 'docker', 'build', '-t', 'cordproject/mavenrepo', '.'
}

task tagMavenRepoImage (type: Exec) {
    commandLine 'docker', 'tag', 'cordproject/mavenrepo', "$targetReg/mavenrepo:$targetTag"
}

task publishMavenRepoImage (type: Exec) {
    dependsOn tagMavenRepoImage
    commandLine 'docker', 'push', "$targetReg/mavenrepo:$targetTag"
}

// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~

task fetch {
    dependsOn fetchGitSubmodules
}

task buildImages (dependsOn: fetch) {
    dependsOn buildOnosApps
    dependsOn copyLocalRepo
    dependsOn buildRepoImage
}

task publish {
    dependsOn publishMavenRepoImage
}

// Depending on the version of the apps this will either make a release or publish a snapshot
task release (type: Exec) {
    workingDir './apps'
    commandLine 'mvn', 'clean', 'deploy'
}

tasks.addRule(new GitSubmoduleUpdateRule(project))
