All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kantega.reststop.development.DevelopmentClassLoaderFactory Maven / Gradle / Ivy

There is a newer version: 3.11.2
Show newest version
package org.kantega.reststop.development;

import org.kantega.reststop.classloaderutils.Artifact;
import org.kantega.reststop.classloaderutils.PluginClassLoader;
import org.kantega.reststop.classloaderutils.PluginInfo;
import org.kantega.reststop.core.ClassLoaderFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class DevelopmentClassLoaderFactory implements ClassLoaderFactory {

    private static DevelopmentClassLoaderFactory instance;

    public static DevelopmentClassLoaderFactory getInstance() {
        return instance;
    }

    public DevelopmentClassLoaderFactory() {
        instance = this;
    }

    @Override
    public PluginClassLoader createPluginClassLoader(PluginInfo pluginInfo, ClassLoader parentClassLoader, List allPlugins) {

        List runtime = getClasspath(pluginInfo, allPlugins, "runtime", true);
        List compile = getClasspath(pluginInfo, allPlugins,  "compile", false);
        List test = getClasspath(pluginInfo, allPlugins,  "test", false);
        File sourceDir = pluginInfo.getSourceDirectory();

        DevelopmentClassloader classloader = new DevelopmentClassloader(pluginInfo, sourceDir, pluginInfo.getFile(),
                compile,
                runtime,
                test,
                parentClassLoader, 1);

        return classloader;
    }

    private List getClasspath(PluginInfo pluginInfo, List allPlugins, String scope, boolean filterParentPlugins) {
        List files = new ArrayList<>();
        for (Artifact artifact : pluginInfo.getClassPath(scope)) {
            if(!filterParentPlugins || allPlugins.stream().noneMatch(p -> p.getPluginId().equals(artifact.getPluginId()))) {
                files.add(artifact.getFile());
            }
        }
        return files;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy