@PostConstruct public void init() { FS commandFileSystem = createFileSystem( this.properties.getCommandPathPatterns(), this.properties.getDisabledCommands()); FS configurationFileSystem = createFileSystem(this.properties.getConfigPathPatterns(), new String[0]); PluginDiscovery discovery = new BeanFactoryFilteringPluginDiscovery( this.resourceLoader.getClassLoader(), this.beanFactory, this.properties.getDisabledPlugins()); PluginContext context = new PluginContext( discovery, createPluginContextAttributes(), commandFileSystem, configurationFileSystem, this.resourceLoader.getClassLoader()); context.refresh(); start(context); }
@Test public void testAuthenticationProvidersAreInstalled() { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(SecurityConfiguration.class); this.context.register(CrshAutoConfiguration.class); this.context.refresh(); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginContext pluginContext = lifeCycle.getContext(); int count = 0; Iterator<AuthenticationPlugin> plugins = pluginContext.getPlugins(AuthenticationPlugin.class).iterator(); while (plugins.hasNext()) { count++; plugins.next(); } assertThat(count).isEqualTo(3); }
Class<? extends T> getClass(String name) throws NoSuchCommandException, NullPointerException { if (name == null) { throw new NullPointerException("No null argument allowed"); } TimestampedObject<Class<? extends T>> providerRef = classes.get(name); // Resource script = context.loadResource(name, kind); // if (script != null) { if (providerRef != null) { if (script.getTimestamp() != providerRef.getTimestamp()) { providerRef = null; } } // if (providerRef == null) { Class<?> clazz; try { GroovyCodeSource gcs = new GroovyCodeSource(new String(script.getContent(), "UTF-8"), name, "/groovy/shell"); GroovyClassLoader gcl = new GroovyClassLoader(context.getLoader(), config); clazz = gcl.parseClass(gcs, false); } catch (UnsupportedEncodingException e) { throw new NoSuchCommandException( name, ErrorType.INTERNAL, "Could not compile command script " + name, e); } catch (CompilationFailedException e) { throw new NoSuchCommandException( name, ErrorType.INTERNAL, "Could not compile command script " + name, e); } // if (baseClass.isAssignableFrom(clazz)) { Class<? extends T> providerClass = clazz.asSubclass(baseClass); providerRef = new TimestampedObject<Class<? extends T>>(script.getTimestamp(), providerClass); classes.put(name, providerRef); } else { throw new NoSuchCommandException( name, ErrorType.INTERNAL, "Parsed script " + clazz.getName() + " does not implements " + CommandInvoker.class.getName()); } } } // if (providerRef == null) { return null; } // return providerRef.getObject(); }