DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page Class Path Scanning made easy for everybody
Notices
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Feb 2010
Thumbs up Class Path Scanning made easy for everybody - 02-20-2010, 09:36 AM

As can be seen on pages like Classpath Scanning: Hidden Spring Gems « It works on my machine! the way to class path scanning so far has been to use the Spring framework's feature for oneself.

There are some drawbacks to that approach however. For one thing you need to depend on the Spring jars, just for class path scanning. If you don’t need them for anything else this is quite cumbersome. For another the API you need to use this way is not really straight-forward.

But now there is a better way for class path scanning. Making this non-trivial issue absolutely easy for everybody. It’s called eXtcos, which is short for Extensible Component Scanner. This little library is inspired by the Spring feature but is a small library solely focused on the task of class path scanning.

It provides an easy to use query language for requesting the classes. This is a refreshing change to the boiler plate code you need to use the Spring classes for your own needs.

Imagine you want to find all the classes annotated with a @PreferencePage annotation in the “sample” package. Your code with eXtcos is just

Code:
ClasspathScanner scanner = new ClasspathScanner();

Set<Class> classes = scanner.getClasses(new ClassQuery() {
    protected void query() {
        select().
        from(“sample”).
        returning(allAnnotatedWith(PreferencePage.class));
    }
});
That’s all.

In case you want to get several different kinds of classes that’s possible with just one query as well. Consider the following listing looking up all classes annotated with the @PreferencePage annotation and all classes extending the JComponent class in two different sets.

Code:
ClasspathScanner scanner = new ClasspathScanner();

final Set<Class> jComponentStore = new ArraySet<Class>();

Set<Class> classes = scanner.getClasses(new ClassQuery() {
    protected void query() {
        select().
        from(“sample”).
        andStore(thoseExtending(JComponent.class).into(jComponentStore)).
        returning(allAnnotatedWith(PreferencePage.class));
    }
});
Like the look and feel of it? Download it now and test drive it yourself. Just go to Extensible Component Scanner | Get Extensible Component Scanner at SourceForge.net. After testing, please leave a comment and spread the word. It’s completely free software.
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Feb 2010
Default 03-10-2010, 02:18 AM

I'm currently looking for developers able to implement extensions for the Extensible Component Scanner. As of now only Java class files are supported, but through an SPI support for other languages running on the JVM can also be implemented.

So if you have experience in Groovy or Scala source code analysis and want to contribute to this project, please get in touch. Thanks.
Reply With Quote
  (#3 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Sep 2011
Default 09-23-2011, 04:02 AM

It looks like with the current version of the code (I downloaded 0.2b today) the example no longer works. It should read:

ComponentScanner scanner = new ComponentScanner();

Set<Class<?>> classes = scanner.getClasses(new ComponentQuery() {
protected void query() {
select().
from("com.my.package").
returning(allAnnotatedWith(MyAnnotation.class));
}
});
Reply With Quote
  (#4 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Feb 2010
Default 11-07-2011, 10:12 AM

That's correct. To put more emphasis on the component I changed the names ClasspathScanner to ComponentScanner and ClassQuery to ComponentQuery with version 0.2b. Thanks @wilpower for updating the example.

Just this weekend version 0.3b has been released. No changes were made to the API, however you can now get the Extensible Component Scanner right from Maven Central. Just add the following dependency to your project pom and you're done:

<dependency>
<groupId>net.sf.extcos</groupId>
<artifactId>extcos</artifactId>
<version>0.3b</version>
</dependency>

The user manual is now also more easily accessible at Extensible Component Scanner - User Manual. Have fun using the Extensible Component Scanner and report back with your experiences at Extensible Component Scanner | Reviews for Extensible Component Scanner at SourceForge.net.
Reply With Quote
Reply

Tags
class path scanning, java, spring inspired

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How are refcardz made? Crucifix Refcardz 1 01-12-2010 12:58 AM
Modrocko's Easy Data Objects Todd_Clarke Microsoft SQL Server 0 01-08-2010 12:25 PM
How can my view in Eclipse listen to the selection made in the package explorer. poonam12jul Eclipse 0 11-15-2008 01:27 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com