use of org.reflections.Reflections in project asterixdb by apache.
the class EvaluatorGeneratorMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
baseDir = project.getBuild().getDirectory() + File.separator + "classes";
try {
// Finds all sub-classes of AbstractScalarFunctionDynamicDescriptor with in the package
// org.apache.asterix.runtime.evaluators.
Reflections reflections = new Reflections(evaluatorPackagePrefix);
Set<Class<? extends AbstractScalarFunctionDynamicDescriptor>> allClasses = reflections.getSubTypesOf(AbstractScalarFunctionDynamicDescriptor.class);
// Generates byte code for all sub-classes of AbstractScalarFunctionDynamicDescriptor.
for (Class<?> cl : allClasses) {
getLog().info("Generating byte code for " + cl.getName());
CodeGenUtil.generateScalarFunctionDescriptorBinary(evaluatorPackagePrefix, cl.getName(), CodeGenUtil.DEFAULT_SUFFIX_FOR_GENERATED_CLASS, reflections.getClass().getClassLoader(), (name, bytes) -> writeFile(name, bytes));
}
} catch (Exception e) {
getLog().error(e);
throw new MojoFailureException(e.toString());
}
}
use of org.reflections.Reflections in project flink by apache.
the class RpcCompletenessTest method testRpcCompleteness.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testRpcCompleteness() {
Reflections reflections = new Reflections("org.apache.flink");
Set<Class<? extends RpcEndpoint>> classes = reflections.getSubTypesOf(RpcEndpoint.class);
Class<? extends RpcEndpoint> c;
mainloop: for (Class<? extends RpcEndpoint> rpcEndpoint : classes) {
c = rpcEndpoint;
LOG.debug("-------------");
LOG.debug("c: {}", c);
// skip abstract classes
if (Modifier.isAbstract(c.getModifiers())) {
LOG.debug("Skipping abstract class");
continue;
}
// check for type parameter bound to RpcGateway
// skip if one is found because a subclass will provide the concrete argument
TypeVariable<? extends Class<? extends RpcEndpoint>>[] typeParameters = c.getTypeParameters();
LOG.debug("Checking {} parameters.", typeParameters.length);
for (int i = 0; i < typeParameters.length; i++) {
for (Type bound : typeParameters[i].getBounds()) {
LOG.debug("checking bound {} of type parameter {}", bound, typeParameters[i]);
if (bound.toString().equals("interface " + RpcGateway.class.getName())) {
if (i > 0) {
fail("Type parameter for RpcGateway should come first in " + c);
}
LOG.debug("Skipping class with type parameter bound to RpcGateway.");
// Type parameter is bound to RpcGateway which a subclass will provide
continue mainloop;
}
}
}
// check if this class or any super class contains the RpcGateway argument
Class<?> rpcGatewayType;
do {
LOG.debug("checking type argument of class: {}", c);
rpcGatewayType = ReflectionUtil.getTemplateType1(c);
LOG.debug("type argument is: {}", rpcGatewayType);
c = (Class<? extends RpcEndpoint>) c.getSuperclass();
} while (!RpcGateway.class.isAssignableFrom(rpcGatewayType));
LOG.debug("Checking RRC completeness of endpoint '{}' with gateway '{}'", rpcEndpoint.getSimpleName(), rpcGatewayType.getSimpleName());
checkCompleteness(rpcEndpoint, (Class<? extends RpcGateway>) rpcGatewayType);
}
}
use of org.reflections.Reflections in project sling by apache.
the class OsgiMetadataUtil method initMetadataDocumentCache.
/**
* Reads all SCR metadata XML documents located at OSGI-INF/ and caches them with quick access by implementation class.
* @return Cache map
*/
private static Map<String, Document> initMetadataDocumentCache() {
Map<String, Document> cacheMap = new HashMap<>();
XPath xpath = XPATH_FACTORY.newXPath();
xpath.setNamespaceContext(NAMESPACE_CONTEXT);
XPathExpression xpathExpression;
try {
xpathExpression = xpath.compile("//*[implementation/@class]");
} catch (XPathExpressionException ex) {
throw new RuntimeException("Compiling XPath expression failed.", ex);
}
Reflections reflections = new Reflections(METADATA_PATH, new ResourcesScanner());
Set<String> paths = reflections.getResources(Pattern.compile("^.*\\.xml$"));
for (String path : paths) {
parseMetadataDocuments(cacheMap, path, xpathExpression);
}
return cacheMap;
}
use of org.reflections.Reflections in project cas by apereo.
the class ConfigurationMetadataGenerator method locatePropertiesClassForType.
private Class locatePropertiesClassForType(final ClassOrInterfaceType type) {
if (cachedPropertiesClasses.containsKey(type.getNameAsString())) {
return cachedPropertiesClasses.get(type.getNameAsString());
}
final Predicate<String> filterInputs = s -> s.contains(type.getNameAsString());
final Predicate<String> filterResults = s -> s.endsWith(type.getNameAsString());
final String packageName = ConfigurationMetadataGenerator.class.getPackage().getName();
final Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filterInputs).setUrls(ClasspathHelper.forPackage(packageName)).setScanners(new TypeElementsScanner().includeFields(false).includeMethods(false).includeAnnotations(false).filterResultsBy(filterResults), new SubTypesScanner(false)));
final Class clz = reflections.getSubTypesOf(Serializable.class).stream().filter(c -> c.getSimpleName().equalsIgnoreCase(type.getNameAsString())).findFirst().orElseThrow(() -> new IllegalArgumentException("Cant locate class for " + type.getNameAsString()));
cachedPropertiesClasses.put(type.getNameAsString(), clz);
return clz;
}
use of org.reflections.Reflections in project cas by apereo.
the class JpaServiceRegistryConfiguration method jpaServicePackagesToScan.
@Bean
public List<String> jpaServicePackagesToScan() {
final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(CentralAuthenticationService.NAMESPACE)).setScanners(new SubTypesScanner(false)));
final Set<Class<? extends AbstractRegisteredService>> subTypes = reflections.getSubTypesOf(AbstractRegisteredService.class);
return subTypes.stream().map(t -> t.getPackage().getName()).collect(Collectors.toList());
}
Aggregations