// Path: Eru/src/main/java/org/assemblits/eru/jfx/JFXClassUtil.java
// @Component
// public class JFXClassUtil {
// 
//     public boolean isNotJavaFxComponent(@NonNull String className) {
//         return !className.startsWith("java.") && !className.startsWith("javax.")
//                 && !className.startsWith("javafx.") && !className.startsWith("com.oracle.javafx.scenebuilder.")
//                 && !className.startsWith("com.javafx.");
//     }
// 
//     public boolean isJFXComponentClass(String className, String classAbsolutePackage) {
//         if (className != null && isNotJavaFxComponent(className)) {
//             try {
//                 Class<?> jfxComponentClass = ClassUtil.loadClass(classAbsolutePackage);
//                 if (!Modifier.isAbstract(jfxComponentClass.getModifiers()) && Node.class.isAssignableFrom(jfxComponentClass)) {
//                     JarExplorer.instantiateWithFXMLLoader(jfxComponentClass, this.getClass().getClassLoader());
//                     return true;
//                 }
//             } catch (Exception ignored) {
//                 return false;
//             }
//         }
//         return false;
//     }
// }
// 
// Path: Eru/src/main/java/org/assemblits/eru/packages/ClassInfo.java
// @Value
// @AllArgsConstructor
// public class ClassInfo {
//     String name;
//     String absolutePackage;
//     File file;
//     Class<?> clazz;
// }
// 
// Path: Eru/src/main/java/org/assemblits/eru/packages/PackageExplorer.java
// @Slf4j
// @Component
// @RequiredArgsConstructor
// public class PackageExplorer {
// 
//     private static final List<String> TOP_PACKAGES = new ArrayList<String>() {{
//         add("main");
//         add("target");
//         add("classes");
//     }};
// 
//     public Set<ClassInfo> exploreAndGetClassesInfo(Collection<String> packages) {
//         Stack<File> directories = new Stack<>();
//         log.debug("Scanning packages {}", packages);
//         for (String location : packages) {
//             directories.push(new File(getClass().getResource(location).getPath()));
//         }
//         Set<ClassInfo> classesInfo = new HashSet<>();
//         while (!directories.isEmpty()) {
//             File directory = directories.pop();
//             for (File file : directory.listFiles()) {
//                 if (file.isDirectory()) {
//                     directories.push(file);
//                 } else {
//                     Optional<String> className = ClassUtil.makeClassNameFromCompiledClassName(file.getName());
//                     if (className.isPresent()) {
//                         String canonicalPackage = getCanonicalPackage(className.get(), file);
//                         try {
//                             classesInfo.add(new ClassInfo(className.get(), canonicalPackage, file,
//                                     ClassUtil.loadClass(canonicalPackage)));
//                         } catch (ClassNotFoundException ignore) {
//                         }
//                     }
//                 }
//             }
//         }
//         return classesInfo;
//     }
// 
//     private String getCanonicalPackage(String className, File file) {
//         StringBuilder stringBuilder = new StringBuilder();
//         while (file.getParentFile() != null && !TOP_PACKAGES.contains(file.getParentFile().getName())) {
//             stringBuilder.insert(0, ".").insert(0, file.getParentFile().getName());
//             file = file.getParentFile();
//         }
//         stringBuilder.append(className);
//         return stringBuilder.toString();
//     }
// }


import static java.io.File.separator;
import static java.lang.String.*;
import com.oracle.javafx.scenebuilder.kit.library.Library;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.assemblits.eru.jfx.JFXClassUtil;
import org.assemblits.eru.packages.ClassInfo;
import org.assemblits.eru.packages.PackageExplorer;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/******************************************************************************
 * Copyright (c) 2017 Assemblits contributors                                 *
 *                                                                            *
 * This file is part of Eru The open JavaFX SCADA by Assemblits Organization. *
 *                                                                            *
 * Eru The open JavaFX SCADA is free software: you can redistribute it        *
 * and/or modify it under the terms of the GNU General Public License         *
 *  as published by the Free Software Foundation, either version 3            *
 *  of the License, or (at your option) any later version.                    *
 *                                                                            *
 * Eru is distributed in the hope that it will be useful,                     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.            *
 ******************************************************************************/
package org.assemblits.eru.jfx.scenebuilder.library;




@Slf4j
@Component
@RequiredArgsConstructor
public class CustomLibraryLoader {

    private static final List<String> DYNAMO_CLASSES_LOCATION = new ArrayList<String>() {{
        add(join(separator, "", "org", "assemblits", "eru", "gui", "dynamo"));
    }};

// Path: Eru/src/main/java/org/assemblits/eru/jfx/JFXClassUtil.java
// @Component
// public class JFXClassUtil {
// 
//     public boolean isNotJavaFxComponent(@NonNull String className) {
//         return !className.startsWith("java.") && !className.startsWith("javax.")
//                 && !className.startsWith("javafx.") && !className.startsWith("com.oracle.javafx.scenebuilder.")
//                 && !className.startsWith("com.javafx.");
//     }
// 
//     public boolean isJFXComponentClass(String className, String classAbsolutePackage) {
//         if (className != null && isNotJavaFxComponent(className)) {
//             try {
//                 Class<?> jfxComponentClass = ClassUtil.loadClass(classAbsolutePackage);
//                 if (!Modifier.isAbstract(jfxComponentClass.getModifiers()) && Node.class.isAssignableFrom(jfxComponentClass)) {
//                     JarExplorer.instantiateWithFXMLLoader(jfxComponentClass, this.getClass().getClassLoader());
//                     return true;
//                 }
//             } catch (Exception ignored) {
//                 return false;
//             }
//         }
//         return false;
//     }
// }
// 
// Path: Eru/src/main/java/org/assemblits/eru/packages/ClassInfo.java
// @Value
// @AllArgsConstructor
// public class ClassInfo {
//     String name;
//     String absolutePackage;
//     File file;
//     Class<?> clazz;
// }
// 
// Path: Eru/src/main/java/org/assemblits/eru/packages/PackageExplorer.java
// @Slf4j
// @Component
// @RequiredArgsConstructor
// public class PackageExplorer {
// 
//     private static final List<String> TOP_PACKAGES = new ArrayList<String>() {{
//         add("main");
//         add("target");
//         add("classes");
//     }};
// 
//     public Set<ClassInfo> exploreAndGetClassesInfo(Collection<String> packages) {
//         Stack<File> directories = new Stack<>();
//         log.debug("Scanning packages {}", packages);
//         for (String location : packages) {
//             directories.push(new File(getClass().getResource(location).getPath()));
//         }
//         Set<ClassInfo> classesInfo = new HashSet<>();
//         while (!directories.isEmpty()) {
//             File directory = directories.pop();
//             for (File file : directory.listFiles()) {
//                 if (file.isDirectory()) {
//                     directories.push(file);
//                 } else {
//                     Optional<String> className = ClassUtil.makeClassNameFromCompiledClassName(file.getName());
//                     if (className.isPresent()) {
//                         String canonicalPackage = getCanonicalPackage(className.get(), file);
//                         try {
//                             classesInfo.add(new ClassInfo(className.get(), canonicalPackage, file,
//                                     ClassUtil.loadClass(canonicalPackage)));
//                         } catch (ClassNotFoundException ignore) {
//                         }
//                     }
//                 }
//             }
//         }
//         return classesInfo;
//     }
// 
//     private String getCanonicalPackage(String className, File file) {
//         StringBuilder stringBuilder = new StringBuilder();
//         while (file.getParentFile() != null && !TOP_PACKAGES.contains(file.getParentFile().getName())) {
//             stringBuilder.insert(0, ".").insert(0, file.getParentFile().getName());
//             file = file.getParentFile();
//         }
//         stringBuilder.append(className);
//         return stringBuilder.toString();
//     }
// }


// Path: Eru/src/main/java/org/assemblits/eru/jfx/scenebuilder/library/CustomLibraryLoader.java
import static java.io.File.separator;
import static java.lang.String.*;
import com.oracle.javafx.scenebuilder.kit.library.Library;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.assemblits.eru.jfx.JFXClassUtil;
import org.assemblits.eru.packages.ClassInfo;
import org.assemblits.eru.packages.PackageExplorer;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/******************************************************************************
 * Copyright (c) 2017 Assemblits contributors                                 *
 *                                                                            *
 * This file is part of Eru The open JavaFX SCADA by Assemblits Organization. *
 *                                                                            *
 * Eru The open JavaFX SCADA is free software: you can redistribute it        *
 * and/or modify it under the terms of the GNU General Public License         *
 *  as published by the Free Software Foundation, either version 3            *
 *  of the License, or (at your option) any later version.                    *
 *                                                                            *
 * Eru is distributed in the hope that it will be useful,                     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with Foobar.  If not, see <http://www.gnu.org/licenses/>.            *
 ******************************************************************************/
package org.assemblits.eru.jfx.scenebuilder.library;




@Slf4j
@Component
@RequiredArgsConstructor
public class CustomLibraryLoader {

    private static final List<String> DYNAMO_CLASSES_LOCATION = new ArrayList<String>() {{
        add(join(separator, "", "org", "assemblits", "eru", "gui", "dynamo"));
    }};

    private final PackageExplorer packageExplorer;