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