Search in sources :

Example 1 with ManifestSectionDescriptor

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

Example 2 with ManifestSectionDescriptor

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();
}
Also used : ManifestSectionDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ManifestSectionDescriptor) ManifestFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ManifestFileDescriptor) Test(org.junit.Test)

Aggregations

ManifestFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ManifestFileDescriptor)2 ManifestSectionDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ManifestSectionDescriptor)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 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Attributes (java.util.jar.Attributes)1 Manifest (java.util.jar.Manifest)1 Test (org.junit.Test)1