Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer improvements #3377

Merged
merged 3 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions analyzer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
api(project(":model"))

implementation(project(":downloader"))
implementation(project(":spdx-utils"))
implementation(project(":utils"))

implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
Expand Down
3 changes: 2 additions & 1 deletion analyzer/src/main/kotlin/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Analyzer(private val config: AnalyzerConfiguration) {

log.debug { "Using the following configuration settings:\n$repositoryConfiguration" }

// Map files by the package manager factory that manages them.
// Associate files by the package manager factory that manages them.
val factoryFiles = if (packageManagers.size == 1 && absoluteProjectPath.isFile) {
// If only one package manager is activated, treat the given path as definition file for that package
// manager despite its name.
Expand All @@ -80,6 +80,7 @@ class Analyzer(private val config: AnalyzerConfiguration) {
PackageManager.findManagedFiles(absoluteProjectPath, packageManagers).toMutableMap()
}

// Associate mapped files by the package manager that manages them.
val managedFiles = factoryFiles.mapNotNull { (factory, files) ->
val manager = factory.create(absoluteProjectPath, config, repositoryConfiguration)
val mappedFiles = manager.mapDefinitionFiles(files)
Expand Down
13 changes: 5 additions & 8 deletions analyzer/src/main/kotlin/PackageManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.createAndLogIssue
import org.ossreviewtoolkit.spdx.VCS_DIRECTORIES
import org.ossreviewtoolkit.utils.collectMessagesAsString
import org.ossreviewtoolkit.utils.isSymbolicLink
import org.ossreviewtoolkit.utils.log
Expand Down Expand Up @@ -70,13 +71,7 @@ abstract class PackageManager(
*/
val ALL by lazy { LOADER.iterator().asSequence().toList() }

private val IGNORED_DIRECTORY_MATCHERS = listOf(
// Ignore VCS configuration directories.
".git",
".hg",
".repo",
".svn",
"CVS",
private val PACKAGE_MANAGER_DIRECTORIES = listOf(
// Ignore intermediate build system directories.
".gradle",
"node_modules",
Expand All @@ -86,7 +81,9 @@ abstract class PackageManager(
// Ignore virtual environments in Python.
"lib/python2.*/dist-packages",
"lib/python3.*/site-packages"
).map {
)

private val IGNORED_DIRECTORY_MATCHERS = (VCS_DIRECTORIES + PACKAGE_MANAGER_DIRECTORIES).map {
FileSystems.getDefault().getPathMatcher("glob:**/$it")
}

Expand Down
4 changes: 3 additions & 1 deletion analyzer/src/main/kotlin/managers/Unmanaged.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.utils.log

/**
* A fake [PackageManager] for projects that do not use any of the known package managers.
* A fake [PackageManager] for projects that do not use any of the known package managers, or no package manager at all.
* It is required as in ORT's data model e.g. scan results need to be attached to projects (or packages), so files that
* do not belong to any other project need to be attached to somewhere.
*/
class Unmanaged(
name: String,
Expand Down
2 changes: 1 addition & 1 deletion spdx-utils/src/main/kotlin/SpdxUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ val NON_LICENSE_FILENAMES = listOf(
/**
* A list of directories used by version control systems to store metadata.
*/
internal val VCS_DIRECTORIES = listOf(
val VCS_DIRECTORIES = listOf(
".git",
".hg",
".repo",
Expand Down