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