From 5a21b04505d5c511570f098151758456e751c99c 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 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/analyzer/src/main/kotlin/Analyzer.kt b/analyzer/src/main/kotlin/Analyzer.kt index 8edad37207b28..2c983d389aaa9 100644 --- a/analyzer/src/main/kotlin/Analyzer.kt +++ b/analyzer/src/main/kotlin/Analyzer.kt @@ -37,6 +37,7 @@ import org.ossreviewtoolkit.model.config.AnalyzerConfiguration import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.model.orEmpty import org.ossreviewtoolkit.utils.common.CommandLineTool +import org.ossreviewtoolkit.utils.common.VCS_DIRECTORIES import org.ossreviewtoolkit.utils.core.Environment import org.ossreviewtoolkit.utils.core.log @@ -77,13 +78,16 @@ class Analyzer(private val config: AnalyzerConfiguration, private val labels: Ma 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().orEmpty().all { + it in managedDirs || it.name in VCS_DIRECTORIES } - val unmanagedFactory = packageManagers.find { it is Unmanaged.Factory } - if (unmanagedFactory != null && (factoryFiles.isEmpty() || !hasDefinitionFileInRootDirectory)) { - unmanagedFactory.create(absoluteProjectPath, config, repositoryConfiguration).let { + if (!hasOnlyManagedDirs) { + val unmanagedFactory = packageManagers.find { it is Unmanaged.Factory } + unmanagedFactory?.create(absoluteProjectPath, config, repositoryConfiguration)?.also { managedFiles[it] = listOf(absoluteProjectPath) } }