Search in sources :

Example 46 with Reflections

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);
                }
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InputStream(java.io.InputStream) Driver(java.sql.Driver) IOException(java.io.IOException) Properties(java.util.Properties) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Example 47 with Reflections

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;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FilterBuilder(org.reflections.util.FilterBuilder) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 48 with Reflections

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;
}
Also used : lombok.val(lombok.val) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Set(java.util.Set) ArrayList(java.util.ArrayList) BaseRandomOp(org.nd4j.linalg.api.ops.random.BaseRandomOp) Variance(org.nd4j.linalg.api.ops.impl.accum.Variance) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) DifferentialFunction(org.nd4j.autodiff.functions.DifferentialFunction) Reflections(org.reflections.Reflections)

Example 49 with Reflections

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");
}
Also used : ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException) ND4JIllegalStateException(org.nd4j.linalg.exception.ND4JIllegalStateException) Reflections(org.reflections.Reflections)

Example 50 with Reflections

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)));
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) AnnotatedClassDescriptor(org.apache.drill.common.scanner.persistence.AnnotatedClassDescriptor) FilterBuilder(org.reflections.util.FilterBuilder) ParentClassDescriptor(org.apache.drill.common.scanner.persistence.ParentClassDescriptor) Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)160 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)54 SubTypesScanner (org.reflections.scanners.SubTypesScanner)41 ArrayList (java.util.ArrayList)26 Set (java.util.Set)23 ResourcesScanner (org.reflections.scanners.ResourcesScanner)21 Test (org.junit.Test)20 FilterBuilder (org.reflections.util.FilterBuilder)20 HashSet (java.util.HashSet)19 URL (java.net.URL)18 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)18 IOException (java.io.IOException)17 Collectors (java.util.stream.Collectors)17 Method (java.lang.reflect.Method)16 List (java.util.List)15 File (java.io.File)13 InputStream (java.io.InputStream)9 Field (java.lang.reflect.Field)9 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)9 ClasspathHelper (org.reflections.util.ClasspathHelper)9