forked from ConnorWGarvey/gradle-grails-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
279 lines (253 loc) · 8.33 KB
/
build.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
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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(
'org.apache.commons:commons-lang3:3.1',
'org.apache.commons:commons-vfs2:2.0',
)
}
}
import org.apache.commons.lang3.SystemUtils
import org.apache.commons.vfs2.FileObject
import org.apache.commons.vfs2.FileSystemManager
import org.apache.commons.vfs2.Selectors
import org.apache.commons.vfs2.VFS
import org.gradle.plugins.signing.Sign
apply plugin: 'eclipse'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'signing'
group = 'com.connorgarvey.gradle'
version = '1.0.1.1'
description = 'A plugin for Gradle to build Grails projects'
repositories {
mavenCentral()
}
dependencies {
groovy localGroovy()
compile gradleApi()
compile(
'commons-io:commons-io:1.3.2',
'org.apache.commons:commons-compress:1.3',
'org.apache.commons:commons-lang3:3.1',
'org.apache.commons:commons-vfs2:2.0',
)
testCompile(
'org.spockframework:spock-core:0.6-groovy-1.8',
'org.gmock:gmock:0.8.2',
)
}
signing {
if (project.hasProperty('com.connorgarvey.sonatype.userName') &&
project.hasProperty('com.connorgarvey.sonatype.password')) {
sign configurations.archives
}
}
task writePom << {
pom {
project {
inceptionYear '2012'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("${buildDir}/libs/${project.name}-${project.version}.pom")
}
def pomConfig = {
name project.name
description project.description
packaging 'jar'
url 'http://connorwgarvey.github.com/gradle-grails-wrapper/'
inceptionYear '2012'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection 'scm:git:[email protected]:ConnorWGarvey/gradle-grails-wrapper.git'
developerConnection 'scm:git:[email protected]:ConnorWGarvey/gradle-grails-wrapper.git'
url '[email protected]:ConnorWGarvey/gradle-grails-wrapper.git'
}
developers {
developer {
id 'ConnorWGarvey'
name 'Connor Garvey'
email '[email protected]'
url 'http://www.connorgarvey.com'
organization 'Rearden Commerce'
organizationUrl 'http://www.reardencommerce.com'
roles {
role 'developer'
}
timezone '-6'
}
}
parent {
groupId 'org.sonatype.oss'
artifactId 'oss-parent'
version '7'
}
}
configure(install.repositories.mavenInstaller) {
pom.project pomConfig
}
uploadArchives {
if (project.hasProperty('com.connorgarvey.sonatype.userName') &&
project.hasProperty('com.connorgarvey.sonatype.password')) {
dependsOn << [signArchives]
repositories.mavenDeployer {
beforeDeployment { deployment ->
signPom(deployment)
for (signTask in project.tasks.withType(Sign)) {
for (signature in signTask.signatures) {
deployment.addArtifact(signature)
}
}
}
name = 'Maven Central Deployer'
configuration = configurations.archives
repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2') {
authentication(userName: project.'com.connorgarvey.sonatype.userName', password: project.'com.connorgarvey.sonatype.password')
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
authentication(userName: project.'com.connorgarvey.sonatype.userName', password: project.'com.connorgarvey.sonatype.password')
}
pom.project pomConfig
}
}
}
task sourceJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn:javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives jar, sourceJar, javadocJar
}
task integrationTest(dependsOn:[install], type:IntegrationTestTask) { }
task publishToGitHub(dependsOn:[clean, build, writePom]) << {
def sep = File.separator
File checkoutFolder = new File(project.buildDir.canonicalPath + sep + 'artifactPublish')
File checkoutProjectFolder = new File(checkoutFolder.canonicalPath + sep + 'gradle-grails-wrapper')
File checkoutRepositoryFolder = new File(checkoutProjectFolder.canonicalPath + sep + 'repo')
File checkoutPublishFolder = new File(checkoutRepositoryFolder.path + sep +
project.group.split('\\.').join(sep) + sep + project.name + sep + project.version)
assert checkoutFolder.deleteDir()
checkoutFolder.mkdirs()
exec {
commandLine('git', 'clone', '[email protected]:ConnorWGarvey/gradle-grails-wrapper.git', '-b',
'gh-pages')
workingDir checkoutFolder
}
assert checkoutRepositoryFolder.deleteDir()
checkoutPublishFolder.mkdirs()
copy {
from new File(project.buildDir.path + sep + 'libs')
into checkoutPublishFolder
}
exec {
commandLine 'git', 'add', '.'
workingDir checkoutProjectFolder
}
exec {
commandLine 'git', 'commit', '-m', "Released version ${project.version}"
workingDir checkoutProjectFolder
}
exec {
commandLine 'git', 'push'
workingDir checkoutProjectFolder
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.0'
}
class IntegrationTestTask extends DefaultTask {
private void appendOutput(InputStream inputStream, Appendable builder) {
String s = null
BufferedReader input = new BufferedReader(new InputStreamReader(inputStream))
while ((s = input.readLine()) != null) {
builder.append(s + '\n')
}
}
private void grailsClean(String gradle, String directory) {
project.exec {
commandLine = [gradle, '--stacktrace', 'grails-clean']
workingDir = directory
}
File target = new File(pathJoin('src', 'integrationTest', 'project', 'target'))
for (file in target.listFiles()) {
if (file.isDirectory()) file.deleteDir()
else file.delete()
}
assert !warExists()
}
private void grailsCleanBeforeEach(String gradle, String directory, List<Closure> actions) {
for (action in actions) {
grailsClean(gradle, directory)
action()
}
}
private void verifyGrailsWar() {
String directory = new File(pathJoin('src', 'integrationTest', 'project')).canonicalPath
String extension = SystemUtils.IS_OS_WINDOWS ? '.bat' : ''
String gradle = "${directory}${File.separator}gradlew${extension}"
grailsClean(gradle, directory)
project.exec {
commandLine = [gradle, '--stacktrace', 'grails-war']
workingDir = directory
}
assert warExists()
grailsClean(gradle, directory)
project.exec {
commandLine = [gradle, '--stacktrace', 'grails-war', '-Parg0="target/haldo"']
workingDir = directory
}
assert fileExists('src', 'integrationTest', 'project', 'target', 'haldo')
grailsClean(gradle, directory)
def stdout = new ByteArrayOutputStream()
project.exec {
commandLine = [gradle, '--stacktrace', 'grails-war', '-Pd0="grails.env=wat"']
workingDir = directory
standardOutput = stdout
}
assert stdout.toString().contains('Environment set to wat')
}
private String pathJoin(String... parts) {
Arrays.asList(parts).join(File.separator)
}
private vfsCopy(String originUri, String destinationUri) {
FileSystemManager manager = VFS.manager
FileObject origin = manager.resolveFile(originUri)
FileObject destination = manager.resolveFile(destinationUri)
destination.copyFrom(origin, Selectors.SELECT_ALL)
}
private vfsTypeCopy(String originPath, String originType, String destinationPath, String destinationType) {
originPath = new File(originPath).canonicalPath
destinationPath = new File(destinationPath).canonicalPath
vfsCopy("${originType}://${originPath}", "${destinationType}://${destinationPath}")
}
private boolean fileExists(String... path) {
File file = new File(pathJoin(path))
file.isFile()
}
private boolean warExists() {
fileExists('src', 'integrationTest', 'project', 'target', 'project-0.1.war')
}
@TaskAction
void integrationTest() {
verifyGrailsWar()
}
}