forked from gchq/stroom-content
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
182 lines (157 loc) · 5.79 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
//root
wrapper {
gradleVersion = '4.10.3'
}
def STROOM_CONTENT_DIR="stroomContent"
def BUILD_DIR_NAME="build"
def DIST_DIR_NAME="${BUILD_DIR_NAME}/distributions"
def ZIP_SOURCE_DIR_NAME="${BUILD_DIR_NAME}/zipSource"
def DEP_SOURCE_DIR_NAME="${ZIP_SOURCE_DIR_NAME}/dependencies"
//Validates all the uuids to make sure there are no dup uuids
//for different entities. Also ensures any Folder entities with the
//same path have the same uuid
//TODO the logic in this script should be rewritten in groovy and stuck in here
task validateContent(type: Exec) {
def validationScript = './validateContentPacks.py'
executable = validationScript
args = ['--all']
}
task cleanRoot() {
delete project.file(BUILD_DIR_NAME)
}
allprojects {
}
subprojects {
apply plugin: 'base'
//zip up all the files that make up the pack
task dist(type: Zip) {
//println "zipping source/${task.project.name}/"
from("." ) {
exclude "${BUILD_DIR_NAME}*"
exclude '**/.gitkeep'
}
archiveName "${project.name}.zip"
}
configurations {
distConfig
compileSource
}
artifacts {
distConfig dist
}
//unzip the project's own pack into zipSource
//while we could just copy the files the zip has already excluded stuff we don't
//want to this is easier
task unzipPack(type: Copy, dependsOn: dist) {
def zipFile = project.file("${DIST_DIR_NAME}/${project.name}.zip")
from zipTree(zipFile)
into ZIP_SOURCE_DIR_NAME
}
//copy any dependency packs into a dependencies dir
task copyDeps(type: Copy, dependsOn: dist) {
from configurations.compileSource
into project.file(DEP_SOURCE_DIR_NAME)
}
//unzip all the dependency pack zips then delete the zips
task unzipDeps(dependsOn: copyDeps) {
doLast {
fileTree(dir: project.file(DEP_SOURCE_DIR_NAME))
.include('*.zip')
.each { depZipFile ->
copy {
//println "Copying ${depZipFile}"
def depName = depZipFile.name - '.zip'
from zipTree(depZipFile)
into project.file("${DEP_SOURCE_DIR_NAME}/${depName}")
}
delete depZipFile
}
}
}
//zip up this project's source + any dependency source into a fat zip
task zipAll(type: Zip, dependsOn: [unzipDeps, unzipPack]) {
destinationDir project.file(DIST_DIR_NAME)
archiveName "${project.name}-all.zip"
from(project.file(ZIP_SOURCE_DIR_NAME))
}
//remove the zip file source
task deleteZipSource(type: Delete, dependsOn: [zipAll]) {
delete project.file(ZIP_SOURCE_DIR_NAME)
}
task CopyZipsToRoot(type: Copy, dependsOn: [deleteZipSource]) {
from project.file(DIST_DIR_NAME)
into rootProject.file(DIST_DIR_NAME)
}
task printDeps() {
doLast {
configurations.compileSource.each { dep ->
println "compileSource $dep"
}
}
}
task validateXmlSchemas() {
doLast {
//def dir = project.file(STROOM_CONTENT_DIR);
fileTree(dir: project.file(STROOM_CONTENT_DIR))
.include('**/*XMLSchema.data.xsd')
.each { xsdFile ->
def basePath = project.file(STROOM_CONTENT_DIR).toPath()
def xsdPath = xsdFile.toPath()
def relativeXsdPath = basePath.relativize(xsdPath)
def execResult = exec() {
// xmlint is available in libxml2-utils
// we have to set XML_CATALOG_FILES so xmllint uses the catalog.xml file
// to define the location of the various xsd files. If we don't it will
// get xml.xsd from w3.org and they impose an arbitrary 15s delay to make
// people cache it.
workingDir project.file(STROOM_CONTENT_DIR)
environment XML_CATALOG_FILES: rootProject.file("catalog.xml")
executable 'xmllint'
args '--noout', '--nowarning', '--schema', rootProject.file("XMLSchema.xsd"), relativeXsdPath
ignoreExitValue true
}
if (execResult.exitValue != 0) {
throw new GradleException("Schema failed validation: $relativeXsdPath")
}
}
}
}
task validateXml() {
doLast {
//def dir = project.file(STROOM_CONTENT_DIR);
fileTree(dir: project.file(STROOM_CONTENT_DIR))
.include('**/*.xml')
.each { xmlFile ->
def xmlFileName = xmlFile.absolutePath
def execResult = exec() {
//xmlint is available in libxml2-utils
executable 'xmllint'
args '--noout', '--nowarning', xmlFileName
ignoreExitValue true
}
if (execResult.exitValue != 0) {
throw new GradleException("XML file failed validation: $xmlFileName")
}
}
}
}
task validate() {
dependsOn validateContent
dependsOn validateXmlSchemas
dependsOn validateXml
}
build {
dependsOn validateContent
dependsOn validateXmlSchemas
dependsOn validateXml
dependsOn copyDeps
dependsOn unzipPack
dependsOn unzipDeps
dependsOn zipAll
dependsOn deleteZipSource
dependsOn CopyZipsToRoot
}
clean {
dependsOn cleanRoot
}
}