Skip to content

Commit fa59738

Browse files
committed
Merge the CLI class into the instrument.
1 parent a401687 commit fa59738

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

src/main/java/com/oracle/simpletool/CLI.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/com/oracle/simpletool/SimpleCodeCoverageInstrument.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import java.util.HashMap;
2626
import java.util.List;
2727
import java.util.Map;
28+
import org.graalvm.options.OptionCategory;
2829
import org.graalvm.options.OptionDescriptors;
30+
import org.graalvm.options.OptionKey;
31+
import org.graalvm.options.OptionStability;
2932
import org.graalvm.options.OptionValues;
3033

3134
/**
@@ -47,6 +50,12 @@
4750
@Registration(id = SimpleCodeCoverageInstrument.ID, name = "Simple Code Coverage", version = "0.1", services = SimpleCodeCoverageInstrument.class)
4851
public final class SimpleCodeCoverageInstrument extends TruffleInstrument {
4952

53+
@Option(name = "", help = "Enable Simple Coverage (default: false).", category = OptionCategory.USER, stability = OptionStability.STABLE)
54+
static final OptionKey<Boolean> ENABLED = new OptionKey<>(false);
55+
56+
@Option(name = "PrintCoverage", help = "Print coverage to stdout on process exit (default: true).", category = OptionCategory.USER, stability = OptionStability.STABLE)
57+
static final OptionKey<Boolean> PRINT_COVERAGE = new OptionKey<>(true);
58+
5059
public static final String ID = "simple-code-coverage";
5160

5261
/**
@@ -67,10 +76,11 @@ public Map<Source, Set<SourceSection>> getSourceToNotYetCoveredSections() {
6776
*
6877
* This method is used to properly initialize the instrument. A common
6978
* practice is to use the {@link Option} system to enable and configure the
70-
* instrument, as is done in this method. Defining {@link Option}s Sis shown
71-
* in the {@link CLI} class, and their usage can be seen in the
72-
* {@link SimpleCodeCoverageInstrumentTest} when the context is being
73-
* created.
79+
* instrument, as is done in this method. Defining {@link Option}s as is
80+
* shown in {@link #ENABLED} and {@link #PRINT_COVERAGE}, and their usage
81+
* can be seen in the {@link SimpleCodeCoverageInstrumentTest} when the
82+
* context is being created. Using them from the command line is shown in
83+
* the runJsWithCoverage.sh script.
7484
*
7585
* @param env the environment for the instrument. Allows us to read the
7686
* {@link Option}s, input and output streams to be used for reading and
@@ -82,9 +92,9 @@ public Map<Source, Set<SourceSection>> getSourceToNotYetCoveredSections() {
8292
@Override
8393
protected void onCreate(final Env env) {
8494
final OptionValues options = env.getOptions();
85-
if (CLI.ENABLED.getValue(options)) {
95+
if (ENABLED.getValue(options)) {
8696
enable(env);
87-
if (CLI.PRINT_COVERAGE.getValue(options)) {
97+
if (PRINT_COVERAGE.getValue(options)) {
8898
ensurePrintCoverage(env);
8999
}
90100
env.registerService(this);
@@ -202,15 +212,15 @@ public List<Integer> notYetCoveredLineNumbers(final Source source) {
202212
*
203213
* If the {@link TruffleInstrument} uses {@link Option}s, it is nesesery to
204214
* specify which {@link Option}s. The {@link OptionDescriptors} is
205-
* automatically generated from the {@link CLI} class due to the
206-
* {@link Option.Group} annotation. In our case, this is the
207-
* {@code CLIOptionDescriptors} class.
215+
* automatically generated from this class due to the {@link Option}
216+
* annotation. In our case, this is the
217+
* {@code SimpleCodeCoverageInstrumentOptionDescriptors} class.
208218
*
209219
* @return The class generated by the {@link Option.Group} annotation
210220
*/
211221
@Override
212222
protected OptionDescriptors getOptionDescriptors() {
213-
return new CLIOptionDescriptors();
223+
return new SimpleCodeCoverageInstrumentOptionDescriptors();
214224
}
215225

216226
/**

0 commit comments

Comments
 (0)