Search in sources :

Example 1 with JavaClassesDirectoryDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor 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();
}
Also used : Scanner(com.buschmais.jqassistant.core.scanner.api.Scanner) JavaClassesDirectoryDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) JavaArtifactFileDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)

Example 2 with JavaClassesDirectoryDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor in project jqa-java-plugin by buschmais.

the class AbstractJavaPluginIT method getArtifactDescriptor.

/**
     * Get or create an
     * {@link com.buschmais.jqassistant.plugin.common.api.model.ArtifactFileDescriptor}
     * .
     *
     * @param artifactId
     *            The artifact id.
     * @return The
     *         {@link com.buschmais.jqassistant.plugin.common.api.model.ArtifactFileDescriptor}
     *         .
     */
protected JavaClassesDirectoryDescriptor getArtifactDescriptor(String artifactId) {
    ArtifactDescriptor artifact = store.find(ArtifactDescriptor.class, artifactId);
    if (artifact == null) {
        artifact = store.create(JavaClassesDirectoryDescriptor.class, artifactId);
        artifact.setFullQualifiedName(artifactId);
    }
    return JavaClassesDirectoryDescriptor.class.cast(artifact);
}
Also used : JavaClassesDirectoryDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor) ArtifactDescriptor(com.buschmais.jqassistant.plugin.common.api.model.ArtifactDescriptor)

Example 3 with JavaClassesDirectoryDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor in project jqa-java-plugin by buschmais.

the class JavaClassesDirectoryScannerPluginTest method createArtifact.

/**
     * Verify that the plugin creates a new artifact if none exists in the
     * context.
     * 
     * @throws IOException
     *             If the test fails.
     */
@Test
public void createArtifact() throws IOException {
    JavaClassesDirectoryScannerPlugin plugin = new JavaClassesDirectoryScannerPlugin();
    when(context.peek(FileResolver.class)).thenReturn(mock(FileResolver.class));
    JavaClassesDirectoryDescriptor artifact = mock(JavaClassesDirectoryDescriptor.class);
    when(context.peekOrDefault(JavaArtifactFileDescriptor.class, null)).thenReturn(null);
    when(store.create(JavaClassesDirectoryDescriptor.class)).thenReturn(artifact);
    JavaClassesDirectoryDescriptor descriptor = plugin.scan(directory, "/", JavaScope.CLASSPATH, scanner);
    verify(context).peekOrDefault(JavaArtifactFileDescriptor.class, null);
    verify(store).create(JavaClassesDirectoryDescriptor.class);
    assertThat(descriptor, is(artifact));
}
Also used : JavaClassesDirectoryDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor) JavaClassesDirectoryScannerPlugin(com.buschmais.jqassistant.plugin.java.impl.scanner.JavaClassesDirectoryScannerPlugin) FileResolver(com.buschmais.jqassistant.plugin.common.api.scanner.FileResolver) Test(org.junit.Test)

Example 4 with JavaClassesDirectoryDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor 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 5 with JavaClassesDirectoryDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor in project jqa-java-plugin by buschmais.

the class JavaClassesDirectoryScannerPluginTest method useArtifactFromContext.

/**
     * Verify that the plugin re-uses an existing artifact which exists in the
     * context (e.g. for dependency resolution).
     * 
     * @throws IOException
     *             If the test fails.
     */
@Test
public void useArtifactFromContext() throws IOException {
    JavaClassesDirectoryScannerPlugin plugin = new JavaClassesDirectoryScannerPlugin();
    File directory = Files.createTempDirectory("directory").toFile();
    when(context.peek(FileResolver.class)).thenReturn(mock(FileResolver.class));
    JavaClassesDirectoryDescriptor artifact = mock(JavaClassesDirectoryDescriptor.class);
    when(context.peekOrDefault(JavaArtifactFileDescriptor.class, null)).thenReturn(artifact);
    when(store.addDescriptorType(artifact, JavaClassesDirectoryDescriptor.class)).thenReturn(mock(JavaClassesDirectoryDescriptor.class));
    JavaClassesDirectoryDescriptor descriptor = plugin.scan(directory, "/", JavaScope.CLASSPATH, scanner);
    verify(context).peekOrDefault(JavaArtifactFileDescriptor.class, null);
    verify(store, never()).create(JavaClassesDirectoryDescriptor.class);
    assertThat(descriptor, is(artifact));
}
Also used : JavaClassesDirectoryDescriptor(com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor) JavaClassesDirectoryScannerPlugin(com.buschmais.jqassistant.plugin.java.impl.scanner.JavaClassesDirectoryScannerPlugin) FileResolver(com.buschmais.jqassistant.plugin.common.api.scanner.FileResolver) File(java.io.File) Test(org.junit.Test)

Aggregations

JavaClassesDirectoryDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaClassesDirectoryDescriptor)5 Test (org.junit.Test)3 Scanner (com.buschmais.jqassistant.core.scanner.api.Scanner)2 FileResolver (com.buschmais.jqassistant.plugin.common.api.scanner.FileResolver)2 JavaArtifactFileDescriptor (com.buschmais.jqassistant.plugin.java.api.model.JavaArtifactFileDescriptor)2 JavaClassesDirectoryScannerPlugin (com.buschmais.jqassistant.plugin.java.impl.scanner.JavaClassesDirectoryScannerPlugin)2 File (java.io.File)2 List (java.util.List)2 ArtifactDescriptor (com.buschmais.jqassistant.plugin.common.api.model.ArtifactDescriptor)1 FileDescriptor (com.buschmais.jqassistant.plugin.common.api.model.FileDescriptor)1 ServiceLoaderDescriptor (com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1