use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor 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;
}
use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor in project jqa-java-plugin by buschmais.
the class ClassFileScannerPlugin method scan.
@Override
public ClassFileDescriptor scan(FileResource file, String path, Scope scope, final Scanner scanner) throws IOException {
final FileDescriptor fileDescriptor = scanner.getContext().getCurrentDescriptor();
VisitorHelper visitorHelper = new VisitorHelper(scanner.getContext(), classModelConfiguration);
final ClassVisitor visitor = new ClassVisitor(fileDescriptor, visitorHelper);
ClassFileDescriptor classFileDescriptor;
try (InputStream stream = file.createStream()) {
classFileDescriptor = MD5DigestDelegate.getInstance().digest(stream, new MD5DigestDelegate.DigestOperation<ClassFileDescriptor>() {
@Override
public ClassFileDescriptor execute(InputStream inputStream) throws IOException {
new ClassReader(inputStream).accept(visitor, 0);
return visitor.getTypeDescriptor();
}
});
classFileDescriptor.setValid(true);
} catch (RuntimeException e) {
LOGGER.warn("Cannot scan class '" + path + "'.", e);
classFileDescriptor = visitor.getTypeDescriptor();
if (classFileDescriptor == null) {
classFileDescriptor = scanner.getContext().getStore().addDescriptorType(fileDescriptor, ClassFileDescriptor.class);
}
classFileDescriptor.setValid(false);
}
return classFileDescriptor;
}
use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor 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();
}
use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor in project jqa-java-plugin by buschmais.
the class InvalidClassFileIT method validClass.
@Test
public void validClass() throws IOException {
scanClasses(InvalidClassFileIT.class);
store.beginTransaction();
List<FileDescriptor> fileDescriptors = query("MATCH (c:Class:File) RETURN c").getColumn("c");
assertThat(fileDescriptors.size(), equalTo(1));
FileDescriptor fileDescriptor = fileDescriptors.get(0);
assertThat(fileDescriptor, instanceOf(ClassFileDescriptor.class));
ClassFileDescriptor classFileDescriptor = (ClassFileDescriptor) fileDescriptor;
assertThat(classFileDescriptor.isValid(), equalTo(true));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor 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();
}
Aggregations