1
1
/*
2
- * Copyright (c) 2017, 2021 , Gluon and/or its affiliates.
2
+ * Copyright (c) 2017, 2024 , Gluon and/or its affiliates.
3
3
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
4
4
* All rights reserved. Use is subject to license terms.
5
5
*
36
36
import java .io .IOException ;
37
37
import java .io .InputStreamReader ;
38
38
import java .io .LineNumberReader ;
39
+ import java .lang .module .ModuleReference ;
39
40
import java .net .MalformedURLException ;
40
41
import java .net .URL ;
41
42
import java .net .URLClassLoader ;
53
54
import java .util .Date ;
54
55
import java .util .HashSet ;
55
56
import java .util .List ;
57
+ import java .util .Optional ;
56
58
import java .util .Set ;
57
59
import java .util .logging .Logger ;
58
60
import java .util .stream .Collectors ;
66
68
import com .oracle .javafx .scenebuilder .kit .library .util .JarExplorer ;
67
69
import com .oracle .javafx .scenebuilder .kit .library .util .JarReport ;
68
70
import com .oracle .javafx .scenebuilder .kit .library .util .JarReportEntry ;
71
+ import com .oracle .javafx .scenebuilder .kit .library .util .ModuleExplorer ;
69
72
70
73
/**
71
74
*
@@ -348,49 +351,55 @@ private LibraryItem makeLibraryItem(Path path) throws IOException {
348
351
}
349
352
350
353
351
- private void exploreAndUpdateLibrary (Collection <Path > jarsOrFolders ) throws IOException {
354
+ private void exploreAndUpdateLibrary (Collection <Path > modulesOrJarsOrFolders ) throws IOException {
352
355
353
356
// 1) we create a classloader
354
- // 2) we explore all the jars and folders
357
+ // 2) we explore all the modules, jars, and folders
355
358
// 3) we construct a list of library items
356
359
// 4) we update the user library with the class loader and items
357
360
// 5) on startup only, we allow opening files that may/may not rely on the user library
358
361
359
362
// 1)
360
363
final ClassLoader classLoader ;
361
- if (jarsOrFolders .isEmpty ()) {
364
+ if (modulesOrJarsOrFolders .isEmpty ()) {
362
365
classLoader = null ;
363
366
} else {
364
- classLoader = new URLClassLoader (makeURLArrayFromPaths (jarsOrFolders ));
367
+ classLoader = new URLClassLoader (makeURLArrayFromPaths (modulesOrJarsOrFolders ));
365
368
}
366
369
367
370
// 2)
368
- final List <JarReport > jarOrFolderReports = new ArrayList <>();
369
- // boolean shouldShowImportGluonJarAlert = false;
370
- for (Path currentJarOrFolder : jarsOrFolders ) {
371
- String jarName = currentJarOrFolder .getName (currentJarOrFolder .getNameCount () - 1 ).toString ();
371
+ final List <JarReport > moduleOrJarOrFolderReports = new ArrayList <>();
372
+ for (Path currentModuleOrJarOrFolder : modulesOrJarsOrFolders ) {
373
+ String jarName = currentModuleOrJarOrFolder .getName (currentModuleOrJarOrFolder .getNameCount () - 1 ).toString ();
372
374
if (JAVAFX_MODULES .stream ().anyMatch (jarName ::startsWith )) {
373
375
continue ;
374
376
}
375
377
376
378
JarReport jarReport ;
377
379
String resultText = "" ;
378
- if (LibraryUtil .isJarPath (currentJarOrFolder )) {
379
- LOGGER .info (I18N .getString ("log.info.explore.jar" , currentJarOrFolder ));
380
- final JarExplorer explorer = new JarExplorer (currentJarOrFolder );
380
+ Optional <ModuleReference > moduleReference = LibraryUtil .getModuleReference (currentModuleOrJarOrFolder );
381
+ if (moduleReference .isPresent ()) {
382
+ LOGGER .info (I18N .getString ("log.info.explore.module" , moduleReference .get ().descriptor ()));
383
+ final ModuleExplorer explorer = new ModuleExplorer (moduleReference .get ());
384
+ jarReport = explorer .explore ();
385
+ resultText = I18N .getString ("log.info.explore.module.results" , jarName );
386
+ }
387
+ else if (LibraryUtil .isJarPath (currentModuleOrJarOrFolder )) {
388
+ LOGGER .info (I18N .getString ("log.info.explore.jar" , currentModuleOrJarOrFolder ));
389
+ final JarExplorer explorer = new JarExplorer (currentModuleOrJarOrFolder );
381
390
jarReport = explorer .explore (classLoader );
382
391
resultText = I18N .getString ("log.info.explore.jar.results" , jarName );
383
392
}
384
- else if (Files .isDirectory (currentJarOrFolder )) {
385
- LOGGER .info (I18N .getString ("log.info.explore.folder" , currentJarOrFolder ));
386
- final FolderExplorer explorer = new FolderExplorer (currentJarOrFolder );
393
+ else if (Files .isDirectory (currentModuleOrJarOrFolder )) {
394
+ LOGGER .info (I18N .getString ("log.info.explore.folder" , currentModuleOrJarOrFolder ));
395
+ final FolderExplorer explorer = new FolderExplorer (currentModuleOrJarOrFolder );
387
396
jarReport = explorer .explore (classLoader );
388
397
resultText = I18N .getString ("log.info.explore.folder.results" , jarName );
389
398
} else {
390
399
continue ;
391
400
}
392
401
393
- jarOrFolderReports .add (jarReport );
402
+ moduleOrJarOrFolderReports .add (jarReport );
394
403
395
404
StringBuilder sb = new StringBuilder (resultText ).append ("\n " );
396
405
if (jarReport .getEntries ().isEmpty ()) {
@@ -400,26 +409,13 @@ else if (Files.isDirectory(currentJarOrFolder)) {
400
409
}
401
410
LOGGER .info (sb .toString ());
402
411
403
- LOGGER .info (I18N .getString ("log.info.explore.end" , currentJarOrFolder ));
404
-
405
- // if (jarReport.hasGluonControls()) {
406
- // // We check if the jar has already been imported to avoid showing the import gluon jar
407
- // // alert every time Scene Builder starts for jars that have already been imported
408
- // if (!hasGluonJarBeenImported(jarReport.getJar().getFileName().toString())) {
409
- // shouldShowImportGluonJarAlert = true;
410
- // }
411
- //
412
- // }
412
+ LOGGER .info (I18N .getString ("log.info.explore.end" , currentModuleOrJarOrFolder ));
413
413
}
414
414
415
- // if (shouldShowImportGluonJarAlert && onImportingGluonControls != null) {
416
- // onImportingGluonControls.run();
417
- // }
418
-
419
415
// 3)
420
416
final List <LibraryItem > newItems = new ArrayList <>();
421
- for (JarReport jarOrFolderReport : jarOrFolderReports ) {
422
- newItems .addAll (makeLibraryItems (jarOrFolderReport ));
417
+ for (JarReport moduleOrJarOrFolderReport : moduleOrJarOrFolderReports ) {
418
+ newItems .addAll (makeLibraryItems (moduleOrJarOrFolderReport ));
423
419
}
424
420
425
421
// 4)
@@ -429,8 +425,8 @@ else if (Files.isDirectory(currentJarOrFolder)) {
429
425
.stream ()
430
426
.distinct ()
431
427
.collect (Collectors .toList ()));
432
- library .updateJarReports (new ArrayList <>(jarOrFolderReports ));
433
- library .getOnFinishedUpdatingJarReports ().accept (jarOrFolderReports );
428
+ library .updateJarReports (new ArrayList <>(moduleOrJarOrFolderReports ));
429
+ library .getOnFinishedUpdatingJarReports ().accept (moduleOrJarOrFolderReports );
434
430
library .updateExplorationDate (new Date ());
435
431
436
432
// 5
@@ -471,9 +467,9 @@ private URL[] makeURLArrayFromPaths(Collection<Path> paths) {
471
467
if (url .toString ().endsWith (".jar" )) {
472
468
result [i ++] = new URL ("jar" , "" , url + "!/" ); // <-- jar:file/path/to/jar!/
473
469
} else {
474
- result [i ++] = url ; // <-- file:/path/to/folder/
470
+ result [i ++] = url ; // <-- file:/path/to/folder/ or jrt:/module.name
475
471
}
476
- } catch (MalformedURLException x ) {
472
+ } catch (MalformedURLException x ) {
477
473
throw new RuntimeException ("Bug in " + getClass ().getSimpleName (), x ); //NOI18N
478
474
}
479
475
}
0 commit comments