From 36054804f4f78629d046cc7c941ec25545571ee6 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Fri, 27 Sep 2024 15:51:10 +0530 Subject: [PATCH 1/8] Migrate to Java 21 --- .../workflows/build-timestamped-master.yml | 2 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- README.md | 2 +- ballerina/Ballerina.toml | 6 +- ballerina/build.gradle | 2 +- build-config/resources/Ballerina.toml | 6 +- build.gradle | 2 + gradle.properties | 5 +- native/build.gradle | 8 ++- .../java/io/ballerina/lib/ldap/Client.java | 72 ++++++++++++------- .../lib/ldap/CustomAsyncResultListener.java | 7 +- .../lib/ldap/CustomSearchEntryListener.java | 8 +-- .../lib/ldap/CustomSearchResultListener.java | 8 +-- spotbugs-exclude.xml | 12 ++++ 18 files changed, 96 insertions(+), 54 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index a7d3528..9a0c3bd 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -15,7 +15,7 @@ jobs: call_workflow: name: Run Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21 secrets: inherit with: additional-build-flags: "-x test" diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 5f1f6c1..9831630 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -30,7 +30,7 @@ jobs: call_stdlib_workflow: name: Run StdLib Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21 with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index cca0723..f752a07 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -15,7 +15,7 @@ jobs: call_workflow: name: Run Central Publish Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21 secrets: inherit with: environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index d886096..a512dea 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,7 +9,7 @@ jobs: call_workflow: name: Run Release Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@java21 secrets: inherit with: package-name: ldap diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4cf39bb..e0ce07a 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,7 +10,7 @@ jobs: call_workflow: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21 secrets: inherit with: additional-windows-test-flags: "-x test" diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 12c95cc..7036741 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,5 +9,5 @@ jobs: call_workflow: name: Run Trivy Scan Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@java21 secrets: inherit diff --git a/README.md b/README.md index e75eaac..9b78515 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ This repository only contains the source code for the package. ### Prerequisites -1. Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources: +1. Download and install Java SE Development Kit (JDK) version 21. You can download it from either of the following sources: - [Oracle JDK](https://www.oracle.com/java/technologies/downloads/) - [OpenJDK](https://adoptium.net/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index b0386b8..64c2700 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -9,16 +9,16 @@ repository = "https://github.com/ballerina-platform/module-ballerina-ldap" license = ["Apache-2.0"] distribution = "2201.8.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "ldap-native" version = "1.0.1" path = "../native/build/libs/ldap-native-1.0.1.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "com.unboundid" artifactId = "unboundid-ldapsdk" version = "7.0.0" diff --git a/ballerina/build.gradle b/ballerina/build.gradle index c741135..48b2d23 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -49,7 +49,7 @@ ballerina { module = packageName testCoverageParam = "--code-coverage --coverage-format=xml" langVersion = ballerinaLangVersion - platform = "java17" + platform = "java21" } configurations { diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index ed90c08..0391423 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,16 +9,16 @@ repository = "https://github.com/ballerina-platform/module-ballerina-ldap" license = ["Apache-2.0"] distribution = "2201.8.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "ldap-native" version = "@project.version@" path = "../native/build/libs/ldap-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "com.unboundid" artifactId = "unboundid-ldapsdk" version = "@unboundIdLdap.version@" diff --git a/build.gradle b/build.gradle index 25ff235..f380c9b 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,8 @@ subprojects { jbalTools ("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") { transitive = false } + /* Standard libraries */ + ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" } } diff --git a/gradle.properties b/gradle.properties index 5bae059..63e0fd1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,14 @@ org.gradle.caching=true group=io.ballerina.lib version=1.0.2-SNAPSHOT -ballerinaLangVersion=2201.8.0 +ballerinaLangVersion=2201.10.0-20240926-231800-8a5a4343 checkstylePluginVersion=10.12.0 -spotbugsPluginVersion=5.0.14 +spotbugsPluginVersion=6.0.18 shadowJarPluginVersion=8.1.1 downloadPluginVersion=5.4.0 releasePluginVersion=2.8.0 ballerinaGradlePluginVersion=2.2.4 +stdlibIoVersion=1.6.2-20240928-084100-656404f unboundIdLdapVersion=7.0.0 diff --git a/native/build.gradle b/native/build.gradle index c35728a..175ad03 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -57,8 +57,12 @@ test { } spotbugsMain { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + ignoreFailures = true + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/native/src/main/java/io/ballerina/lib/ldap/Client.java b/native/src/main/java/io/ballerina/lib/ldap/Client.java index e08cded..85e3108 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/Client.java +++ b/native/src/main/java/io/ballerina/lib/ldap/Client.java @@ -37,7 +37,6 @@ import com.unboundid.ldap.sdk.SearchScope; import com.unboundid.util.Base64; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; @@ -55,6 +54,7 @@ import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.concurrent.CompletableFuture; import static com.unboundid.ldap.sdk.ResultCode.NO_SUCH_OBJECT; import static com.unboundid.ldap.sdk.ResultCode.OTHER; @@ -102,69 +102,83 @@ public static BError initLdapConnection(BObject ldapClient, BMap entry) { - Future future = env.markAsync(); + env.markAsync(); + CompletableFuture future = new CompletableFuture<>(); try { LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); validateConnection(ldapConnection); AddRequest addRequest = generateAddRequest(dN, entry); CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); ldapConnection.asyncAdd(addRequest, customAsyncResultListener); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; } public static Object modify(Environment env, BObject ldapClient, BString dN, BMap entry) { - Future future = env.markAsync(); + env.markAsync(); + CompletableFuture future = new CompletableFuture<>(); try { LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); validateConnection(ldapConnection); ModifyRequest modifyRequest = generateModifyRequest(dN, entry); CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); ldapConnection.asyncModify(modifyRequest, customAsyncResultListener); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; } public static Object modifyDn(Environment env, BObject ldapClient, BString currentDn, BString newRdn, boolean deleteOldRdn) { - Future future = env.markAsync(); + env.markAsync(); + CompletableFuture future = new CompletableFuture<>(); try { LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); validateConnection(ldapConnection); ModifyDNRequest modifyRequest = new ModifyDNRequest(currentDn.getValue(), newRdn.getValue(), deleteOldRdn); CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); ldapConnection.asyncModifyDN(modifyRequest, customAsyncResultListener); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; + } public static Object delete(Environment env, BObject ldapClient, BString dN) { - Future future = env.markAsync(); + env.markAsync(); + CompletableFuture future = new CompletableFuture<>(); try { LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); validateConnection(ldapConnection); CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); ldapConnection.asyncDelete(new DeleteRequest(dN.getValue()), customAsyncResultListener); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; } public static Object compare(Environment env, BObject ldapClient, BString dN, BString attributeName, BString assertionValue) { - Future future = env.markAsync(); + env.markAsync(); try { LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); validateConnection(ldapConnection); CompareRequest compareRequest = new CompareRequest(dN.getValue(), attributeName.getValue(), - assertionValue.getValue()); + assertionValue.getValue()); + CompletableFuture future = new CompletableFuture<>(); ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> { if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) { future.complete(true); @@ -175,10 +189,12 @@ public static Object compare(Environment env, BObject ldapClient, future.complete(Utils.createError(ldapException.getMessage(), ldapException)); } }); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; } public static Object getEntry(BObject ldapClient, BString dN, BTypedesc typeParam) { @@ -200,7 +216,8 @@ public static Object getEntry(BObject ldapClient, BString dN, BTypedesc typePara } public static Object search(Environment env, BObject ldapClient, BString baseDn, BString filter, BString scope) { - Future future = env.markAsync(); + env.markAsync(); + CompletableFuture future = new CompletableFuture<>(); try { SearchScope searchScope = getSearchScope(scope); LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); @@ -209,28 +226,33 @@ public static Object search(Environment env, BObject ldapClient, BString baseDn, SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(), searchScope, filter.getValue()); ldapConnection.asyncSearch(searchRequest); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; } public static Object searchWithType(Environment env, BObject ldapClient, BString baseDn, BString filter, BString scope, BTypedesc typeParam) { - Future future = env.markAsync(); + env.markAsync(); + CompletableFuture future = new CompletableFuture<>(); try { SearchScope searchScope = getSearchScope(scope); LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); validateConnection(ldapConnection); SearchResultListener searchResultListener = new CustomSearchEntryListener(future, typeParam, - baseDn.getValue()); + baseDn.getValue()); SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(), - searchScope, filter.getValue()); + searchScope, filter.getValue()); ldapConnection.asyncSearch(searchRequest); + return future.get(); } catch (LDAPException e) { - future.complete(Utils.createError(e.getMessage(), e)); + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); } - return null; } public static void close(BObject ldapClient) { diff --git a/native/src/main/java/io/ballerina/lib/ldap/CustomAsyncResultListener.java b/native/src/main/java/io/ballerina/lib/ldap/CustomAsyncResultListener.java index 16c763e..f99a4eb 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/CustomAsyncResultListener.java +++ b/native/src/main/java/io/ballerina/lib/ldap/CustomAsyncResultListener.java @@ -23,7 +23,8 @@ import com.unboundid.ldap.sdk.LDAPException; import com.unboundid.ldap.sdk.LDAPResult; import com.unboundid.ldap.sdk.ResultCode; -import io.ballerina.runtime.api.Future; + +import java.util.concurrent.CompletableFuture; import static io.ballerina.lib.ldap.Client.generateLdapResponse; @@ -31,9 +32,9 @@ * Callback class to handle asynchronous operations. */ public class CustomAsyncResultListener implements AsyncResultListener { - private final Future future; + private final CompletableFuture future; - public CustomAsyncResultListener(Future future) { + public CustomAsyncResultListener(CompletableFuture future) { this.future = future; } diff --git a/native/src/main/java/io/ballerina/lib/ldap/CustomSearchEntryListener.java b/native/src/main/java/io/ballerina/lib/ldap/CustomSearchEntryListener.java index 33c3765..c92a863 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/CustomSearchEntryListener.java +++ b/native/src/main/java/io/ballerina/lib/ldap/CustomSearchEntryListener.java @@ -26,7 +26,6 @@ import com.unboundid.ldap.sdk.SearchResult; import com.unboundid.ldap.sdk.SearchResultEntry; import com.unboundid.ldap.sdk.SearchResultReference; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.utils.ValueUtils; @@ -40,6 +39,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serial; +import java.util.concurrent.CompletableFuture; import static io.ballerina.lib.ldap.Client.processAttribute; import static io.ballerina.lib.ldap.Utils.ENTRY_NOT_FOUND; @@ -51,13 +51,13 @@ public class CustomSearchEntryListener implements AsyncSearchResultListener { @Serial private static final long serialVersionUID = 1L; - private transient Future future; + private transient CompletableFuture future; private transient BArray array; private transient BError error; private transient BTypedesc typeDesc; private final String dN; - public CustomSearchEntryListener(Future future, BTypedesc typeDesc, String dN) { + public CustomSearchEntryListener(CompletableFuture future, BTypedesc typeDesc, String dN) { this.future = future; this.array = ValueCreator.createArrayValue((ArrayType) typeDesc.getDescribingType()); this.dN = dN; @@ -113,7 +113,7 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound this.error = null; } - public void setFuture(Future future) { + public void setFuture(CompletableFuture future) { this.future = future; } diff --git a/native/src/main/java/io/ballerina/lib/ldap/CustomSearchResultListener.java b/native/src/main/java/io/ballerina/lib/ldap/CustomSearchResultListener.java index ee152ac..6d542f5 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/CustomSearchResultListener.java +++ b/native/src/main/java/io/ballerina/lib/ldap/CustomSearchResultListener.java @@ -26,7 +26,6 @@ import com.unboundid.ldap.sdk.SearchResult; import com.unboundid.ldap.sdk.SearchResultEntry; import com.unboundid.ldap.sdk.SearchResultReference; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; @@ -36,6 +35,7 @@ import java.io.Serial; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import static io.ballerina.lib.ldap.Client.processAttribute; import static io.ballerina.lib.ldap.Utils.ENTRY_NOT_FOUND; @@ -46,12 +46,12 @@ public class CustomSearchResultListener implements AsyncSearchResultListener { @Serial private static final long serialVersionUID = 1L; - private transient Future future; + private transient CompletableFuture future; private transient List> references; private transient List> entries; private final String dN; - public CustomSearchResultListener(Future future, String dN) { + public CustomSearchResultListener(CompletableFuture future, String dN) { this.dN = dN; this.future = future; this.references = new ArrayList<>(); @@ -100,7 +100,7 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound this.entries = new ArrayList<>(); } - public void setFuture(Future future) { + public void setFuture(CompletableFuture future) { this.future = future; } } diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index b5d3519..7153752 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -19,4 +19,16 @@ + + + + + + + + + + + + From 55ca1d2e76ed1bc6845122a3302f14f87787887f Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Fri, 11 Oct 2024 21:42:29 +0530 Subject: [PATCH 2/8] Add yieldAndRun API changes --- gradle.properties | 2 +- .../java/io/ballerina/lib/ldap/Client.java | 231 +++++++++--------- 2 files changed, 120 insertions(+), 113 deletions(-) diff --git a/gradle.properties b/gradle.properties index 63e0fd1..10e70fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib version=1.0.2-SNAPSHOT -ballerinaLangVersion=2201.10.0-20240926-231800-8a5a4343 +ballerinaLangVersion=2201.10.0-20241011-161100-51978649 checkstylePluginVersion=10.12.0 spotbugsPluginVersion=6.0.18 diff --git a/native/src/main/java/io/ballerina/lib/ldap/Client.java b/native/src/main/java/io/ballerina/lib/ldap/Client.java index 85e3108..1eb4d24 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/Client.java +++ b/native/src/main/java/io/ballerina/lib/ldap/Client.java @@ -102,99 +102,104 @@ public static BError initLdapConnection(BObject ldapClient, BMap entry) { - env.markAsync(); - CompletableFuture future = new CompletableFuture<>(); - try { - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - AddRequest addRequest = generateAddRequest(dN, entry); - CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); - ldapConnection.asyncAdd(addRequest, customAsyncResultListener); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } + return env.yieldAndRun(() -> { + CompletableFuture future = new CompletableFuture<>(); + try { + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + AddRequest addRequest = generateAddRequest(dN, entry); + CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); + ldapConnection.asyncAdd(addRequest, customAsyncResultListener); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static Object modify(Environment env, BObject ldapClient, BString dN, BMap entry) { - env.markAsync(); - CompletableFuture future = new CompletableFuture<>(); - try { - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - ModifyRequest modifyRequest = generateModifyRequest(dN, entry); - CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); - ldapConnection.asyncModify(modifyRequest, customAsyncResultListener); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } + return env.yieldAndRun(() -> { + CompletableFuture future = new CompletableFuture<>(); + try { + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + ModifyRequest modifyRequest = generateModifyRequest(dN, entry); + CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); + ldapConnection.asyncModify(modifyRequest, customAsyncResultListener); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static Object modifyDn(Environment env, BObject ldapClient, BString currentDn, BString newRdn, boolean deleteOldRdn) { - env.markAsync(); - CompletableFuture future = new CompletableFuture<>(); - try { - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - ModifyDNRequest modifyRequest = new ModifyDNRequest(currentDn.getValue(), newRdn.getValue(), deleteOldRdn); - CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); - ldapConnection.asyncModifyDN(modifyRequest, customAsyncResultListener); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } - + return env.yieldAndRun(() -> { + CompletableFuture future = new CompletableFuture<>(); + try { + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + ModifyDNRequest modifyRequest = + new ModifyDNRequest(currentDn.getValue(), newRdn.getValue(), deleteOldRdn); + CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); + ldapConnection.asyncModifyDN(modifyRequest, customAsyncResultListener); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static Object delete(Environment env, BObject ldapClient, BString dN) { - env.markAsync(); - CompletableFuture future = new CompletableFuture<>(); - try { - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); - ldapConnection.asyncDelete(new DeleteRequest(dN.getValue()), customAsyncResultListener); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } + return env.yieldAndRun(() -> { + CompletableFuture future = new CompletableFuture<>(); + try { + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + CustomAsyncResultListener customAsyncResultListener = new CustomAsyncResultListener(future); + ldapConnection.asyncDelete(new DeleteRequest(dN.getValue()), customAsyncResultListener); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static Object compare(Environment env, BObject ldapClient, BString dN, BString attributeName, BString assertionValue) { - env.markAsync(); - try { - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - CompareRequest compareRequest = new CompareRequest(dN.getValue(), attributeName.getValue(), - assertionValue.getValue()); - CompletableFuture future = new CompletableFuture<>(); - ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> { - if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) { - future.complete(true); - } else if (compareResult.getResultCode().equals(ResultCode.COMPARE_FALSE)) { - future.complete(false); - } else { - LDAPException ldapException = new LDAPException(compareResult); - future.complete(Utils.createError(ldapException.getMessage(), ldapException)); - } - }); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } + return env.yieldAndRun(() -> { + try { + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + CompareRequest compareRequest = new CompareRequest(dN.getValue(), attributeName.getValue(), + assertionValue.getValue()); + CompletableFuture future = new CompletableFuture<>(); + ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> { + if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) { + future.complete(true); + } else if (compareResult.getResultCode().equals(ResultCode.COMPARE_FALSE)) { + future.complete(false); + } else { + LDAPException ldapException = new LDAPException(compareResult); + future.complete(Utils.createError(ldapException.getMessage(), ldapException)); + } + }); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static Object getEntry(BObject ldapClient, BString dN, BTypedesc typeParam) { @@ -216,43 +221,45 @@ public static Object getEntry(BObject ldapClient, BString dN, BTypedesc typePara } public static Object search(Environment env, BObject ldapClient, BString baseDn, BString filter, BString scope) { - env.markAsync(); - CompletableFuture future = new CompletableFuture<>(); - try { - SearchScope searchScope = getSearchScope(scope); - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - SearchResultListener searchResultListener = new CustomSearchResultListener(future, baseDn.getValue()); - SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(), - searchScope, filter.getValue()); - ldapConnection.asyncSearch(searchRequest); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } + return env.yieldAndRun(() -> { + CompletableFuture future = new CompletableFuture<>(); + try { + SearchScope searchScope = getSearchScope(scope); + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + SearchResultListener searchResultListener = new CustomSearchResultListener(future, baseDn.getValue()); + SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(), + searchScope, filter.getValue()); + ldapConnection.asyncSearch(searchRequest); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static Object searchWithType(Environment env, BObject ldapClient, BString baseDn, BString filter, BString scope, BTypedesc typeParam) { - env.markAsync(); - CompletableFuture future = new CompletableFuture<>(); - try { - SearchScope searchScope = getSearchScope(scope); - LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); - validateConnection(ldapConnection); - SearchResultListener searchResultListener = new CustomSearchEntryListener(future, typeParam, - baseDn.getValue()); - SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(), - searchScope, filter.getValue()); - ldapConnection.asyncSearch(searchRequest); - return future.get(); - } catch (LDAPException e) { - return Utils.createError(e.getMessage(), e); - } catch (Throwable e) { - return Utils.createError(e.getMessage(), e); - } + return env.yieldAndRun(() -> { + CompletableFuture future = new CompletableFuture<>(); + try { + SearchScope searchScope = getSearchScope(scope); + LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT); + validateConnection(ldapConnection); + SearchResultListener searchResultListener = new CustomSearchEntryListener(future, typeParam, + baseDn.getValue()); + SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(), + searchScope, filter.getValue()); + ldapConnection.asyncSearch(searchRequest); + return future.get(); + } catch (LDAPException e) { + return Utils.createError(e.getMessage(), e); + } catch (Throwable e) { + return Utils.createError(e.getMessage(), e); + } + }); } public static void close(BObject ldapClient) { From edb8acccb8846b898058a4b501fb0739d0bb30fb Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 12 Nov 2024 23:03:32 +0530 Subject: [PATCH 3/8] Migrate to new Runtime APIs --- gradle.properties | 2 +- native/src/main/java/io/ballerina/lib/ldap/Client.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 10e70fc..e8f67e9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib version=1.0.2-SNAPSHOT -ballerinaLangVersion=2201.10.0-20241011-161100-51978649 +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 checkstylePluginVersion=10.12.0 spotbugsPluginVersion=6.0.18 diff --git a/native/src/main/java/io/ballerina/lib/ldap/Client.java b/native/src/main/java/io/ballerina/lib/ldap/Client.java index 1eb4d24..d861981 100644 --- a/native/src/main/java/io/ballerina/lib/ldap/Client.java +++ b/native/src/main/java/io/ballerina/lib/ldap/Client.java @@ -37,8 +37,8 @@ import com.unboundid.ldap.sdk.SearchScope; import com.unboundid.util.Base64; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.utils.ValueUtils; From a2bf29a360bf64e27a4a8a0129e134ee18f49bd7 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Wed, 13 Nov 2024 08:17:50 +0530 Subject: [PATCH 4/8] Bump crypto version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index de9dc75..8b434d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,5 +13,5 @@ ballerinaGradlePluginVersion=2.2.4 stdlibIoVersion=1.6.2-20240928-084100-656404f unboundIdLdapVersion=7.0.0 -stdlibCryptoVersion=2.7.2 +stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 stdlibTimeVersion=2.5.1-20241112-230500-2f4e8e9 From 37e4b392b5bf98912806941feae70d3e1586efcf Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Wed, 13 Nov 2024 08:28:45 +0530 Subject: [PATCH 5/8] Bump time version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8b434d7..dffac5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,4 +14,4 @@ stdlibIoVersion=1.6.2-20240928-084100-656404f unboundIdLdapVersion=7.0.0 stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 -stdlibTimeVersion=2.5.1-20241112-230500-2f4e8e9 +stdlibTimeVersion=2.6.0-20241113-073800-201b904 From f4a3d0423c2e79d9d0b5cd12f2ad56914a50a405 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Wed, 13 Nov 2024 08:31:28 +0530 Subject: [PATCH 6/8] [Automated] Update the toml files --- ballerina/Dependencies.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 80b73fd..8594c70 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.11.0-20241112-214900-6b80ab87" [[package]] org = "ballerina" name = "crypto" -version = "2.7.2" +version = "2.7.3" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -92,7 +92,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.5.0" +version = "2.6.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] From ea581b79715d37187f30e8de8a68ab90dcfeecab Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Wed, 13 Nov 2024 08:39:47 +0530 Subject: [PATCH 7/8] Bump io version --- build.gradle | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2f98e2c..b2fec17 100644 --- a/build.gradle +++ b/build.gradle @@ -78,6 +78,7 @@ subprojects { } /* Standard libraries */ + ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" ballerinaStdLibs "io.ballerina.stdlib:crypto-ballerina:${stdlibCryptoVersion}" ballerinaStdLibs "io.ballerina.stdlib:time-ballerina:${stdlibTimeVersion}" } diff --git a/gradle.properties b/gradle.properties index dffac5d..a5faf9e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,8 +10,8 @@ downloadPluginVersion=5.4.0 releasePluginVersion=2.8.0 ballerinaGradlePluginVersion=2.2.4 -stdlibIoVersion=1.6.2-20240928-084100-656404f unboundIdLdapVersion=7.0.0 +stdlibIoVersion=1.6.2-20240928-084100-656404f stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 stdlibTimeVersion=2.6.0-20241113-073800-201b904 From 50e9bdea622515652d53d908ab7a8c28738018fc Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Mon, 18 Nov 2024 09:35:00 +0530 Subject: [PATCH 8/8] Use main branch for github actions --- .github/workflows/build-timestamped-master.yml | 2 +- .github/workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- gradle.properties | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 9a0c3bd..a7d3528 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -15,7 +15,7 @@ jobs: call_workflow: name: Run Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main secrets: inherit with: additional-build-flags: "-x test" diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 9831630..5f1f6c1 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -30,7 +30,7 @@ jobs: call_stdlib_workflow: name: Run StdLib Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index f752a07..cca0723 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -15,7 +15,7 @@ jobs: call_workflow: name: Run Central Publish Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main secrets: inherit with: environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index a512dea..d886096 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,7 +9,7 @@ jobs: call_workflow: name: Run Release Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main secrets: inherit with: package-name: ldap diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index e0ce07a..4cf39bb 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,7 +10,7 @@ jobs: call_workflow: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main secrets: inherit with: additional-windows-test-flags: "-x test" diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 7036741..12c95cc 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,5 +9,5 @@ jobs: call_workflow: name: Run Trivy Scan Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit diff --git a/gradle.properties b/gradle.properties index a5faf9e..1511d18 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib version=1.1.0-SNAPSHOT -ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 +ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77 checkstylePluginVersion=10.12.0 spotbugsPluginVersion=6.0.18