Search in sources :

Example 6 with JavaArtifactFileDescriptor

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

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

Example 8 with JavaArtifactFileDescriptor

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();
}
Also used : A(com.buschmais.jqassistant.plugin.java.test.set.scanner.resolver.A) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) Test(org.junit.Test)

Example 9 with JavaArtifactFileDescriptor

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();
}
Also used : JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor) Test(org.junit.Test)

Example 10 with JavaArtifactFileDescriptor

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()));
}
Also used : Store(com.buschmais.jqassistant.core.store.api.Store) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)

Aggregations

JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)11 Test (org.junit.Test)7 Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)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 JavaClassesDirectoryDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor)2 A (com.buschmais.jqassistant.plugin.java.test.set.scanner.resolver.A)2 ScannerContext (com.buschmais.jqassistant.core.scanner.api.ScannerContext)1 Store (com.buschmais.jqassistant.core.store.api.Store)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 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Collections.singletonList (java.util.Collections.singletonList)1