Skip to content

Commit

Permalink
Migrate to Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Sep 28, 2024
1 parent 0a1a385 commit 3605480
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ballerina {
module = packageName
testCoverageParam = "--code-coverage --coverage-format=xml"
langVersion = ballerinaLangVersion
platform = "java17"
platform = "java21"
}

configurations {
Expand Down
6 changes: 3 additions & 3 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "com.unboundid"
artifactId = "unboundid-ldapsdk"
version = "@unboundIdLdap.version@"
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ subprojects {
jbalTools ("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") {
transitive = false
}
/* Standard libraries */
ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}"
}
}

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 47 additions & 25 deletions native/src/main/java/io/ballerina/lib/ldap/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -102,69 +102,83 @@ public static BError initLdapConnection(BObject ldapClient, BMap<BString, Object
}

public static Object add(Environment env, BObject ldapClient, BString dN, BMap<BString, Object> entry) {
Future future = env.markAsync();
env.markAsync();
CompletableFuture<Object> 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<BString, BString> entry) {
Future future = env.markAsync();
env.markAsync();
CompletableFuture<Object> 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<Object> 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<Object> 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<Object> future = new CompletableFuture<>();
ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> {
if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) {
future.complete(true);
Expand All @@ -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) {
Expand All @@ -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<Object> future = new CompletableFuture<>();
try {
SearchScope searchScope = getSearchScope(scope);
LDAPConnection ldapConnection = (LDAPConnection) ldapClient.getNativeData(NATIVE_CLIENT);
Expand All @@ -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<Object> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
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;

/**
* Callback class to handle asynchronous operations.
*/
public class CustomAsyncResultListener implements AsyncResultListener {
private final Future future;
private final CompletableFuture<Object> future;

public CustomAsyncResultListener(Future future) {
public CustomAsyncResultListener(CompletableFuture<Object> future) {
this.future = future;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -51,13 +51,13 @@ public class CustomSearchEntryListener implements AsyncSearchResultListener {

@Serial
private static final long serialVersionUID = 1L;
private transient Future future;
private transient CompletableFuture<Object> 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<Object> future, BTypedesc typeDesc, String dN) {
this.future = future;
this.array = ValueCreator.createArrayValue((ArrayType) typeDesc.getDescribingType());
this.dN = dN;
Expand Down Expand Up @@ -113,7 +113,7 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound
this.error = null;
}

public void setFuture(Future future) {
public void setFuture(CompletableFuture<Object> future) {
this.future = future;
}

Expand Down
Loading

0 comments on commit 3605480

Please sign in to comment.