use of org.reflections.Reflections in project nd4j by deeplearning4j.
the class DriverFinder method discoverDriverClazz.
private static void discoverDriverClazz() {
Reflections r = new Reflections();
Set<Class<? extends Driver>> clazzes = new HashSet<>(r.getSubTypesOf(Driver.class));
if (clazzes.isEmpty()) {
throw new IllegalStateException("No org.nd4j.jdbc drivers found.");
} else if (clazzes.size() != 1) {
Set<Class<? extends Driver>> remove = new HashSet<>();
for (Class<? extends Driver> clazz : clazzes) {
if (Modifier.isAbstract(clazz.getModifiers())) {
remove.add(clazz);
} else if (Modifier.isInterface(clazz.getModifiers())) {
remove.add(clazz);
}
}
clazzes.removeAll(remove);
if (clazzes.size() != 1) {
InputStream i = DriverFinder.class.getResourceAsStream("/" + ND4j_JDBC_PROPERTIES);
if (i == null)
throw new IllegalStateException("Only one jdbc driver allowed on the class path");
else {
Properties props = new Properties();
try {
props.load(i);
} catch (IOException e) {
throw new RuntimeException(e);
}
String clazz = props.getProperty(JDBC_KEY);
if (clazz == null)
throw new IllegalStateException("Unable to find jdbc driver. Please specify a " + ND4j_JDBC_PROPERTIES + " with the key " + JDBC_KEY);
try {
DriverFinder.clazz = (Class<? extends Driver>) Class.forName(clazz);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Unable to find jdbc driver. Please specify a " + ND4j_JDBC_PROPERTIES + " with the key " + JDBC_KEY);
}
}
}
}
}
use of org.reflections.Reflections in project nd4j by deeplearning4j.
the class VersionCheck method listGitPropertiesFiles.
/**
* @return A list of the property files containing the build/version info
*/
public static List<String> listGitPropertiesFiles() {
Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().exclude(".*").include("/ai/skymind/*")).setScanners(new ResourcesScanner()));
Set<String> resources = reflections.getResources(Pattern.compile(".*-git.properties"));
List<String> out = new ArrayList<>(resources);
// Equivalent to sorting by groupID and artifactID
Collections.sort(out);
return out;
}
use of org.reflections.Reflections in project nd4j by deeplearning4j.
the class OpsMappingTests method getOperations.
protected List<Operation> getOperations(@NonNull Op.Type type) {
val list = new ArrayList<Operation>();
Reflections f = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.nd4j.*")).exclude("^(?!.*\\.class$).*$")).setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner()));
switch(type) {
case SUMMARYSTATS:
{
Set<Class<? extends Variance>> clazzes = f.getSubTypesOf(Variance.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case RANDOM:
{
Set<Class<? extends BaseRandomOp>> clazzes = f.getSubTypesOf(BaseRandomOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case INDEXREDUCE:
{
Set<Class<? extends BaseIndexAccumulation>> clazzes = f.getSubTypesOf(BaseIndexAccumulation.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case REDUCE3:
case REDUCE:
{
Set<Class<? extends BaseAccumulation>> clazzes = f.getSubTypesOf(BaseAccumulation.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case BROADCAST:
{
Set<Class<? extends BaseBroadcastOp>> clazzes = f.getSubTypesOf(BaseBroadcastOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case SCALAR:
{
Set<Class<? extends BaseScalarOp>> clazzes = f.getSubTypesOf(BaseScalarOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case PAIRWISE:
case TRANSFORM:
{
Set<Class<? extends BaseTransformOp>> clazzes = f.getSubTypesOf(BaseTransformOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
}
break;
case CUSTOM:
{
Set<Class<? extends DynamicCustomOp>> clazzes = f.getSubTypesOf(DynamicCustomOp.class);
for (Class<? extends DifferentialFunction> clazz : clazzes) {
if (clazz.getSimpleName().equalsIgnoreCase("dynamiccustomop"))
continue;
addOperation(clazz, list);
}
}
break;
}
log.info("Group: {}; List size: {}", type, list.size());
return list;
}
use of org.reflections.Reflections in project nd4j by deeplearning4j.
the class TrainerProvider method scanClasspath.
protected void scanClasspath() {
// TODO: reflection stuff to fill trainers
Reflections reflections = new Reflections("org");
Set<Class<? extends TrainingDriver>> classes = reflections.getSubTypesOf(TrainingDriver.class);
for (Class clazz : classes) {
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers()))
continue;
try {
TrainingDriver driver = (TrainingDriver) clazz.newInstance();
trainers.put(driver.targetMessageClass(), driver);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
if (trainers.size() < 1)
throw new ND4JIllegalStateException("No TrainingDrivers were found");
}
use of org.reflections.Reflections in project drill by apache.
the class ClassPathScanner method scan.
/**
* @param pathsToScan the locations to scan for .class files
* @param packagePrefixes the whitelist of package prefixes to scan
* @param parentResult if there was a prescan, its result
* @return the merged scan
*/
static ScanResult scan(Collection<URL> pathsToScan, Collection<String> packagePrefixes, Collection<String> scannedClasses, Collection<String> scannedAnnotations, ScanResult parentResult) {
Stopwatch watch = Stopwatch.createStarted();
try {
AnnotationScanner annotationScanner = new AnnotationScanner(scannedAnnotations);
SubTypesScanner subTypesScanner = new SubTypesScanner(parentResult.getImplementations());
if (packagePrefixes.size() > 0) {
final FilterBuilder filter = new FilterBuilder();
for (String prefix : packagePrefixes) {
filter.include(FilterBuilder.prefix(prefix));
}
ConfigurationBuilder conf = new ConfigurationBuilder().setUrls(pathsToScan).setMetadataAdapter(// Scanners depend on this
METADATA_ADAPTER).filterInputsBy(filter).setScanners(annotationScanner, subTypesScanner);
// scans stuff, but don't use the funky storage layer
new Reflections(conf);
}
List<ParentClassDescriptor> implementations = new ArrayList<>();
for (String baseTypeName : scannedClasses) {
implementations.add(new ParentClassDescriptor(baseTypeName, new ArrayList<>(subTypesScanner.getChildrenOf(baseTypeName))));
}
List<AnnotatedClassDescriptor> annotated = annotationScanner.getAnnotatedClasses();
verifyClassUnicity(annotated, pathsToScan);
return new ScanResult(packagePrefixes, scannedClasses, scannedAnnotations, annotated, implementations);
} finally {
logger.info(format("Scanning packages %s in locations %s took %dms", packagePrefixes, pathsToScan, watch.elapsed(MILLISECONDS)));
}
}
Aggregations