Skip to content

Commit 340f11e

Browse files
authored
Gradle 7, JDK related changes and OS 2.0 (#179)
* Gradle 7, JDK related changes and OS 2.0 Signed-off-by: Sagar Upadhyaya <[email protected]> * Changing logic for clone git repo to make it compatible with gradle 7 Signed-off-by: Sagar Upadhyaya <[email protected]> * Fixing unit tests to remove reference of deleted fields in OS 2.0 Signed-off-by: Sagar Upadhyaya <[email protected]> * Fixing apache Conflict depedency issue Signed-off-by: Sagar Upadhyaya <[email protected]> * Reverting temporary changes to point to local RCA repo Signed-off-by: Sagar Upadhyaya <[email protected]>
1 parent 8da5fe8 commit 340f11e

File tree

8 files changed

+123
-177
lines changed

8 files changed

+123
-177
lines changed

.github/workflows/gradle.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
java:
16-
- 8
1716
- 11
18-
- 14
17+
- 17
1918
runs-on: [ubuntu-latest]
2019
name: Building PA package
2120
steps:
@@ -40,14 +39,17 @@ jobs:
4039
run: |
4140
./gradlew build -Dperformance-analyzer-rca.build=true \
4241
-Dperformance-analyzer-rca.repo="https://github.com/opensearch-project/performance-analyzer-rca.git" \
43-
-Dperformance-analyzer-rca.branch=main \
44-
-Dopensearch.version=1.3.0-SNAPSHOT
42+
-Dperformance-analyzer-rca.branch=main
4543
- name: Assemble PA jar for BWC tests
4644
working-directory: ./tmp/performance-analyzer
4745
run: |
48-
./gradlew assemble -Dopensearch.version=1.3.0-SNAPSHOT
49-
mkdir -p ./src/test/resources/org/opensearch/performanceanalyzer/bwc/1.3.0.0-SNAPSHOT
50-
cp ./build/distributions/*.zip ./src/test/resources/org/opensearch/performanceanalyzer/bwc/1.3.0.0-SNAPSHOT
46+
./gradlew assemble
47+
version=`./gradlew properties -q | grep "opensearch_version:" | awk '{print $2}'`
48+
IFS='-' read -r -a version_array <<< "$version"
49+
plugin_version="${version_array[0]}.0"; for entry in ${version_array[@]:1}; do plugin_version+="-$entry"; done
50+
echo $plugin_version
51+
mkdir -p ./src/test/resources/org/opensearch/performanceanalyzer/bwc/$plugin_version
52+
cp ./build/distributions/*.zip ./src/test/resources/org/opensearch/performanceanalyzer/bwc/$plugin_version
5153
- name: Generate Jacoco coverage report
5254
working-directory: ./tmp/performance-analyzer
5355
run: ./gradlew jacocoTestReport
@@ -58,7 +60,7 @@ jobs:
5860
run: bash <(curl -s https://codecov.io/bash) -f ./build/reports/jacoco/test/jacocoTestReport.xml
5961
- name: Run Integration Tests
6062
working-directory: ./tmp/performance-analyzer
61-
run: ./gradlew integTest -Dtests.enableIT -Dtests.useDockerCluster -Dopensearch.version=1.3.0-SNAPSHOT
63+
run: ./gradlew integTest -Dtests.enableIT -Dtests.useDockerCluster
6264
- name: Run PerformanceAnalzyer Backwards Compatibility Tests
6365
working-directory: ./tmp/performance-analyzer
6466
run: ./gradlew bwcTestSuite -Dtests.security.manager=false

DEVELOPER_GUIDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- [Developer Guide](#developer-guide)
22
- [Forking and Cloning](#forking-and-cloning)
33
- [Install Prerequisites](#install-prerequisites)
4-
- [JDK 11](#jdk-11)
4+
- [JDK](#jdk)
55
- [Building](#building)
66
- [Using IntelliJ IDEA](#using-intellij-idea)
77
- [Submitting Changes](#submitting-changes)
@@ -18,7 +18,7 @@ Fork this repository on GitHub, and clone locally with `git clone`.
1818

1919
#### JDK 11
2020

21-
OpenSearch components build using Java 11 at a minimum. This means you must have a JDK 11 installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK 11 installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-11`.
21+
OpenSearch components build using Java 11 at a minimum and supports JDK 11, 17. This means you must have a JDK of supported version installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-11`.
2222

2323
### Building
2424

build.gradle

Lines changed: 97 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66
buildscript {
77

88
ext {
9-
opensearch_version = System.getProperty("opensearch.version", "1.3.0-SNAPSHOT")
9+
opensearch_version = System.getProperty("opensearch.version", "2.0.0-alpha1-SNAPSHOT")
10+
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
11+
buildVersionQualifier = System.getProperty("build.version_qualifier", "alpha1")
12+
13+
// 2.0.0-alpha1-SNAPSHOT -> 2.0.0.0-alpha1-SNAPSHOT
14+
version_tokens = opensearch_version.tokenize('-')
15+
opensearch_build = version_tokens[0] + '.0'
16+
if (buildVersionQualifier) {
17+
opensearch_build += "-${buildVersionQualifier}"
18+
}
19+
if (isSnapshot) {
20+
opensearch_build += "-SNAPSHOT"
21+
}
1022
}
1123

1224
// Used to resolve build file dependencies
@@ -26,11 +38,13 @@ buildscript {
2638
plugins {
2739
id 'java'
2840
id 'nebula.ospackage' version "8.3.0"
29-
id 'com.github.spotbugs' version '4.6.0'
41+
id 'com.github.spotbugs' version '5.0.0'
3042
id 'jacoco'
3143
id 'com.diffplug.spotless' version '5.11.0'
3244
id 'checkstyle'
45+
id 'org.ajoberstar.grgit' version '5.0.0'
3346
id 'org.gradle.test-retry' version '1.3.1'
47+
3448
}
3549

3650
spotbugsMain {
@@ -49,8 +63,6 @@ spotbugsTest {
4963
}
5064

5165
ext {
52-
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
53-
5466
// The RCA branch that will be built. Default branch is main.
5567
rcaProjectRepo = System.getProperty("performance-analyzer-rca.repo", "https://github.com/opensearch-project/performance-analyzer-rca.git")
5668
rcaProjectBranch = System.getProperty("performance-analyzer-rca.branch", "main")
@@ -64,10 +76,7 @@ ext {
6476

6577
allprojects {
6678
group = "org.opensearch"
67-
version = opensearch_version - '-SNAPSHOT' + '.0'
68-
if (isSnapshot) {
69-
version += "-SNAPSHOT"
70-
}
79+
version = opensearch_build
7180
}
7281

7382
apply plugin: 'opensearch.opensearchplugin'
@@ -78,7 +87,7 @@ noticeFile = rootProject.file('NOTICE.txt')
7887
spotless {
7988
java {
8089
licenseHeaderFile(file('license-header'))
81-
googleJavaFormat().aosp()
90+
googleJavaFormat('1.12.0').aosp()
8291
importOrder()
8392
removeUnusedImports()
8493
trimTrailingWhitespace()
@@ -112,22 +121,14 @@ opensearchplugin {
112121
classname 'org.opensearch.performanceanalyzer.PerformanceAnalyzerPlugin'
113122
}
114123

115-
sourceCompatibility = 1.8
116-
targetCompatibility = 1.8
124+
sourceCompatibility = JavaVersion.VERSION_11
125+
targetCompatibility = JavaVersion.VERSION_11
117126

118127
compileJava {
119128
dependsOn spotlessApply
120-
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
121-
if (targetVersion.isJava9Compatible()) {
122-
options.compilerArgs += ["--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED"]
123-
}
124129
}
125130

126131
javadoc {
127-
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
128-
if (targetVersion.isJava9Compatible()) {
129-
options.addStringOption("-add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED")
130-
}
131132
}
132133

133134
project.afterEvaluate {
@@ -159,7 +160,7 @@ tasks.withType(JavaCompile) {
159160
}
160161

161162
jacoco {
162-
toolVersion = "0.8.5"
163+
toolVersion = "0.8.7"
163164
}
164165

165166
jacocoTestReport {
@@ -212,7 +213,7 @@ checkstyleTest.enabled = false
212213

213214
dependencies {
214215
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
215-
compile files("${System.properties['java.home']}/../lib/tools.jar")
216+
implementation files("${System.properties['java.home']}/../lib/tools.jar")
216217
}
217218

218219
def jacksonVersion = "2.12.6"
@@ -233,88 +234,92 @@ dependencies {
233234
force "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
234235
force "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
235236
force "com.fasterxml.jackson.module:jackson-module-paranamer:${jacksonVersion}"
237+
force "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${jacksonVersion}"
238+
force "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
239+
force "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${jacksonVersion}"
240+
force "org.apache.commons:commons-lang3:3.12.0"
236241
}
237242
}
238243

239-
compile('com.google.guava:guava:30.1-jre') {
244+
implementation('com.google.guava:guava:30.1-jre') {
240245
force = 'true'
241246
}
242-
compile 'org.jooq:jooq:3.10.8'
243-
compile 'org.apache.commons:commons-lang3:3.9'
244-
compile 'org.bouncycastle:bcprov-jdk15on:1.70'
245-
compile 'org.bouncycastle:bcpkix-jdk15on:1.70'
246-
compile "org.opensearch:performanceanalyzer-rca:${version}"
247-
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
248-
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
249-
compile "com.fasterxml.jackson.module:jackson-module-paranamer:${jacksonVersion}"
250-
compile(group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1')
251-
compile(group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1')
252-
compile(group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.9.0') {
247+
implementation 'org.jooq:jooq:3.10.8'
248+
implementation 'org.apache.commons:commons-lang3:3.9'
249+
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
250+
implementation 'org.bouncycastle:bcpkix-jdk15on:1.70'
251+
implementation "org.opensearch:performanceanalyzer-rca:${version}"
252+
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
253+
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
254+
implementation "com.fasterxml.jackson.module:jackson-module-paranamer:${jacksonVersion}"
255+
implementation(group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1')
256+
implementation(group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1')
257+
implementation(group: 'com.google.errorprone', name: 'error_prone_annotations', version: '2.9.0') {
253258
force = 'true'
254259
}
255-
compile(group: 'com.google.protobuf', name:'protobuf-java', version: '3.19.2') {
260+
implementation(group: 'com.google.protobuf', name:'protobuf-java', version: '3.19.2') {
256261
force = 'true'
257262
}
258-
compile("io.netty:netty-buffer:${nettyVersion}") {
263+
implementation("io.netty:netty-buffer:${nettyVersion}") {
259264
force = 'true'
260265
}
261-
compile("io.netty:netty-codec:${nettyVersion}") {
266+
implementation("io.netty:netty-codec:${nettyVersion}") {
262267
force = 'true'
263268
}
264-
compile("io.netty:netty-codec-http:${nettyVersion}") {
269+
implementation("io.netty:netty-codec-http:${nettyVersion}") {
265270
force = 'true'
266271
}
267-
compile("io.netty:netty-common:${nettyVersion}") {
272+
implementation("io.netty:netty-common:${nettyVersion}") {
268273
force = 'true'
269274
}
270-
compile("io.netty:netty-handler:${nettyVersion}") {
275+
implementation("io.netty:netty-handler:${nettyVersion}") {
271276
force = 'true'
272277
}
273-
compile("io.netty:netty-resolver:${nettyVersion}") {
278+
implementation("io.netty:netty-resolver:${nettyVersion}") {
274279
force = 'true'
275280
}
276-
compile("io.netty:netty-transport:${nettyVersion}") {
281+
implementation("io.netty:netty-transport:${nettyVersion}") {
277282
force = 'true'
278283
}
279-
compile("io.netty:netty-codec-http2:${nettyVersion}") {
284+
implementation("io.netty:netty-codec-http2:${nettyVersion}") {
280285
force = 'true'
281286
}
282-
compile("io.netty:netty-codec-socks:${nettyVersion}") {
287+
implementation("io.netty:netty-codec-socks:${nettyVersion}") {
283288
force = 'true'
284289
}
285-
compile("io.netty:netty-handler-proxy:${nettyVersion}") {
290+
implementation("io.netty:netty-handler-proxy:${nettyVersion}") {
286291
force = 'true'
287292
}
288293

289294

290295
// JDK9+ has to run powermock 2+. https://github.com/powermock/powermock/issues/888
291-
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
292-
testCompile(group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0') {
296+
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
297+
testImplementation(group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0') {
293298
exclude(group: 'org.hamcrest', module: 'hamcrest-core')
294299
}
295-
testCompile(group: 'org.mockito', name: 'mockito-core', version: '2.23.0') {
300+
testImplementation(group: 'org.mockito', name: 'mockito-core', version: '2.23.0') {
296301
force = 'true'
297302
}
298303
// Dependency to mock final classes.
299304
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '2.13.0'
300-
testCompile group: 'org.powermock', name: 'powermock-core', version: '2.0.0'
301-
testCompile group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
302-
testCompile(group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.0') {
305+
testImplementation group: 'org.powermock', name: 'powermock-core', version: '2.0.0'
306+
testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
307+
testImplementation(group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.0') {
303308
exclude(group: 'org.hamcrest', module: 'hamcrest-core')
304309
}
305-
testCompile group: 'org.javassist', name: 'javassist', version: '3.24.0-GA'
306-
testCompile group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
310+
testImplementation group: 'org.javassist', name: 'javassist', version: '3.24.0-GA'
311+
testImplementation group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
307312
//minimum byte-buddy version to be compatible with mockito-core 2.23.0 is 1.9.7+. https://github.com/mockito/mockito/issues/1606
308-
testCompile(group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.7') {
313+
testImplementation(group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.7') {
309314
force = 'true'
310315
}
311-
testCompile(group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.9.7') {
316+
testImplementation(group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.9.7') {
312317
force = 'true'
313318
}
314-
testCompile(group: 'org.objenesis', name: 'objenesis', version: '3.0.1') {
319+
testImplementation(group: 'org.objenesis', name: 'objenesis', version: '3.0.1') {
315320
force = 'true'
316321
}
317-
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
322+
testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
318323
}
319324

320325
dependencyLicenses {
@@ -332,7 +337,7 @@ gradle.startParameter.excludedTaskNames += [ "forbiddenApisMain",
332337
"testingConventions"]
333338

334339
import java.util.concurrent.Callable
335-
import org.ajoberstar.gradle.git.tasks.GitClone
340+
import org.ajoberstar.grgit.Grgit
336341
import org.opensearch.gradle.test.RestIntegTestTask
337342
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask
338343

@@ -347,16 +352,21 @@ static def propEnabled(property) {
347352
* cloneRcaGitRepo clones the performance-analyzer-rca repo if the -Dtests.enableIT=true flag is passed
348353
* to the Gradle JVM
349354
*/
350-
task cloneRcaGitRepo(type: GitClone) {
355+
task cloneRcaGitRepo() {
351356
def destination = file(rcaProjectDir)
352-
uri = rcaProjectRepo
353-
branch = rcaProjectBranch
354-
destinationPath = destination
355-
bare = false
356-
enabled = cloneRcaProject && !destination.exists() // to clone only once
357-
357+
def uri = rcaProjectRepo
358+
def branch = rcaProjectBranch
358359
doFirst {
359-
logger.info("Cloning performance-analyzer-rca into ${rcaProjectDir} from ${rcaProjectRepo}#${rcaProjectBranch}")
360+
println "Cloning performance-analyzer-rca into ${rcaProjectDir} from ${rcaProjectRepo}#${rcaProjectBranch}"
361+
}
362+
doLast {
363+
if (destination.exists() && destination.isDirectory()) { // If directory exists, use this instead.
364+
def grgit = Grgit.open(dir: destination.toString())
365+
} else { // Otherwise pull it from git.
366+
def grgit = Grgit.clone(dir: destination.toString(), uri: uri)
367+
grgit.fetch(remote: 'origin')
368+
grgit.checkout(branch: branch)
369+
}
360370
}
361371
}
362372

@@ -370,11 +380,21 @@ task buildRca() {
370380
doLast {
371381
exec {
372382
workingDir("$rcaProjectDir")
373-
commandLine './gradlew', 'build', '-x', 'test', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}"
383+
if (buildVersionQualifier == null || buildVersionQualifier == '' || buildVersionQualifier == 'null') {
384+
commandLine './gradlew', 'build', '-x', 'test', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}"
385+
}
386+
else {
387+
commandLine './gradlew', 'build', '-x', 'test', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}", "-Dbuild.version_qualifier=${buildVersionQualifier}"
388+
}
374389
}
375390
exec {
376391
workingDir("$rcaProjectDir")
377-
commandLine './gradlew', 'publishToMavenLocal', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}"
392+
if (buildVersionQualifier == null || buildVersionQualifier == '' || buildVersionQualifier == 'null') {
393+
commandLine './gradlew', 'publishToMavenLocal', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}"
394+
}
395+
else {
396+
commandLine './gradlew', 'publishToMavenLocal', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}", "-Dbuild.version_qualifier=${buildVersionQualifier}"
397+
}
378398
}
379399
exec {
380400
def licenseDir = "$projectDir/licenses"
@@ -401,6 +421,14 @@ task unpackRca(type: Copy) {
401421
}
402422
}
403423

424+
tasks.withType(Test) {
425+
jvmArgs('--add-opens=java.base/sun.security.jca=ALL-UNNAMED')
426+
jvmArgs('--add-opens=java.base/java.util.concurrent=ALL-UNNAMED')
427+
jvmArgs('--add-opens=java.base/java.io=ALL-UNNAMED')
428+
jvmArgs('--add-opens=java.base/java.nio.file=ALL-UNNAMED')
429+
}
430+
431+
404432
bundlePlugin {
405433
dependsOn 'unpackRca'
406434
from("$rcaArtifactsDir/pa_config") {
@@ -522,7 +550,7 @@ String bwcFilePath = "src/test/resources/org/opensearch/performanceanalyzer/bwc/
522550
testClusters {
523551
"${baseName}$i" {
524552
testDistribution = "ARCHIVE"
525-
versions = ["7.10.2","1.3.0-SNAPSHOT"]
553+
versions = ["7.10.2", opensearch_version]
526554
numberOfNodes = 3
527555
plugin(provider(new Callable<RegularFile>(){
528556
@Override
@@ -662,7 +690,7 @@ afterEvaluate {
662690
ospackage {
663691
packageName = "opensearch-performance-analyzer"
664692
release = isSnapshot ? "0.1" : '1'
665-
version = "${project.version}" - "-SNAPSHOT"
693+
version = "${project.version}"
666694

667695
into '/usr/share/opensearch/plugins'
668696
from(zipTree(bundlePlugin.archivePath)) {

0 commit comments

Comments
 (0)