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-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 Jun 22, 2021
1 parent 5bf32d6 commit 8ff2d46
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 @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8ff2d46

Please sign in to comment.