forked from midonet/midonet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpm.gradle
169 lines (138 loc) · 4 KB
/
fpm.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Derived from gradle-fpm-plugin at https://github.com/kenshoo/gradle-fpm-plugin
*
* Copyright 2012 Kenshoo.com
*
* 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.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
apply plugin: PackagingPlugin
class PackagingPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.ext.pkgDestDir = "${project.buildDir}/TMPINST"
project.extensions.create('packaging', PackagingPluginExtension)
project.packaging.packageDir = new File(project.buildDir, "/packages")
project.task('debian', group: 'Build', type: DebianTask)
project.task('rpm', group: 'Build', type: RpmTask)
project.task('tar', group: 'Build', type: TarTask)
project.task('cleanPkg', group: 'Build', type: Delete) {
delete "${project.pkgDestDir}"
}
}
}
class PackagingPluginExtension {
@Input
def version
@Input
def iteration
@Input
def maintainer
@Input
def vendor
@Input
def url
@Input
def description
@Input
def dependencies = []
@Input
def prefix
@OutputDirectory
def packageDir
@Input
def fpmOpts = []
@Input
def confFiles = []
}
class DebianTask extends PackagingTask {
DebianTask(){
super('deb')
}
}
class RpmTask extends PackagingTask {
RpmTask(){
super('rpm')
}
}
class TarTask extends PackagingTask {
TarTask(){
super('tar')
}
def getArgs() {
def version = project.version
if (conf.version)
version = conf.version
def name = "${project.name}-"+version
def compress_ext = ".tar.gz"
["-t", this.type, "-s", "dir", "-n", name,
"-p", name+compress_ext, "-C", project.ext.pkgDestDir]
}
}
class PackagingTask extends DefaultTask {
def conf
def type
PackagingTask(String type_){
type = type_
}
@TaskAction
pkg() {
conf = project.packaging
def outDir = conf.packageDir
if (!outDir.exists())
outDir.mkdirs()
def fpmArgs = getArgs()
logger.info('running fpm with: ' + fpmArgs)
project.exec {
commandLine 'fpm'
args fpmArgs
workingDir outDir.getAbsolutePath()
}
}
def getArgs() {
def version = project.version
if (conf.version)
version = conf.version
def fpmArgs = ["-t", this.type, "-s", "dir", "-n", "${project.name}",
"-v", version, "-C", project.ext.pkgDestDir]
if (conf.prefix)
fpmArgs.addAll(["--prefix", prefix])
if (conf.description)
fpmArgs.addAll(["--description", conf.description])
if (conf.vendor)
fpmArgs.addAll(["--vendor", conf.vendor])
if (conf.iteration)
fpmArgs.addAll(["--iteration", conf.iteration])
if (conf.maintainer)
fpmArgs.addAll(["--maintainer", conf.maintainer])
if (conf.url)
fpmArgs.addAll(["--url", conf.url])
conf.dependencies.each() {
fpmArgs << "-d"
fpmArgs << it
}
conf.confFiles.each() {
fpmArgs << "--config-files"
fpmArgs << it
}
if (conf.fpmOpts)
fpmArgs.addAll(conf.fpmOpts)
fpmArgs << "."
fpmArgs
}
}