-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
133 lines (107 loc) · 3.87 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
buildscript {
repositories {
mavenLocal()
maven {
url 'https://artifactory.wetransform.to/artifactory/libs-snapshot-local'
}
}
dependencies {
classpath 'to.wetransform.hale:gradle-hale-plugin:1.2.0-SNAPSHOT'
}
}
apply plugin: 'to.wetransform.hale'
repositories {
// mavenLocal() // for testing
}
hale {
cliVersion = '4.2.0-SNAPSHOT'
}
afterEvaluate {
if (!project.hasProperty('haleCliExecutable')) {
// add schemabuilder reader as dependency
dependencies {
hale "eu.esdihumboldt.hale:eu.esdihumboldt.hale.io.schemabuilder:${hale.cliVersion}"
hale "eu.esdihumboldt.hale:eu.esdihumboldt.hale.io.instancebuilder:${hale.cliVersion}"
}
}
}
class Format {
String extension
String providerId
String contentType
}
def formats = [
// List of supported formats
//
// Limited to formats that can write well in a generic way
Shapefile: new Format(extension: 'shp', providerId: 'eu.esdihumboldt.hale.io.shp.instance.writer'),
CSV: new Format(extension: 'csv', providerId: 'eu.esdihumboldt.hale.io.csv.writer.instance'),
GeoJson: new Format(extension: 'geo.json', providerId: 'eu.esdihumboldt.hale.io.geojson.writer'),
Json: new Format(extension: 'json', providerId: 'eu.esdihumboldt.hale.io.json.writer'),
GPKG: new Format(extension: 'gpkg', providerId: 'eu.esdihumboldt.hale.io.geopackage.instance.writer'),
XLSX: new Format(extension: 'xlsx', providerId: 'eu.esdihumboldt.hale.io.xls.writer.instance', contentType: 'eu.esdihumboldt.hale.io.xls.xlsx')
]
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
def allTask = task('buildSchemas') {
group 'Schema'
description "Build all schemas"
}
def schemasDir = file('schemas')
schemasDir.eachDir { dir ->
def name = dir.name
def buildTask = task("buildSchema-$name", type: hale.cli()) {
args << 'schema'
args << 'rewrite'
args << '--source'
args << new File(dir, 'schema.groovy').absolutePath
args << '--target'
args << new File(dir, 'schema.hsd.json')
args << '--target-writer'
args << 'eu.esdihumboldt.hale.common.schema.persist.hsd.json.write'
logToConsole = true
description "Builds the $name schema file from the schema builder definition."
group 'Schema'
}
// buildTask.outputs.upToDateWhen { false } // XXX work-around for current Gradle plugin no longer always running the task; see also https://stackoverflow.com/a/18410574/982265
allTask.dependsOn(buildTask)
def instanceFile = new File(dir, 'instances.groovy')
if (instanceFile.exists()) {
def genSchemaTask = task("genInstances-$name") {
group 'Instances'
description "Generate all instance files for $name schema"
}
formats.each { String formatId, Format formatSpec ->
def genTask = task("genInstances-$name-$formatId", type: hale.cli(), dependsOn: buildTask) {
args << 'data'
args << 'rewrite'
args << '--data'
args << instanceFile.absolutePath
args << '--schema'
args << new File(dir, 'schema.groovy').absolutePath
args << '--target'
args << new File(dir, "instances.${formatSpec.extension}")
args << '--target-writer'
args << formatSpec.providerId
if (formatSpec.contentType) {
args << '--target-setting'
args << "contentType=${formatSpec.contentType}"
}
logToConsole = true
description "Generate instances for $name schema in $formatId from the instance builder definition."
group 'Instances'
}.doFirst {
// delete target file first
// Note: only deletes the main file (but primarily needed for Geopackage at the moment)
new File(dir, "instances.${formatSpec.extension}").delete()
}
// genTask.outputs.upToDateWhen { false }
genSchemaTask.dependsOn(genTask)
}
}
}
defaultTasks 'buildSchemas'
wrapper {
gradleVersion = '8.4'
}