Skip to content

Commit

Permalink
analyzer: Do not create an unmanaged project for a single root directory
Browse files Browse the repository at this point in the history
So far, if the directory structure was like

root
 |
 +-.git
 |
 +-project

still an unmanaged project would have been created because no definition
file is in the root, 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 Nov 25, 2020
1 parent 511d438 commit e6b9dc7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions analyzer/src/main/kotlin/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.spdx.VCS_DIRECTORIES
import org.ossreviewtoolkit.utils.NamedThreadFactory
import org.ossreviewtoolkit.utils.ORT_REPO_CONFIG_FILENAME
import org.ossreviewtoolkit.utils.log
Expand Down Expand Up @@ -87,11 +88,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 (either because of an unsupported, deactivated or non-present package
// manager) which we need to attach to a "fake" unmanaged project.
val managedDirectories = managedFiles.values.flatten().mapNotNull { it.parentFile }
val unmanagedFiles = absoluteProjectPath.listFiles().filterNot {
it in managedDirectories || it.name in VCS_DIRECTORIES
}

if (factoryFiles.isEmpty() || !hasDefinitionFileInRootDirectory) {
if (unmanagedFiles.isNotEmpty()) {
Unmanaged.Factory().create(absoluteProjectPath, config, repositoryConfiguration).let {
managedFiles[it] = listOf(absoluteProjectPath)
}
Expand Down

0 comments on commit e6b9dc7

Please sign in to comment.