Search in sources :

Example 1 with AbstractFileResource

use of com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource 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 2 with AbstractFileResource

use of com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource in project jqa-java-plugin by buschmais.

the class ClassTypeScannerPlugin method scan.

@Override
public ClassFileDescriptor scan(final Class<?> item, String path, Scope scope, Scanner scanner) throws IOException {
    final String fileName = "/" + item.getName().replace('.', '/') + ".class";
    AbstractFileResource fileResource = new AbstractFileResource() {

        @Override
        public InputStream createStream() throws IOException {
            return item.getResourceAsStream(fileName);
        }
    };
    return scanner.scan(fileResource, fileName, scope);
}
Also used : AbstractFileResource(com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource)

Aggregations

AbstractFileResource (com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.AbstractFileResource)2 Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)1 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)1 FileResource (com.buschmais.jqassistant.plugin.common.api.scanner.filesystem.FileResource)1 ClassFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ClassFileDescriptor)1 JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 List (java.util.List)1 Test (org.junit.Test)1