Skip to content

Scanner Implementations

manzke edited this page Dec 21, 2011 · 7 revisions

The pure-ASM Implementation is my own one. It was inspired by my experiences with Reflections, Sonatype and a lot of Classpath Scanning. A multi-threaded Implementation is planned and started, but the Feature is disabled, due the fact, that it is experimental. ;)

pure-ASM:

		<dependency>
			<groupId>de.devsurf.injection.guice.scanner</groupId>
			<artifactId>de.devsurf.injection.guice.scanner.asm</artifactId>
			<version>0.8.7</version>
		</dependency>

The Idea for the Automatic Binding for Guice, was inspired by a Presentation of one of the Sonatype Guys. They do fantastic and interesting work. I really like their products, software, source code, ... So this is just a Wrapper around their Implementation. Sonatype:

		<dependency>
			<groupId>de.devsurf.injection.guice.scanner</groupId>
			<artifactId>de.devsurf.injection.guice.scanner.sonatype</artifactId>
			<version>0.8.7</version>
		</dependency>

Reflections is the only multi-threaded Implementation. It scans the Classpath in multiple Threads. Depends on the Number of your Cores, but it has a problem. It doesn't use the whole Classpath, so it can be, that it won't find every Class. Maybe this will change later, by a new release of them. Reflections:

		<dependency>
			<groupId>de.devsurf.injection.guice.scanner</groupId>
			<artifactId>de.devsurf.injection.guice.scanner.reflections</artifactId>
			<version>0.8.7</version>
		</dependency>

If you want to create your own Scanner Implementation, here is an Example. You don't have to use this Constructor, but these parameters can be injected by the Framework.

		public class DummyScanner implements ClasspathScanner {
			@Inject
			public DummyScanner(Set<ScannerFeature> features, @Named("classpath")URL[] classPath,
					@Named("packages") PackageFilter... filter) {
				...
			}

			public void scan() throws IOException {
				... //search for the classes 
				feature.found(clazz, annotations); //Class<Object> clazz, Map<String, Annotation> annotations
			}
		}