-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
107 lines (87 loc) · 3.78 KB
/
build.gradle.kts
File metadata and controls
107 lines (87 loc) · 3.78 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.File
import java.util.*
plugins {
kotlin("jvm") version "1.3.72"
}
group = "kr3v"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("it.unimi.dsi:fastutil:8.2.3")
implementation("com.baqend:bloom-filter:2.2.2")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.7")
implementation("org.fusesource.leveldbjni:leveldbjni-all:1.8")
implementation("org.postgresql:postgresql:42.2.6")
testImplementation("org.junit.jupiter:junit-jupiter:5.5.1")
testImplementation("org.assertj:assertj-core:3.12.2")
}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
sourceSets["test"].java {
srcDir("src/test/testUnit")
srcDir("src/test/testIntegration")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
data class WebdetectOptions(
val input: String?,
val output: String?,
val memory: String?
) {
constructor(mp: Map<*, *>) : this(
mp["input"] as String?,
mp["output"] as String?,
mp["memory"] as String?
)
constructor(path: String) : this((project.file(path)
.takeIf(File::exists)
?.let { file -> Properties().apply { load(file.inputStream()) } } as? Map<Any?, Any?>)
?: emptyMap<Any?, Any?>())
}
tasks {
create<JavaExec>("generateDatabase") {
dependsOn("compileKotlin")
main = "kr3v.webdetect.MainKt"
classpath = sourceSets["main"].runtimeClasspath
val usage = "\n\n" + """
Usage: ./gradlew generateDatabase [options]
Options can be also specified in props/webdetect.properties and props/local.properties.
Example:
./gradlew generateDatabase -Pinput=./whitelist.csv -Poutput=./db
Options:
-Pinput=<whitelist csv> path to CSV generated by scanner from webdetect_client (required)
-Poutput=<output path> path where generated DB will be stored (required)
- leveldb DB will be stored in <output path>.ldb directory
- JSON DB will be stored on path <output path>.json
-Pmemory=<integer>{m|g} amount of memory available to JVM; recommended value is 2x of CSV size
Options to be added later, currently hard-coded in sources:
-Ptypes={json|leveldb|json,leveldb}
generate specified DB types; if more than one type specified,
output path becomes -Poutput argument value with type name appended
-PmaxChecksums=<max> maximum count of checksums per app-version that can be included in DB
-PminChecksums=<min> minimum count of checksums per app-version that can be included in DB
""".trimIndent()
fun raiseUsage(): Nothing = throw Exception(usage)
doFirst {
val webdetectProperties = WebdetectOptions("props/webdetect.properties")
val localProperties = WebdetectOptions("props/local.properties")
val projectOptions = WebdetectOptions(project.properties)
args(
projectOptions.input ?: localProperties.input ?: webdetectProperties.output ?: raiseUsage(),
projectOptions.output ?: localProperties.output ?: webdetectProperties.output ?: raiseUsage()
)
val memory = projectOptions.memory ?: localProperties.memory ?: webdetectProperties.memory
jvmArgs("-Xms$memory", "-Xmx$memory", "-ea")
}
}
}