use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor in project jqa-java-plugin by buschmais.
the class ServiceLoaderIT method invalidDescriptor.
/**
* Verifies that any files not representing service descriptors are ignored.
*
* @throws java.io.IOException
* If the test fails.
*/
@Test
public void invalidDescriptor() throws IOException {
File file = getClassesDirectory(ServiceLoaderIT.class);
final File propsFile = new File(file, "META-INF/test.properties");
final String path = "META-INF/services/test.properties";
store.beginTransaction();
JavaClassesDirectoryDescriptor artifactDescriptor = getArtifactDescriptor("a1");
execute(artifactDescriptor, new ScanClassPathOperation() {
@Override
public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
return singletonList(scanner.<File, FileDescriptor>scan(propsFile, path, JavaScope.CLASSPATH));
}
}, getScanner());
List<ServiceLoaderDescriptor> s = query("MATCH (s:ServiceLoader:Properties:File) RETURN s").getColumn("s");
assertThat(s.size(), equalTo(1));
ServiceLoaderDescriptor serviceLoaderDescriptor = s.get(0);
assertThat(serviceLoaderDescriptor.getFileName(), equalTo(path));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor 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.plugin.common.api.model.FileDescriptor 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.plugin.common.api.model.FileDescriptor 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;
}
}
use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor in project jqa-java-plugin by buschmais.
the class AbstractJavaPluginIT method scanClassPathResources.
protected void scanClassPathResources(final Scope scope, String artifactId, final String... resources) throws IOException {
final File directory = getClassesDirectory(this.getClass());
execute(artifactId, new ScanClassPathOperation() {
@Override
public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
List<FileDescriptor> result = new ArrayList<>();
for (String resource : resources) {
File file = new File(directory, resource);
FileDescriptor fileDescriptor = scanner.scan(file, resource, scope);
result.add(fileDescriptor);
}
return result;
}
});
}
Aggregations