use of com.buschmais.jqassistant.plugin.java.api.model.ManifestSectionDescriptor 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.java.api.model.ManifestSectionDescriptor in project jqa-java-plugin by buschmais.
the class ManifestFileIT method manifestFile.
/**
* Verifies that manifest files are scanned.
*
* @throws java.io.IOException
* If the test fails.
*/
@Test
public void manifestFile() throws IOException {
scanClassPathResource(JavaScope.CLASSPATH, "/META-INF/MANIFEST.MF");
store.beginTransaction();
List<ManifestFileDescriptor> manifestFileDescriptors = query("MATCH (mf:Manifest:File) RETURN mf").getColumn("mf");
assertThat(manifestFileDescriptors.size(), equalTo(1));
ManifestFileDescriptor manifestFileDescriptor = manifestFileDescriptors.get(0);
assertThat(manifestFileDescriptor.getFileName(), endsWith("/META-INF/MANIFEST.MF"));
List<ManifestSectionDescriptor> manifestSections = query("MATCH (mf:Manifest:File)-[:DECLARES]->(ms:ManifestSection) WHERE ms.name='Main' RETURN ms").getColumn("ms");
assertThat(manifestSections.size(), equalTo(1));
store.commitTransaction();
}
Aggregations