DevClassesScanner implements ClassesScanner { @Override public ScanResult scan(Path pluginDirectory, List<Class> extensionPoints) throws PluginException { if (Files.exists(pluginDirectory) && Files.isDirectory(pluginDirectory)) { try { ClassLoader classLoader = BuildToolClassLoaderFactory.getClassLoader(pluginDirectory, buildToolType); Path classesPath = BuildToolClassLoaderFactory.getClassesPath(pluginDirectory, buildToolType); PluginImplementationsAware pluginImplementationsAware = Files.exists(classesPath) ? PluginUtils.getMatchingClasses(extensionPoints, classesPath, classLoader) : new ClassesRegistry(Collections.emptyMap()); return new DefaultScanResult(classLoader, pluginImplementationsAware); } catch (Exception e) { throw new PluginException(e); } } return new DefaultScanResult(getClass().getClassLoader(), new ClassesRegistry(Collections.emptyMap())); } DevClassesScanner(BuildToolType buildToolType); @Override ScanResult scan(Path pluginDirectory, List<Class> extensionPoints);  }
@Test public void testScan() throws Exception { createFiles(); DevClassesScanner devClassesScanner = new DevClassesScanner(BuildToolType.MAVEN); ScanResult scanResult = devClassesScanner.scan(baseDirectory, EXTENSION_POINTS); assertThat(scanResult.getClassLoader(), notNullValue()); PluginImplementationsAware contents = scanResult.getContents(); assertThat(contents.getExtensionPoints(), hasSize(2)); List<Class> pluginImplementations = contents.getImplementations(TestAnnotation.class); assertThat(pluginImplementations, hasSize(1)); assertThat(pluginImplementations, contains(AnnotatedImpl.class)); List<Class> testExtensionPointImplementations = contents.getImplementations(TestExtensionPoint.class); assertThat(testExtensionPointImplementations, hasSize(1)); assertThat(testExtensionPointImplementations, contains(TestExtensionPointImpl.class)); }
@Test public void testPluginDirectoryMissing() throws PluginException { DevClassesScanner devClassesScanner = new DevClassesScanner(BuildToolType.MAVEN); ScanResult scanResult = devClassesScanner.scan(Paths.get("missing-directory"), EXTENSION_POINTS); assertThat(scanResult.getContents().getExtensionPoints(), hasSize(0)); }
@Test public void testClassesDirectoryMissing() throws Exception { createBaseDirectory(); DevClassesScanner devClassesScanner = new DevClassesScanner(BuildToolType.MAVEN); ScanResult scanResult = devClassesScanner.scan(baseDirectory, EXTENSION_POINTS); assertThat(scanResult.getContents().getExtensionPoints(), hasSize(0)); }