|
28 | 28 | import java.util.ArrayList;
|
29 | 29 | import java.util.Arrays;
|
30 | 30 | import java.util.HashSet;
|
| 31 | +import java.util.List; |
31 | 32 | import java.util.Optional;
|
32 | 33 | import java.util.Set;
|
33 | 34 | import java.util.UUID;
|
@@ -424,28 +425,42 @@ public Optional<Module> findModuleByExpressionId(UUID expressionId) {
|
424 | 425 | }
|
425 | 426 |
|
426 | 427 | /**
|
427 |
| - * Modifies the classpath to use to lookup {@code polyglot java} imports. |
| 428 | + * Creates a class path. A class path is capable to load Java classes in an isolated manner. |
428 | 429 | *
|
429 |
| - * @param file the file to register |
| 430 | + * @param files files to register |
430 | 431 | */
|
431 | 432 | @TruffleBoundary
|
432 |
| - public void addToClassPath(TruffleFile file) { |
433 |
| - if (findGuestJava() == null) { |
434 |
| - try { |
435 |
| - var url = file.toUri().toURL(); |
436 |
| - hostClassLoader.add(url); |
437 |
| - } catch (MalformedURLException ex) { |
438 |
| - throw new IllegalStateException(ex); |
| 433 | + public EnsoClassPath createClassPath(List<TruffleFile> files) { |
| 434 | + return new EnsoClassPath(files); |
| 435 | + } |
| 436 | + |
| 437 | + public final class EnsoClassPath { |
| 438 | + // private final TruffleFile[] files; |
| 439 | + |
| 440 | + private EnsoClassPath(List<TruffleFile> files) { |
| 441 | + for (var f : files) { |
| 442 | + add(f); |
439 | 443 | }
|
440 |
| - } else { |
441 |
| - try { |
442 |
| - var path = new File(file.toUri()).getAbsoluteFile(); |
443 |
| - if (!path.exists()) { |
444 |
| - throw new IllegalStateException("File not found " + path); |
| 444 | + } |
| 445 | + |
| 446 | + private void add(TruffleFile file) { |
| 447 | + if (findGuestJava() == null) { |
| 448 | + try { |
| 449 | + var url = file.toUri().toURL(); |
| 450 | + hostClassLoader.add(url); |
| 451 | + } catch (MalformedURLException ex) { |
| 452 | + throw new IllegalStateException(ex); |
| 453 | + } |
| 454 | + } else { |
| 455 | + try { |
| 456 | + var path = new File(file.toUri()).getAbsoluteFile(); |
| 457 | + if (!path.exists()) { |
| 458 | + throw new IllegalStateException("File not found " + path); |
| 459 | + } |
| 460 | + InteropLibrary.getUncached().invokeMember(findGuestJava(), "addPath", path.getPath()); |
| 461 | + } catch (InteropException ex) { |
| 462 | + throw new IllegalStateException(ex); |
445 | 463 | }
|
446 |
| - InteropLibrary.getUncached().invokeMember(findGuestJava(), "addPath", path.getPath()); |
447 |
| - } catch (InteropException ex) { |
448 |
| - throw new IllegalStateException(ex); |
449 | 464 | }
|
450 | 465 | }
|
451 | 466 | }
|
@@ -518,11 +533,12 @@ public boolean isColorTerminalOutput() {
|
518 | 533 | * resolves to an inner class, then the import of the outer class is resolved, and the inner class
|
519 | 534 | * is looked up by iterating the members of the outer class via Truffle's interop protocol.
|
520 | 535 | *
|
| 536 | + * @param pkg Enso package to load the class for |
521 | 537 | * @param className Fully qualified class name, can also be nested static inner class.
|
522 | 538 | * @return If the java class is found, return it, otherwise return null.
|
523 | 539 | */
|
524 | 540 | @TruffleBoundary
|
525 |
| - public Object lookupJavaClass(String className) { |
| 541 | + public Object lookupJavaClass(Package<?> pkg, String className) { |
526 | 542 | var binaryName = new StringBuilder(className);
|
527 | 543 | var collectedExceptions = new ArrayList<Exception>();
|
528 | 544 | for (; ; ) {
|
|
0 commit comments