use of com.buschmais.jqassistant.core.scanner.api.ScannerContext 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.scanner.api.ScannerContext in project jqa-java-plugin by buschmais.
the class ServiceLoaderFileScannerPlugin method scan.
@Override
public ServiceLoaderDescriptor scan(FileResource item, String path, Scope scope, Scanner scanner) throws IOException {
Matcher matcher = PATTERN.matcher(path);
if (!matcher.matches()) {
throw new IOException("Cannot match path name: " + path);
}
String serviceInterface = matcher.group(2);
ScannerContext context = scanner.getContext();
FileDescriptor fileDescriptor = context.getCurrentDescriptor();
ServiceLoaderDescriptor serviceLoaderDescriptor = context.getStore().addDescriptorType(fileDescriptor, ServiceLoaderDescriptor.class);
TypeDescriptor interfaceTypeDescriptor = getTypeDescriptor(serviceInterface, context);
serviceLoaderDescriptor.setType(interfaceTypeDescriptor);
try (InputStream stream = item.createStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String serviceImplementation;
while ((serviceImplementation = reader.readLine()) != null) {
if (!isEmptyOrComment(serviceImplementation)) {
TypeDescriptor implementationTypeDescriptor = getTypeDescriptor(serviceImplementation, context);
serviceLoaderDescriptor.getContains().add(implementationTypeDescriptor);
}
}
}
return serviceLoaderDescriptor;
}
use of com.buschmais.jqassistant.core.scanner.api.ScannerContext 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