Search in sources :

Example 6 with ScannerContext

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;
}
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)

Example 7 with ScannerContext

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;
}
Also used : TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) ServiceLoaderDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Example 8 with ScannerContext

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;
    }
}
Also used : ManifestSectionDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ManifestSectionDescriptor) InputStream(java.io.InputStream) Attributes(java.util.jar.Attributes) Store(com.buschmais.jqassistant.core.store.api.Store) Manifest(java.util.jar.Manifest) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) ManifestFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ManifestFileDescriptor) Map(java.util.Map) ManifestFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ManifestFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Aggregations

ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)8 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)4 InputStream (java.io.InputStream)3 ScannerPlugin (com.buschmais.jqassistant.core.scanner.api.ScannerPlugin)2 Store (com.buschmais.jqassistant.core.store.api.Store)2 TestScannerPlugin (com.buschmais.jqassistant.plugin.impl.plugin.TestScannerPlugin)2 PluginConfigurationReaderImpl (com.buschmais.jqassistant.core.plugin.impl.PluginConfigurationReaderImpl)1 PluginRepositoryImpl (com.buschmais.jqassistant.core.plugin.impl.PluginRepositoryImpl)1 ReportPlugin (com.buschmais.jqassistant.core.report.api.ReportPlugin)1 Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)1 DirectoryDescriptor (com.buschmais.jqassistant.plugin.common.api.model.DirectoryDescriptor)1 PropertyDescriptor (com.buschmais.jqassistant.plugin.common.api.model.PropertyDescriptor)1 ContainerFileResolver (com.buschmais.jqassistant.plugin.common.api.scanner.ContainerFileResolver)1 TestReportPlugin (com.buschmais.jqassistant.plugin.impl.plugin.TestReportPlugin)1 JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)1 ManifestFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ManifestFileDescriptor)1 ManifestSectionDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ManifestSectionDescriptor)1 PackageDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)1 PropertyFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor)1 ServiceLoaderDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor)1