use of com.buschmais.jqassistant.core.store.api.Store in project jqa-java-plugin by buschmais.
the class PropertyFileScannerPlugin method scan.
@Override
public PropertyFileDescriptor scan(FileResource item, String path, Scope scope, Scanner scanner) throws IOException {
ScannerContext context = scanner.getContext();
Store store = context.getStore();
FileDescriptor fileDescriptor = context.getCurrentDescriptor();
PropertyFileDescriptor propertyFileDescriptor = store.addDescriptorType(fileDescriptor, PropertyFileDescriptor.class);
Properties properties = new Properties();
try (InputStream stream = item.createStream()) {
properties.load(stream);
} catch (IllegalArgumentException e) {
LOGGER.warn("Cannot load properties from '" + path + "': " + e.getMessage());
}
for (String name : properties.stringPropertyNames()) {
String value = properties.getProperty(name);
PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class);
propertyDescriptor.setName(name);
propertyDescriptor.setValue(value);
propertyFileDescriptor.getProperties().add(propertyDescriptor);
}
return propertyFileDescriptor;
}
use of com.buschmais.jqassistant.core.store.api.Store in project jqa-core-framework by buschmais.
the class ScannerTest method pluginPipeline.
@Test
public void pluginPipeline() {
ScannerContext scannerContext = mock(ScannerContext.class);
Store store = mock(Store.class);
when(scannerContext.getStore()).thenReturn(store);
when(store.create(Mockito.any(Class.class))).thenAnswer(new Answer<Descriptor>() {
@Override
public Descriptor answer(InvocationOnMock invocation) throws Throwable {
Class<? extends Descriptor> descriptorType = (Class<? extends Descriptor>) invocation.getArguments()[0];
return mock(descriptorType);
}
});
when(store.addDescriptorType(Mockito.any(Descriptor.class), Mockito.any(Class.class))).thenAnswer(new Answer<Descriptor>() {
@Override
public Descriptor answer(InvocationOnMock invocation) throws Throwable {
Class<? extends Descriptor> descriptorType = (Class<? extends Descriptor>) invocation.getArguments()[1];
return mock(descriptorType);
}
});
Map<String, ScannerPlugin<?, ?>> scannerPlugins = new HashMap<>();
scannerPlugins.put("TestScanner1", new TestScannerPlugin1());
scannerPlugins.put("TestScanner2", new TestScannerPlugin2());
scannerPlugins.put("TestScanner2A", new TestScannerPlugin2A());
Scanner scanner = new ScannerImpl(new ScannerConfiguration(), scannerContext, scannerPlugins, Collections.<String, Scope>emptyMap());
Descriptor descriptor = scanner.scan(new TestItem(), "/", DefaultScope.NONE);
assertThat(descriptor, instanceOf(TestDescriptor2.class));
verify(store).create(Mockito.eq(TestDescriptor1.class));
verify(store).addDescriptorType(Mockito.any(TestDescriptor1.class), Mockito.eq(TestDescriptor2A.class));
verify(store).addDescriptorType(Mockito.any(TestDescriptor2A.class), Mockito.eq(TestDescriptor2.class));
verify(scannerContext).push(Mockito.eq(TestDescriptor1.class), Mockito.any(TestDescriptor1.class));
verify(scannerContext).peek(TestDescriptor1.class);
verify(scannerContext).pop(TestDescriptor1.class);
}
use of com.buschmais.jqassistant.core.store.api.Store in project jqa-java-plugin by buschmais.
the class JavaClassesDirectoryScannerPlugin method getContainerDescriptor.
@Override
protected JavaClassesDirectoryDescriptor getContainerDescriptor(File classPathDirectory, ScannerContext scannerContext) {
JavaArtifactFileDescriptor javaArtifactDescriptor = scannerContext.peekOrDefault(JavaArtifactFileDescriptor.class, null);
Store store = scannerContext.getStore();
if (javaArtifactDescriptor == null) {
return store.create(JavaClassesDirectoryDescriptor.class);
}
if (JavaClassesDirectoryDescriptor.class.isAssignableFrom(javaArtifactDescriptor.getClass())) {
return JavaClassesDirectoryDescriptor.class.cast(javaArtifactDescriptor);
}
throw new IllegalStateException("Expected an instance of " + JavaClassesDirectoryDescriptor.class.getName() + " but got " + Arrays.asList(javaArtifactDescriptor.getClass().getInterfaces()));
}
use of com.buschmais.jqassistant.core.store.api.Store in project jqa-java-plugin by buschmais.
the class ManifestFileScannerPlugin method scan.
@Override
public ManifestFileDescriptor scan(FileResource item, String path, Scope scope, Scanner scanner) throws IOException {
try (InputStream stream = item.createStream()) {
Manifest manifest = new Manifest(stream);
ScannerContext context = scanner.getContext();
Store store = context.getStore();
FileDescriptor fileDescriptor = context.getCurrentDescriptor();
ManifestFileDescriptor manifestFileDescriptor = store.addDescriptorType(fileDescriptor, ManifestFileDescriptor.class);
ManifestSectionDescriptor mainSectionDescriptor = store.create(ManifestSectionDescriptor.class);
mainSectionDescriptor.setName(SECTION_MAIN);
manifestFileDescriptor.setMainSection(mainSectionDescriptor);
readSection(manifest.getMainAttributes(), mainSectionDescriptor, store);
for (Map.Entry<String, Attributes> sectionEntry : manifest.getEntries().entrySet()) {
ManifestSectionDescriptor sectionDescriptor = store.create(ManifestSectionDescriptor.class);
sectionDescriptor.setName(sectionEntry.getKey());
readSection(sectionEntry.getValue(), sectionDescriptor, store);
manifestFileDescriptor.getManifestSections().add(sectionDescriptor);
}
return manifestFileDescriptor;
}
}
Aggregations