From 8ff2d460412785e8374df4d093b12dbf8ecfc1db Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 29 Sep 2020 09:27:09 +0200 Subject: [PATCH] analyzer: Do not create an unmanaged project for a single root directory So far, if the directory structure was like root-dir | +-.git | +-project-dir still an unmanaged project would have been created because no definition file is in the root directory, and the project directory is regarded as an unmanaged "file", even though there are not really any unmanaged files in the root. Fix this by a introducing a check that removes all managed paths (or ignored files) from all files in the root. Signed-off-by: Sebastian Schuberth --- analyzer/src/main/kotlin/Analyzer.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/analyzer/src/main/kotlin/Analyzer.kt b/analyzer/src/main/kotlin/Analyzer.kt index edea03ffc7c61..311831a25692d 100644 --- a/analyzer/src/main/kotlin/Analyzer.kt +++ b/analyzer/src/main/kotlin/Analyzer.kt @@ -35,6 +35,7 @@ import org.ossreviewtoolkit.model.Repository import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.RepositoryConfiguration +import org.ossreviewtoolkit.spdx.VCS_DIRECTORIES import org.ossreviewtoolkit.utils.CommandLineTool import org.ossreviewtoolkit.utils.Environment import org.ossreviewtoolkit.utils.log @@ -72,11 +73,14 @@ class Analyzer(private val config: AnalyzerConfiguration) { Pair(manager, mappedFiles).takeIf { mappedFiles.isNotEmpty() } }.toMap(mutableMapOf()) - val hasDefinitionFileInRootDirectory = managedFiles.values.flatten().any { - it.parentFile.absoluteFile == absoluteProjectPath + // Check whether there are unmanaged files (because of deactivated, unsupported, or non-present package + // managers) which we need to attach to an artificial "unmanaged" project. + val managedDirs = managedFiles.values.flatten().mapNotNull { it.parentFile } + val hasOnlyManagedDirs = absoluteProjectPath in managedDirs || absoluteProjectPath.listFiles().all { + it in managedDirs || it.name in VCS_DIRECTORIES } - if (factoryFiles.isEmpty() || !hasDefinitionFileInRootDirectory) { + if (!hasOnlyManagedDirs) { Unmanaged.Factory().create(absoluteProjectPath, config, repositoryConfiguration).let { managedFiles[it] = listOf(absoluteProjectPath) }