Skip to content

Commit

Permalink
analyzer: Do not create an unmanaged project if all files are managed
Browse files Browse the repository at this point in the history
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 <sebastian.schuberth@bosch.io>
  • Loading branch information
sschuberth committed May 3, 2022
1 parent f8f4192 commit 0d903e4
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions analyzer/src/main/kotlin/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -77,15 +78,17 @@ 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 {
managedFiles[it] = listOf(absoluteProjectPath)
}
if (!hasOnlyManagedDirs) {
packageManagers.find { it is Unmanaged.Factory }
?.create(absoluteProjectPath, config, repositoryConfiguration)
?.run { managedFiles[this] = listOf(absoluteProjectPath) }
}

return ManagedFileInfo(absoluteProjectPath, managedFiles, repositoryConfiguration)
Expand Down

0 comments on commit 0d903e4

Please sign in to comment.