-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
134 lines (121 loc) · 4.28 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
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
}
}
apply plugin: 'org.asciidoctor.convert'
repositories {
maven { url "http://repo.spring.io/release" }
}
wrapper {
gradleVersion '3.5'
}
dependencies {
asciidoctor "io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.1.RELEASE"
}
// Documentation tasks
asciidoctor {
sourceDir = file('docs')
sources {
include 'index.adoc', 'workshops.adoc', 'tutorials/*'
}
outputDir = file('docs')
separateOutputDirs = false
resources { }
attributes 'source-highlighter': 'prettify'
}
task removeHtml() {
doLast {
FileTree tree = fileTree(dir: 'docs', include: ['**/*.html'])
tree.each {
it.delete()
}
}
}
asciidoctor.mustRunAfter removeHtml
task generateDocumentation(dependsOn: ["removeHtml", "asciidoctor"]) {
group = "Documentation"
description = "Creates full documentation for the project"
}
// Workshop tasks
task removeFiles(type: Delete) {
group = "Workshops"
description = "Removes all contracts"
List<String> producers = project.rootDir.list(new FilenameFilter() {
@Override
public boolean accept(File current, String name) {
return new File(current, name).isDirectory() && name.startsWith("producer")
}
})
List<String> folders = producers.collect {
"${it}/src/test/resources/contracts/"
}
List<String> adocTests = producers.collect {
"${it}/src/test/java/com/example/GenerateAdocsFromContractsTests.java"
}
List<String> graphsTests = producers.collect {
"${it}/src/test/java/com/example/GenerateGraphFromContractsTests.java"
}
delete folders
delete adocTests
delete graphsTests
delete 'beer_contracts/src/main/resources/contracts/'
delete 'beer_contracts/src/test/java/docs/GenerateAdocsFromContractsTests.java'
delete 'beer_contracts/src/test/java/docs/GenerateGraphFromContractsTests.java'
}
task removeTextFromFiles() {
group = "Workshops"
description = "Removes written implementation"
doLast {
FileTree tree = fileTree(dir: '.', include: ['**/*.java',
'**/*.groovy',
'**/*.gvy',
'**/*.xml',
'**/*.gradle',
'**/*.yml',
'**/*.properties'])
tree.each { File file ->
if (file.absolutePath == new File(project.rootDir, "build.gradle").absolutePath) {
return
}
String text = file.text
if (!text.contains("remove::start")) {
return
}
StringBuilder newString = new StringBuilder()
boolean remove = false
text.eachLine { String line ->
if(["import org.springframework.cloud.contract", "tag::", "end::"].any { line.contains(it) }) {
return
}
if (line.contains("remove::end[]")) {
remove = false
} else if (line.contains("remove::end[return]")) {
// only related to java
newString.append(line.replace("//remove::end[return]", "return null;")).append("\n")
remove = false
return
} else if (line.contains("//@org.junit.Ignore")) {
// only related to java
newString.append(line.replace("//", "")).append("\n")
return
}
if (!remove) {
if (line.contains("remove::start")) {
remove = true
} else if (!line.contains("remove::end")) {
newString.append(line).append("\n")
}
}
}
file.text = newString.toString()
}
}
}
task prepareForWorkshops(dependsOn: ['removeFiles', 'removeTextFromFiles']) {
group = "Workshops"
description = "Executes all tasks to set initial state for workshops"
}