Skip to content

Commit

Permalink
Restore support for Java 8 (#798)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 32da329 commit 7acd729
Show file tree
Hide file tree
Showing 67 changed files with 135 additions and 52 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [ 11, 17, 21 ]
java: [ 8, 11, 17, 21 ]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout Java Client
Expand All @@ -21,4 +21,17 @@ jobs:
cache: 'gradle'

- name: Run Unit Test
if: ${{ matrix.java != 8 }}
run: ./gradlew clean unitTest

- name: Set up JDK 11
uses: actions/setup-java@v3
if: ${{ matrix.java == 8 }}
with:
java-version: 11
distribution: 'temurin'
cache: 'gradle'

- name: Run Unit Test
if: ${{ matrix.java == 8 }}
run: ./gradlew clean unitTest -D"runtime.java=8"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Dependencies

### Changed
- Restore support for Java 8 ([#767](https://github.com/opensearch-project/opensearch-java/pull/767))
- Add an integration test that runs on JDK-8 ([#795](https://github.com/opensearch-project/opensearch-java/pull/795))

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The below matrix shows the compatibility of the [`opensearch-java-client`](https
| Client Version | JDK |
|----------------|--------------------|
| 1.0.0 | 8 |
| 2.x.0 | 11 / 17 / 21 |
| 2.x.0 | 8 / 11 / 17 / 21 |

## Upgrading

Expand Down
62 changes: 56 additions & 6 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.github.jk1.license.ProjectData
import com.github.jk1.license.render.ReportRenderer
import org.gradle.api.tasks.testing.Test
import java.io.FileWriter

buildscript {
Expand Down Expand Up @@ -60,16 +61,27 @@ configurations {
}
}

val runtimeJavaVersion = (System.getProperty("runtime.java")?.toInt())?.let(JavaVersion::toVersion) ?: JavaVersion.current()
logger.quiet("=======================================")
logger.quiet(" Runtime JDK Version : " + runtimeJavaVersion)
logger.quiet(" Gradle JDK Version : " + JavaVersion.current())
logger.quiet("=======================================")

java {
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8

withJavadocJar()
withSourcesJar()

registerFeature("awsSdk2Support") {
usingSourceSet(sourceSets.get("main"))
}

toolchain {
languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion)
vendor = JvmVendorSpec.ADOPTIUM
}
}

tasks.withType<ProcessResources> {
Expand Down Expand Up @@ -146,15 +158,19 @@ val integrationTest = task<Test>("integrationTest") {
System.getProperty("tests.awsSdk2support.domainRegion", "us-east-1"))
}

val opensearchVersion = "2.12.0"

dependencies {

val opensearchVersion = "2.7.0"
val jacksonVersion = "2.15.2"
val jacksonDatabindVersion = "2.15.2"
val jacksonVersion = "2.16.1"
val jacksonDatabindVersion = "2.16.1"

// Apache 2.0
implementation("org.opensearch.client", "opensearch-rest-client", opensearchVersion)
testImplementation("org.opensearch.test", "framework", opensearchVersion)
testImplementation("org.hamcrest:hamcrest:2.2")
testImplementation("com.carrotsearch.randomizedtesting:randomizedtesting-runner:2.8.1") {
exclude(group = "junit")
}

// Apache 2.0
// https://search.maven.org/artifact/com.google.code.findbugs/jsr305
Expand Down Expand Up @@ -327,3 +343,37 @@ publishing {
}
}
}

if (runtimeJavaVersion >= JavaVersion.VERSION_11) {
val java11: SourceSet = sourceSets.create("java11") {
java {
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output
srcDir("src/test/java11")
}
}

configurations[java11.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
configurations[java11.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())

dependencies {
testImplementation("org.opensearch.test", "framework", opensearchVersion) {
exclude(group = "org.hamcrest")
}
}

tasks.named<JavaCompile>("compileJava11Java") {
targetCompatibility = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.named<JavaCompile>("compileTestJava") {
targetCompatibility = JavaVersion.VERSION_11.toString()
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.test {
testClassesDirs += java11.output.classesDirs
classpath = sourceSets["java11"].runtimeClasspath
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch._types.GeoLocation;
import org.opensearch.client.opensearch.model.ModelTestCase;
Expand All @@ -9,7 +9,7 @@ public class GeoDistanceQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
GeoDistanceQuery origin = new GeoDistanceQuery.Builder().field("field")
.location(new GeoLocation.Builder().coords(List.of(1.0)).build())
.location(new GeoLocation.Builder().coords(Collections.singletonList(1.0)).build())
.build();
GeoDistanceQuery copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class PinnedQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
PinnedQuery origin = new PinnedQuery.Builder().organic(buildDummyQuery()).ids(List.of("1")).build();
PinnedQuery origin = new PinnedQuery.Builder().organic(buildDummyQuery()).ids(Collections.singletonList("1")).build();
PinnedQuery copied = origin.toBuilder().build();

assertEquals(toJson(copied), toJson(origin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanContainingQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanContainingQuery origin = new SpanContainingQuery.Builder().big(
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build();
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build();
SpanContainingQuery copied = origin.toBuilder().build();

assertEquals(toJson(copied), toJson(origin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanFieldMaskingQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanFieldMaskingQuery origin = new SpanFieldMaskingQuery.Builder().field("field")
.query(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
.query(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build())
.build();
SpanFieldMaskingQuery copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanFirstQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanFirstQuery origin = new SpanFirstQuery.Builder().end(1)
.match(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
.match(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build())
.build();
SpanFirstQuery copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanNearQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanNearQuery origin = new SpanNearQuery.Builder().clauses(
List.of(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
Collections.singletonList(
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
)
).build();
SpanNearQuery copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanNotQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanNotQuery origin = new SpanNotQuery.Builder().include(
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()
).exclude(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build();
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
).exclude(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build();
SpanNotQuery copied = origin.toBuilder().build();

assertEquals(toJson(copied), toJson(origin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanOrQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanOrQuery origin = new SpanOrQuery.Builder().clauses(
List.of(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
Collections.singletonList(
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
)
).build();
SpanOrQuery copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanQuery origin = new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build();
SpanQuery origin = new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build();
SpanQuery copied = origin.toBuilder().build();

assertEquals(toJson(copied), toJson(origin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class SpanWithinQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
SpanWithinQuery origin = new SpanWithinQuery.Builder().big(
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build();
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build();
SpanWithinQuery copied = origin.toBuilder().build();

assertEquals(toJson(copied), toJson(origin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class TermsQueryFieldTest extends ModelTestCase {
@Test
public void toBuilder() {
TermsQueryField origin = new TermsQueryField.Builder().value(List.of(FieldValue.of("1"))).build();
TermsQueryField origin = new TermsQueryField.Builder().value(Collections.singletonList(FieldValue.of("1"))).build();
TermsQueryField copied = origin.toBuilder().build();

assertEquals(toJson(copied), toJson(origin));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opensearch.client.opensearch._types.query_dsl;

import java.util.List;
import java.util.Collections;
import org.junit.Test;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch.model.ModelTestCase;
Expand All @@ -9,7 +9,7 @@ public class TermsQueryTest extends ModelTestCase {
@Test
public void toBuilder() {
TermsQuery origin = new TermsQuery.Builder().field("field")
.terms(new TermsQueryField.Builder().value(List.of(FieldValue.of("1"))).build())
.terms(new TermsQueryField.Builder().value(Collections.singletonList(FieldValue.of("1"))).build())
.build();
TermsQuery copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opensearch.client.opensearch.core;

import java.util.List;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.client.opensearch.core.bulk.BulkOperation;
Expand All @@ -11,7 +11,9 @@ public class BulkRequestTest extends Assert {
@Test
public void toBuilder() {
BulkRequest origin = new BulkRequest.Builder().index("index")
.operations(List.of(new BulkOperation.Builder().delete(new DeleteOperation.Builder().id("id").build()).build()))
.operations(
Collections.singletonList(new BulkOperation.Builder().delete(new DeleteOperation.Builder().id("id").build()).build())
)
.build();
BulkRequest copied = origin.toBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch.core;

import java.util.List;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;

public class ClearScrollRequestTest extends Assert {

@Test
public void toBuilder() {
ClearScrollRequest origin = new ClearScrollRequest.Builder().scrollId(List.of("1")).build();
ClearScrollRequest origin = new ClearScrollRequest.Builder().scrollId(Collections.singletonList("1")).build();
ClearScrollRequest copied = origin.toBuilder().build();

assertEquals(copied.scrollId(), origin.scrollId());
Expand Down
Loading

0 comments on commit 7acd729

Please sign in to comment.