use of com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor 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.java.api.model.JavaArtifactFileDescriptor 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();
}
use of com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor in project jqa-java-plugin by buschmais.
the class TypeResolverIT method ambiguousDependencies.
/**
* Verifies scanning a type depending on another type which exists in two
* independent artifacts.
*
* @throws IOException
* If the test fails.
*/
@Test
public void ambiguousDependencies() throws IOException {
store.beginTransaction();
JavaArtifactFileDescriptor a1 = getArtifactDescriptor("a1");
JavaArtifactFileDescriptor a2 = getArtifactDescriptor("a2");
JavaArtifactFileDescriptor a3 = getArtifactDescriptor("a3");
store.create(a3, DependsOnDescriptor.class, a1);
store.create(a3, DependsOnDescriptor.class, a2);
store.commitTransaction();
scanClasses("a1", A.class);
scanClasses("a2", A.class);
scanClasses("a3", B.class);
store.beginTransaction();
TestResult testResult = query("match (:Artifact)-[:CONTAINS]->(t:Type) where t.fqn={t} return t", MapBuilder.<String, Object>create("t", A.class.getName()).get());
assertThat(testResult.getRows().size(), equalTo(2));
testResult = query("match (artifact3:Artifact)-[:CONTAINS]->(b:Type)-[:DEPENDS_ON]->(a:Type)-[:CONTAINS]-(otherArtifact:Artifact) where b.fqn={b} return otherArtifact", MapBuilder.<String, Object>create("a", A.class.getName()).put("b", B.class.getName()).get());
assertThat(testResult.getRows().size(), equalTo(1));
JavaArtifactFileDescriptor otherArtifact = (JavaArtifactFileDescriptor) testResult.getColumn("otherArtifact").get(0);
assertThat(otherArtifact, anyOf(equalTo(a1), equalTo(a2)));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor in project jqa-java-plugin by buschmais.
the class TypeResolverIT method dependentArtifacts.
/**
* Verifies scanning dependent types located in dependent artifacts.
*
* @throws IOException
* If the test fails.
*/
@Test
public void dependentArtifacts() throws IOException {
store.beginTransaction();
JavaArtifactFileDescriptor a1 = getArtifactDescriptor("a1");
JavaArtifactFileDescriptor a2 = getArtifactDescriptor("a2");
store.create(a2, DependsOnDescriptor.class, a1);
store.commitTransaction();
scanClasses("a1", A.class);
scanClasses("a2", B.class);
store.beginTransaction();
TestResult testResult = query("match (artifact:Artifact)-[:CONTAINS]->(t:Type) where artifact.fqn={artifact} return t", MapBuilder.<String, Object>create("artifact", "a1").get());
assertThat(testResult.getRows().size(), equalTo(1));
assertThat(testResult.getColumn("t"), hasItem(typeDescriptor(A.class)));
testResult = query("match (artifact:Artifact)-[:CONTAINS]->(t:Type) where artifact.fqn={artifact} return t", MapBuilder.<String, Object>create("artifact", "a2").get());
assertThat(testResult.getRows().size(), equalTo(1));
assertThat(testResult.getColumn("t"), hasItem(typeDescriptor(B.class)));
testResult = query("match (artifact2:Artifact)-[:CONTAINS]->(b:Type)-[:DEPENDS_ON]->(a:Type)<-[:CONTAINS]-(artifact1:Artifact) where artifact1.fqn={a1} and artifact2.fqn={a2} and b.fqn={b} return a", MapBuilder.<String, Object>create("b", B.class.getName()).put("a1", "a1").put("a2", "a2").get());
assertThat(testResult.getColumn("a"), hasItem(typeDescriptor(A.class)));
// java.lang.Object is only required by artifact A1
testResult = query("match (a:Artifact)-[:REQUIRES]->(o:Type) where o.fqn={object} return a", MapBuilder.<String, Object>create("object", Object.class.getName()).get());
List<JavaArtifactFileDescriptor> objects = testResult.getColumn("a");
assertThat(objects.size(), equalTo(1));
assertThat(objects.get(0), equalTo(a1));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor in project jqa-java-plugin by buschmais.
the class JavaClassesDirectoryScannerPlugin method getContainerDescriptor.
@Override
protected JavaClassesDirectoryDescriptor getContainerDescriptor(File classPathDirectory, ScannerContext scannerContext) {
JavaArtifactFileDescriptor javaArtifactDescriptor = scannerContext.peekOrDefault(JavaArtifactFileDescriptor.class, null);
Store store = scannerContext.getStore();
if (javaArtifactDescriptor == null) {
return store.create(JavaClassesDirectoryDescriptor.class);
}
if (JavaClassesDirectoryDescriptor.class.isAssignableFrom(javaArtifactDescriptor.getClass())) {
return JavaClassesDirectoryDescriptor.class.cast(javaArtifactDescriptor);
}
throw new IllegalStateException("Expected an instance of " + JavaClassesDirectoryDescriptor.class.getName() + " but got " + Arrays.asList(javaArtifactDescriptor.getClass().getInterfaces()));
}
Aggregations