Skip to content

Commit

Permalink
refactor: Introduce a constant for the status code for failures
Browse files Browse the repository at this point in the history
This aligns with the constant in the `Jenkinsfile`.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Jan 27, 2024
1 parent f228d98 commit 95dcce2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion plugins/commands/advisor/src/main/kotlin/AdvisorCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import org.ossreviewtoolkit.plugins.commands.api.utils.readOrtResult
import org.ossreviewtoolkit.plugins.commands.api.utils.writeOrtResult
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.common.safeMkdirs
import org.ossreviewtoolkit.utils.ort.ORT_FAILURE_STATUS_CODE
import org.ossreviewtoolkit.utils.ort.ORT_RESOLUTIONS_FILENAME
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory

Expand Down Expand Up @@ -156,6 +157,6 @@ class AdvisorCommand : OrtCommand(
val resolutionProvider = DefaultResolutionProvider.create(ortResultOutput, resolutionsFile)
val issues = advisorRun.results.getIssues().flatMap { it.value }
SeverityStatsPrinter(terminal, resolutionProvider).stats(issues)
.print().conclude(ortConfig.severeIssueThreshold, 2)
.print().conclude(ortConfig.severeIssueThreshold, ORT_FAILURE_STATUS_CODE)
}
}
3 changes: 2 additions & 1 deletion plugins/commands/analyzer/src/main/kotlin/AnalyzerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import org.ossreviewtoolkit.plugins.packagecurationproviders.api.PackageCuration
import org.ossreviewtoolkit.plugins.packagecurationproviders.api.SimplePackageCurationProvider
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.common.safeMkdirs
import org.ossreviewtoolkit.utils.ort.ORT_FAILURE_STATUS_CODE
import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME
import org.ossreviewtoolkit.utils.ort.ORT_RESOLUTIONS_FILENAME
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
Expand Down Expand Up @@ -227,6 +228,6 @@ class AnalyzerCommand : OrtCommand(
val resolutionProvider = DefaultResolutionProvider.create(ortResult, resolutionsFile)
val issues = analyzerRun.result.getAllIssues().flatMap { it.value }
SeverityStatsPrinter(terminal, resolutionProvider).stats(issues)
.print().conclude(ortConfig.severeIssueThreshold, 2)
.print().conclude(ortConfig.severeIssueThreshold, ORT_FAILURE_STATUS_CODE)
}
}
3 changes: 2 additions & 1 deletion plugins/commands/scanner/src/main/kotlin/ScannerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import org.ossreviewtoolkit.scanner.provenance.DefaultProvenanceDownloader
import org.ossreviewtoolkit.scanner.utils.DefaultWorkingTreeCache
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.common.safeMkdirs
import org.ossreviewtoolkit.utils.ort.ORT_FAILURE_STATUS_CODE
import org.ossreviewtoolkit.utils.ort.ORT_RESOLUTIONS_FILENAME
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory

Expand Down Expand Up @@ -154,7 +155,7 @@ class ScannerCommand : OrtCommand(
val resolutionProvider = DefaultResolutionProvider.create(ortResult, resolutionsFile)
val issues = scannerRun.getIssues().flatMap { it.value }
SeverityStatsPrinter(terminal, resolutionProvider).stats(issues)
.print().conclude(ortConfig.severeIssueThreshold, 2)
.print().conclude(ortConfig.severeIssueThreshold, ORT_FAILURE_STATUS_CODE)
}

private fun runScanners(
Expand Down
6 changes: 6 additions & 0 deletions utils/ort/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ const val ORT_EVALUATOR_RULES_FILENAME = "evaluator.rules.kts"
* The name of the ORT notifier script.
*/
const val ORT_NOTIFIER_SCRIPT_FILENAME = "notifier.notifications.kts"

/**
* The minimum status code ORT CLI commands return on exit for failures (like rule violations), not errors (like
* existing output files).
*/
const val ORT_FAILURE_STATUS_CODE = 2

0 comments on commit 95dcce2

Please sign in to comment.