Skip to content

Commit da4afb7

Browse files
Allow specifying custom maven repository name (VirtusLab#402)
Resolves VirtusLab#401
1 parent 5af1208 commit da4afb7

File tree

11 files changed

+70
-33
lines changed

11 files changed

+70
-33
lines changed

app/src/main/kotlin/org/virtuslab/bazelsteward/app/AppBuilder.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.virtuslab.bazelsteward.bazel.version.BazelVersionDependencyKind
2020
import org.virtuslab.bazelsteward.bzlmod.BzlModDataExtractor
2121
import org.virtuslab.bazelsteward.bzlmod.BzlModDependencyKind
2222
import org.virtuslab.bazelsteward.bzlmod.BzlModRepository
23+
import org.virtuslab.bazelsteward.config.repo.MavenConfig
2324
import org.virtuslab.bazelsteward.config.repo.RepoConfigParser
2425
import org.virtuslab.bazelsteward.core.Environment
2526
import org.virtuslab.bazelsteward.core.FileFinder
@@ -98,7 +99,8 @@ object AppBuilder {
9899

99100
val repoConfig =
100101
runBlocking { RepoConfigParser().load(configPath?.let { Path(it) }, repositoryRoot, noInternalConfig) }
101-
val mavenDataExtractor = MavenDataExtractor(appConfig.workspaceRoot)
102+
val mavenConfig = repoConfig.maven ?: MavenConfig()
103+
val mavenDataExtractor = MavenDataExtractor(appConfig.workspaceRoot, mavenConfig.repositoryName)
102104
val mavenRepository = MavenRepository()
103105
val updateLogic = UpdateLogic()
104106
val gitOperations = runBlocking { GitOperations.resolve(appConfig.workspaceRoot, appConfig.baseBranch) }

app/src/main/resources/internal-config.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ update-rules:
55
- kinds: bazel-rules
66
dependencies: rules_jvm_external
77
versioning: 'regex:^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)(?:\.(?<patch>0|[1-9]\d*))?$'
8+
9+
maven:
10+
repository-name: maven

app/src/test/kotlin/org/virtuslab/bazelsteward/app/UpdateRulesProviderTest.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class UpdateRulesProviderTest {
8383
val workspaceRoot = Paths.get(".")
8484
return listOf(
8585
BazelVersionDependencyKind(BazelUpdater()),
86-
MavenDependencyKind(MavenDataExtractor(workspaceRoot), MavenRepository()),
86+
MavenDependencyKind(MavenDataExtractor(workspaceRoot, "maven"), MavenRepository()),
8787
BzlModDependencyKind(BzlModDataExtractor(workspaceRoot), BzlModRepository()),
8888
BazelRulesDependencyKind(BazelRulesExtractor(), GithubRulesResolver(GitHub.connectAnonymously())),
8989
)

app/src/test/kotlin/org/virtuslab/bazelsteward/fixture/DependencyKindsFixture.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.nio.file.Paths
1818
class DependencyKindsFixture(workspaceRoot: Path = Paths.get(".")) {
1919

2020
val bazelVersion = BazelVersionDependencyKind(BazelUpdater())
21-
val maven = MavenDependencyKind(MavenDataExtractor(workspaceRoot), MavenRepository())
21+
val maven = MavenDependencyKind(MavenDataExtractor(workspaceRoot, "maven"), MavenRepository())
2222
val bzlmod = BzlModDependencyKind(BzlModDataExtractor(workspaceRoot), BzlModRepository())
2323
val bazelRules = BazelRulesDependencyKind(
2424
BazelRulesExtractor(),

docs/docs/configuration/configuration-file/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ post-update-hooks:
8383
- "WORKSPACE"
8484
run-for: pull-request
8585
commit-message: "Apply buildifier"
86+
maven:
87+
repository-name: maven
8688
```
8789
8890
## Rule Resolution
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: default
3+
title: Post Update Hooks
4+
parent: Configuration File
5+
grand_parent: Configuration
6+
nav_order: 4
7+
---
8+
9+
# Post Update Hooks
10+
11+
Bazel Steward is able to run arbitrary commands and commit their effects into its pull requests. It is useful for running tools like buildifier or pinning dependencies.
12+
13+
```yaml
14+
post-update-hooks:
15+
- kinds: maven
16+
commands:
17+
- "REPIN=1 bazel run @unpinned_maven//:pin"
18+
files-to-commit:
19+
- "maven_install.json"
20+
run-for: commit
21+
- commands: "buildifier --lint=fix -r ."
22+
files-to-commit:
23+
- "**/*.bzl"
24+
- "**/BUILD.bazel"
25+
- "WORKSPACE"
26+
run-for: pull-request
27+
commit-message: "Apply buildifier"
28+
```
29+
30+
Available fields:
31+
* `commands` (list of strings) <br/>
32+
List of commands to run after applying an update. Commands are run separately under `sh -c`
33+
* `files to commit` (list of strings) <br/>
34+
List of path patterns of files to commit after running the commands (syntax is the same as for `search-paths.path-patterns`).
35+
* `run-for` (string) <br/>
36+
Scope for running commands.
37+
1. `commit` - runs for each commit and includes changes in the commit
38+
2. `pull-request` - runs for the whole pull request, after creating all commits. It creates a separate commit with modified files. Message can be configured with the `commit-message` setting.
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
---
22
layout: default
3-
title: Post Update Hooks
3+
title: Maven Config
44
parent: Configuration File
55
grand_parent: Configuration
66
nav_order: 4
77
---
88

9-
# Post Update Hooks
9+
# Maven Config
10+
Settings specific to rules_jvm_external, i.e. maven dependencies resolution.
1011

11-
Bazel Steward is able to run arbitrary commands and commit their effects into its pull requests. It is useful for running tools like buildifier or pinning dependencies.
1212

1313
```yaml
14-
post-update-hooks:
15-
- kinds: maven
16-
commands:
17-
- "REPIN=1 bazel run @unpinned_maven//:pin"
18-
files-to-commit:
19-
- "maven_install.json"
20-
run-for: commit
21-
- commands: "buildifier --lint=fix -r ."
22-
files-to-commit:
23-
- "**/*.bzl"
24-
- "**/BUILD.bazel"
25-
- "WORKSPACE"
26-
run-for: pull-request
27-
commit-message: "Apply buildifier"
14+
maven:
15+
repository-name: maven
2816
```
2917
3018
Available fields:
31-
* `commands` (list of strings) <br/>
32-
List of commands to run after applying an update. Commands are run separately under `sh -c`
33-
* `files to commit` (list of strings) <br/>
34-
List of path patterns of files to commit after running the commands (syntax is the same as for `search-paths.path-patterns`).
35-
* `run-for` (string) <br/>
36-
Scope for running commands.
37-
1. `commit` - runs for each commit and includes changes in the commit
38-
2. `pull-request` - runs for the whole pull request, after creating all commits. It creates a separate commit with modified files. Message can be configured with the `commit-message` setting.
19+
* `repository-name` (string) <br/>
20+
Name of repository where maven dependencies appear, by default it is "maven", i.e. dependencies will be queried
21+
under `@maven//...`
22+

e2e/src/test/kotlin/org/virtuslab/bazelsteward/e2e/fixture/E2EBase.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ open class E2EBase : IntegrationTestBase() {
196196
return this.copy(
197197
dependencyKinds = listOf(
198198
MavenDependencyKind(
199-
MavenDataExtractor(this.workspaceRoot),
199+
MavenDataExtractor(this.workspaceRoot, "maven"),
200200
MockMavenRepository().also(configure),
201201
),
202202
),

e2e/src/test/resources/rules/rules_jvm_external/WORKSPACE.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ http_archive(
88
name = "rules_jvm_external",
99
sha256 = RULES_JVM_EXTERNAL_SHA,
1010
strip_prefix = "rules_jvm_external-{}".format(RULES_JVM_EXTERNAL_TAG),
11-
url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/5.1/rules_jvm_external-5.1.tar.gz",
11+
url = "https://github.com/bazel-contrib/rules_jvm_external/releases/download/5.1/rules_jvm_external-5.1.tar.gz",
1212
)
1313

1414
load("@rules_jvm_external//:defs.bzl", "maven_install")

kinds/maven/src/main/kotlin/org/virtuslab/bazelsteward/maven/MavenDataExtractor.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import kotlinx.coroutines.withContext
55
import org.virtuslab.bazelsteward.core.common.CommandRunner
66
import java.nio.file.Path
77

8-
class MavenDataExtractor(private val workspaceRoot: Path) {
9-
private val regexPattern = """<source-file location="(.*):1:1" name="@maven//:%s">"""
8+
class MavenDataExtractor(private val workspaceRoot: Path, private val bazelRepositoryName: String) {
9+
private val regexPattern = """<source-file location="(.*):1:1" name="@$bazelRepositoryName//:%s">"""
1010

1111
suspend fun extract(): MavenData {
1212
val repositories = extractFromFile("outdated.repositories")
@@ -22,7 +22,7 @@ class MavenDataExtractor(private val workspaceRoot: Path) {
2222
workspaceRoot,
2323
"bazel",
2424
"query",
25-
"@maven//:$fileName",
25+
"@$bazelRepositoryName//:$fileName",
2626
"--output",
2727
"xml",
2828
"--noshow_progress",

repo-config/src/main/kotlin/org/virtuslab/bazelsteward/config/repo/RepoConfig.kt

+8
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ data class RepoConfig(
1919
val pullRequests: List<PullRequestsConfig> = emptyList(),
2020
@JsonSetter(nulls = Nulls.AS_EMPTY)
2121
val postUpdateHooks: List<PostUpdateHooksConfig> = emptyList(),
22+
@JsonSetter(nulls = Nulls.AS_EMPTY)
23+
val maven: MavenConfig? = null,
2224
) {
2325
fun withFallback(fallback: RepoConfig): RepoConfig {
2426
return RepoConfig(
2527
updateRules = updateRules + fallback.updateRules,
2628
searchPaths = searchPaths + fallback.searchPaths,
2729
pullRequests = pullRequests + fallback.pullRequests,
2830
postUpdateHooks = postUpdateHooks + fallback.postUpdateHooks,
31+
maven = maven ?: fallback.maven,
2932
)
3033
}
3134
}
@@ -93,3 +96,8 @@ data class PostUpdateHooksConfig(
9396
val runFor: HookRunFor? = null,
9497
val commitMessage: String? = null,
9598
) : DependencyFilter
99+
100+
data class MavenConfig(
101+
@JsonSetter(nulls = Nulls.AS_EMPTY)
102+
val repositoryName: String = "maven",
103+
)

0 commit comments

Comments
 (0)