forked from googleapis/gapic-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
363 lines (315 loc) · 9.58 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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
// Build Script
// ============
import groovy.io.FileType
buildscript {
repositories {
mavenLocal()
maven {
// For 0.7.2-SNAPSHOT of protobuf gradle plugin. This should be removed once
// this version is releaed.
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.2-SNAPSHOT'
}
}
apply plugin: "java"
apply plugin: "maven"
apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "com.google.protobuf"
sourceCompatibility = 1.7
group = "com.google.api"
version = "0.0.0-SNAPSHOT"
// url to the snapshot repository of a private maven repo.
def privateSnapshotRepo = "http://104.197.230.53:8081/nexus/content/repositories/snapshots/"
// Dependencies
// ------------
ext {
// Shortcuts for libraries we are using
libraries = [
// General
guava: 'com.google.guava:guava:19.0',
jsr305: 'com.google.code.findbugs:jsr305:3.0.0',
autovalue: 'com.google.auto.value:auto-value:1.1',
cglib: 'cglib:cglib:3.1',
guice: 'com.google.inject:guice:4.0',
commonsLang: 'org.apache.commons:commons-lang3:3.4',
commonsCli: 'commons-cli:commons-cli:1.3',
snakeyaml: 'org.yaml:snakeyaml:1.16',
gax: 'com.google.api:gax:0.0.8',
// Gapi
// TODO(cbao): Use released version instead of snapshot.
toolsFx: 'io.gapi:gapi-tools-framework:0.0.0-SNAPSHOT',
// Testing
junit: 'junit:junit:4.11',
mockito: 'org.mockito:mockito-core:1.10.19',
truth: 'com.google.truth:truth:0.27',
toolsFxTesting: 'io.gapi:gapi-tools-framework:0.0.0-SNAPSHOT:testing',
// Protobuf
protobuf: 'com.google.protobuf:protobuf-java:3.0.0-beta-1',
protoc: 'com.google.protobuf:protoc:3.0.0-beta-1',
protobufGradlePlugin: 'com.google.protobuf:protobuf-gradle-plugin:0.7.2-SNAPSHOT',
// JSON
jackson: 'com.fasterxml.jackson.core:jackson-databind:2.7.0',
// Formatter
javaFomatter: 'com.google.googlejavaformat:google-java-format:0.1-alpha'
]
}
repositories {
mavenCentral()
maven {
// For 0.7.2-SNAPSHOT of protobuf gradle plugin. This should be removed once
// this version is releaed.
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
maven {
// Private maven repo.
url privateSnapshotRepo
}
mavenLocal()
}
dependencies {
compile libraries.guava,
libraries.autovalue,
libraries.cglib,
libraries.commonsCli,
libraries.commonsLang,
libraries.gax,
libraries.guice,
libraries.jackson,
libraries.javaFomatter,
libraries.jsr305,
libraries.protobuf,
libraries.snakeyaml,
libraries.toolsFx,
libraries.toolsFxTesting
testCompile libraries.junit,
libraries.mockito,
libraries.truth,
libraries.toolsFxTesting
}
// Source jar
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
// Protobuf
// --------
sourceSets {
main {
proto {
// Include proto sources for GAPIC generator config.
srcDir "src/main/proto"
}
java {
// Include location where proto plugin puts generated sources.
srcDir "${buildDir}/generated/source/proto/main/java"
}
}
}
protobuf {
protoc {
artifact = libraries.protoc
}
}
// Test data
// ---------
sourceSets {
test {
resources {
// Include all resources from testdata folders.
srcDir 'src/test/java'
include '**/testdata/**'
}
resources {
// Include protos of core platform and toolkit,
// as some tests depend on this.
srcDir 'src/main/proto'
srcDir "${projectDir}/../../googleapis/src/core"
include '**/*.proto'
}
}
}
task setupProtocEnvironment << {
test.setEnvironment(PROTOC_COMPILER: project.protobuf.tools.protoc.path)
}
test.dependsOn setupProtocEnvironment
task showRuntimeClassPath << {
println sourceSets.main.runtimeClasspath.asPath
}
// Test Logging
// ============
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
// Eclipse Annotation Processing
// -----------------------------
// TODO(wrwg): figure whether there is direct support for this in eclipse plugin,
// and use that instead.
ext {
eclipseAptFolder = '.apt_generated'
eclipseSettingsDir = file('.settings')
}
configurations {
codeGeneration
}
dependencies {
codeGeneration libraries.autovalue, libraries.jsr305
compile libraries.autovalue, libraries.jsr305
}
compileJava.classpath += configurations.codeGeneration
eclipse {
jdt.file.withProperties {
it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled'
}
}
tasks.eclipseJdt {
doFirst {
def aptPrefs =
file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs")
aptPrefs.parentFile.mkdirs()
aptPrefs.text = """\
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=${eclipseAptFolder}
org.eclipse.jdt.apt.reconcileEnabled=true
""".stripIndent()
file('.factorypath').withWriter {
new groovy.xml.MarkupBuilder(it).'factorypath' {
project.configurations.codeGeneration.each { dep->
factorypathentry(
kind:'EXTJAR',
id:dep.absolutePath,
enabled:true,
runInBatchMode:false)
}
}
}
}
}
tasks.cleanEclipseJdt {
doFirst {
delete file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs"),
file('.factorypath')
}
}
if (project.hasProperty('privateOssrhUsername') && project.hasProperty('privateOssrhPassword')) {
uploadArchives {
repositories {
mavenDeployer {
snapshotRepository(url: privateSnapshotRepo) {
authentication(userName: privateOssrhUsername, password: privateOssrhPassword)
}
pom.project {
name 'Gapi Tools'
packaging 'jar'
description 'Google API tools frameworks.'
url 'http://www.googleapis.com'
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
}
}
}
}
} else {
logger.warn("The uploadArchives task was skipped. The privateOssrhUsername "
+ "and privateOssrhPassword properties need to be set correctly in "
+ "your ~/.gradle/gradle.properties file in order to upload archives.")
}
// Task to run CodeGeneratorTool
// =============================
//
// Command line args can be passed to the tool as a comma-separated list:
// ./gradlew runVGen '-Pclargs=--arg1=val1,--arg2=val2,--arg3=val3'
task runVGen(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.google.api.codegen.CodeGeneratorTool'
if (project.hasProperty('clargs')) {
args = clargs.split(',').toList()
}
}
// Task to run SynchronizerTool
// =============================
//
// Command line args can be passed to the tool as a comma-separated list:
// ./gradlew runSynchronizer '-Pclargs=--arg1=val1,--arg2=val2,--arg3=val3'
task runSynchronizer(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.google.api.codegen.SynchronizerTool'
if (project.hasProperty('clargs')) {
args = clargs.split(',').toList()
}
}
// Task to display the cache path of GRPC Java plugin
task showGrpcJavaPluginPath << {
DependencyResolver resolver = new DependencyResolver(project)
println 'output: ' + resolver.resolveExecutable(
'io.grpc:protoc-gen-grpc-java:0.12.0')
}
// Task to display the cache path of protobuf
task showProtobufPath() << {
DependencyResolver resolver = new DependencyResolver(project)
println 'output: ' + resolver.extractArchive(
'com.google.protobuf:protobuf-java:3.0.0-beta-1');
}
// Task to display the cache path of Google Java formatter
task showJavaFormatterPath << {
DependencyResolver resolver = new DependencyResolver(project)
println 'output: ' + resolver.locateArchive(
'com.google.googlejavaformat:google-java-format:0.1-alpha')
}
// Task to run ConfigGeneratorTool
// =============================
//
// Command line args can be passed to the tool as a comma-separated list:
// ./gradlew runConfigGen '-Pclargs=--arg1=val1,--arg2=val2,--arg3=val3'
task runConfigGen(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.google.api.codegen.config.ConfigGeneratorTool'
if (project.hasProperty('clargs')) {
args = clargs.split(',').toList()
}
}
// Task to run DiscoveryFragmentGeneratorTool
// =================================================================
task runDiscoGen(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.google.api.codegen.DiscoveryFragmentGeneratorTool'
if (project.hasProperty('clargs')) {
args = clargs.split(',').toList()
}
}
task runDiscoBatch(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'com.google.api.codegen.DiscoveryFragmentGeneratorBatch'
if (project.hasProperty('clargs')) {
args = clargs.split(',').toList()
}
}
task verifyLicense << {
def licenseText = new File(rootProject.rootDir, 'license-header-javadoc.txt').text
def srcFiles = []
sourceSets
.collectMany{it.allJava.getSrcDirs()}
.each{it.eachFileRecurse(FileType.FILES, {srcFiles << it})}
srcFiles = srcFiles
.findAll{!it.path.contains("/generated/") && it.path.endsWith(".java")}
.findAll{!it.text.startsWith(licenseText)}
if (srcFiles.asList().size() > 0) {
srcFiles.each({println 'missing license: ' + it})
throw new IllegalStateException("Above files do not have licenses")
}
}
test.dependsOn verifyLicense