Hello,

I noticed ClassFinder while tweaking ActionRouter and I believe it should
be replace with a proper service declaration and loading.

I'm a fan of the Lookup API (see [1] [2]) which is a small standalone JAR
used a lot in NetBeans.

The standard ServiceLoader [3] would also be a better replacement.

Some remarks:

* ClassFinder is almost always called with JMeterUtils.getSearchPaths().
This must be expected to be the class path actually.
* many calls of ClassFinder do some filtering, excluding some
implementations. This would be simple by just not registering those
implementations as a service.

With the ServiceLoader, ActionRouter would load commands with something
like:

> ServiceLoader<Command> commands = ServiceLoader.load(Command.class);

An each command will have to be registered in META-INF/services (for Java
8) or in the module declaration (for Java 9).

In NetBeans we have an annotation @ServiceProvider [4] which is simpler and
behind the scenes the build system generates at build time the
META-INF/services registration file.

Note that service registration and loading would work the same for 3rd
party JARs.

The only downside is we have to think about older external JARs that expect
the current behaviour. We could use some flag (in MANIFEST perhaps?) to
differentiate between them.

1.
http://bits.netbeans.org/8.0/javadoc/org-openide-util-lookup/org/openide/util/Lookup.html
2.
http://bits.netbeans.org/8.0/javadoc/org-openide-util-lookup/org/openide/util/lookup/doc-files/lookup-api.html
3. http://download.java.net/java/jdk9/docs/api/java/util/ServiceLoader.html
4.
http://bits.netbeans.org/8.0/javadoc/org-openide-util-lookup/org/openide/util/lookup/ServiceProvider.html

--emi

Reply via email to