Skip to content

Commit

Permalink
remove duplication parsing booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Dec 13, 2024
1 parent d32d900 commit 10bc017
Showing 1 changed file with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,21 +457,16 @@ private ParseResult parseCommandLine(final ReportOptions data,
data.setArgLine(this.argLine.value(userArgs));

data.addChildJVMArgs(this.jvmArgsProcessor.values(userArgs));
data.setFullMutationMatrix(
(userArgs.has(this.fullMutationMatrixSpec) && !userArgs.hasArgument(this.fullMutationMatrixSpec))
|| this.fullMutationMatrixSpec.value(userArgs));
data.setDetectInlinedCode(
(userArgs.has(this.detectInlinedCode) && !userArgs.hasArgument(this.detectInlinedCode))
|| this.detectInlinedCode.value(userArgs));
data.setIncludeLaunchClasspath(
(userArgs.has(this.includeLaunchClasspathSpec) && !userArgs.hasArgument(this.includeLaunchClasspathSpec))
|| this.includeLaunchClasspathSpec.value(userArgs));
data.setUseClasspathJar(
(userArgs.has(this.useClasspathJarSpec) && !userArgs.hasArgument(this.useClasspathJarSpec))
|| this.useClasspathJarSpec.value(userArgs));
data.setShouldCreateTimestampedReports(
(userArgs.has(this.timestampedReportsSpec) && !userArgs.hasArgument(this.timestampedReportsSpec))
|| this.timestampedReportsSpec.value(userArgs));
data.setFullMutationMatrix(booleanValue(fullMutationMatrixSpec, userArgs));

data.setDetectInlinedCode(booleanValue(detectInlinedCode, userArgs));

data.setIncludeLaunchClasspath(booleanValue(includeLaunchClasspathSpec, userArgs));

data.setUseClasspathJar(booleanValue(useClasspathJarSpec, userArgs));

data.setShouldCreateTimestampedReports(booleanValue(timestampedReportsSpec, userArgs));

data.setNumberOfThreads(this.threadsSpec.value(userArgs));
data.setTimeoutFactor(this.timeoutFactorSpec.value(userArgs));
data.setTimeoutConstant(this.timeoutConstSpec.value(userArgs));
Expand All @@ -484,12 +479,10 @@ private ParseResult parseCommandLine(final ReportOptions data,
configureVerbosity(data, userArgs);

data.addOutputFormats(this.outputFormatSpec.values(userArgs));
data.setFailWhenNoMutations(
(userArgs.has(this.failWhenNoMutations) && !userArgs.hasArgument(this.failWhenNoMutations))
|| this.failWhenNoMutations.value(userArgs));
data.setSkipFailingTests(
(userArgs.has(this.skipFailingTests) && !userArgs.hasArgument(this.skipFailingTests))
|| this.skipFailingTests.value(userArgs));
data.setFailWhenNoMutations(booleanValue(failWhenNoMutations, userArgs));

data.setSkipFailingTests(booleanValue(skipFailingTests, userArgs));

data.setCodePaths(this.codePaths.values(userArgs));
data.setMutationUnitSize(this.mutationUnitSizeSpec.value(userArgs));
data.setHistoryInputLocation(this.historyInputSpec.value(userArgs));
Expand All @@ -500,9 +493,7 @@ private ParseResult parseCommandLine(final ReportOptions data,
data.setCoverageThreshold(this.coverageThreshHoldSpec.value(userArgs));
data.setMutationEngine(this.mutationEngine.value(userArgs));
data.setFreeFormProperties(listToProperties(this.pluginPropertiesSpec.values(userArgs)));
data.setExportLineCoverage(
(userArgs.has(this.exportLineCoverageSpec) && !userArgs.hasArgument(this.exportLineCoverageSpec))
|| this.exportLineCoverageSpec.value(userArgs));
data.setExportLineCoverage(booleanValue(exportLineCoverageSpec, userArgs));

setClassPath(userArgs, data);

Expand Down Expand Up @@ -534,9 +525,7 @@ private void setEncoding(ReportOptions data, OptionSet userArgs) {
}

private void configureVerbosity(ReportOptions data, OptionSet userArgs) {
boolean isVerbose = (userArgs.has(this.verboseSpec) && !userArgs.hasArgument(this.verboseSpec))
|| this.verboseSpec.value(userArgs);
if (isVerbose) {
if (booleanValue(verboseSpec, userArgs)) {
data.setVerbosity(Verbosity.VERBOSE);
} else {
data.setVerbosity(Verbosity.fromString(this.verbositySpec.value(userArgs)));
Expand All @@ -545,13 +534,12 @@ private void configureVerbosity(ReportOptions data, OptionSet userArgs) {
}

private void configureExecutionMode(ReportOptions data, OptionSet userArgs) {
boolean isDryRun = (userArgs.has(this.dryRunSpec) && !userArgs.hasArgument(this.dryRunSpec))
|| this.dryRunSpec.value(userArgs);
if (isDryRun) {
if (booleanValue(dryRunSpec, userArgs)) {
data.setExecutionMode(ExecutionMode.DRY_RUN);
}
}


private void setClassPath(final OptionSet userArgs, final ReportOptions data) {

final List<String> elements = new ArrayList<>();
Expand Down Expand Up @@ -607,5 +595,9 @@ public void printHelp() {
}
}

private boolean booleanValue(ArgumentAcceptingOptionSpec<Boolean> spec, OptionSet userArgs) {
return (userArgs.has(spec) && !userArgs.hasArgument(spec))
|| spec.value(userArgs);
}

}

0 comments on commit 10bc017

Please sign in to comment.