Skip to content

Commit 6decdca

Browse files
committed
refactor: Move a private CLI helper function to the public analyzer API
Move the function to determine the enabled package managers to the public API of the analyzer to make it available when programmatically using ORT. Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
1 parent 55558dd commit 6decdca

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2022 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.analyzer
21+
22+
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
23+
24+
/**
25+
* Return the list of enabled [PackageManager]s based on the [AnalyzerConfiguration.enabledPackageManagers] and
26+
* [AnalyzerConfiguration.disabledPackageManagers] configuration properties and the
27+
* [default][PackageManagerFactory.isEnabledByDefault] of the [PackageManager]s.
28+
*/
29+
fun AnalyzerConfiguration.determineEnabledPackageManagers(): Set<PackageManagerFactory> {
30+
val enabled = enabledPackageManagers?.mapNotNull { PackageManager.ALL[it] } ?: PackageManager.ENABLED_BY_DEFAULT
31+
val disabled = disabledPackageManagers?.mapNotNull { PackageManager.ALL[it] }.orEmpty()
32+
33+
return enabled.toSet() - disabled.toSet()
34+
}

plugins/commands/analyzer/src/main/kotlin/AnalyzerCommand.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.apache.logging.log4j.kotlin.Logging
4040
import org.ossreviewtoolkit.analyzer.Analyzer
4141
import org.ossreviewtoolkit.analyzer.PackageManager
4242
import org.ossreviewtoolkit.analyzer.PackageManagerFactory
43+
import org.ossreviewtoolkit.analyzer.determineEnabledPackageManagers
4344
import org.ossreviewtoolkit.model.FileFormat
4445
import org.ossreviewtoolkit.model.ResolvedPackageCurations.Companion.REPOSITORY_CONFIGURATION_PROVIDER_ID
4546
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
@@ -235,10 +236,3 @@ class AnalyzerCommand : OrtCommand(
235236
severityStats.print().conclude(ortConfig.severeIssueThreshold, 2)
236237
}
237238
}
238-
239-
private fun AnalyzerConfiguration.determineEnabledPackageManagers(): Set<PackageManagerFactory> {
240-
val enabled = enabledPackageManagers?.mapNotNull { PackageManager.ALL[it] } ?: PackageManager.ENABLED_BY_DEFAULT
241-
val disabled = disabledPackageManagers?.mapNotNull { PackageManager.ALL[it] }.orEmpty()
242-
243-
return enabled.toSet() - disabled.toSet()
244-
}

0 commit comments

Comments
 (0)