Search in sources :

Example 1 with DefaultClasspathScanner

use of com.canoo.dp.impl.server.scanner.DefaultClasspathScanner in project dolphin-platform by canoo.

the class ClasspathScannerTest method testInPackageScan.

@Test
public void testInPackageScan() {
    // There can't be a class that is annotated with Inject
    final DefaultClasspathScanner scanner = new DefaultClasspathScanner(CLASSPATH_SCAN);
    assertNotNull(scanner);
    assertForAnnotation(scanner);
}
Also used : DefaultClasspathScanner(com.canoo.dp.impl.server.scanner.DefaultClasspathScanner) Test(org.testng.annotations.Test) AnnotationForClasspathScanTest(com.canoo.impl.server.util.AnnotationForClasspathScanTest)

Example 2 with DefaultClasspathScanner

use of com.canoo.dp.impl.server.scanner.DefaultClasspathScanner in project dolphin-platform by canoo.

the class ClasspathScannerTest method testSimpleScan.

@Test
public void testSimpleScan() {
    // There can't be a class that is annotated with Inject
    final ServerConfiguration defaultPlatformConfiguration = ConfigurationFileLoader.loadConfiguration();
    final DefaultClasspathScanner scanner = new DefaultClasspathScanner(defaultPlatformConfiguration.getListProperty(ROOT_PACKAGE_FOR_CLASSPATH_SCAN));
    Set<Class<?>> classes = scanner.getTypesAnnotatedWith(Resources.class);
    assertNotNull(classes);
    assertEquals(classes.size(), 0);
    classes = scanner.getTypesAnnotatedWith(AnnotationForClasspathScanTest.class);
    assertNotNull(classes);
    assertEquals(classes.size(), 1);
    assertTrue(classes.contains(AnnotatedClassForClasspathScan.class));
}
Also used : DefaultClasspathScanner(com.canoo.dp.impl.server.scanner.DefaultClasspathScanner) ServerConfiguration(com.canoo.dp.impl.server.config.ServerConfiguration) DocumentAnnotatedClass(com.canoo.impl.server.classpathscan.documented.DocumentAnnotatedClass) AnnotationForClasspathScanTest(com.canoo.impl.server.util.AnnotationForClasspathScanTest) AnnotatedClassForClasspathScan(com.canoo.impl.server.util.AnnotatedClassForClasspathScan) Test(org.testng.annotations.Test) AnnotationForClasspathScanTest(com.canoo.impl.server.util.AnnotationForClasspathScanTest)

Example 3 with DefaultClasspathScanner

use of com.canoo.dp.impl.server.scanner.DefaultClasspathScanner in project dolphin-platform by canoo.

the class ClasspathScannerTest method testInMultiplePackagesWithBasePackageFirst.

@Test
public void testInMultiplePackagesWithBasePackageFirst() {
    // There can't be a class that is annotated with Inject
    final DefaultClasspathScanner scanner = new DefaultClasspathScanner(CLASSPATH_SCAN, "com.canoo.impl.server.classpathscan.documented", "com.canoo.impl.server.classpathscan.resource");
    assertForAnnotation(scanner);
}
Also used : DefaultClasspathScanner(com.canoo.dp.impl.server.scanner.DefaultClasspathScanner) Test(org.testng.annotations.Test) AnnotationForClasspathScanTest(com.canoo.impl.server.util.AnnotationForClasspathScanTest)

Example 4 with DefaultClasspathScanner

use of com.canoo.dp.impl.server.scanner.DefaultClasspathScanner in project dolphin-platform by canoo.

the class PlatformBootstrap method init.

public void init(final ServletContext servletContext, final ServerConfiguration configuration) {
    Assert.requireNonNull(servletContext, "servletContext");
    Assert.requireNonNull(configuration, "configuration");
    ContextManagerImpl.getInstance().addGlobalContext(APPLICATION_CONTEXT, configuration.getProperty(APPLICATION_NAME_PROPERTY));
    if (configuration.getBooleanProperty(PLATFORM_ACTIVE)) {
        PlatformLogo.printLogo();
        try {
            LOG.info("Will boot Dolphin Plaform now");
            servletContext.setAttribute(CONFIGURATION_ATTRIBUTE_NAME, configuration);
            configuration.log();
            MBeanRegistry.getInstance().setMbeanSupport(configuration.getBooleanProperty(MBEAN_REGISTRATION));
            // TODO: We need to provide a container specific thread factory that contains managed threads
            // See https://github.com/canoo/dolphin-platform/issues/498
            final PlatformThreadFactory threadFactory = new SimpleDolphinPlatformThreadFactory();
            final ManagedBeanFactory beanFactory = getBeanFactory(servletContext);
            final DefaultClasspathScanner classpathScanner = new DefaultClasspathScanner(configuration.getListProperty(ROOT_PACKAGE_FOR_CLASSPATH_SCAN));
            serverCoreComponents = new ServerCoreComponentsImpl(servletContext, configuration, threadFactory, classpathScanner, beanFactory);
            final Set<Class<?>> moduleClasses = classpathScanner.getTypesAnnotatedWith(ModuleDefinition.class);
            final Map<String, ServerModule> modules = new HashMap<>();
            for (final Class<?> moduleClass : moduleClasses) {
                if (!ServerModule.class.isAssignableFrom(moduleClass)) {
                    throw new DolphinRuntimeException("Class " + moduleClass + " is annoated with " + ModuleDefinition.class.getSimpleName() + " but do not implement " + ServerModule.class.getSimpleName());
                }
                ModuleDefinition moduleDefinition = moduleClass.getAnnotation(ModuleDefinition.class);
                ServerModule instance = (ServerModule) moduleClass.newInstance();
                modules.put(instance.getName(), instance);
            }
            LOG.info("Found {} Dolphin Plaform modules", modules.size());
            if (LOG.isTraceEnabled()) {
                for (final String moduleName : modules.keySet()) {
                    LOG.trace("Found Dolphin Plaform module {}", moduleName);
                }
            }
            for (final Map.Entry<String, ServerModule> moduleEntry : modules.entrySet()) {
                LOG.debug("Will initialize Dolphin Plaform module {}", moduleEntry.getKey());
                final ServerModule module = moduleEntry.getValue();
                if (module.shouldBoot(serverCoreComponents.getConfiguration())) {
                    final List<String> neededModules = module.getModuleDependencies();
                    for (final String neededModule : neededModules) {
                        if (!modules.containsKey(neededModule)) {
                            throw new ModuleInitializationException("Module " + moduleEntry.getKey() + " depends on missing module " + neededModule);
                        }
                    }
                    module.initialize(serverCoreComponents);
                }
            }
            LOG.info("Dolphin Plaform booted");
        } catch (Exception e) {
            throw new RuntimeException("Can not boot Dolphin Platform", e);
        }
    } else {
        LOG.info("Dolphin Plaform is deactivated");
    }
}
Also used : HashMap(java.util.HashMap) DefaultClasspathScanner(com.canoo.dp.impl.server.scanner.DefaultClasspathScanner) SimpleDolphinPlatformThreadFactory(com.canoo.dp.impl.platform.core.SimpleDolphinPlatformThreadFactory) ModuleInitializationException(com.canoo.platform.server.spi.ModuleInitializationException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) ModuleInitializationException(com.canoo.platform.server.spi.ModuleInitializationException) ServerModule(com.canoo.platform.server.spi.ServerModule) ModuleDefinition(com.canoo.platform.server.spi.ModuleDefinition) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) ManagedBeanFactory(com.canoo.platform.server.spi.components.ManagedBeanFactory) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) PlatformThreadFactory(com.canoo.platform.core.PlatformThreadFactory) SimpleDolphinPlatformThreadFactory(com.canoo.dp.impl.platform.core.SimpleDolphinPlatformThreadFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with DefaultClasspathScanner

use of com.canoo.dp.impl.server.scanner.DefaultClasspathScanner in project dolphin-platform by canoo.

the class ControllerRepositoryTest method testWrongControllersName.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testWrongControllersName() throws Exception {
    ControllerRepository controllerRepository = new ControllerRepository(new DefaultClasspathScanner(ControllerRepositoryTest.class.getPackage().getName()));
    controllerRepository.getControllerClassForName("WrongControllerName");
}
Also used : DefaultClasspathScanner(com.canoo.dp.impl.server.scanner.DefaultClasspathScanner) ControllerRepository(com.canoo.dp.impl.server.controller.ControllerRepository) Test(org.testng.annotations.Test)

Aggregations

DefaultClasspathScanner (com.canoo.dp.impl.server.scanner.DefaultClasspathScanner)9 Test (org.testng.annotations.Test)8 AnnotationForClasspathScanTest (com.canoo.impl.server.util.AnnotationForClasspathScanTest)6 DocumentAnnotatedClass (com.canoo.impl.server.classpathscan.documented.DocumentAnnotatedClass)3 ControllerRepository (com.canoo.dp.impl.server.controller.ControllerRepository)2 SimpleDolphinPlatformThreadFactory (com.canoo.dp.impl.platform.core.SimpleDolphinPlatformThreadFactory)1 ServerConfiguration (com.canoo.dp.impl.server.config.ServerConfiguration)1 AnnotatedClassForClasspathScan (com.canoo.impl.server.util.AnnotatedClassForClasspathScan)1 DolphinRuntimeException (com.canoo.platform.core.DolphinRuntimeException)1 PlatformThreadFactory (com.canoo.platform.core.PlatformThreadFactory)1 ModuleDefinition (com.canoo.platform.server.spi.ModuleDefinition)1 ModuleInitializationException (com.canoo.platform.server.spi.ModuleInitializationException)1 ServerModule (com.canoo.platform.server.spi.ServerModule)1 ManagedBeanFactory (com.canoo.platform.server.spi.components.ManagedBeanFactory)1 Documented (java.lang.annotation.Documented)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1