Skip to content

Commit 80a0864

Browse files
committed
Fix indentation in Kotlin DSL test project buildscript, use 2 spaces instead of 4.
1 parent 44ae23c commit 80a0864

1 file changed

Lines changed: 93 additions & 88 deletions

File tree

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,121 @@
11
import com.google.protobuf.gradle.*
22

33
plugins {
4-
java
5-
idea
6-
id("com.google.protobuf")
4+
java
5+
idea
6+
id("com.google.protobuf")
77
}
88

99
repositories {
10-
maven("https://plugins.gradle.org/m2/")
10+
maven("https://plugins.gradle.org/m2/")
1111
}
1212

1313
java {
14-
sourceCompatibility = JavaVersion.VERSION_1_7
15-
targetCompatibility = JavaVersion.VERSION_1_7
14+
sourceCompatibility = JavaVersion.VERSION_1_7
15+
targetCompatibility = JavaVersion.VERSION_1_7
1616
}
1717

1818
val grpcCompile by configurations.creating
1919

2020
the<JavaPluginConvention>().sourceSets {
2121

22-
val grpc by creating {
23-
compileClasspath += grpcCompile
24-
}
22+
val grpc by creating {
23+
compileClasspath += grpcCompile
24+
}
2525

26-
"test"{
27-
compileClasspath += grpc.output
28-
runtimeClasspath += grpc.output
29-
}
26+
"test"{
27+
compileClasspath += grpc.output
28+
runtimeClasspath += grpc.output
29+
}
3030
}
3131

3232
val protobufDep = "com.google.protobuf:protobuf-java:3.0.0"
3333

3434
dependencies {
35-
protobuf(files("lib/protos.tar.gz"))
36-
protobuf(files("ext/"))
37-
testProtobuf(files("lib/protos-test.tar.gz"))
38-
39-
compile(protobufDep)
40-
testCompile("junit:junit:4.12")
41-
// KotlinFooTest.kt requires reflection utilities
42-
testCompile("org.jetbrains.kotlin:kotlin-reflect:1.2.0")
43-
grpcCompile(protobufDep)
44-
grpcCompile("io.grpc:grpc-stub:1.0.0-pre2")
45-
grpcCompile("io.grpc:grpc-protobuf:1.0.0-pre2")
35+
protobuf(files("lib/protos.tar.gz"))
36+
protobuf(files("ext/"))
37+
testProtobuf(files("lib/protos-test.tar.gz"))
38+
39+
compile(protobufDep)
40+
testCompile("junit:junit:4.12")
41+
// KotlinFooTest.kt requires reflection utilities
42+
testCompile("org.jetbrains.kotlin:kotlin-reflect:1.2.0")
43+
grpcCompile(protobufDep)
44+
grpcCompile("io.grpc:grpc-stub:1.0.0-pre2")
45+
grpcCompile("io.grpc:grpc-protobuf:1.0.0-pre2")
4646
}
4747

4848
protobuf {
49-
protoc {
50-
artifact = "com.google.protobuf:protoc:3.0.0"
49+
protoc {
50+
artifact = "com.google.protobuf:protoc:3.0.0"
51+
}
52+
plugins {
53+
id("grpc") {
54+
artifact = "io.grpc:protoc-gen-grpc-java:1.0.0-pre2"
5155
}
52-
plugins {
56+
}
57+
generateProtoTasks {
58+
ofSourceSet("grpc").forEach { task ->
59+
task.plugins {
5360
id("grpc") {
54-
artifact = "io.grpc:protoc-gen-grpc-java:1.0.0-pre2"
55-
}
56-
}
57-
generateProtoTasks {
58-
ofSourceSet("grpc").forEach { task ->
59-
task.plugins {
60-
id("grpc") {
61-
outputSubDir = "grpc_output"
62-
}
63-
}
64-
task.generateDescriptorSet = true
61+
outputSubDir = "grpc_output"
6562
}
63+
}
64+
task.generateDescriptorSet = true
6665
}
66+
}
6767
}
6868

6969
tasks {
7070

71-
"jar"(Jar::class) {
72-
sourceSets.forEach { sourceSet ->
73-
from(sourceSet.output)
71+
"jar"(Jar::class) {
72+
sourceSets.forEach { sourceSet ->
73+
from(sourceSet.output)
7474

75-
val compileTaskName = sourceSet.getCompileTaskName("java")
76-
dependsOn(project.tasks.getByName(compileTaskName))
77-
}
75+
val compileTaskName = sourceSet.getCompileTaskName("java")
76+
dependsOn(project.tasks.getByName(compileTaskName))
7877
}
78+
}
7979

80-
"test"{
80+
"test"{
8181

82-
doLast{
83-
val generateProtoTasks = project.protobuf.protobuf.generateProtoTasks
82+
doLast {
83+
val generateProtoTasks = project.protobuf.protobuf.generateProtoTasks
8484

85-
val generateProtoTaskNames = generateProtoTasks.all().map { it.name }.toSet()
86-
val generateProtoTaskNamesMain = generateProtoTasks.ofSourceSet("main").map { it.name }.toSet()
85+
val generateProtoTaskNames = generateProtoTasks.all().map { it.name }.toSet()
86+
val generateProtoTaskNamesMain =
87+
generateProtoTasks.ofSourceSet("main").map { it.name }.toSet()
8788

88-
assert(setOf("generateProto", "generateGrpcProto", "generateTestProto") == generateProtoTaskNames)
89-
assert(setOf("generateProto") == generateProtoTaskNamesMain)
89+
assert(setOf("generateProto",
90+
"generateGrpcProto",
91+
"generateTestProto") == generateProtoTaskNames)
92+
assert(setOf("generateProto") == generateProtoTaskNamesMain)
9093

91-
assertJavaCompileHasProtoGeneratedDir("main", listOf("java"))
92-
assertJavaCompileHasProtoGeneratedDir("test", listOf("java"))
93-
assertJavaCompileHasProtoGeneratedDir("grpc", listOf("java", "grpc_output"))
94+
assertJavaCompileHasProtoGeneratedDir("main", listOf("java"))
95+
assertJavaCompileHasProtoGeneratedDir("test", listOf("java"))
96+
assertJavaCompileHasProtoGeneratedDir("grpc", listOf("java", "grpc_output"))
9497

95-
listOf("main", "test").forEach { sourceSet ->
96-
assertFileExists(false, "$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc")
97-
}
98-
assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc")
99-
}
98+
listOf("main", "test").forEach { sourceSet ->
99+
assertFileExists(false,
100+
"$buildDir/generated/source/proto/$sourceSet/descriptor_set.desc")
101+
}
102+
assertFileExists(true, "$buildDir/generated/source/proto/grpc/descriptor_set.desc")
100103
}
104+
}
101105
}
102106

103107
fun assertJavaCompileHasProtoGeneratedDir(sourceSet: String, codegenPlugins: Collection<String>) {
104-
val compileJavaTask = tasks.getByName(sourceSets.getByName(sourceSet).getCompileTaskName("java")) as JavaCompile
105-
assertJavaCompileHasProtoGeneratedDir(project, sourceSet, compileJavaTask, codegenPlugins)
108+
val compileJavaTask =
109+
tasks.getByName(sourceSets.getByName(sourceSet).getCompileTaskName("java")) as JavaCompile
110+
assertJavaCompileHasProtoGeneratedDir(project, sourceSet, compileJavaTask, codegenPlugins)
106111
}
107112

108113
fun assertFileExists(exists: Boolean, path: String) {
109-
if (exists) {
110-
assert(File(path).exists())
111-
} else {
112-
assert(!File(path).exists())
113-
}
114+
if (exists) {
115+
assert(File(path).exists())
116+
} else {
117+
assert(!File(path).exists())
118+
}
114119
}
115120

116121
fun assertJavaCompileHasProtoGeneratedDir(
@@ -119,28 +124,28 @@ fun assertJavaCompileHasProtoGeneratedDir(
119124
compileJavaTask: JavaCompile,
120125
codegenPlugins: Collection<String>
121126
) {
122-
val baseDir = File("${project.buildDir}/generated/source/proto/$sourceSet")
123-
// The expected direct subdirectories under baseDir
124-
val expectedDirs = codegenPlugins.map { codegenPlugin ->
125-
File("${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin")
126-
}.toSet()
127-
128-
val actualDirs = mutableSetOf<File>()
129-
compileJavaTask.source.visit {
130-
131-
// If the visited file is or is under a direct subdirectory of baseDir, add
132-
// that subdirectory to actualDirs.
133-
var file = this@visit.file
134-
while (true) {
135-
if (file.parentFile == baseDir) {
136-
actualDirs.add(file)
137-
}
138-
if (file.parentFile == null) {
139-
break
140-
}
141-
file = file.parentFile
142-
}
127+
val baseDir = File("${project.buildDir}/generated/source/proto/$sourceSet")
128+
// The expected direct subdirectories under baseDir
129+
val expectedDirs = codegenPlugins.map { codegenPlugin ->
130+
File("${project.buildDir}/generated/source/proto/$sourceSet/$codegenPlugin")
131+
}.toSet()
132+
133+
val actualDirs = mutableSetOf<File>()
134+
compileJavaTask.source.visit {
135+
136+
// If the visited file is or is under a direct subdirectory of baseDir, add
137+
// that subdirectory to actualDirs.
138+
var file = this@visit.file
139+
while (true) {
140+
if (file.parentFile == baseDir) {
141+
actualDirs.add(file)
142+
}
143+
if (file.parentFile == null) {
144+
break
145+
}
146+
file = file.parentFile
143147
}
144-
assert(expectedDirs == actualDirs)
148+
}
149+
assert(expectedDirs == actualDirs)
145150
}
146151

0 commit comments

Comments
 (0)