-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.gradle
113 lines (93 loc) · 3.85 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
plugins {
id 'java-library'
id "de.undercouch.download" version "5.4.0"
}
apply from: 'gradle/version.gradle'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.worksap.nlp:sudachi:0.7.2'
testImplementation 'junit:junit:4.13.1', 'org.hamcrest:hamcrest:2.1'
}
def dictionarySrc = [ small: ['small'], core: ['small', 'core'], 'full': ['small', 'core', 'notcore']]
def downloadCacheDir = new File(project.buildDir, "cache")
def matrixDefDownload = tasks.register("downloadMatrixDef", Download) {
src "https://d2ej7fkh96fzlu.cloudfront.net/sudachidict-raw/matrix.def.zip"
dest new File(downloadCacheDir, "matrix.def.zip")
overwrite false
}
def unzipMatrixDef = tasks.register('unzipMatrixDef', Copy) {
def zipFile = matrixDefDownload.get().outputs.files.singleFile
def outputDir = new File(project.buildDir, "dict/raw/matrix")
from zipTree(zipFile)
into outputDir
dependsOn(matrixDefDownload)
inputs.file(zipFile)
}
def rawDictSrcs = dictionarySrc.collectMany { it.value }.toSet()
rawDictSrcs.forEach { name ->
final String capitalName = name.capitalize()
final String version = project.property("dict.version").toString()
def downloadTask = tasks.register("download${capitalName}Zip", Download) {
def filename = "${name}_lex.zip"
src "https://d2ej7fkh96fzlu.cloudfront.net/sudachidict-raw/${version}/$filename"
dest new File(downloadCacheDir, "${version}/$name/$filename")
overwrite false
inputs.property("version", version)
}
tasks.register("unzip${capitalName}Dict", Copy) {
def zipFile = downloadTask.get().outputs.files.singleFile
def outputDir = new File(project.buildDir, "dict/raw/$version/$name")
from zipTree(zipFile)
into outputDir
dependsOn(downloadTask)
}
}
def builtDictDir = new File(project.buildDir, "dict/bin/${property("dict.version")}")
dictionarySrc.entrySet().forEach { e ->
def capitalName = e.key.capitalize()
def version = project.property("dict.version").toString()
def name = e.key
def compileTask = tasks.register("compile${capitalName}Dict", JavaExec) { t ->
def sources = e.value.collect { source ->
def srcName = source.toString().capitalize()
t.dependsOn(tasks.named("unzip${srcName}Dict"))
def dictCsv = new File(project.buildDir, "dict/raw/$version/$source/${source}_lex.csv")
t.inputs.file(dictCsv)
dictCsv
}
def outputFile = new File(builtDictDir, "system_${name}.dic")
def matrixFile = new File(unzipMatrixDef.get().outputs.files.singleFile, "matrix.def")
t.mainClass.set("com.worksap.nlp.sudachi.dictionary.DictionaryBuilder")
t.classpath = sourceSets.main.runtimeClasspath
t.args('-o', outputFile.toString(), '-m', matrixFile, '-d', "${version}", *sources)
t.maxHeapSize = "4g"
t.dependsOn unzipMatrixDef
t.systemProperty('file.encoding', 'UTF-8')
t.inputs.file(matrixFile)
t.outputs.file(outputFile)
}
test.dependsOn(compileTask)
}
dictionarySrc.entrySet().forEach {
def name = it.key
def task = tasks.register("zip${name.capitalize()}Dict", Zip) {
def compileTask = tasks.getByName("compile${name.capitalize()}Dict")
def compiledDict = compileTask.outputs.files.singleFile
archiveBaseName = 'sudachi-dictionary'
archiveVersion.set(version)
archiveClassifier = name
from compiledDict, 'LEGAL', 'LICENSE-2.0.txt'
into "sudachi-dictionary-${version}"
dependsOn(compileTask)
}
tasks.named('build').configure { dependsOn(task) }
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
tasks.withType(Test).configureEach {
systemProperty('buildDirectory', builtDictDir.toString())
systemProperty('file.encoding', 'UTF-8')
}