@@ -38,6 +38,7 @@ import org.ossreviewtoolkit.model.VcsInfo
3838import org.ossreviewtoolkit.model.VcsType
3939import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
4040import org.ossreviewtoolkit.model.config.Excludes
41+ import org.ossreviewtoolkit.model.config.Includes
4142import org.ossreviewtoolkit.model.config.PackageManagerConfiguration
4243import org.ossreviewtoolkit.model.config.RepositoryConfiguration
4344import org.ossreviewtoolkit.model.createAndLogIssue
@@ -84,7 +85,8 @@ abstract class PackageManager(val projectType: String) : Plugin {
8485 fun findManagedFiles (
8586 directory : File ,
8687 packageManagers : Collection <PackageManager >,
87- excludes : Excludes = Excludes .EMPTY
88+ excludes : Excludes = Excludes .EMPTY ,
89+ includes : Includes = Includes .EMPTY
8890 ): ManagedProjectFiles {
8991 require(directory.isDirectory) {
9092 " The provided path is not a directory: ${directory.absolutePath} "
@@ -96,6 +98,8 @@ abstract class PackageManager(val projectType: String) : Plugin {
9698 val rootPath = directory.toPath()
9799 val distinctPackageManagers = packageManagers.distinct()
98100
101+ // Note: Even if the directory is not included and other includes are defined, it has to be walked as
102+ // subdirectories or files may be included.
99103 directory.walk().onEnter { dir ->
100104 val dirAsPath = dir.toPath()
101105
@@ -119,7 +123,8 @@ abstract class PackageManager(val projectType: String) : Plugin {
119123 }
120124 }.filter { it.isDirectory }.forEach { dir ->
121125 val filesInCurrentDir = dir.walk().maxDepth(1 ).filterTo(mutableListOf ()) {
122- it.isFile && ! excludes.isPathExcluded(rootPath, it.toPath())
126+ val isIncluded = includes.isPathIncluded(rootPath, it.toPath())
127+ it.isFile && ! excludes.isPathExcluded(rootPath, it.toPath()) && isIncluded
123128 }
124129
125130 distinctPackageManagers.forEach { manager ->
@@ -200,6 +205,15 @@ abstract class PackageManager(val projectType: String) : Plugin {
200205 internal fun AnalyzerConfiguration.excludes (repositoryConfiguration : RepositoryConfiguration ): Excludes =
201206 repositoryConfiguration.excludes.takeIf { skipExcluded } ? : Excludes .EMPTY
202207
208+ /* *
209+ * Return an [Includes] instance to be applied during analysis based on the given [repositoryConfiguration].
210+ * If this [AnalyzerConfiguration] has the [AnalyzerConfiguration.skipExcluded] flag set to true, the
211+ * includes configured in [repositoryConfiguration] are actually applied. Otherwise, return an empty [Includes]
212+ * object. This means that all dependencies are collected, and includes are applied later on the report level.
213+ */
214+ internal fun AnalyzerConfiguration.includes (repositoryConfiguration : RepositoryConfiguration ): Includes =
215+ repositoryConfiguration.includes.takeIf { skipExcluded } ? : Includes .EMPTY
216+
203217 /* *
204218 * Check whether the given [path] interpreted relatively against [root] is matched by a path exclude in this
205219 * [Excludes] object.
0 commit comments