@@ -35,6 +35,9 @@ import com.github.ajalt.clikt.parameters.options.split
35
35
import com.github.ajalt.clikt.parameters.types.enum
36
36
import com.github.ajalt.clikt.parameters.types.file
37
37
38
+ import org.koin.core.component.KoinComponent
39
+ import org.koin.core.component.inject
40
+
38
41
import org.ossreviewtoolkit.analyzer.Analyzer
39
42
import org.ossreviewtoolkit.analyzer.PackageManager
40
43
import org.ossreviewtoolkit.analyzer.PackageManagerFactory
@@ -54,6 +57,7 @@ import org.ossreviewtoolkit.cli.utils.outputGroup
54
57
import org.ossreviewtoolkit.cli.utils.writeOrtResult
55
58
import org.ossreviewtoolkit.model.FileFormat
56
59
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
60
+ import org.ossreviewtoolkit.model.config.OrtConfiguration
57
61
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
58
62
import org.ossreviewtoolkit.model.readValueOrNull
59
63
import org.ossreviewtoolkit.model.utils.DefaultResolutionProvider
@@ -66,7 +70,10 @@ import org.ossreviewtoolkit.utils.ort.ORT_REPO_CONFIG_FILENAME
66
70
import org.ossreviewtoolkit.utils.ort.ORT_RESOLUTIONS_FILENAME
67
71
import org.ossreviewtoolkit.utils.ort.ortConfigDirectory
68
72
69
- class AnalyzerCommand : CliktCommand (name = " analyze" , help = " Determine dependencies of a software project." ) {
73
+ class AnalyzerCommand : KoinComponent , CliktCommand (
74
+ name = " analyze" ,
75
+ help = " Determine dependencies of a software project."
76
+ ) {
70
77
private val inputDir by option(
71
78
" --input-dir" , " -i" ,
72
79
help = " The project directory to analyze. As a special case, if only one package manager is enabled, this " +
@@ -177,6 +184,7 @@ class AnalyzerCommand : CliktCommand(name = "analyze", help = "Determine depende
177
184
)
178
185
179
186
private val globalOptionsForSubcommands by requireObject<GlobalOptions >()
187
+ private val ortConfig by inject<OrtConfiguration >()
180
188
181
189
override fun run () {
182
190
val outputFiles = outputFormats.mapTo(mutableSetOf ()) { format ->
@@ -209,12 +217,10 @@ class AnalyzerCommand : CliktCommand(name = "analyze", help = "Determine depende
209
217
println (" Looking for analyzer-specific configuration in the following files and directories:" )
210
218
println (" \t " + configurationInfo)
211
219
212
- val config = globalOptionsForSubcommands.config
213
-
214
220
val enabledPackageManagers = if (enabledPackageManagers != null || disabledPackageManagers != null ) {
215
221
(enabledPackageManagers ? : PackageManager .ALL .values).toSet() - disabledPackageManagers.orEmpty().toSet()
216
222
} else {
217
- config .analyzer.determineEnabledPackageManagers()
223
+ ortConfig .analyzer.determineEnabledPackageManagers()
218
224
}
219
225
220
226
println (" The following package managers are enabled:" )
@@ -226,7 +232,7 @@ class AnalyzerCommand : CliktCommand(name = "analyze", help = "Determine depende
226
232
? : RepositoryConfiguration ()
227
233
228
234
val analyzerConfiguration =
229
- repositoryConfiguration.analyzer?.let { config .analyzer.merge(it) } ? : config .analyzer
235
+ repositoryConfiguration.analyzer?.let { ortConfig .analyzer.merge(it) } ? : ortConfig .analyzer
230
236
231
237
val analyzer = Analyzer (analyzerConfiguration, labels)
232
238
@@ -237,7 +243,7 @@ class AnalyzerCommand : CliktCommand(name = "analyze", help = "Determine depende
237
243
238
244
val repositoryPackageCurations = repositoryConfiguration.curations.packages
239
245
240
- if (config .enableRepositoryPackageCurations) {
246
+ if (ortConfig .enableRepositoryPackageCurations) {
241
247
add(SimplePackageCurationProvider (repositoryPackageCurations))
242
248
} else if (repositoryPackageCurations.isNotEmpty()) {
243
249
logger.warn {
@@ -249,7 +255,7 @@ class AnalyzerCommand : CliktCommand(name = "analyze", help = "Determine depende
249
255
250
256
val curationProviders = listOfNotNull(
251
257
CompositePackageCurationProvider (defaultCurationProviders),
252
- config .analyzer.sw360Configuration?.let {
258
+ ortConfig .analyzer.sw360Configuration?.let {
253
259
Sw360PackageCurationProvider (it).takeIf { useSw360Curations }
254
260
},
255
261
ClearlyDefinedPackageCurationProvider ().takeIf { useClearlyDefinedCurations }
@@ -301,7 +307,7 @@ class AnalyzerCommand : CliktCommand(name = "analyze", help = "Determine depende
301
307
analyzerResult.collectIssues().flatMap { it.value }.partition { resolutionProvider.isResolved(it) }
302
308
val severityStats = SeverityStats .createFromIssues(resolvedIssues, unresolvedIssues)
303
309
304
- severityStats.print ().conclude(config .severeIssueThreshold, 2 )
310
+ severityStats.print ().conclude(ortConfig .severeIssueThreshold, 2 )
305
311
}
306
312
}
307
313
0 commit comments