-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
180 lines (153 loc) · 5.23 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
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1'
classpath "com.bmuschko:gradle-docker-plugin:3.0.4"
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'com.bmuschko.docker-remote-api'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'checkstyle'
apply from: "$rootDir/gradle/additional-artifacts.gradle"
apply from: "$rootDir/gradle/dependencies.gradle"
apply from: "$rootDir/gradle/documentation.gradle"
apply from: "$rootDir/gradle/publishing.gradle"
apply from: "$rootDir/gradle/release.gradle"
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile ('org.apache.jclouds:jclouds-core:2.0.0')
compile ('org.apache.jclouds.driver:jclouds-okhttp:2.0.0')
compile ('com.google.auto.service:auto-service:1.0-rc2')
compile ('com.google.auto.value:auto-value:1.2')
testCompile ('org.apache.jclouds:jclouds-core:2.0.0:tests')
testCompile ('org.testng:testng:6.8.21')
testCompile ('org.assertj:assertj-core:1.7.0')
testCompile ('com.squareup.okhttp:mockwebserver:2.2.0')
testCompile ('org.apache.jclouds.driver:jclouds-slf4j:2.0.0')
testCompile ('ch.qos.logback:logback-core:1.1.2')
testCompile ('ch.qos.logback:logback-classic:1.1.2')
}
ext.compatibilityVersion = '1.7'
sourceCompatibility = compatibilityVersion
targetCompatibility = compatibilityVersion
jar {
manifest {
attributes 'Implementation-Title': 'Etcd REST client',
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion
}
}
checkstyle {
toolVersion = "6.13"
}
tasks.withType(JavaCompile) {
options.compilerArgs += ["-Xlint:-options"]
}
tasks.withType(Test) {
testLogging {
showStandardStreams = true
events 'started', 'passed', 'failed'
}
}
task mockTest(type: Test) {
useTestNG()
include "**/*MockTest.class"
}
task integTest(type: Test, dependsOn: ['mockTest']) {
useTestNG()
include "**/**LiveTest.class"
doFirst {
String runtimeURL = bootstrapDocker ? "http://${getLocalHost()}:2379" : "${testEtcdEndpoint}"
systemProperties = ["test.etcd.endpoint" : runtimeURL]
}
}
if (bootstrapDocker) {
def integTestTask = project.tasks.getByName('integTest')
integTestTask.dependsOn('startNode')
integTestTask.finalizedBy('teardownNode')
}
docker {
url = testDockerEndpoint
}
ext.etcdContainerName = "etcd-integ-test"
task inspectNode(type: com.bmuschko.gradle.docker.tasks.container.DockerInspectContainer) {
targetContainerId { etcdContainerName }
}
task pullEtcdImage(type: com.bmuschko.gradle.docker.tasks.image.DockerPullImage) {
repository = testEtcdImage
tag = testEtcdTag
}
task stopNode(type: com.bmuschko.gradle.docker.tasks.container.DockerStopContainer) {
onlyIf { checkNode() }
dependsOn pullEtcdImage
targetContainerId { etcdContainerName }
timeout = 30
}
task removeNode(type: com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer) {
onlyIf { checkNode() }
dependsOn stopNode
targetContainerId { etcdContainerName }
removeVolumes = true
force = true
}
task createNode(type: com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer) {
dependsOn removeNode
targetImageId { pullEtcdImage.repository + ":" + pullEtcdImage.tag }
containerName = etcdContainerName
portBindings = ['2379:2379', '2380:2380']
binds = ['/usr/share/ca-certificates/' : '/etc/ssl/certs']
cmd = ['-name', 'etcd0',
'-advertise-client-urls', "http://${getLocalHost()}:2379",
'-listen-client-urls', 'http://0.0.0.0:2379',
'-initial-advertise-peer-urls', "http://${getLocalHost()}:2380",
'-listen-peer-urls', 'http://0.0.0.0:2380',
'-initial-cluster-token', 'etcd-cluster-1',
'-initial-cluster', "etcd0=http://${getLocalHost()}:2380",
'-initial-cluster-state', 'new']
}
task startNode(type: com.bmuschko.gradle.docker.tasks.container.DockerStartContainer) {
dependsOn createNode
targetContainerId { createNode.getContainerId() }
doLast {
logger.quiet "Sleeping for 5 seconds to allow cluster to init..."
sleep(5000)
}
}
task postTestStopNode(type: com.bmuschko.gradle.docker.tasks.container.DockerStopContainer) {
targetContainerId { etcdContainerName }
timeout = 30
}
task teardownNode(type: com.bmuschko.gradle.docker.tasks.container.DockerRemoveContainer) {
dependsOn postTestStopNode
targetContainerId { etcdContainerName }
removeVolumes = true
force = true
}
public boolean checkNode() {
boolean containerFound = false
try {
def inspect = project.tasks.getByName("inspectNode")
inspect.execute()
containerFound = true
} catch (Exception e) {
// println e.message
}
containerFound
}
public String getLocalHost() {
InetAddress.getLocalHost().getHostAddress()
}