This repository was archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathbuild.gradle
152 lines (128 loc) · 5.1 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
/*
* Modifications Copyright (c) 2019 BrowserUp, Inc.
*/
plugins {
id 'java-library'
id 'groovy'
id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.6"
id 'org.openapi.generator' version '4.3.1'
}
ext {
jerseyVersion = '2.32'
}
resolve {
outputFileName = 'openapi'
outputFormat = 'YAML'
prettyPrint = 'TRUE'
openApiFile = file("src/main/resources/openapi-config.json")
classpath = sourceSets.main.runtimeClasspath
readerClass = "com.browserup.bup.rest.openapi.CustomOpenApiReader"
resourcePackages = ['com.browserup.bup.rest.resource']
outputPath = "$buildDir/openapi"
}
class Constants {
static String apiPackage = 'browserup'
static String modelPackage = 'browserup.model'
}
/*
https://github.com/OpenAPITools/openapi-generator/issues/3285
*/
class PythonClientPostProcessor {
String projectDir
void process() {
def clientDir = new File("$projectDir/build/openapi-clients/python")
clientDir.eachFileRecurse {
if (it.name.endsWith(".py")) {
processInitFile(it)
}
}
new File("${clientDir}/openapi_client/${Constants.apiPackage}/model/__init__.py") <<
new File("${clientDir}/openapi_client/${Constants.modelPackage}/__init__.py").text
}
private static void processInitFile(File initFile) {
initFile.text = initFile.text.replaceAll(
~/(from ${Constants.apiPackage}.default_api import)/,
"from openapi_client.${Constants.apiPackage}.default_api import"
)
}
}
class ClientInfo {
String language
Closure postProcessor
}
def clients = [
new ClientInfo(language: 'JavaScript'),
new ClientInfo(language: 'Ruby'),
new ClientInfo(
language: 'Python',
postProcessor: new PythonClientPostProcessor(projectDir: projectDir).&process)
] as ClientInfo[]
clients.each { client ->
def lang = client.language
def postProcessor = client.postProcessor
task "openApiGenerate${lang}Client"(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
def language = lang.toLowerCase()
generatorName = language
inputSpec = "$buildDir/openapi/openapi.yaml".toString()
outputDir = "$buildDir/openapi-clients/$language/".toString()
apiPackage = Constants.apiPackage
modelPackage = Constants.modelPackage
invokerPackage = "browserup.invoker"
systemProperties = [
modelDocs: 'false'
]
skipValidateSpec = true
logToStderr = true
generateAliasAsModel = false
}
if (postProcessor) tasks.getByName("openApiGenerate${lang}Client").doLast(postProcessor)
}
test {
testLogging.showStandardStreams = true
}
task openApiGenerateClients(dependsOn: resolve) {
clients.each { c ->
dependsOn "openApiGenerate${c.language}Client"
}
doLast {
clients.each { client ->
def langName = client.language.toLowerCase()
delete "src/test/${langName}/client"
copy {
from "$buildDir/openapi-clients/${langName}/"
into "src/test/${langName}/client"
}
}
project.delete "$buildDir/openapi-clients"
}
}
archivesBaseName = 'browserup-proxy-rest-clients'
dependencies {
implementation project(':browserup-proxy-core')
implementation project(':browserup-proxy-rest')
testImplementation "org.glassfish.jersey.containers:jersey-container-servlet-core:${jerseyVersion}"
testImplementation "org.glassfish.jersey.media:jersey-media-json-jackson:${jerseyVersion}"
testImplementation "org.glassfish.jersey.inject:jersey-hk2:${jerseyVersion}"
testImplementation "org.glassfish.jersey.ext:jersey-bean-validation:${jerseyVersion}"
testImplementation project(':browserup-proxy-mitm')
testImplementation "com.google.inject:guice:$guiceVersion"
testImplementation "com.google.inject.extensions:guice-servlet:$guiceVersion"
testImplementation "com.google.inject.extensions:guice-multibindings:$guiceVersion"
testImplementation 'com.google.sitebricks:sitebricks:0.8.11'
testImplementation 'junit:junit:4.12'
testImplementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
testImplementation 'org.codehaus.groovy:groovy-all:2.5.7'
testImplementation 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.2'
testImplementation 'org.hamcrest:hamcrest:2.1'
testImplementation 'org.hamcrest:hamcrest-library:2.1'
testImplementation 'org.mockito:mockito-core:3.11.2'
testImplementation 'org.seleniumhq.selenium:selenium-api:3.4.0'
testImplementation 'org.awaitility:awaitility:3.1.6'
testImplementation 'xyz.rogfam:littleproxy:2.0.0-beta-3'
testImplementation 'com.github.tomakehurst:wiremock-jre8:2.24.0'
testImplementation 'org.testcontainers:testcontainers:1.15.1'
}
openApiGenerateClients.mustRunAfter(resolve)
test.dependsOn(openApiGenerateClients)