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 27, 2024
1 parent 0a1a385 commit 0d6eaeb
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 58 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 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
12 changes: 6 additions & 6 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
[package]
org = "ballerina"
name = "ldap"
version = "1.0.1"
version = "1.0.2"
authors = ["Ballerina"]
export=["ldap"]
keywords = ["ldap"]
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"
version = "1.0.2-SNAPSHOT"
path = "../native/build/libs/ldap-native-1.0.2-SNAPSHOT.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "com.unboundid"
artifactId = "unboundid-ldapsdk"
version = "7.0.0"
Expand Down
31 changes: 29 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.0"
distribution-version = "2201.10.0-20240926-231800-8a5a4343"

[[package]]
org = "ballerina"
Expand All @@ -15,6 +15,26 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
Expand All @@ -24,10 +44,16 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "ldap"
version = "1.0.1"
version = "1.0.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "test"}
Expand All @@ -43,6 +69,7 @@ version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
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
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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
Expand Down
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ 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")
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = file("$project.buildDir/reports/spotbugs")
reports {
html.enabled true
Expand Down
67 changes: 38 additions & 29 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,76 @@ 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);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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());
CompletableFuture<Object> future = new CompletableFuture<>();
ldapConnection.asyncCompare(compareRequest, (requestID, compareResult) -> {
if (compareResult.getResultCode().equals(ResultCode.COMPARE_TRUE)) {
future.complete(true);
Expand All @@ -175,10 +182,10 @@ public static Object compare(Environment env, BObject ldapClient,
future.complete(Utils.createError(ldapException.getMessage(), ldapException));
}
});
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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 +207,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,15 +217,16 @@ public static Object search(Environment env, BObject ldapClient, BString baseDn,
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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);
Expand All @@ -227,10 +236,10 @@ public static Object searchWithType(Environment env, BObject ldapClient, BString
SearchRequest searchRequest = new SearchRequest(searchResultListener, baseDn.getValue(),
searchScope, filter.getValue());
ldapConnection.asyncSearch(searchRequest);
} catch (LDAPException e) {
future.complete(Utils.createError(e.getMessage(), e));
return future.get();
} 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 0d6eaeb

Please sign in to comment.