Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Java 21 #62

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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.values.BMap;
import io.ballerina.runtime.api.values.BString;

Expand All @@ -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;
Expand All @@ -46,12 +46,12 @@
public class CustomSearchResultListener implements AsyncSearchResultListener {
@Serial
private static final long serialVersionUID = 1L;
private transient Future future;
private transient CompletableFuture<Object> future;
private transient List<BMap<BString, Object>> references;
private transient List<BMap<BString, Object>> entries;
private final String dN;

public CustomSearchResultListener(Future future, String dN) {
public CustomSearchResultListener(CompletableFuture<Object> future, String dN) {
this.dN = dN;
this.future = future;
this.references = new ArrayList<>();
Expand Down Expand Up @@ -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<Object> future) {
this.future = future;
}
}
3 changes: 3 additions & 0 deletions native/src/main/java/io/ballerina/lib/ldap/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ private Utils() {
public static final String LDAP_CONNECTION_CLOSED_ERROR = "LDAP Connection has been closed";

public static BError createError(String message, Throwable throwable) {
if (throwable.getCause() instanceof LDAPException ldapException) {
return createError(ldapException.getMessage(), ldapException.getCause());
}
BError cause = Objects.isNull(throwable) ? null : ErrorCreator.createError(throwable);
return ErrorCreator.createError(getModule(), ERROR_TYPE, fromString(message), cause, null);
}
Expand Down
Loading
Loading