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