Skip to content

Commit

Permalink
analyzer: Pass config from .ort.yml to package managers
Browse files Browse the repository at this point in the history
This is done in preparation of implementing BitBake support (#722),
which requires a mechanism to pass a list of recipes to analyze.

Since this list is specific to the repository being analyzed, it
makes sense to add this information to .ort.yml and give package
manager instances access to it, analogous to the command line
parameters via AnalyzerConfiguration.
  • Loading branch information
Haiko Schol authored and haikoschol committed Aug 20, 2018
1 parent b046f6b commit fada611
Show file tree
Hide file tree
Showing 30 changed files with 154 additions and 93 deletions.
5 changes: 3 additions & 2 deletions analyzer/src/funTest/kotlin/BabelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import com.here.ort.model.yamlMapper
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.safeDeleteRecursively
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.patchActualResult
import com.here.ort.utils.test.patchExpectedResult
import com.here.ort.utils.test.USER_DIR

import io.kotlintest.Description
import io.kotlintest.TestResult
Expand Down Expand Up @@ -59,7 +60,7 @@ class BabelTest : WordSpec() {
init {
"Babel dependencies" should {
"be correctly analyzed" {
val npm = NPM.create(DEFAULT_ANALYZER_CONFIGURATION)
val npm = NPM.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
val packageFile = File(projectDir, "package.json")

val expectedResult = patchExpectedResult(
Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/funTest/kotlin/BundlerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.here.ort.model.yamlMapper
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.safeDeleteRecursively
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.patchExpectedResult

Expand All @@ -48,7 +49,7 @@ class BundlerTest : WordSpec() {
val definitionFile = File(projectsDir, "lockfile/Gemfile")

try {
val actualResult = Bundler.create(DEFAULT_ANALYZER_CONFIGURATION)
val actualResult = Bundler.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile]
val expectedResult = patchExpectedResult(
File(projectsDir.parentFile, "bundler-expected-output-lockfile.yml"),
Expand All @@ -66,7 +67,7 @@ class BundlerTest : WordSpec() {
"show error if no lockfile is present" {
val definitionFile = File(projectsDir, "no-lockfile/Gemfile")

val actualResult = Bundler.create(DEFAULT_ANALYZER_CONFIGURATION)
val actualResult = Bundler.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile]

actualResult shouldNotBe null
Expand All @@ -83,7 +84,7 @@ class BundlerTest : WordSpec() {
val definitionFile = File(projectsDir, "gemspec/Gemfile")

try {
val actualResult = Bundler.create(DEFAULT_ANALYZER_CONFIGURATION)
val actualResult = Bundler.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile]
val expectedResult = patchExpectedResult(
File(projectsDir.parentFile, "bundler-expected-output-gemspec.yml"),
Expand Down
15 changes: 8 additions & 7 deletions analyzer/src/funTest/kotlin/GoDepTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.here.ort.model.VcsInfo
import com.here.ort.model.config.AnalyzerConfiguration
import com.here.ort.model.yamlMapper
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.USER_DIR

import io.kotlintest.matchers.startWith
Expand All @@ -43,7 +44,7 @@ class GoDepTest : WordSpec() {
"GoDep" should {
"resolve dependencies from a lockfile correctly" {
val manifestFile = File(projectsDir, "external/qmstr/Gopkg.toml")
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION)
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)

val result = godep.resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile]
val expectedResult = File(projectsDir, "external/qmstr-expected-output.yml").readText()
Expand All @@ -53,7 +54,7 @@ class GoDepTest : WordSpec() {

"show error if no lockfile is present" {
val manifestFile = File(projectsDir, "synthetic/godep/no-lockfile/Gopkg.toml")
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION)
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)

val result = godep.resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile]

Expand All @@ -70,7 +71,7 @@ class GoDepTest : WordSpec() {
"invoke the dependency solver if no lockfile is present and allowDynamicVersions is set" {
val manifestFile = File(projectsDir, "synthetic/godep/no-lockfile/Gopkg.toml")
val config = AnalyzerConfiguration(false, true, false)
val godep = GoDep.create(config)
val godep = GoDep.create(config, DEFAULT_REPOSITORY_CONFIGURATION)

val result = godep.resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile]

Expand All @@ -82,7 +83,7 @@ class GoDepTest : WordSpec() {

"import dependencies from Glide" {
val manifestFile = File(projectsDir, "external/sprig/glide.yaml")
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION)
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)

val result = godep.resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile]
val expectedResult = File(projectsDir, "external/sprig-expected-output.yml").readText()
Expand All @@ -92,7 +93,7 @@ class GoDepTest : WordSpec() {

"import dependencies from godeps" {
val manifestFile = File(projectsDir, "external/godep/Godeps/Godeps.json")
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION)
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)

val result = godep.resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile]
val expectedResult = File(projectsDir, "external/godep-expected-output.yml").readText()
Expand All @@ -101,7 +102,7 @@ class GoDepTest : WordSpec() {
}

"construct an import path from VCS info" {
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION)
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
val gopath = File("/tmp/gopath")
val projectDir = File(projectsDir, "external/qmstr")
val vcs = VersionControlSystem.forDirectory(projectDir)!!.getInfo()
Expand All @@ -112,7 +113,7 @@ class GoDepTest : WordSpec() {
}

"construct an import path for directories that are not repositories" {
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION)
val godep = GoDep.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
val gopath = File("/tmp/gopath")
val projectDir = File(projectsDir, "synthetic/godep/no-lockfile")
val vcs = VcsInfo.EMPTY
Expand Down
9 changes: 5 additions & 4 deletions analyzer/src/funTest/kotlin/GradleAndroidTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import com.here.ort.model.yamlMapper
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.test.AndroidTag
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.patchExpectedResult
import com.here.ort.utils.test.USER_DIR

import io.kotlintest.shouldBe
import io.kotlintest.shouldNotBe
Expand All @@ -49,7 +50,7 @@ class GradleAndroidTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -65,7 +66,7 @@ class GradleAndroidTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -81,7 +82,7 @@ class GradleAndroidTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/funTest/kotlin/GradleLibraryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.here.ort.downloader.VersionControlSystem
import com.here.ort.model.yamlMapper
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.patchExpectedResult

Expand All @@ -48,7 +49,7 @@ class GradleLibraryTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -64,7 +65,7 @@ class GradleLibraryTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -80,7 +81,7 @@ class GradleLibraryTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand Down
15 changes: 8 additions & 7 deletions analyzer/src/funTest/kotlin/GradleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import com.here.ort.model.yamlMapper
import com.here.ort.utils.ProcessCapture
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.ExpensiveTag
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.patchActualResult
import com.here.ort.utils.test.patchExpectedResult
import com.here.ort.utils.test.USER_DIR

import io.kotlintest.Description
import io.kotlintest.Spec
Expand Down Expand Up @@ -65,7 +66,7 @@ class GradleTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -81,7 +82,7 @@ class GradleTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -97,7 +98,7 @@ class GradleTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -113,7 +114,7 @@ class GradleTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand All @@ -129,7 +130,7 @@ class GradleTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand Down Expand Up @@ -186,7 +187,7 @@ class GradleTest : StringSpec() {
revision = vcsRevision
)

val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Gradle.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]

result shouldNotBe null
Expand Down
13 changes: 7 additions & 6 deletions analyzer/src/funTest/kotlin/MavenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.here.ort.model.yamlMapper
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.safeDeleteRecursively
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.patchExpectedResult

Expand All @@ -45,7 +46,7 @@ class MavenTest : StringSpec() {
val pomFile = File(projectDir, "pom.xml")
val expectedResult = File(projectDir.parentFile, "jgnash-expected-output.yml").readText()

val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(pomFile))[pomFile]

yamlMapper.writeValueAsString(result) shouldBe expectedResult
Expand All @@ -62,7 +63,7 @@ class MavenTest : StringSpec() {
// jgnash-core depends on jgnash-resources, so we also have to pass the pom.xml of jgnash-resources to
// resolveDependencies so that it is available in the Maven.projectsByIdentifier cache. Otherwise resolution
// of transitive dependencies would not work.
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(pomFileCore, pomFileResources))[pomFileCore]

yamlMapper.writeValueAsString(result) shouldBe expectedResult
Expand All @@ -76,7 +77,7 @@ class MavenTest : StringSpec() {
revision = vcsRevision
)

val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(pomFile))[pomFile]

yamlMapper.writeValueAsString(result) shouldBe expectedResult
Expand All @@ -94,7 +95,7 @@ class MavenTest : StringSpec() {
// app depends on lib, so we also have to pass the pom.xml of lib to resolveDependencies so that it is
// available in the Maven.projectsByIdentifier cache. Otherwise resolution of transitive dependencies would
// not work.
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(pomFileApp, pomFileLib))[pomFileApp]

yamlMapper.writeValueAsString(result) shouldBe expectedResult
Expand All @@ -108,7 +109,7 @@ class MavenTest : StringSpec() {
revision = vcsRevision
)

val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(pomFile))[pomFile]

yamlMapper.writeValueAsString(result) shouldBe expectedResult
Expand All @@ -128,7 +129,7 @@ class MavenTest : StringSpec() {
revision = vcsRevision
)

val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = Maven.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(pomFile))[pomFile]

yamlMapper.writeValueAsString(result) shouldBe expectedResult
Expand Down
11 changes: 6 additions & 5 deletions analyzer/src/funTest/kotlin/NpmTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import com.here.ort.model.yamlMapper
import com.here.ort.utils.normalizeVcsUrl
import com.here.ort.utils.safeDeleteRecursively
import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION
import com.here.ort.utils.test.USER_DIR
import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION
import com.here.ort.utils.test.patchActualResult
import com.here.ort.utils.test.patchExpectedResult
import com.here.ort.utils.test.USER_DIR

import io.kotlintest.Description
import io.kotlintest.TestResult
Expand Down Expand Up @@ -62,7 +63,7 @@ class NpmTest : WordSpec() {
val workingDir = File(projectsDir, "shrinkwrap")
val packageFile = File(workingDir, "package.json")

val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]
val vcsPath = vcsDir.getPathToRoot(workingDir)
val expectedResult = patchExpectedResult(
Expand All @@ -81,7 +82,7 @@ class NpmTest : WordSpec() {
val workingDir = File(projectsDir, "package-lock")
val packageFile = File(workingDir, "package.json")

val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]
val vcsPath = vcsDir.getPathToRoot(workingDir)
val expectedResult = patchExpectedResult(
Expand All @@ -100,7 +101,7 @@ class NpmTest : WordSpec() {
val workingDir = File(projectsDir, "no-lockfile")
val packageFile = File(workingDir, "package.json")

val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]
val vcsPath = vcsDir.getPathToRoot(workingDir)
val expectedResult = patchExpectedResult(
Expand All @@ -119,7 +120,7 @@ class NpmTest : WordSpec() {
val workingDir = File(projectsDir, "node-modules")
val packageFile = File(workingDir, "package.json")

val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION)
val result = NPM.create(DEFAULT_ANALYZER_CONFIGURATION, DEFAULT_REPOSITORY_CONFIGURATION)
.resolveDependencies(USER_DIR, listOf(packageFile))[packageFile]
val vcsPath = vcsDir.getPathToRoot(workingDir)
val expectedResult = patchExpectedResult(
Expand Down
Loading

0 comments on commit fada611

Please sign in to comment.