Skip to content

Commit 8cff640

Browse files
committed
feat(workers): Support Maven mirror definitions in MavenDefinition
Extend `MavenDefinition` with an optional `mirrorOf` property. If the new property is set, the definition represents a mirror and associates it with the specified repository ID. Signed-off-by: Onur Demirci <[email protected]>
1 parent 2f934c1 commit 8cff640

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

workers/common/src/main/kotlin/common/env/config/EnvironmentDefinitionFactory.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ class EnvironmentDefinitionFactory {
107107
properties: DefinitionProperties
108108
): Result<EnvironmentServiceDefinition> =
109109
properties.withRequiredProperties("id") {
110-
MavenDefinition(service, credentialsTypes(), getProperty("id"))
110+
MavenDefinition(
111+
service = service,
112+
credentialsTypes = credentialsTypes(),
113+
id = getProperty("id"),
114+
mirrorOf = getOptionalProperty("mirrorOf")
115+
)
111116
}
112117

113118
/**

workers/common/src/main/kotlin/common/env/definition/MavenDefinition.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,15 @@ class MavenDefinition(
3838
* In the generated _settings.xml_ file, the ID appears as the _id_ property for the corresponding server in the
3939
* _servers_ section. See https://maven.apache.org/settings.html#servers.
4040
*/
41-
val id: String
41+
val id: String,
42+
43+
/**
44+
* If set, this [MavenDefinition] is treated as a mirror definition and will additionally appear in the _mirrors_
45+
* section of the generated _settings.xml_ file.
46+
*
47+
* The value specifies the repository ID that this mirror should apply to, as used in the _mirrorOf_ element of
48+
* Maven’s mirror configuration. For example, to mirror Maven Central, use `"central"`, or use `"*"` to apply this
49+
* mirror to all repositories.
50+
*/
51+
val mirrorOf: String? = null
4252
) : EnvironmentServiceDefinition(service, credentialsTypes)

workers/common/src/test/kotlin/common/env/config/EnvironmentDefinitionFactoryTest.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,24 @@ class EnvironmentDefinitionFactoryTest : WordSpec() {
6868
"A MavenDefinition" should {
6969
"be created successfully" {
7070
val repositoryId = "my-repository"
71-
val properties = mapOf("id" to repositoryId)
71+
val mirrorOf = "central"
72+
val properties = mapOf("id" to repositoryId, "mirrorOf" to mirrorOf)
7273

7374
val definition = createSuccessful(EnvironmentDefinitionFactory.MAVEN_TYPE, properties)
7475

7576
definition.shouldBeInstanceOf<MavenDefinition>()
7677
definition.id shouldBe repositoryId
78+
definition.mirrorOf shouldBe mirrorOf
79+
}
80+
81+
"be created with default values" {
82+
val repositoryId = "my-repository"
83+
val properties = mapOf("id" to repositoryId)
84+
85+
val definition = createSuccessful(EnvironmentDefinitionFactory.MAVEN_TYPE, properties)
86+
87+
definition.shouldBeInstanceOf<MavenDefinition>()
88+
definition.mirrorOf should beNull()
7789
}
7890

7991
"fail if the ID is missing" {

workers/common/src/test/resources/.ort.env.all-options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ environmentDefinitions:
3737
id: "internal-repo"
3838
credentialsTypes:
3939
- "GIT_CREDENTIALS_FILE"
40+
mirrorOf: "central"
4041
npm:
4142
- service: "example-npm-registry"
4243
scope: "@example"

0 commit comments

Comments
 (0)