Skip to content

Commit

Permalink
feat(package-manager): Add initial support for Bazel
Browse files Browse the repository at this point in the history
This is based on #264.

Signed-off-by: Haiko Schol <[email protected]>
  • Loading branch information
haikoschol committed Mar 19, 2024
1 parent bf4924b commit 0d98c17
Show file tree
Hide file tree
Showing 26 changed files with 3,528 additions and 8 deletions.
2 changes: 2 additions & 0 deletions analyzer/src/funTest/kotlin/PackageManagerFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.ossreviewtoolkit.model.config.PathExcludeReason

class PackageManagerFunTest : WordSpec({
val definitionFiles = listOf(
"bazel/MODULE.bazel",
"bower/bower.json",
"bundler/Gemfile",
"cargo/Cargo.toml",
Expand Down Expand Up @@ -93,6 +94,7 @@ class PackageManagerFunTest : WordSpec({
val managedFilesByName = managedFiles.groupByName(projectDir)

assertSoftly {
managedFilesByName["Bazel"] should containExactly("bazel/MODULE.bazel")
managedFilesByName["Bower"] should containExactly("bower/bower.json")
managedFilesByName["Bundler"] should containExactly("bundler/Gemfile")
managedFilesByName["Cargo"] should containExactly("cargo/Cargo.toml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private val JSON = Json {
}

/**
* The service uses the Bazel Central Registry by default.
* The client uses the Bazel Central Registry by default.
*/
private const val DEFAULT_URL = "https://bcr.bazel.build"

Expand All @@ -51,13 +51,10 @@ private const val DEFAULT_URL = "https://bcr.bazel.build"
interface BazelModuleRegistryClient {
companion object {
/**
* Create a Bazel Module Registry service instance for communicating with a server running at the given [url],
* Create a Bazel Module Registry client instance for communicating with a server running at the given [url],
* defaulting to the Bazel Central Registry, optionally with a pre-built OkHttp [client].
*/
fun create(
url: String? = null,
client: OkHttpClient? = null
): BazelModuleRegistryClient {
fun create(url: String? = null, client: OkHttpClient? = null): BazelModuleRegistryClient {
val bmrClient = client ?: OkHttpClient()

val contentType = "application/json".toMediaType()
Expand Down
4 changes: 2 additions & 2 deletions clients/bazel-module-registry/src/main/kotlin/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ data class ModuleMetadata(
val repository: List<String>? = null,
val versions: List<String>,
// The key in the map is the version, the value the reason for yanking it.
val yankedVersions: Map<String, String>,
val yankedVersions: Map<String, String>
) {
@Serializable
data class Maintainer(
Expand All @@ -61,5 +61,5 @@ data class ModuleSourceInfo(
val patchStrip: Int? = null,
val patches: Map<String, String>? = null,
val stripPrefix: String? = null,
@Serializable(URISerializer::class) val url: URI,
@Serializable(URISerializer::class) val url: URI
)
60 changes: 60 additions & 0 deletions plugins/package-managers/bazel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2024 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
*
* 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
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")

// Apply third-party plugins.
alias(libs.plugins.kotlinSerialization)
}

dependencies {
api(projects.analyzer)
api(projects.model)
api(projects.utils.commonUtils) {
because("This is a CommandLineTool.")
}

api(libs.semver4j) {
because("This is a CommandLineTool.")
}

implementation(projects.downloader)
implementation(projects.clients.bazelModuleRegistryClient)
implementation(projects.utils.ortUtils)
implementation(projects.utils.spdxUtils)

implementation(libs.bundles.kotlinxSerialization)
implementation(libs.kotlinx.coroutines)

funTestImplementation(testFixtures(projects.analyzer))
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module(name="bazel-test-module", version="0.42.23", compatibility_level=0)

bazel_dep(name = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "com_google_googletest", dev_dependency = True)

Loading

0 comments on commit 0d98c17

Please sign in to comment.