Search in sources :

Example 1 with PropertyFileDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor in project jqa-java-plugin by buschmais.

the class PropertyFileIT method invalidPropertyFile.

/**
     * Verifies that invalid property files don't make the scanner fail.
     *
     * @throws java.io.IOException
     *             If the test fails.
     */
@Test
public void invalidPropertyFile() throws IOException {
    scanClassPathResource(JavaScope.CLASSPATH, "/META-INF/invalid.properties");
    store.beginTransaction();
    List<PropertyFileDescriptor> propertyFileDescriptors = query("MATCH (p:Properties:File) RETURN p").getColumn("p");
    assertThat(propertyFileDescriptors.size(), equalTo(1));
    PropertyFileDescriptor propertyFileDescriptor = propertyFileDescriptors.get(0);
    assertThat(propertyFileDescriptor.getFileName(), endsWith("/META-INF/invalid.properties"));
    assertThat(propertyFileDescriptor.getProperties().size(), equalTo(0));
    store.commitTransaction();
}
Also used : PropertyFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor) Test(org.junit.Test)

Example 2 with PropertyFileDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor in project jqa-java-plugin by buschmais.

the class PropertyFileIT method propertyFile.

/**
     * Verifies that property files are scanned.
     * 
     * @throws java.io.IOException
     *             If the test fails.
     */
@Test
public void propertyFile() throws IOException {
    scanClassPathResource(JavaScope.CLASSPATH, "/META-INF/test.properties");
    store.beginTransaction();
    List<PropertyFileDescriptor> propertyFileDescriptors = query("MATCH (p:Properties:File) RETURN p").getColumn("p");
    assertThat(propertyFileDescriptors.size(), equalTo(1));
    PropertyFileDescriptor propertyFileDescriptor = propertyFileDescriptors.get(0);
    Matcher<? super PropertyDescriptor> valueMatcher = valueDescriptor("foo", equalTo("bar"));
    assertThat(propertyFileDescriptor.getFileName(), endsWith("/META-INF/test.properties"));
    assertThat(propertyFileDescriptor.getProperties(), hasItem(valueMatcher));
    store.commitTransaction();
}
Also used : PropertyFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor) Test(org.junit.Test)

Example 3 with PropertyFileDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor 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

PropertyFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor)3 Test (org.junit.Test)2 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 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1