1 /*
   2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 var JFX_CLASSES = {
  27     "javafx.base": [],
  28     "javafx.controls": [],
  29     "javafx.deploy": [],
  30     "javafx.fxml": [],
  31     "javafx.graphics": [],
  32     "javafx.media": [],
  33     "javafx.swing": [],
  34     "javafx.web": []
  35 };
  36 
  37 function LOAD_FX_CLASSES(global, module) {
  38     if (JFX_CLASSES[module]) {
  39         for each (var cls in JFX_CLASSES[module]) {
  40             // Ex. Stage = Java.type("javafx.stage.Stage");
  41             var name = cls.join(".");
  42             var type = Java.type(name);
  43             global[cls[cls.length - 1]] = type;
  44         }
  45 
  46         JFX_CLASSES[module] = undefined;
  47     }
  48 }
  49 
  50 (function() {
  51     var Files = Java.type("java.nio.file.Files");
  52     var FileSystems = Java.type("java.nio.file.FileSystems");
  53     var FileVisitor = Java.type("java.nio.file.FileVisitor");
  54     var FileVisitResult = Java.type("java.nio.file.FileVisitResult");
  55     var CONTINUE = FileVisitResult.CONTINUE;
  56     var SKIP_SUBTREE = FileVisitResult.SKIP_SUBTREE;
  57 
  58     var URI = Java.type("java.net.URI");
  59     var uri = new URI("jrt:/");
  60     var jrtfs = FileSystems.getFileSystem(uri);
  61     var rootDirectories = jrtfs.getRootDirectories();
  62 
  63     var JRTFSWalker = Java.extend(FileVisitor, {
  64         preVisitDirectory: function(path, attrs) {
  65             var name = path.toString();
  66 
  67             if (name.startsWith("/packages")) {
  68                  return SKIP_SUBTREE;
  69             }
  70 
  71             if (name.startsWith("/modules") && !name.equals("/modules") && !name.startsWith("/modules/javafx")) {
  72                 return SKIP_SUBTREE;
  73             }
  74 
  75             return CONTINUE;
  76         },
  77 
  78         postVisitDirectory: function(path, attrs) {
  79             return CONTINUE;
  80         },
  81 
  82         visitFile: function(file, attrs) {
  83             var name = file.toString();
  84 
  85             if (!name.endsWith(".class") || name.endsWith("module-info.class")) {
  86                 return CONTINUE;
  87             }
  88 
  89             var parts = name.split("/");
  90             parts = parts.slice(2);
  91             var module = parts.shift();
  92             var path = parts;
  93             var cls = path.pop();
  94             cls = cls.substring(0, cls.length() - 6);
  95             path.push(cls);
  96 
  97             if (path[0] !== "javafx" || /\$\d+$/.test(cls)) {
  98                 return CONTINUE;
  99             }
 100 
 101             JFX_CLASSES[module].push(path);
 102 
 103             return CONTINUE;
 104         },
 105 
 106         visitFileFailed: function(file, ex) {
 107             return CONTINUE;
 108         }
 109     });
 110 
 111     Files.walkFileTree(rootDirectories[0], new JRTFSWalker());
 112 })();
 113 
 114 LOAD_FX_CLASSES(this, "javafx.base");