Search in sources :

Example 1 with Scanner

use of com.buschmais.jqassistant.core.scanner.api.Scanner 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 2 with Scanner

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

the class AbstractJavaPluginIT method scanClassPathDirectory.

/**
     * Scans the a directory.
     * 
     * @param artifactId
     *            The artifact to use.
     * @param directory
     *            The directory.
     * @throws java.io.IOException
     *             If scanning fails.
     */
protected void scanClassPathDirectory(String artifactId, final File directory) throws IOException {
    Scanner scanner = getScanner();
    store.beginTransaction();
    JavaClassesDirectoryDescriptor artifactDescriptor = getArtifactDescriptor(artifactId);
    execute(artifactDescriptor, new ScanClassPathOperation() {

        @Override
        public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
            scanner.scan(directory, directory.getAbsolutePath(), JavaScope.CLASSPATH);
            return Collections.emptyList();
        }
    }, scanner);
    store.commitTransaction();
}
Also used : Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) JavaClassesDirectoryDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)

Example 3 with Scanner

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

the class InvalidClassFileIT method classFileWithHeaderOnly.

@Test
public void classFileWithHeaderOnly() throws IOException {
    final String path = "/com.buschmais.Test.class";
    final FileResource fileResource = new AbstractFileResource() {

        @Override
        public InputStream createStream() throws IOException {
            return new ByteArrayInputStream(ClassFileScannerPlugin.CAFEBABE);
        }
    };
    List<? extends FileDescriptor> fileDescriptors = execute(ARTIFACT_ID, new ScanClassPathOperation() {

        @Override
        public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
            FileDescriptor fileDescriptor = scanner.scan(fileResource, path, JavaScope.CLASSPATH);
            return Collections.singletonList(fileDescriptor);
        }
    });
    store.beginTransaction();
    assertThat(fileDescriptors.size(), equalTo(1));
    FileDescriptor fileDescriptor = fileDescriptors.get(0);
    assertThat(fileDescriptor, instanceOf(ClassFileDescriptor.class));
    ClassFileDescriptor classFileDescriptor = (ClassFileDescriptor) fileDescriptor;
    assertThat(classFileDescriptor.getFileName(), equalTo(path));
    assertThat(classFileDescriptor.isValid(), equalTo(false));
    store.commitTransaction();
}
Also used : Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) ByteArrayInputStream(java.io.ByteArrayInputStream) FileResource(com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.FileResource) AbstractFileResource(com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource) List(java.util.List) AbstractFileResource(com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor) ClassFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor) Test(org.junit.Test)

Example 4 with Scanner

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

the class TypeResolverIT method duplicateTypeInSameArtifact.

/**
     * @throws IOException
     *             If the test fails.
     */
@Test
public void duplicateTypeInSameArtifact() throws IOException {
    File directory = getClassesDirectory(A.class);
    final String resource = "/" + A.class.getName().replace(".", "/") + ".class";
    final File file = new File(directory, resource);
    scanClasses(B.class);
    List<? extends FileDescriptor> descriptors = execute("a1", new ScanClassPathOperation() {

        @Override
        public List<FileDescriptor> scan(JavaArtifactFileDescriptor artifact, Scanner scanner) {
            List<FileDescriptor> result = new ArrayList<>();
            FileDescriptor fileDescriptor1 = scanner.scan(file, "/1.0" + resource, JavaScope.CLASSPATH);
            FileDescriptor fileDescriptor2 = scanner.scan(file, resource, JavaScope.CLASSPATH);
            result.add(fileDescriptor1);
            result.add(fileDescriptor2);
            return result;
        }
    });
    store.beginTransaction();
    assertThat(descriptors.size(), equalTo(2));
    FileDescriptor fileDescriptor1 = descriptors.get(0);
    assertThat(fileDescriptor1.getFileName(), equalTo("/1.0" + resource));
    assertThat(fileDescriptor1, instanceOf(TypeDescriptor.class));
    assertThat(((TypeDescriptor) fileDescriptor1).getFullQualifiedName(), equalTo(A.class.getName()));
    FileDescriptor fileDescriptor2 = descriptors.get(1);
    assertThat(fileDescriptor2.getFileName(), equalTo(resource));
    assertThat(fileDescriptor2, instanceOf(TypeDescriptor.class));
    assertThat(((TypeDescriptor) fileDescriptor2).getFullQualifiedName(), equalTo(A.class.getName()));
    store.commitTransaction();
}
Also used : A(com.buschmais.jqassistant.plugin.java.test.set.scanner.resolver.A) Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) File(java.io.File) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) ArtifactFileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.ArtifactFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor) Test(org.junit.Test)

Example 5 with Scanner

use of com.buschmais.jqassistant.core.scanner.api.Scanner 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();
}
Also used : Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) JavaClassesDirectoryDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) ServiceLoaderDescriptor(com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor) File(java.io.File) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) FileDescriptor(com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor) Test(org.junit.Test)

Aggregations

Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)6 JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)6 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)5 List (java.util.List)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 JavaClassesDirectoryDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor)2 ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)1 ArtifactFileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.ArtifactFileDescriptor)1 ContainerFileResolver (com.buschmais.jqassistant.plugin.common.api.scanner.ContainerFileResolver)1 AbstractFileResource (com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource)1 FileResource (com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.FileResource)1 ClassFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)1 ServiceLoaderDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor)1 TypeDescriptor (com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor)1 A (com.buschmais.jqassistant.plugin.java.test.set.scanner.resolver.A)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Collections.singletonList (java.util.Collections.singletonList)1