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

Package libraries Java code as Java Modules #10714

Draft
wants to merge 49 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9c149b9
Must specify --repl to enable debug server
JaroslavTulach Jul 29, 2024
76070ba
Use --repl to enable REPL changelog note
JaroslavTulach Jul 29, 2024
873c418
Towards a ClassPath per Package
JaroslavTulach Jul 30, 2024
3b1bc98
One ClassLoader per each Package
JaroslavTulach Jul 30, 2024
45f62cf
Define ModuleLayer for each Package
JaroslavTulach Jul 30, 2024
8700cc8
Load classes via ModuleLayer
JaroslavTulach Jul 30, 2024
74f8111
Turning std-base and std-aws into Java modules
JaroslavTulach Jul 30, 2024
7e865ce
Turn common-polyglot-core-utils into JPMS module
Akirathan Jul 30, 2024
3a6c335
Add depedencies to org.enso.std.base JPMS module
Akirathan Jul 30, 2024
b23be3d
Turn std-database into JPMS module
Akirathan Jul 30, 2024
f0dd3f7
Add depedencies to org.enso.std.aws JPMS module
Akirathan Jul 30, 2024
c4c1842
Using module-info to register SPI services
JaroslavTulach Jul 31, 2024
149dc7e
Removing another no longer needed dependency on NetBeans Lookup API
JaroslavTulach Jul 31, 2024
48b29c7
Removing add to class path concept
JaroslavTulach Jul 31, 2024
dd5723e
Turn std-table into JPMS module
Akirathan Jul 31, 2024
74fa9e1
Move tests that need internal access to Standard.Base into test/Base_…
JaroslavTulach Jul 31, 2024
1e48979
Resolving merge conficts
JaroslavTulach Jul 31, 2024
bbe754c
No more of Polyglot.Java
JaroslavTulach Aug 1, 2024
1514ad2
Nicer formatting with var
JaroslavTulach Aug 1, 2024
09c6946
Allow Standard.Table to depend on modules from Standard.Base
JaroslavTulach Aug 1, 2024
3148976
language-server/test compiles again
JaroslavTulach Aug 1, 2024
ae64b8a
Host Files values group_builder
JaroslavTulach Aug 5, 2024
c5e41ab
Merging in develop branch
JaroslavTulach Aug 5, 2024
6fdd11c
Merge with most recent develop branch that includes many JPMS
JaroslavTulach Sep 26, 2024
cfdda7b
Using moduleDependencies and internalModuleDependencies for standard …
JaroslavTulach Sep 26, 2024
d50f006
There can be Enso sources without associated package
JaroslavTulach Sep 26, 2024
202b1d8
Merging with develop
JaroslavTulach Oct 1, 2024
b04ce5c
Avoid duplicated modules. Use the one from boot layer.
JaroslavTulach Oct 1, 2024
d94a44d
Load all library Java modules with a single class loader
JaroslavTulach Oct 1, 2024
c71183c
Opening std-table.jar for reflection from Enso code
JaroslavTulach Oct 1, 2024
9bc7a3a
Visualization_Tests run and yield just nine errors
JaroslavTulach Oct 1, 2024
16b82c3
Standard.Test loads classes from Standard.Base
JaroslavTulach Oct 1, 2024
405e88d
Always prefer modules from parent layers
JaroslavTulach Oct 1, 2024
57e64e0
AWS requires access to Standard.Base and Standard.Database JARs
JaroslavTulach Oct 1, 2024
efda30f
Opening up std-table JAR, so Enso can access all Java classes
JaroslavTulach Oct 1, 2024
e9a0456
Less functional boilerplate
JaroslavTulach Oct 2, 2024
c0359e2
Merge remote-tracking branch 'origin/develop' into wip/jtulach/ClassP…
JaroslavTulach Oct 2, 2024
5b14f89
Special Lookup class and registration via a property to allow searchi…
JaroslavTulach Oct 2, 2024
841de5f
Turning Standard.Image into Java module
JaroslavTulach Oct 2, 2024
e6e5c09
Making test/Image_Tests pass OK
JaroslavTulach Oct 2, 2024
3194f6d
Avoid DriverManager. Directly talk to Driver instances.
JaroslavTulach Oct 2, 2024
cbe625f
Register SQLServerConnectionDetailsSPI in std-bits/microsoft/*/module…
JaroslavTulach Oct 3, 2024
c72ab8e
No polyglot symbol for org.enso.base.encoding.NewlineDetector in Tabl…
JaroslavTulach Oct 3, 2024
062b26e
No polyglot symbol for org.enso.table.data.table.Table in Table_Tests
JaroslavTulach Oct 3, 2024
e4cc4b4
No polyglot symbol for org.enso.table.data.table.join.between.SortedL…
JaroslavTulach Oct 3, 2024
9c86f7a
Using for loop
JaroslavTulach Oct 3, 2024
6992103
Make enso-test-java-helpers available to Table_Tests
JaroslavTulach Oct 3, 2024
98eeb64
No need to generate .bindings index to run benchmarks
JaroslavTulach Oct 3, 2024
60b4277
BenchProcessor puts runtime.jar into own layer. Use that one as bootL…
JaroslavTulach Oct 3, 2024
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
Prev Previous commit
Next Next commit
Avoid DriverManager. Directly talk to Driver instances.
  • Loading branch information
JaroslavTulach committed Oct 2, 2024
commit 3194f6d0bb6e69e7d530dc7f0baa826974c0a904
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.net.http.HttpRequest.Builder;
import java.net.http.HttpResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.List;
import java.util.Properties;
Expand All @@ -20,13 +20,23 @@ public final class EnsoSecretHelper extends SecretValueResolver {

/** Gets a JDBC connection resolving EnsoKeyValuePair into the properties. */
public static Connection getJDBCConnection(
String url, List<Pair<String, HideableValue>> properties) throws SQLException {
Iterable<Driver> drivers, String url, List<Pair<String, HideableValue>> properties)
throws SQLException {
var javaProperties = new Properties();
for (var pair : properties) {
javaProperties.setProperty(pair.getLeft(), resolveValue(pair.getRight()));
}

return DriverManager.getConnection(url, javaProperties);
var err = new StringBuilder();
for (var driver : drivers) {
err.append("\nTrying ").append(driver.getClass().getName());
var c = driver.connect(url, javaProperties);
if (c != null) {
return c;
}
}
err.insert(0, "No handler to connect to " + url);
throw new SQLException(err.toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.enso.database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;

import org.enso.base.enso_cloud.EnsoSecretAccessDenied;
import org.enso.base.enso_cloud.EnsoSecretHelper;
import org.enso.base.enso_cloud.HideableValue;
import org.enso.base.lookup.Lookup;
import org.enso.database.audit.CloudAuditedConnection;
import org.enso.database.audit.LocalAuditedConnection;
import org.graalvm.collections.Pair;
Expand All @@ -31,7 +32,8 @@ public final class JDBCProxy {
* @return an array of JDBC drivers that are currently registered
*/
public static Object[] getDrivers() {
return DriverManager.drivers().toArray();
var drivers = Lookup.lookup((l) -> ServiceLoader.load(l, java.sql.Driver.class));
return drivers.stream().toArray();
}

/**
Expand All @@ -46,17 +48,11 @@ public static Object[] getDrivers() {
*/
public static Connection getConnection(String url, List<Pair<String, HideableValue>> properties)
throws SQLException {
// We need to manually register all the drivers because the DriverManager is not able
// to correctly use our class loader, it only delegates to the platform class loader when
// loading the java.sql.Driver service.
var sl = ServiceLoader.load(java.sql.Driver.class, JDBCProxy.class.getClassLoader());
for (var driver : sl) {
DriverManager.registerDriver(driver);
}
var drivers = Lookup.lookup((l) -> ServiceLoader.load(l, java.sql.Driver.class));

PartitionedProperties partitionedProperties = PartitionedProperties.parse(properties);
var rawConnection =
EnsoSecretHelper.getJDBCConnection(url, partitionedProperties.jdbcProperties);
EnsoSecretHelper.getJDBCConnection(drivers, url, partitionedProperties.jdbcProperties);
return switch (partitionedProperties.audited()) {
case "local" -> new LocalAuditedConnection(rawConnection);
case "cloud" -> new CloudAuditedConnection(
Expand Down
Loading