1
+ package io.deepmedia.tools.grease
2
+
3
+ import org.gradle.testkit.runner.GradleRunner
4
+ import java.nio.file.Path
5
+ import kotlin.io.path.ExperimentalPathApi
6
+ import kotlin.io.path.createTempDirectory
7
+ import kotlin.io.path.deleteRecursively
8
+ import kotlin.io.path.readText
9
+ import kotlin.io.path.writeText
10
+ import kotlin.test.AfterTest
11
+ import kotlin.test.BeforeTest
12
+ import kotlin.test.Test
13
+ import kotlin.test.assertContains
14
+ import kotlin.test.assertFails
15
+ import kotlin.test.assertFalse
16
+
17
+ class GeneratedPomFileTest {
18
+
19
+ private var testProjectDir = createTempDirectory(" tmp" )
20
+ private lateinit var settingsFile: Path
21
+ private lateinit var buildFile: Path
22
+
23
+ @BeforeTest
24
+ fun setup () {
25
+ settingsFile = testProjectDir.resolve(" settings.gradle.kts" )
26
+ buildFile = testProjectDir.resolve(" build.gradle.kts" )
27
+ }
28
+
29
+ @Test
30
+ fun test () {
31
+ buildFile.writeText(
32
+ """
33
+ plugins {
34
+ `maven-publish`
35
+ id("com.android.library") version "8.1.4"
36
+ }
37
+
38
+ apply<io.deepmedia.tools.grease.GreasePlugin>()
39
+
40
+ android {
41
+ namespace = "io.deepmedia.tools.grease.sample"
42
+ compileSdk = 34
43
+ defaultConfig {
44
+ minSdk = 21
45
+ }
46
+ publishing {
47
+ singleVariant("debug") {
48
+ withSourcesJar()
49
+ }
50
+ }
51
+ }
52
+
53
+ repositories {
54
+ google()
55
+ gradlePluginPortal()
56
+ mavenCentral()
57
+ }
58
+
59
+ publishing {
60
+ publications {
61
+ create("Test", MavenPublication::class.java) {
62
+ afterEvaluate {
63
+ from(components["debug"])
64
+ }
65
+ }
66
+ }
67
+ }
68
+ dependencies {
69
+ "grease"("com.otaliastudios:cameraview:2.7.2")
70
+ "greaseTree"("androidx.core:core:1.0.0")
71
+ }
72
+ """ .trimIndent()
73
+ )
74
+
75
+ settingsFile.writeText("""
76
+ pluginManagement {
77
+ repositories {
78
+ google()
79
+ gradlePluginPortal()
80
+ mavenCentral()
81
+ }
82
+ }
83
+
84
+ rootProject.name = "Sample"
85
+ """ .trimIndent())
86
+
87
+ GradleRunner .create()
88
+ .withPluginClasspath()
89
+ .withProjectDir(testProjectDir.toFile())
90
+ .forwardOutput()
91
+ .withArguments(" generatePomFileForTestPublication" )
92
+ .build()
93
+
94
+ val pomContent = testProjectDir.resolve(" build/publications/Test/pom-default.xml" ).readText()
95
+ assertFalse(pomContent.contains(" <groupId>androidx.core</groupId>" ) )
96
+ assertFalse(pomContent.contains(" <groupId>com.otaliastudios</groupId>" ) )
97
+ }
98
+
99
+ @OptIn(ExperimentalPathApi ::class )
100
+ @AfterTest
101
+ fun teardown () {
102
+ testProjectDir.deleteRecursively()
103
+ }
104
+ }
0 commit comments