forked from logstash-plugins/logstash-filter-useragent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
133 lines (117 loc) · 4.88 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
import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify
import java.nio.file.Files
import java.nio.file.Paths
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
apply plugin: "java"
apply plugin: 'maven-publish'
apply plugin: "distribution"
apply plugin: "idea"
group "org.logstash.filters"
version Files.readAllLines(Paths.get("version")).first()
sourceCompatibility = JavaVersion.VERSION_1_8
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath group: 'org.jruby', name: 'jruby-complete', version: "9.2.11.0"
classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
classpath 'de.undercouch:gradle-download-task:4.0.4'
}
}
repositories {
mavenCentral()
}
String yamlResourceRoot = 'https://raw.githubusercontent.com/ua-parser/uap-core/v0.12.0'
def yamlTempDir = File.createTempDir()
def yamlTempFile = yamlTempDir.toPath().resolve('regexes.yaml')
task downloadYaml(type: Download, overwrite: false) {
src yamlResourceRoot + '/regexes.yaml'
dest yamlTempFile.toFile()
}
task patchYaml(type: Copy, dependsOn: [downloadYaml]) {
from yamlTempFile
into buildDir.toPath().resolve('resources/main')
filteringCharset 'UTF-8'
filter { line ->
// work-around a 'regression' with extracting Mac OS version, without the '?'
// the pattern would extract major: '18', minor: '2' from agent strings like:
// "MacOutlook/16.24.0.190414 (Intelx64 Mac OS X Version 10.14.4 (Build 18E226))"
line.replace("- regex: 'Mac OS X\\s.{1,50}\\s(\\d+).(\\d+).(\\d+)'", "- regex: 'Mac OS X\\s.{1,50}?\\s(\\d+).(\\d+).(\\d+)'")
}
}
task downloadTestYaml(type: Download, overwrite: false) {
src([
yamlResourceRoot + '/test_resources/additional_os_tests.yaml',
yamlResourceRoot + '/test_resources/firefox_user_agent_strings.yaml',
yamlResourceRoot + '/test_resources/opera_mini_user_agent_strings.yaml',
yamlResourceRoot + '/test_resources/pgts_browser_list.yaml',
yamlResourceRoot + '/test_resources/pgts_browser_list-orig.yaml',
yamlResourceRoot + '/tests/test_device.yaml',
yamlResourceRoot + '/tests/test_os.yaml',
yamlResourceRoot + '/tests/test_ua.yaml'
])
dest buildDir.toPath().resolve('resources/test').toFile()
}
task verifyYaml(type: Verify, dependsOn: [patchYaml, processResources]) {
inputs.file("${buildDir}/resources/main/regexes.yaml")
src buildDir.toPath().resolve('resources/main/regexes.yaml').toFile()
algorithm 'SHA1'
checksum '5a8ea18a9c9153e83159b8662e3f6650fbca60a8' // after replacement
}
dependencies {
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
implementation group: 'org.yaml', name: 'snakeyaml', version: '1.18'
implementation group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
testImplementation group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}
test {
dependsOn 'verifyYaml'
dependsOn 'downloadTestYaml'
minHeapSize = "256m"
maxHeapSize = "1024m"
testLogging {
events = [TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED]
showStandardStreams = true
exceptionFormat = TestExceptionFormat.FULL
}
}
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
dependsOn 'verifyYaml'
archiveClassifier = null
}
task vendor(dependsOn: shadowJar) {
doLast {
String vendorPathPrefix = "vendor/jar-dependencies"
String projectGroupPath = project.group.replaceAll('\\.', '/')
File projectJarFile = file("${vendorPathPrefix}/${projectGroupPath}/${project.name}/${project.version}/${project.name}-${project.version}.jar")
projectJarFile.mkdirs()
Files.copy(file("$buildDir/libs/${project.name}-${project.version}.jar").toPath(), projectJarFile.toPath(), REPLACE_EXISTING)
}
}