Skip to content

Commit

Permalink
Try putting options on a separate interface for just the task
Browse files Browse the repository at this point in the history
I also tried just defining abstract setter methods, but to no avail
  • Loading branch information
jonnybot0 committed May 2, 2024
1 parent 00536a1 commit 074302b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/champeau/jmh/JMHTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* The JMH task is responsible for launching a JMH benchmark.
*/
public abstract class JMHTask extends DefaultTask implements JmhParameters {
public abstract class JMHTask extends DefaultTask implements JmhSetters {
private final static String JAVA_IO_TMPDIR = "java.io.tmpdir";

@Inject
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/me/champeau/jmh/JmhParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,38 @@
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.options.Option;

public interface JmhParameters extends WithJavaToolchain {

@Option(option = "jmhVersion", description = "JMH version")
@Input
Property<String> getJmhVersion();

@Option(option = "includeTests", description = "Include test sources in generated jar file")
@Input
Property<Boolean> getIncludeTests();

@Option(option = "includes", description = "Include pattern for benchmarks to be executed")
@Input
ListProperty<String> getIncludes();

@Option(option = "excludes", description = "Exclude pattern for benchmarks to be executed")
@Input
ListProperty<String> getExcludes();

@Option(option = "benchmarkMode", description = "Benchmark mode. Available modes are: [Throughput/thrpt, AverageTime/avgt, SampleTime/sample, SingleShotTime/ss, All/all]")
@Input
ListProperty<String> getBenchmarkMode();

@Input
@Optional
Property<Integer> getIterations();

@Option(option = "iterations", description = "Number of measurement iterations to do.")
default void setIterations(Integer iterations) {
getIterations().set(iterations);
}

@Option(option = "batchSize", description = "Batch size: number of benchmark method calls per operation. (some benchmark modes can ignore this setting)")
@Input
@Optional
Property<Integer> getBatchSize();

@Option(option = "fork", description = "How many times to forks a single benchmark. Use 0 to disable forking altogether")
@Input
@Optional
Property<Integer> getFork();

@Option(option = "failOnError", description = "Should JMH fail immediately if any benchmark had experienced the unrecoverable error?")
@Input
Property<Boolean> getFailOnError();

@Option(option = "forceGC", description = "Should JMH force GC between iterations?")
@Input
Property<Boolean> getForceGC();

Expand Down Expand Up @@ -131,7 +115,6 @@ default void setIterations(Integer iterations) {
@Optional
Property<String> getJmhTimeout();

@Option(option = "warmup", description = "")
@Input
@Optional
Property<String> getWarmup();
Expand All @@ -144,7 +127,6 @@ default void setIterations(Integer iterations) {
@Optional
Property<Integer> getWarmupForks();

@Option(option = "warmupIterations", description = "")
@Input
@Optional
Property<Integer> getWarmupIterations();
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/me/champeau/jmh/JmhSetters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.champeau.jmh;

import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.options.Option;

import java.util.List;

public interface JmhSetters extends JmhParameters {

@Option(option = "iterations", description = "Number of measurement iterations to do.")
default void setIterations(Integer iterations) {
this.getIterations().set(iterations);
}

@Option(option = "includes", description = "include pattern (regular expression) for benchmarks to be executed")
default void setIncludes(List<String> includes) {
this.getIncludes().set(includes);
}
}

0 comments on commit 074302b

Please sign in to comment.