forked from abayer/gradle-hpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 50
/
JpiExtension.groovy
346 lines (282 loc) · 9.03 KB
/
JpiExtension.groovy
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
* Copyright 2011 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.
*/
package org.jenkinsci.gradle.plugins.jpi
import hudson.util.VersionNumber
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.DependencySet
import org.gradle.api.model.ReplacedBy
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.SourceSet
import org.gradle.util.ConfigureUtil
import org.jenkinsci.gradle.plugins.jpi.internal.DependencyLookup
/**
* This gets exposed to the project as 'jpi' to offer additional convenience methods.
*
* @author Kohsuke Kawaguchi
* @author Andrew Bayer
*/
class JpiExtension {
final Project project
@Deprecated
Map<String, String> jenkinsWarCoordinates
final Property<String> jenkinsVersion
JpiExtension(Project project) {
this.project = project
this.jenkinsVersion = project.objects.property(String)
}
private String shortName
/**
* Short name of the plugin is the ID that uniquely identifies a plugin.
* If unspecified, we use the project name except the trailing "-plugin"
*/
String getShortName() {
shortName ?: trimOffPluginSuffix(project.name)
}
void setShortName(String shortName) {
this.shortName = shortName
}
private static String trimOffPluginSuffix(String s) {
s.endsWith('-plugin') ? s[0..-8] : s
}
private String fileExtension
/**
* File extension for plugin archives.
*/
String getFileExtension() {
fileExtension ?: 'hpi'
}
void setFileExtension(String s) {
this.fileExtension = s
}
private String displayName
/**
* One-line display name of this plugin. Should be human readable.
* For example, "Git plugin", "Acme Executor plugin", etc.
*/
@SuppressWarnings('UnnecessaryGetter')
String getDisplayName() {
displayName ?: getShortName()
}
void setDisplayName(String s) {
this.displayName = s
}
/**
* URL that points to the home page of this plugin.
*/
String url
/**
* TODO: document
*/
String compatibleSinceVersion
/**
* TODO: document
*/
boolean sandboxStatus
/**
* TODO: document
*/
String maskClasses
boolean pluginFirstClassLoader
/**
* Version of core that we depend on.
*/
@Deprecated
@ReplacedBy('jenkinsVersion')
private String coreVersion
@Deprecated
@ReplacedBy('jenkinsVersion')
String getCoreVersion() {
coreVersion
}
@Deprecated
@ReplacedBy('jenkinsVersion')
void setCoreVersion(String v) {
jenkinsVersion.convention(v)
this.coreVersion = v
if (new VersionNumber(this.coreVersion) <= new VersionNumber('1.419.99')) {
throw new GradleException('The gradle-jpi-plugin requires Jenkins 1.420 or later')
}
if (new VersionNumber(this.coreVersion) < new VersionNumber('1.598')) {
Delete clean = project.tasks.clean as Delete
clean.delete('target')
}
if (this.coreVersion) {
jenkinsWarCoordinates = [group: 'org.jenkins-ci.main', name: 'jenkins-war', version: v]
def lookup = new DependencyLookup()
for (String config : lookup.configurations()) {
def toAdd = lookup.find(config, coreVersion).collect {
project.dependencies.create(it) { Dependency d ->
d.because('Added by org.jenkins-ci.jpi plugin')
}
}
project.configurations.getByName(config) { Configuration c ->
c.withDependencies { DependencySet deps ->
deps.addAll(toAdd)
}
}
}
}
}
private Object localizerOutputDir
/**
* Sets the localizer output directory
*/
void setLocalizerOutputDir(Object localizerOutputDir) {
this.localizerOutputDir = localizerOutputDir
}
/**
* Returns the localizer output directory.
*/
File getLocalizerOutputDir() {
project.file(localizerOutputDir ?: "${project.buildDir}/generated-src/localizer")
}
private File workDir
File getWorkDir() {
workDir ?: new File(project.projectDir, 'work')
}
/**
* Work directory to run Jenkins.war with.
*/
void setWorkDir(File workDir) {
this.workDir = workDir
}
private String repoUrl
/**
* The URL for the Maven repository to deploy the built plugin to.
*/
String getRepoUrl() {
if (System.properties.containsKey('jpi.repoUrl')) {
return System.properties['jpi.repoUrl']
}
repoUrl ?: 'https://repo.jenkins-ci.org/releases'
}
void setRepoUrl(String repoUrl) {
this.repoUrl = repoUrl
}
private String snapshotRepoUrl
/**
* The URL for the Maven snapshot repository to deploy the built plugin to.
*/
String getSnapshotRepoUrl() {
if (System.properties.containsKey('jpi.snapshotRepoUrl')) {
return System.properties['jpi.snapshotRepoUrl']
}
snapshotRepoUrl ?: 'https://repo.jenkins-ci.org/snapshots'
}
void setSnapshotRepoUrl(String snapshotRepoUrl) {
this.snapshotRepoUrl = snapshotRepoUrl
}
/**
* The GitHub URL. Optional. Used to construct the SCM section of the POM.
*/
String gitHubUrl
/**
* The license for the plugin. Optional.
*/
Licenses licenses = new Licenses()
def licenses(Closure closure) {
ConfigureUtil.configure(closure, licenses)
}
/**
* If true, the automatic test injection will be skipped.
*
* Disabled by default because of <a href="https://issues.jenkins-ci.org/browse/JENKINS-21977">JENKINS-21977</a>.
*/
boolean disabledTestInjection = true
/**
* Name of the injected test.
*/
String injectedTestName = 'InjectedTest'
/**
* If true, verify that all the jelly scripts have the Jelly XSS PI in them.
*/
boolean requirePI = true
/**
* Set to false to disable configuration of Maven Central, the local Maven cache and the Jenkins Maven repository.
*/
boolean configureRepositories = true
/**
* If false, no publications or repositories for the Maven Publishing plugin will be configured.
*/
boolean configurePublishing = true
Developers developers = new Developers()
def developers(Closure closure) {
ConfigureUtil.configure(closure, developers)
}
SourceSet mainSourceTree() {
project.convention.getPlugin(JavaPluginConvention).sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
}
SourceSet testSourceTree() {
project.convention.getPlugin(JavaPluginConvention).sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME)
}
class Developers {
def developerMap = [:]
def getProperty(String id) {
developerMap[id]
}
void setProperty(String id, val) {
developerMap[id] = val
}
def developer(Closure closure) {
def developer = new JpiDeveloper(JpiExtension.this.project.logger)
developer.configure(closure)
setProperty(developer.id, developer)
}
def each(Closure closure) {
developerMap.values().each(closure)
}
def collect(Closure closure) {
developerMap.values().collect(closure)
}
def getProperties() {
developerMap
}
boolean isEmpty() {
developerMap.isEmpty()
}
}
class Licenses {
def licenseMap = [:]
def getProperty(String name) {
licenseMap[name]
}
void setProperty(String name, val) {
licenseMap[name] = val
}
def license(Closure closure) {
def license = new JpiLicense(JpiExtension.this.project.logger)
license.configure(closure)
setProperty(license.name, license)
}
def each(Closure closure) {
licenseMap.values().each(closure)
}
def collect(Closure closure) {
licenseMap.values().collect(closure)
}
def getProperties() {
licenseMap
}
boolean isEmpty() {
licenseMap.isEmpty()
}
}
}