Search in sources :

Example 1 with ScannerContext

use of com.buschmais.jqassistant.core.scanner.api.ScannerContext in project jqa-core-framework by buschmais.

the class PluginRepositoryTest method repositories.

@Test
public void repositories() throws PluginRepositoryException {
    PluginConfigurationReader pluginConfigurationReader = new PluginConfigurationReaderImpl(PluginRepositoryTest.class.getClassLoader());
    PluginRepository pluginRepository = new PluginRepositoryImpl(pluginConfigurationReader);
    // Scanner plugins
    ScannerContext scannerContext = mock(ScannerContext.class);
    Map<String, ScannerPlugin<?, ?>> scannerPlugins = pluginRepository.getScannerPluginRepository().getScannerPlugins(scannerContext, Collections.<String, Object>emptyMap());
    assertThat(scannerPlugins.size(), equalTo(2));
    assertThat(scannerPlugins.get(TestScannerPlugin.class.getSimpleName()), notNullValue());
    assertThat(scannerPlugins.get("testScanner"), notNullValue());
    // Report plugins
    Map<String, ReportPlugin> reportPlugins = pluginRepository.getReportPluginRepository().getReportPlugins(Collections.<String, Object>emptyMap());
    assertThat(reportPlugins.size(), equalTo(2));
    assertThat(reportPlugins.get(TestReportPlugin.class.getSimpleName()), notNullValue());
    assertThat(reportPlugins.get("testReport"), notNullValue());
}
Also used : ReportPlugin(com.buschmais.jqassistant.core.report.api.ReportPlugin) TestReportPlugin(com.buschmais.jqassistant.plugin.impl.plugin.TestReportPlugin) ScannerPlugin(com.buschmais.jqassistant.core.scanner.api.ScannerPlugin) TestScannerPlugin(com.buschmais.jqassistant.plugin.impl.plugin.TestScannerPlugin) PluginConfigurationReaderImpl(com.buschmais.jqassistant.core.plugin.impl.PluginConfigurationReaderImpl) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) PluginRepositoryImpl(com.buschmais.jqassistant.core.plugin.impl.PluginRepositoryImpl) Test(org.junit.Test)

Example 2 with ScannerContext

use of com.buschmais.jqassistant.core.scanner.api.ScannerContext in project jqa-java-plugin by buschmais.

the class AbstractJavaPluginIT method execute.

protected List<? extends FileDescriptor> execute(JavaArtifactFileDescriptor artifact, ScanClassPathOperation operation, Scanner scanner) {
    ScannerContext context = scanner.getContext();
    context.push(JavaArtifactFileDescriptor.class, artifact);
    context.push(TypeResolver.class, new ArtifactScopedTypeResolver(artifact));
    List<? extends FileDescriptor> descriptors = operation.scan(artifact, scanner);
    context.pop(TypeResolver.class);
    context.pop(JavaArtifactFileDescriptor.class);
    return descriptors;
}
Also used : ArtifactScopedTypeResolver(com.buschmais.jqassistant.plugin.java.api.scanner.ArtifactScopedTypeResolver) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext)

Example 3 with ScannerContext

use of com.buschmais.jqassistant.core.scanner.api.ScannerContext in project jqa-java-plugin by buschmais.

the class AbstractJavaPluginIT method execute.

/**
     * Executes the given scan operation.
     * 
     * @param artifactId
     *            The artifact id of the artifact to push on the context.
     * @param operation
     *            The operation.
     */
protected List<? extends FileDescriptor> execute(String artifactId, ScanClassPathOperation operation) {
    Scanner scanner = getScanner();
    ScannerContext context = scanner.getContext();
    store.beginTransaction();
    JavaArtifactFileDescriptor artifact = getArtifactDescriptor(artifactId);
    artifact.setFullQualifiedName(artifactId);
    context.push(JavaArtifactFileDescriptor.class, artifact);
    ContainerFileResolver fileResolverStrategy = new ContainerFileResolver(artifact);
    context.push(FileResolver.class, fileResolverStrategy);
    List<? extends FileDescriptor> descriptors = execute(artifact, operation, scanner);
    for (FileDescriptor descriptor : descriptors) {
        fileResolverStrategy.put(descriptor.getFileName(), descriptor);
    }
    context.pop(JavaArtifactFileDescriptor.class);
    context.pop(FileResolver.class);
    fileResolverStrategy.flush();
    store.commitTransaction();
    return descriptors;
}
Also used : Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) ContainerFileResolver(com.buschmais.jqassistant.plugin.common.api.scanner.ContainerFileResolver) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)

Example 4 with ScannerContext

use of com.buschmais.jqassistant.core.scanner.api.ScannerContext in project jqa-core-framework by buschmais.

the class PluginRepositoryTest method getScannerPluginProperties.

private Map<String, Object> getScannerPluginProperties(PluginRepository pluginRepository, Map<String, Object> properties) throws PluginRepositoryException {
    ScannerPluginRepository scannerPluginRepository = pluginRepository.getScannerPluginRepository();
    ScannerContext scannerContext = mock(ScannerContext.class);
    Map<String, ScannerPlugin<?, ?>> scannerPlugins = scannerPluginRepository.getScannerPlugins(scannerContext, properties);
    assertThat(scannerPlugins.size(), greaterThan(0));
    for (ScannerPlugin<?, ?> scannerPlugin : scannerPlugins.values()) {
        if (scannerPlugin instanceof TestScannerPlugin) {
            return ((TestScannerPlugin) scannerPlugin).getProperties();
        }
    }
    return null;
}
Also used : TestScannerPlugin(com.buschmais.jqassistant.plugin.impl.plugin.TestScannerPlugin) ScannerPlugin(com.buschmais.jqassistant.core.scanner.api.ScannerPlugin) TestScannerPlugin(com.buschmais.jqassistant.plugin.impl.plugin.TestScannerPlugin) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext)

Example 5 with ScannerContext

use of com.buschmais.jqassistant.core.scanner.api.ScannerContext in project jqa-java-plugin by buschmais.

the class PackageDirectoryScannerPlugin method scan.

@Override
public PackageDescriptor scan(DirectoryResource item, String path, Scope scope, Scanner scanner) throws IOException {
    ScannerContext context = scanner.getContext();
    DirectoryDescriptor directoryDescriptor = context.getCurrentDescriptor();
    PackageDescriptor descriptor = context.getStore().addDescriptorType(directoryDescriptor, PackageDescriptor.class);
    String packageName = path.substring(1).replaceAll("/", ".");
    String name;
    int separatorIndex = packageName.lastIndexOf('.');
    if (separatorIndex != -1) {
        name = packageName.substring(separatorIndex + 1);
    } else {
        name = packageName;
    }
    descriptor.setName(name);
    descriptor.setFullQualifiedName(packageName);
    return descriptor;
}
Also used : DirectoryDescriptor(com.buschmais.jqassistant.plugin.common.api.model.DirectoryDescriptor) ScannerContext(com.buschmais.jqassistant.core.scanner.api.ScannerContext) PackageDescriptor(com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)

Aggregations

ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)8 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)4 InputStream (java.io.InputStream)3 ScannerPlugin (com.buschmais.jqassistant.core.scanner.api.ScannerPlugin)2 Store (com.buschmais.jqassistant.core.store.api.Store)2 TestScannerPlugin (com.buschmais.jqassistant.plugin.impl.plugin.TestScannerPlugin)2 PluginConfigurationReaderImpl (com.buschmais.jqassistant.core.plugin.impl.PluginConfigurationReaderImpl)1 PluginRepositoryImpl (com.buschmais.jqassistant.core.plugin.impl.PluginRepositoryImpl)1 ReportPlugin (com.buschmais.jqassistant.core.report.api.ReportPlugin)1 Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)1 DirectoryDescriptor (com.buschmais.jqassistant.plugin.common.api.model.DirectoryDescriptor)1 PropertyDescriptor (com.buschmais.jqassistant.plugin.common.api.model.PropertyDescriptor)1 ContainerFileResolver (com.buschmais.jqassistant.plugin.common.api.scanner.ContainerFileResolver)1 TestReportPlugin (com.buschmais.jqassistant.plugin.impl.plugin.TestReportPlugin)1 JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)1 ManifestFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ManifestFileDescriptor)1 ManifestSectionDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ManifestSectionDescriptor)1 PackageDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PackageDescriptor)1 PropertyFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.PropertyFileDescriptor)1 ServiceLoaderDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor)1