Skip to content

Commit

Permalink
Update project (except capture proxy and dependencies) to Java 17 for…
Browse files Browse the repository at this point in the history
… Graalvm compatibility

-s
Signed-off-by: Andre Kurait <[email protected]>
  • Loading branch information
AndreKurait committed Jan 10, 2025
1 parent 397d72e commit 738cf2b
Show file tree
Hide file tree
Showing 25 changed files with 127 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

env:
python-version: '3.11'
java-version: '11'
java-version: '17'
gradle-version: '8.0.2'
node-version: '18.x'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
tags:
- "*"
env:
java-version: '11'
java-version: '17'
gradle-version: '8.0.2'

permissions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar-qube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:

env:
java-version: '11'
java-version: '17'
gradle-version: '8.0.2'

jobs:
Expand All @@ -32,7 +32,7 @@ jobs:
with:
distribution: 'corretto'
java-version: |
11
17
- name: Cache SonarQube Scanner
uses: actions/cache@v3
with:
Expand Down
3 changes: 0 additions & 3 deletions CreateSnapshot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ plugins {
id 'org.opensearch.migrations.java-application-conventions'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation project(':coreUtilities')
implementation project(":RFS")
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

## Prerequisites

- Java Development Kit (JDK) 11
- Java Development Kit (JDK) 17
- Gradle 8
- Python3
- Docker and Docker Compose (for local deployment)
Expand Down
3 changes: 0 additions & 3 deletions DataGenerator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation project(":coreUtilities")
implementation project(":RFS")
Expand Down
3 changes: 0 additions & 3 deletions DocumentsFromSnapshotMigration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import groovy.transform.Canonical
import org.opensearch.migrations.common.CommonUtils

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

@Canonical
class DockerServiceProps {
String projectName = ""
Expand Down
2 changes: 1 addition & 1 deletion DocumentsFromSnapshotMigration/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Using same base image as other Java containers in this repo
FROM amazoncorretto:11-al2023-headless
FROM amazoncorretto:17-al2023-headless

# Install the AWS CLI in the container
RUN dnf install -y aws-cli --setopt=install_weak_deps=False && \
Expand Down
3 changes: 0 additions & 3 deletions MetadataMigration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation project(":coreUtilities")
implementation project(":RFS")
Expand Down
3 changes: 0 additions & 3 deletions RFS/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ plugins {
id 'me.champeau.jmh'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

ext {
awsSdkVersion = '2.25.16'
dataset = findProperty('dataset') ?: 'skip_dataset'
Expand Down
3 changes: 0 additions & 3 deletions TrafficCapture/captureKafkaOffloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation project(':TrafficCapture:captureOffloader')
implementation project(':coreUtilities')
Expand Down
3 changes: 0 additions & 3 deletions TrafficCapture/captureOffloader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ plugins {
id 'java-test-fixtures'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

sourceSets {
main {
java {
Expand Down
3 changes: 0 additions & 3 deletions TrafficCapture/captureProtobufs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ plugins {
id 'com.google.protobuf' version "0.9.2"
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
api group: 'com.google.protobuf', name: 'protobuf-java'
}
Expand Down
3 changes: 0 additions & 3 deletions TrafficCapture/nettyWireLogging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation project(':TrafficCapture:captureOffloader')
implementation project(':coreUtilities')
Expand Down
94 changes: 91 additions & 3 deletions TrafficCapture/trafficCaptureProxyServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ configurations {
opensearchSecurityPlugin
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
def openSearch = '2.11.1'
implementation "org.opensearch.plugin:opensearch-security:${openSearch}.0"
Expand Down Expand Up @@ -68,3 +65,94 @@ application {
// Define the main class for the application.
mainClass = 'org.opensearch.migrations.trafficcapture.proxyserver.CaptureProxy'
}

tasks.register("verifyCompatibilityWithJDK11") {
group = "verification"
description = "Verify Java major versions of compiled classes and dependencies for compatibility with JDK 11."

// Declare task inputs
inputs.files(fileTree("${buildDir}/classes/java/main")).withPropertyName("compiledClasses")
inputs.files(configurations.compileClasspath).withPropertyName("compileClasspath")
inputs.files(configurations.runtimeClasspath).withPropertyName("runtimeClasspath")

// Declare outputs (optional if no files are written, just up-to-date checking)
outputs.upToDateWhen { true }

doLast {
// Task implementation logic
def isCompatible = true
def analyzedFiles = [] // To avoid duplicate processing

def getMajorVersion = { InputStream inputStream ->
inputStream.skip(6)
def majorVersion = inputStream.read() << 8 | inputStream.read()
inputStream.close()
return majorVersion
}

def processClassFile = { InputStream inputStream, String name, String source ->
def majorVersion = getMajorVersion(inputStream)
if (majorVersion > 55) {
isCompatible = false
println "Incompatible class file in ${source}: ${name} (Java major version ${majorVersion})"
}
}

def analyzeCompiledClasses = {
def outputDir = file("${buildDir}/classes/java/main")
if (outputDir.exists()) {
println "Analyzing compiled classes in ${outputDir}..."
fileTree(dir: outputDir, include: '**/*.class').forEach { classFile ->
classFile.withInputStream { inputStream ->
processClassFile(inputStream, classFile.name, outputDir.toString())
}
}
} else {
println "No compiled classes found in ${outputDir}."
}
}

def analyzeDependencies = { configuration ->
println "\nAnalyzing ${configuration.name} dependencies..."
configuration.files.each { dependency ->
if (dependency.name.endsWith(".jar") && !analyzedFiles.contains(dependency)) {
analyzedFiles.add(dependency)
def zipStream = new java.util.zip.ZipInputStream(new FileInputStream(dependency))
def entry
while ((entry = zipStream.nextEntry) != null) {
if (entry.name.endsWith(".class")) {
if (entry.name.startsWith("META-INF/versions/")) {
def versionDir = entry.name.split("/")[2]
def versionNumber = versionDir.isInteger() ? versionDir.toInteger() : 0
if (versionNumber > 11) {
continue
}
}
def tempFile = File.createTempFile("class", ".tmp")
tempFile.deleteOnExit()
tempFile.withOutputStream { it << zipStream }
tempFile.withInputStream { inputStream ->
processClassFile(inputStream, entry.name, dependency.name)
}
}
}
zipStream.close()
}
}
}

analyzeCompiledClasses()
analyzeDependencies(configurations.compileClasspath)
analyzeDependencies(configurations.runtimeClasspath)

if (!isCompatible) {
throw new GradleException("Incompatible class files detected! Ensure all classes are compatible with JDK 11 (major version ≤ 55).")
}
}
dependsOn tasks.named("assemble")
}

// Add class version verification to slowTest
tasks.named("slowTest") {
finalizedBy("verifyCompatibilityWithJDK11")
}
3 changes: 0 additions & 3 deletions awsUtilities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ plugins {
id 'java'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation group: 'software.amazon.awssdk', name: 'arns'
implementation group: 'software.amazon.awssdk', name: 'auth'
Expand Down
29 changes: 29 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ allprojects {
}
}


// Ensure Capture Proxy and Dependencies are built with JDK 11 for On Node Install

// Cache dependencies during the configuration phase
ext.captureProxyDependencies = []
gradle.projectsEvaluated {
def captureProxyProject = rootProject.project(":TrafficCapture:trafficCaptureProxyServer")
captureProxyDependencies = captureProxyProject.configurations.collectMany { configuration ->
configuration.dependencies.findAll { it instanceof ProjectDependency }.collect { it.dependencyProject.path }
}
// Add the TrafficCaptureProxyServer project itself
captureProxyDependencies << captureProxyProject.path
}

// Modify sourceCompatibility during the execution phase
gradle.taskGraph.whenReady { taskGraph ->
allprojects {
tasks.withType(JavaCompile).configureEach {
if (project.path in rootProject.captureProxyDependencies) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
} else {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
}
}

// Define version properties
ext {
// support -Dbuild.version, but include default
Expand Down
3 changes: 0 additions & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ plugins {
id 'org.owasp.dependencycheck' version '8.2.1'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CommonUtils {
runCommand("sed -i -e \"s|mirrorlist=|#mirrorlist=|g\" /etc/yum.repos.d/CentOS-* ; sed -i -e \"s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g\" /etc/yum.repos.d/CentOS-*")
}
} else {
from 'amazoncorretto:11-al2023-headless'
from 'amazoncorretto:17-al2023-headless'
}

copyFile("jars", "/jars")
Expand Down
3 changes: 0 additions & 3 deletions commonDependencyVersionConstraints/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ plugins {
id "java-library"
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

ext {
protobufVersion='3.25.5'
}
Expand Down
3 changes: 0 additions & 3 deletions coreUtilities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ plugins {
id 'java-test-fixtures'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
implementation group: "com.google.protobuf", name: "protobuf-java"
implementation group: 'org.slf4j', name: 'slf4j-api'
Expand Down
3 changes: 0 additions & 3 deletions dashboardsSanitizer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ plugins {
id 'java'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}
Expand Down
3 changes: 0 additions & 3 deletions libraries/kafkaCommandLineFormatter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ plugins {
id 'io.freefair.lombok'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation group: 'org.apache.kafka', name:'kafka-clients', version:'3.8.0'
}
3 changes: 0 additions & 3 deletions testHelperFixtures/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ plugins {
id 'java-test-fixtures'
}

java.sourceCompatibility = JavaVersion.VERSION_11
java.targetCompatibility = JavaVersion.VERSION_11

dependencies {
testFixturesImplementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind'
testFixturesImplementation group: 'com.google.guava', name: 'guava'
Expand Down
3 changes: 0 additions & 3 deletions transformation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ plugins {
id 'java-test-fixtures'
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

dependencies {
implementation project(':transformation:transformationPlugins:jsonMessageTransformers:jsonMessageTransformerInterface')

Expand Down

0 comments on commit 738cf2b

Please sign in to comment.