use of com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor 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.ServiceLoaderDescriptor in project jqa-java-plugin by buschmais.
the class ServiceLoaderIT method verifyServiceLoaderDescriptor.
/**
* Verifies the expected service loader descriptor and its content.
*/
private void verifyServiceLoaderDescriptor() {
store.beginTransaction();
List<ServiceLoaderDescriptor> serviceLoaderDescriptors = query("MATCH (sd:ServiceLoader:File) RETURN sd").getColumn("sd");
assertThat(serviceLoaderDescriptors.size(), equalTo(1));
ServiceLoaderDescriptor serviceLoaderDescriptor = serviceLoaderDescriptors.get(0);
assertThat(serviceLoaderDescriptor.getFileName(), endsWith("/META-INF/services/" + Service.class.getName()));
assertThat(serviceLoaderDescriptor.getType(), typeDescriptor(Service.class));
List<TypeDescriptor> serviceTypes = serviceLoaderDescriptor.getContains();
assertThat(serviceTypes.size(), equalTo(2));
assertThat(serviceTypes, hasItem(typeDescriptor(ServiceImpl.class)));
assertThat(serviceTypes, hasItem(typeDescriptor(OuterClass.InnerClassServiceImpl.class)));
store.commitTransaction();
}
use of com.buschmais.jqassistant.plugin.java.api.model.ServiceLoaderDescriptor in project jqa-java-plugin by buschmais.
the class ServiceLoaderFileScannerPlugin method scan.
@Override
public ServiceLoaderDescriptor scan(FileResource item, String path, Scope scope, Scanner scanner) throws IOException {
Matcher matcher = PATTERN.matcher(path);
if (!matcher.matches()) {
throw new IOException("Cannot match path name: " + path);
}
String serviceInterface = matcher.group(2);
ScannerContext context = scanner.getContext();
FileDescriptor fileDescriptor = context.getCurrentDescriptor();
ServiceLoaderDescriptor serviceLoaderDescriptor = context.getStore().addDescriptorType(fileDescriptor, ServiceLoaderDescriptor.class);
TypeDescriptor interfaceTypeDescriptor = getTypeDescriptor(serviceInterface, context);
serviceLoaderDescriptor.setType(interfaceTypeDescriptor);
try (InputStream stream = item.createStream()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String serviceImplementation;
while ((serviceImplementation = reader.readLine()) != null) {
if (!isEmptyOrComment(serviceImplementation)) {
TypeDescriptor implementationTypeDescriptor = getTypeDescriptor(serviceImplementation, context);
serviceLoaderDescriptor.getContains().add(implementationTypeDescriptor);
}
}
}
return serviceLoaderDescriptor;
}
Aggregations