Skip to content

Commit 8b23b10

Browse files
committed
feat(workers): Introduce a generator for Gradle's init.gradle.kts file
Introduce the `GradleInitGenerator`, which generates an `init.gradle.kts` file inside the `$HOME/.gradle` directory. The generator currently creates an empty file, but upcoming commits will use the dedicated `GradleDefinition` class to populate it with environment definitions. Signed-off-by: Onur Demirci <[email protected]>
1 parent e992720 commit 8b23b10

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

workers/common/src/main/kotlin/common/env/EnvironmentModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fun buildEnvironmentModule(): Module = module {
5353
ConanGenerator(),
5454
GitConfigGenerator.create(get()),
5555
GitCredentialsGenerator(),
56+
GradleInitGenerator(),
5657
MavenSettingsGenerator(),
5758
NpmRcGenerator(),
5859
NuGetGenerator(),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.eclipse.apoapsis.ortserver.workers.common.env
21+
22+
import org.eclipse.apoapsis.ortserver.workers.common.env.definition.GradleDefinition
23+
24+
/**
25+
* A specialized generator class to generate the content of the _init.gradle.kts_ file.
26+
*
27+
* See https://docs.gradle.org/current/userguide/init_scripts.html.
28+
*/
29+
class GradleInitGenerator : EnvironmentConfigGenerator<GradleDefinition> {
30+
companion object {
31+
/** The name of the file that is generated by this generator. */
32+
private const val TARGET_NAME = ".gradle/init.gradle.kts"
33+
}
34+
override val environmentDefinitionType: Class<GradleDefinition> = GradleDefinition::class.java
35+
36+
override suspend fun generate(builder: ConfigFileBuilder, definitions: Collection<GradleDefinition>) {
37+
builder.buildInUserHome(TARGET_NAME) {}
38+
}
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.eclipse.apoapsis.ortserver.workers.common.env.definition
21+
22+
import org.eclipse.apoapsis.ortserver.model.CredentialsType
23+
import org.eclipse.apoapsis.ortserver.model.InfrastructureService
24+
25+
/**
26+
* A specific [EnvironmentServiceDefinition] class for generating the Gradle _init.gradle.kts_ file.
27+
*
28+
* This class is used to define the Gradle-specific configuration for an [InfrastructureService].
29+
*/
30+
class GradleDefinition(
31+
service: InfrastructureService,
32+
33+
credentialsTypes: Set<CredentialsType>?,
34+
) : EnvironmentServiceDefinition(service, credentialsTypes)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.eclipse.apoapsis.ortserver.workers.common.env
21+
22+
import io.kotest.core.spec.style.WordSpec
23+
import io.kotest.matchers.shouldBe
24+
25+
import org.eclipse.apoapsis.ortserver.workers.common.env.definition.GradleDefinition
26+
27+
class GradleInitGeneratorTest : WordSpec({
28+
"environmentDefinitionType" should {
29+
"return the correct definition class" {
30+
val definitionType = GradleInitGenerator().environmentDefinitionType
31+
32+
definitionType shouldBe GradleDefinition::class.java
33+
}
34+
}
35+
36+
"generate" should {
37+
"generate the file at the correct location" {
38+
val mockBuilder = MockConfigFileBuilder()
39+
40+
GradleInitGenerator().generate(mockBuilder.builder, emptyList())
41+
42+
mockBuilder.homeFileName shouldBe ".gradle/init.gradle.kts"
43+
}
44+
}
45+
})

0 commit comments

Comments
 (0)