-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPluginSpecification.groovy
More file actions
87 lines (72 loc) · 2.23 KB
/
PluginSpecification.groovy
File metadata and controls
87 lines (72 loc) · 2.23 KB
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
package ru.endlesscode.bukkitgradle
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
class PluginSpecification extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
File settingsFile
protected Project project
protected GradleRunner runner
protected BuildResult result
def setup() {
buildFile = file('build.gradle.kts')
settingsFile = file('settings.gradle.kts')
//language=kotlin
buildFile << '''
plugins {
id("ru.endlesscode.bukkitgradle")
}
version = "1.0"
group = "com.example.testplugin"
'''.stripIndent()
settingsFile << '''
rootProject.name = "test-plugin"
'''.stripIndent()
}
File file(String path) {
def file = new File(testProjectDir.root, path)
if (!file.exists()) {
file.parentFile.mkdirs()
return testProjectDir.newFile(path)
}
return file
}
File dir(String path) {
def file = new File(testProjectDir.root, path)
if (!file.exists()) {
file.parentFile.mkdirs()
return testProjectDir.newFolder(path)
}
return file
}
Project getProject() {
if (project == null) {
project = ProjectBuilder.builder()
.withProjectDir(testProjectDir.root)
.build()
}
return project
}
GradleRunner getRunner() {
if (runner == null) {
runner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.forwardOutput()
.withPluginClasspath()
}
return runner
}
protected def run(String... args) {
result = getRunner().withArguments(args.toList() + "--stacktrace").build()
}
protected TaskOutcome taskOutcome(String task) {
return result.task(task).outcome
}
}