-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use annotation-indexer as suggested by @jglick
- Loading branch information
1 parent
061ed49
commit 992fc81
Showing
3 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,41 @@ | ||
package jenkins.benchmark.jmh; | ||
|
||
|
||
import net.java.sezpoz.Index; | ||
import net.java.sezpoz.IndexItem; | ||
import org.jvnet.hudson.annotation_indexer.Index; | ||
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.AnnotatedElement; | ||
|
||
/** | ||
* Find classes annotated with {@link JmhBenchmark} to run their benchmark methods. | ||
* | ||
* @since 2.50 | ||
*/ | ||
@SuppressWarnings("WeakerAccess") | ||
public final class BenchmarkFinder { | ||
private BenchmarkFinder() { | ||
private final ClassLoader classLoader; | ||
|
||
/** | ||
* Class whose {@link ClassLoader} will be used to search for benchmarks. | ||
* | ||
* @param clazz the class whose {@link ClassLoader} will be used to search for benchmarks. | ||
*/ | ||
BenchmarkFinder(Class<?> clazz) { | ||
this.classLoader = clazz.getClassLoader(); | ||
} | ||
|
||
/** | ||
* Includes classes annotated with {@link JmhBenchmark} as candidates for JMH benchmarks. | ||
* | ||
* @param optionsBuilder the optionsBuilder used to build the benchmarks | ||
*/ | ||
public static void findBenchmarks(ChainedOptionsBuilder optionsBuilder) { | ||
for (IndexItem<JmhBenchmark, Object> item : Index.load(JmhBenchmark.class, Object.class)) { | ||
optionsBuilder.include(item.className() + item.annotation().value()); | ||
public void findBenchmarks(ChainedOptionsBuilder optionsBuilder) throws IOException { | ||
for (AnnotatedElement e : Index.list(JmhBenchmark.class, classLoader)) { | ||
Class<?> clazz = (Class<?>) e; | ||
JmhBenchmark annotation = clazz.getAnnotation(JmhBenchmark.class); | ||
optionsBuilder.include(clazz.getName() + annotation.value()); | ||
System.out.println(clazz.getName()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters