diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc new file mode 100644 index 0000000000000..4eefef3c024ed --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelrc @@ -0,0 +1,4 @@ +common --registry=file://%workspace%/registry/ + +common --registry=https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/ + diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion new file mode 100644 index 0000000000000..9fe9ff9d996b3 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/.bazelversion @@ -0,0 +1 @@ +7.0.1 diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel new file mode 100644 index 0000000000000..5e5b6f3be548a --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/MODULE.bazel @@ -0,0 +1 @@ +bazel_dep(name = "module_a", version = "0.0.1") diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json new file mode 100644 index 0000000000000..88fa9c17ce3cb --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/bazel_registry.json @@ -0,0 +1,3 @@ +{ + "module_base_path": "../modulesSrc/" +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel new file mode 100644 index 0000000000000..89a02b88c660a --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/MODULE.bazel @@ -0,0 +1,6 @@ +module( + name = "module_a", + version = "0.0.1", +) + +bazel_dep(name = "module_b", version = "0.0.1") diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json new file mode 100644 index 0000000000000..09bdd5ef7da4e --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/0.0.1/source.json @@ -0,0 +1,4 @@ +{ + "integrity": "sha256-VixL51B9xvtJl+zWSL+TXYTv4XtUcV+lz73awFJ59mg=", + "url": "https://example.com/module_a-0.0.1.zip" +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json new file mode 100644 index 0000000000000..b64d9d1fa7135 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_a/metadata.json @@ -0,0 +1,9 @@ +{ + "homepage": "", + "maintainers": [], + "repository": [], + "versions": [ + "0.0.1" + ], + "yanked_versions": {} +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel new file mode 100644 index 0000000000000..f97dd435534fc --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/MODULE.bazel @@ -0,0 +1,4 @@ +module( + name = "module_b", + version = "0.0.1", +) diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json new file mode 100644 index 0000000000000..bdca86dfe2c1c --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/0.0.1/source.json @@ -0,0 +1,4 @@ +{ + "integrity": "sha256-VixL51B9xvtJl+zWSL+TXYTv4XtUcV+lz73awFJ59mg=", + "url": "https://example.com/module_b-0.0.1.zip" +} diff --git a/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json new file mode 100644 index 0000000000000..b64d9d1fa7135 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-local-registry2/registry/modules/module_b/metadata.json @@ -0,0 +1,9 @@ +{ + "homepage": "", + "maintainers": [], + "repository": [], + "versions": [ + "0.0.1" + ], + "yanked_versions": {} +} diff --git a/plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt b/plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt new file mode 100644 index 0000000000000..fffc46eb9d860 --- /dev/null +++ b/plugins/package-managers/bazel/src/funTest/kotlin/BazelDetectionTest.kt @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 The ORT Project Authors (see ) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +package org.ossreviewtoolkit.plugins.packagemanagers.bazel + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.nulls.shouldNotBeNull +import io.kotest.matchers.string.shouldContain + +import org.ossreviewtoolkit.analyzer.analyze +import org.ossreviewtoolkit.utils.test.getAssetFile + +class BazelDetectionTest : StringSpec({ + "MODULE.bazel files present in a local registry should not be considered as definition files" { + val definitionFile = getAssetFile("projects/synthetic/bazel-local-registry2/MODULE.bazel") + + val exception = shouldThrow { + analyze(definitionFile.parentFile, packageManagers = listOf(Bazel.Factory())) + } + + exception.shouldNotBeNull { + // Running the Analyzer on a project depending on packages present in a local registry currently fails + // with this message (issue #9076). This is because the "MODULE.bazel" files present in the local + // registry should not be considered as definition files. + message shouldContain + "Unable to create the AnalyzerResult as it contains packages and projects with the same ids" + } + } +})