@ SuppressWarnings ( "deprecation" ) private void init ( String ... packages ) throws Siren4JException { LOG . info ( "Siren4J scanning classpath for resource entries..." ) ; Reflections reflections = null ; ConfigurationBuilder builder = new ConfigurationBuilder ( ) ; Collection < URL > urls = new HashSet < URL > ( ) ; if ( packages != null && packages . length > 0 ) { //limit scan to packages for ( String pkg : packages ) { urls . addAll ( ClasspathHelper . forPackage ( pkg ) ) ; } } else { urls . addAll ( ClasspathHelper . forPackage ( "com." ) ) ; urls . addAll ( ClasspathHelper . forPackage ( "org." ) ) ; urls . addAll ( ClasspathHelper . forPackage ( "net." ) ) ; } //Always add Siren4J Resources by default, this will add the collection resource //and what ever other resource gets added to this package and has the entity annotation. urls . addAll ( ClasspathHelper . forPackage ( "com.google.code.siren4j.resource" ) ) ; builder . setUrls ( urls ) ; reflections = new Reflections ( builder ) ; Set < Class < ? > > types = reflections . getTypesAnnotatedWith ( Siren4JEntity . class ) ; for ( Class < ? > c : types ) { Siren4JEntity anno = c . getAnnotation ( Siren4JEntity . class ) ; String name = StringUtils . defaultIfBlank ( anno . name ( ) , anno . entityClass ( ) . length > 0 ? anno . entityClass ( ) [ 0 ] : c . getName ( ) ) ; putEntry ( StringUtils . defaultIfEmpty ( name , c . getName ( ) ) , c , false ) ; // Always add the class name as an entry in the index if it does not already exist. if ( ! containsEntityEntry ( c . getName ( ) ) ) { putEntry ( StringUtils . defaultIfEmpty ( c . getName ( ) , c . getName ( ) ) , c , false ) ; } } }
Scans the classpath for resources .