ZmtDeployPlugin.groovy 2.08 KB
Newer Older
1
2
3
4
5
package de.zmt.gradle;

import org.gradle.api.*

/*
6
 * Deploy plugin for simulations based on zmt.core
7
 * <p>
8
9
 * Adds 'deployZip' task for uploading to dochost. A CHANGES file is also
 * added containing git tags and their descriptions.
10
 */
11
public class ZmtDeployPlugin implements Plugin<Project> {
12
    private static final def CONFIGURE = {
13
        apply plugin: "org.hidetake.ssh"
14
    
15
16
17
18
19
20
21
22
        remotes {
            dochost {
                host = determineCredentials.host
                knownHosts = allowAnyHosts
                user = credentials.dochostUser
                password = credentials.dochostPw
            }
        }
23
    
24
        task('deployZip') {
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
            group = 'Upload'
            description = 'Uploads zip distribution to dochost.'
            dependsOn distZip, determineCredentials
        }

        deployZip.doLast {
            println "\nConnecting to ${remotes.dochost.host}..."
            ssh.run {
                session(remotes.dochost) {
                    def remoteTargetDir = determineCredentials.wwwPath + 'dist'
                    
                    // create target directory on remote
                    execute "mkdir -p ${remoteTargetDir}"
                    
                    put from: distZip.archivePath, into: remoteTargetDir
                    // create CHANGES file from git version list
41
                    put text: obtainVersionListFromGit(project), into: remoteTargetDir + '/CHANGES'
42
43
44
45
46
47
48
49
50
                }
            }
        }
    }
    
    private static String obtainVersionListFromGit(Project project) {
        def output = new ByteArrayOutputStream()
        
        try {
51
            project.exec {
52
53
54
55
56
57
                commandLine 'git', 'tag', '-n99'
                standardOutput = output
            }
        }
        catch (org.gradle.process.internal.ExecException e) {
            println "git tag for ${project.name} failed. Cannot obtain version list."
58
            return ''
59
60
61
62
63
64
65
66
67
        }
        return output.toString().trim()
    }

    @Override
    void apply(Project project) {
        project.configure(project, CONFIGURE)
    }
}