Package net.xeoh.plugins.base.impl.classpath

Examples of net.xeoh.plugins.base.impl.classpath.ClassPathManager


     * @param initialProperties
     */
    protected PluginManagerImpl(final Properties initialProperties) {
        // Create helper classes and config (needed early)
        this.spawner = new Spawner(this);
        this.classPathManager = new ClassPathManager(this);
        this.configuration = new PluginConfigurationImpl(initialProperties);

        // Hook fundamental plugins
        hookPlugin(new SpawnResult(this));
        hookPlugin(new SpawnResult(this.configuration));
View Full Code Here


     * we find.
     *
     * @param root The top level to start from.
     */
    void locateAllPluginsAt(File root) {
        final ClassPathManager manager = this.pluginManager.getClassPathManager();
        final ClassPathLocator locator = manager.getLocator();

        final Collection<AbstractClassPathLocation> locations = locator.findBelow(root.toURI());
        for (AbstractClassPathLocation location : locations) {
            manager.registerLocation(location);

            Collection<String> subclasses = null;

            // Check if it has a list of plugins
            if (location instanceof JARClasspathLocation) {
                final JARClasspathLocation jarLocation = (JARClasspathLocation) location;
                subclasses = jarLocation.getPredefinedPluginList();
            }

            // Add all found files ... if we have no predefined list
            if (subclasses == null)
                subclasses = manager.findSubclassesFor(location, Plugin.class);

            // Try to load them
            for (String string : subclasses) {
                tryToLoadClassAsPlugin(location, string);
            }
View Full Code Here

                                               AddPluginsFromOption[] options) {
        // Start the classpath search
        this.logger.finer("Starting classpath search with pattern " + pattern);

        // Get all classpath locations of the current classpath
        final ClassPathManager manager = this.pluginManager.getClassPathManager();
        final ClassPathLocator locator = manager.getLocator();
        final Collection<AbstractClassPathLocation> locations = locator.findInCurrentClassPath(options);

        // Process all locations
        for (AbstractClassPathLocation location : locations) {
            manager.registerLocation(location);

            final Collection<String> candidates = manager.findSubclassesFor(location, Plugin.class);

            this.logger.finer("Found " + candidates.size() + " candidates.");

            // Check all candidates
            for (String string : candidates) {
View Full Code Here

                                          final String name) {
        this.logger.finest("Trying to load " + name + " as a plugin.");

        // Obtain some shared objects
        // final JARCache jarCache = this.pluginManager.getJARCache();
        final ClassPathManager classPathManager = this.pluginManager.getClassPathManager();
        final PluginRegistry pluginRegistry = this.pluginManager.getPluginRegistry();
        final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration());
        final Spawner spawner = this.pluginManager.getSpawner();

        // Obtain information
        // final JARInformation jarInformation = jarCache.getJARInformation(name);
        // final String file = jarCache.classTofile(name);

        try {
            // Get class of the candidate
            final Class<?> possiblePlugin = classPathManager.loadClass(location, name);

            // Don't load plugins already spawned.
            if (name.startsWith("net.xeoh.plugins.base") ||
                name.startsWith("net.xeoh.plugins.diagnosis.") ||
                name.startsWith("net.xeoh.plugins.informationbroker.")) return;
           
            // Get the plugin's annotation
            final PluginImplementation annotation = possiblePlugin.getAnnotation(PluginImplementation.class);

            // Nothing to load here if no annotation is present
            if (annotation == null) { return; }


           
            // Don't load classes already loaded from this location
            final PluginClassMetaInformation preexistingMeta = pluginRegistry.getMetaInformationFor((Class<? extends Plugin>) possiblePlugin);
            if (preexistingMeta != null) {
                this.logger.info("Skipping plugin " + possiblePlugin + " because we already have it ");
                return;
            }

           
            // Register class at registry
            final PluginClassMetaInformation metaInformation = new PluginClassMetaInformation();
            metaInformation.pluginClassStatus = PluginClassStatus.ACCEPTED;
            if (location != null) {
                metaInformation.pluginOrigin = location.getToplevelLocation();
            } else {
                metaInformation.pluginOrigin = new URI("classpath://UNDEFINED");
            }
            pluginRegistry.registerPluginClass((Class<? extends Plugin>) possiblePlugin, metaInformation);

            // Update the class information of the corresponding cache entry
            this.logger.finer("Updating cache information");

            // Avoid loading if annotation request it.
            if (pcu.getBoolean(possiblePlugin, "plugin.disabled", false) || possiblePlugin.getAnnotation(IsDisabled.class) != null) {
                metaInformation.pluginClassStatus = PluginClassStatus.DISABLED;
                this.logger.fine("Ignoring " + name + " due to request.");
                return;
            }
           
            // Up from here we know we will (eventually) use the plugin. So load its
            // configuration.
            final String properties = (possiblePlugin.getAnnotation(ConfigurationFile.class) != null) ? possiblePlugin.getAnnotation(ConfigurationFile.class).file() : null;
            if (properties != null && properties.length() > 0) {
                final String resourcePath = name.replaceAll("\\.", "/").replaceAll(possiblePlugin.getSimpleName(), "") + properties;
                this.logger.fine("Adding configuration from " + resourcePath + " for plugin " + name);

                final Properties p = new Properties();

                // Try to load resource by special classloader
                try {
                    p.load(classPathManager.getResourceAsStream(location, resourcePath));

                    final Set<Object> keys = p.keySet();

                    // Add every string that is not already in the configuration.
                    for (final Object object : keys) {
View Full Code Here

     * @param initialProperties
     */
    protected PluginManagerImpl(final Properties initialProperties) {
        // Create helper classes and config (needed early)
        this.spawner = new Spawner(this);
        this.classPathManager = new ClassPathManager(this);
        this.configuration = new PluginConfigurationImpl(initialProperties);

        // Hook fundamental plugins
        hookPlugin(new SpawnResult(this));
        hookPlugin(new SpawnResult(this.configuration));
View Full Code Here

                                          final String name) {
        this.logger.finest("Trying to load " + name + " as a plugin.");

        // Obtain some shared objects
        // final JARCache jarCache = this.pluginManager.getJARCache();
        final ClassPathManager classPathManager = this.pluginManager.getClassPathManager();
        final PluginRegistry pluginRegistry = this.pluginManager.getPluginRegistry();
        final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration());
        final Spawner spawner = this.pluginManager.getSpawner();

        // Obtain information
        // final JARInformation jarInformation = jarCache.getJARInformation(name);
        // final String file = jarCache.classTofile(name);

        try {
            // Get class of the candidate
            final Class<?> possiblePlugin = classPathManager.loadClass(location, name);

            // Don't load plugins already spawned.
            if (name.startsWith("net.xeoh.plugins.base") ||
                name.startsWith("net.xeoh.plugins.diagnosis.") ||
                name.startsWith("net.xeoh.plugins.informationbroker.")) return;
           
            // Get the plugin's annotation
            final PluginImplementation annotation = possiblePlugin.getAnnotation(PluginImplementation.class);

            // Nothing to load here if no annotation is present
            if (annotation == null) { return; }


           
            // Don't load classes already loaded from this location
            final PluginClassMetaInformation preexistingMeta = pluginRegistry.getMetaInformationFor((Class<? extends Plugin>) possiblePlugin);
            if (preexistingMeta != null) {
                this.logger.info("Skipping plugin " + possiblePlugin + " because we already have it ");
                return;
            }

           
            // Register class at registry
            final PluginClassMetaInformation metaInformation = new PluginClassMetaInformation();
            metaInformation.pluginClassStatus = PluginClassStatus.ACCEPTED;
            if (location != null) {
                metaInformation.pluginOrigin = location.getToplevelLocation();
            } else {
                metaInformation.pluginOrigin = new URI("classpath://UNDEFINED");
            }
            pluginRegistry.registerPluginClass((Class<? extends Plugin>) possiblePlugin, metaInformation);

            // Update the class information of the corresponding cache entry
            this.logger.finer("Updating cache information");

            // Avoid loading if annotation request it.
            if (pcu.getBoolean(possiblePlugin, "plugin.disabled", false) || possiblePlugin.getAnnotation(IsDisabled.class) != null) {
                metaInformation.pluginClassStatus = PluginClassStatus.DISABLED;
                this.logger.fine("Ignoring " + name + " due to request.");
                return;
            }
           
            // Up from here we know we will (eventually) use the plugin. So load its
            // configuration.
            final String properties = (possiblePlugin.getAnnotation(ConfigurationFile.class) != null) ? possiblePlugin.getAnnotation(ConfigurationFile.class).file() : null;
            if (properties != null && properties.length() > 0) {
                final String resourcePath = name.replaceAll("\\.", "/").replaceAll(possiblePlugin.getSimpleName(), "") + properties;
                this.logger.fine("Adding configuration from " + resourcePath + " for plugin " + name);

                final Properties p = new Properties();

                // Try to load resource by special classloader
                InputStream ism = null;
                try {
                   ism = classPathManager.getResourceAsStream(location, resourcePath);
                    p.load(ism);

                    final Set<Object> keys = p.keySet();

                    // Add every string that is not already in the configuration.
View Full Code Here

    protected PluginManagerImpl(final Properties initialProperties) {

        // TODO: Is getClass().getClassLoader() okay? ... at least the applet seems to need it,
        // but will other apps have problems otherwise?
        this.classPathLocator = new ClassPathLocator(this.jarCache);
        this.classPathManager = new ClassPathManager();

        this.pluginManagerUtil = new PluginManagerUtil(this);
        this.spawner = new Spawner(this);

        this.configuration = new PluginConfigurationImpl(initialProperties);
View Full Code Here

            return;
        }
    }

    void locateAllPluginsAt(File root) {
        final ClassPathManager manager = this.pluginManager.getClassPathManager();
        final ClassPathLocator locator = this.pluginManager.getClassPathLocator();

        final Collection<AbstractClassPathLocation> locations = locator.findBelow(root.toURI());
        for (AbstractClassPathLocation location : locations) {
            manager.registerLocation(location);

            Collection<String> subclasses = null;

            // Check if it has a list of plugins
            if (location instanceof JARClasspathLocation) {
                final JARClasspathLocation jarLocation = (JARClasspathLocation) location;
                subclasses = jarLocation.getPredefinedPluginList();
            }

            // Add all found files ... if we have no predefined list
            if (subclasses == null)
                subclasses = manager.findSubclassesFor(location, Plugin.class);

            // Try to load them
            for (String string : subclasses) {
                tryToLoadClassAsPlugin(location, string);
            }
View Full Code Here

    /** */
    private void loadAllClasspathPluginClasses() {
        // Start the classpath search
        this.logger.finer("Starting classpath search ...");

        final ClassPathManager manager = this.pluginManager.getClassPathManager();
        final ClassPathLocator locator = this.pluginManager.getClassPathLocator();

        final Collection<AbstractClassPathLocation> locations = locator.findInCurrentClassPath();
        for (AbstractClassPathLocation location : locations) {
            manager.registerLocation(location);

            final Collection<String> candidates = manager.findSubclassesFor(location, Plugin.class);

            this.logger.finer("Found " + candidates.size() + " candidates.");

            for (String string : candidates) {
                tryToLoadClassAsPlugin(location, string);
View Full Code Here

                                          final String name) {
        this.logger.finest("Trying to load " + name + " as a plugin.");

        // Obtain some shared objects
        //final JARCache jarCache = this.pluginManager.getJARCache();
        final ClassPathManager classPathManager = this.pluginManager.getClassPathManager();
        final PluginRegistry pluginRegistry = this.pluginManager.getPluginRegistry();
        final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration());
        final Spawner spawner = this.pluginManager.getSpawner();

        // Obtain information
        //final JARInformation jarInformation = jarCache.getJARInformation(name);
        //final String file = jarCache.classTofile(name);

        try {
            // Get class of the candidate
            final Class<?> possiblePlugin = classPathManager.loadClass(location, name);

            // Don't load plugins already spawned.
            if (name.startsWith("net.xeoh.plugins.base")) return;

            // Get the plugin's annotation
            final PluginImplementation annotation = possiblePlugin.getAnnotation(PluginImplementation.class);

            // Nothing to load here if no annotation is present
            if (annotation == null) { return; }

            // Don't load classes already loaded from this location
            final PluggableClassMetaInformation preexistingMeta = pluginRegistry.getMetaInformationFor((Class<? extends Plugin>) possiblePlugin);
            if (preexistingMeta != null) {
                System.err.println("SKIPPING BECAUSE DOUBLE");
                return;
            }

            // Register class at registry
            final PluggableClassMetaInformation metaInformation = new PluggableClassMetaInformation();
            metaInformation.pluginClassStatus = PluginClassStatus.ACCEPTED;
            if (location != null) {
                metaInformation.pluginOrigin = location.getLocation();
            } else {
                metaInformation.pluginOrigin = new URI("classpath://UNDEFINED");
            }
            pluginRegistry.registerPluginClass((Class<? extends Plugin>) possiblePlugin, metaInformation);

            // Update the class information of the corresponding cache entry
            this.logger.finer("Updating cache information");

            /*
            jarInformation.lastAccess = System.currentTimeMillis();
            jarInformation.usageCount++;
            if (!jarInformation.contents.contains(name)) {
                this.logger.finer("Adding " + name + " to cache of " + file);
                jarInformation.contents.add(name);
            }
            */

            // Avoid loading if annotation request it.
            if (pcu.getBoolean(possiblePlugin, "disabled", false) || possiblePlugin.getAnnotation(IsDisabled.class) != null) {
                metaInformation.pluginClassStatus = PluginClassStatus.DISABLED;
                this.logger.fine("Ignoring " + name + " due to request.");
                return;
            }

            // Up from here we know we will (eventually) use the plugin. So load
            // its configuration.           
            final String properties = (possiblePlugin.getAnnotation(ConfigurationFile.class) != null) ? possiblePlugin.getAnnotation(ConfigurationFile.class).configurationFile() : null;
            if (properties != null && properties.length() > 0) {
                final String resourcePath = name.replaceAll("\\.", "/").replaceAll(possiblePlugin.getSimpleName(), "") + properties;
                this.logger.fine("Adding configuration from " + resourcePath + " for plugin " + name);

                final Properties p = new Properties();

                // Try to load resource by special classloader
                try {
                    p.load(classPathManager.getResourceAsStream(location, resourcePath));
                    final Set<Object> keys = p.keySet();

                    // Add every string that is not already in the configuration.
                    for (final Object object : keys) {
                        if (pcu.getString(null, (String) object) == null) {
View Full Code Here

TOP

Related Classes of net.xeoh.plugins.base.impl.classpath.ClassPathManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.