Search in sources :

Example 1 with PropertyDescriptor

use of com.buschmais.jqassistant.plugin.common.api.model.PropertyDescriptor 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;
}
Also used : PropertyFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor) PropertyDescriptor(com.buschmais.jqassistant.plugin.common.api.model.PropertyDescriptor) InputStream(java.io.InputStream) Store(com.buschmais.jqassistant.core.store.api.Store) Properties(java.util.Properties) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) PropertyFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Aggregations

ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)1 Store (com.buschmais.jqassistant.core.store.api.Store)1 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)1 PropertyDescriptor (com.buschmais.jqassistant.plugin.common.api.model.PropertyDescriptor)1 PropertyFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1