Skip to content

Commit 5e7e1e6

Browse files
ksiarheySpace Team
authored and
Space Team
committed
add gradle integration tests for explicit api mode in android KT-59117
1 parent 24debfd commit 5e7e1e6

File tree

15 files changed

+457
-0
lines changed

15 files changed

+457
-0
lines changed

libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/ExplicitApiIT.kt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,85 @@ class ExplicitApiIT : KGPBaseTest() {
189189
}
190190
}
191191
}
192+
193+
@DisplayName("Explicit api mode is enabled if added inside android extension")
194+
@AndroidGradlePluginTests
195+
@GradleAndroidTest
196+
fun explicitApiInsideAndroidExtension(
197+
gradleVersion: GradleVersion,
198+
agpVersion: String,
199+
jdkVersion: JdkVersions.ProvidedJdk
200+
) {
201+
project(
202+
"AndroidSimpleApp",
203+
gradleVersion,
204+
buildOptions = defaultBuildOptions.copy(
205+
androidVersion = agpVersion,
206+
logLevel = LogLevel.DEBUG,
207+
),
208+
buildJdk = jdkVersion.location
209+
) {
210+
buildGradle.modify {
211+
it.replace(
212+
"kotlin {",
213+
"""
214+
|kotlin {
215+
| explicitApiWarning()
216+
""".trimMargin()
217+
)
218+
}
219+
build(":compileDebugKotlin") {
220+
assertTasksExecuted(":compileDebugKotlin")
221+
assertCompilerArgument(":compileDebugKotlin", "-Xexplicit-api=warning")
222+
}
223+
build(":compileDebugUnitTestKotlin") {
224+
assertTasksExecuted(":compileDebugUnitTestKotlin")
225+
assertNoCompilerArgument(":compileDebugUnitTestKotlin", "-Xexplicit-api=warning")
226+
}
227+
}
228+
}
229+
230+
@DisplayName("Explicit api mode is enabled only for non-test variants in Android project in customized source directories")
231+
@AndroidGradlePluginTests
232+
@GradleAndroidTest
233+
fun explicitApiCustomizedAndroidSourceSets(
234+
gradleVersion: GradleVersion,
235+
agpVersion: String,
236+
jdkVersion: JdkVersions.ProvidedJdk
237+
) {
238+
project(
239+
"AndroidExtraSourceDirsApp",
240+
gradleVersion,
241+
buildOptions = defaultBuildOptions.copy(
242+
androidVersion = agpVersion,
243+
logLevel = LogLevel.DEBUG,
244+
),
245+
buildJdk = jdkVersion.location
246+
) {
247+
buildGradle.modify {
248+
it.replace(
249+
"compileOptions {",
250+
"""
251+
|kotlin {
252+
| explicitApi = 'warning'
253+
| }
254+
| compileOptions {
255+
""".trimMargin()
256+
)
257+
}
258+
build(":compileDebugKotlin") {
259+
assertTasksExecuted(":compileDebugKotlin")
260+
assertCompilerArgument(":compileDebugKotlin", "-Xexplicit-api=warning")
261+
assertOutputContains("Visibility must be specified in explicit API mode")
262+
}
263+
build(":compileDebugUnitTestKotlin") {
264+
assertTasksExecuted(":compileDebugUnitTestKotlin")
265+
assertNoCompilerArgument(":compileDebugUnitTestKotlin", "-Xexplicit-api=warning")
266+
}
267+
build(":compileDebugAndroidTestKotlin") {
268+
assertTasksExecuted(":compileDebugAndroidTestKotlin")
269+
assertNoCompilerArgument(":compileDebugAndroidTestKotlin", "-Xexplicit-api=warning")
270+
}
271+
}
272+
}
192273
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id "com.android.application"
3+
id "org.jetbrains.kotlin.android"
4+
}
5+
6+
repositories {
7+
mavenLocal()
8+
google()
9+
mavenCentral()
10+
}
11+
12+
android {
13+
namespace = "com.example.android_many_source_dirs_app"
14+
compileSdkVersion 33
15+
16+
defaultConfig {
17+
applicationId "com.example"
18+
minSdkVersion 24
19+
targetSdkVersion 33
20+
versionCode 1
21+
versionName "1.0"
22+
}
23+
24+
// Needed for older AGP. It can be removed when the lowest supported AGP version is 4.2.0 or newer.
25+
compileOptions {
26+
sourceCompatibility 1.8
27+
targetCompatibility 1.8
28+
}
29+
30+
kotlinOptions {
31+
jvmTarget = '1.8'
32+
}
33+
34+
sourceSets.getByName("test").kotlin.srcDirs += 'src/test/reserveUnitTest'
35+
sourceSets.getByName("androidTest").kotlin.srcDirs += 'src/androidTest/additionalTest'
36+
sourceSets.getByName("main").kotlin.srcDirs += 'src/main/extraSources'
37+
38+
}
39+
40+
dependencies {
41+
implementation "androidx.core:core-ktx:1.6.0"
42+
implementation "com.google.android.material:material:1.6.0"
43+
implementation "androidx.appcompat:appcompat:1.4.1"
44+
testImplementation "junit:junit:4.13.2"
45+
androidTestImplementation "androidx.test.ext:junit:1.1.5"
46+
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
android.useAndroidX=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package android_many_source_dirs_app
2+
3+
open class BaseInstrumentedTest {
4+
5+
fun setUp() {}
6+
7+
fun updateUserInfo() {
8+
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.android_many_source_dirs_app
2+
3+
import android_many_source_dirs_app.BaseInstrumentedTest
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
7+
import org.junit.Test
8+
import org.junit.runner.RunWith
9+
10+
import org.junit.Assert.*
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* See [testing documentation](http://d.android.com/tools/testing).
16+
*/
17+
@RunWith(AndroidJUnit4::class)
18+
class ExampleInstrumentedTest : BaseInstrumentedTest() {
19+
@Test
20+
fun useAppContext() {
21+
// Context of the app under test.
22+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
23+
assertEquals("com.example.android_many_source_dirs_app", appContext.packageName)
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:supportsRtl="true"
9+
tools:targetApi="31">
10+
<activity
11+
android:name=".MainActivity"
12+
android:exported="true">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package android_many_source_dirs_app
2+
3+
import android.app.Application
4+
5+
class NotesApplication : Application() {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.android_many_source_dirs_app
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import android_many_source_dirs_app.NotesApplication
6+
7+
public class MainActivity : AppCompatActivity() {
8+
9+
private lateinit var notesApp: NotesApplication
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(R.layout.activity_main)
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path
8+
android:fillColor="#3DDC84"
9+
android:pathData="M0,0h108v108h-108z" />
10+
<path
11+
android:fillColor="#00000000"
12+
android:pathData="M9,0L9,108"
13+
android:strokeWidth="0.8"
14+
android:strokeColor="#33FFFFFF" />
15+
<path
16+
android:fillColor="#00000000"
17+
android:pathData="M19,0L19,108"
18+
android:strokeWidth="0.8"
19+
android:strokeColor="#33FFFFFF" />
20+
<path
21+
android:fillColor="#00000000"
22+
android:pathData="M29,0L29,108"
23+
android:strokeWidth="0.8"
24+
android:strokeColor="#33FFFFFF" />
25+
<path
26+
android:fillColor="#00000000"
27+
android:pathData="M39,0L39,108"
28+
android:strokeWidth="0.8"
29+
android:strokeColor="#33FFFFFF" />
30+
<path
31+
android:fillColor="#00000000"
32+
android:pathData="M49,0L49,108"
33+
android:strokeWidth="0.8"
34+
android:strokeColor="#33FFFFFF" />
35+
<path
36+
android:fillColor="#00000000"
37+
android:pathData="M59,0L59,108"
38+
android:strokeWidth="0.8"
39+
android:strokeColor="#33FFFFFF" />
40+
<path
41+
android:fillColor="#00000000"
42+
android:pathData="M69,0L69,108"
43+
android:strokeWidth="0.8"
44+
android:strokeColor="#33FFFFFF" />
45+
<path
46+
android:fillColor="#00000000"
47+
android:pathData="M79,0L79,108"
48+
android:strokeWidth="0.8"
49+
android:strokeColor="#33FFFFFF" />
50+
<path
51+
android:fillColor="#00000000"
52+
android:pathData="M89,0L89,108"
53+
android:strokeWidth="0.8"
54+
android:strokeColor="#33FFFFFF" />
55+
<path
56+
android:fillColor="#00000000"
57+
android:pathData="M99,0L99,108"
58+
android:strokeWidth="0.8"
59+
android:strokeColor="#33FFFFFF" />
60+
<path
61+
android:fillColor="#00000000"
62+
android:pathData="M0,9L108,9"
63+
android:strokeWidth="0.8"
64+
android:strokeColor="#33FFFFFF" />
65+
<path
66+
android:fillColor="#00000000"
67+
android:pathData="M0,19L108,19"
68+
android:strokeWidth="0.8"
69+
android:strokeColor="#33FFFFFF" />
70+
<path
71+
android:fillColor="#00000000"
72+
android:pathData="M0,29L108,29"
73+
android:strokeWidth="0.8"
74+
android:strokeColor="#33FFFFFF" />
75+
<path
76+
android:fillColor="#00000000"
77+
android:pathData="M0,39L108,39"
78+
android:strokeWidth="0.8"
79+
android:strokeColor="#33FFFFFF" />
80+
<path
81+
android:fillColor="#00000000"
82+
android:pathData="M0,49L108,49"
83+
android:strokeWidth="0.8"
84+
android:strokeColor="#33FFFFFF" />
85+
<path
86+
android:fillColor="#00000000"
87+
android:pathData="M0,59L108,59"
88+
android:strokeWidth="0.8"
89+
android:strokeColor="#33FFFFFF" />
90+
<path
91+
android:fillColor="#00000000"
92+
android:pathData="M0,69L108,69"
93+
android:strokeWidth="0.8"
94+
android:strokeColor="#33FFFFFF" />
95+
<path
96+
android:fillColor="#00000000"
97+
android:pathData="M0,79L108,79"
98+
android:strokeWidth="0.8"
99+
android:strokeColor="#33FFFFFF" />
100+
<path
101+
android:fillColor="#00000000"
102+
android:pathData="M0,89L108,89"
103+
android:strokeWidth="0.8"
104+
android:strokeColor="#33FFFFFF" />
105+
<path
106+
android:fillColor="#00000000"
107+
android:pathData="M0,99L108,99"
108+
android:strokeWidth="0.8"
109+
android:strokeColor="#33FFFFFF" />
110+
<path
111+
android:fillColor="#00000000"
112+
android:pathData="M19,29L89,29"
113+
android:strokeWidth="0.8"
114+
android:strokeColor="#33FFFFFF" />
115+
<path
116+
android:fillColor="#00000000"
117+
android:pathData="M19,39L89,39"
118+
android:strokeWidth="0.8"
119+
android:strokeColor="#33FFFFFF" />
120+
<path
121+
android:fillColor="#00000000"
122+
android:pathData="M19,49L89,49"
123+
android:strokeWidth="0.8"
124+
android:strokeColor="#33FFFFFF" />
125+
<path
126+
android:fillColor="#00000000"
127+
android:pathData="M19,59L89,59"
128+
android:strokeWidth="0.8"
129+
android:strokeColor="#33FFFFFF" />
130+
<path
131+
android:fillColor="#00000000"
132+
android:pathData="M19,69L89,69"
133+
android:strokeWidth="0.8"
134+
android:strokeColor="#33FFFFFF" />
135+
<path
136+
android:fillColor="#00000000"
137+
android:pathData="M19,79L89,79"
138+
android:strokeWidth="0.8"
139+
android:strokeColor="#33FFFFFF" />
140+
<path
141+
android:fillColor="#00000000"
142+
android:pathData="M29,19L29,89"
143+
android:strokeWidth="0.8"
144+
android:strokeColor="#33FFFFFF" />
145+
<path
146+
android:fillColor="#00000000"
147+
android:pathData="M39,19L39,89"
148+
android:strokeWidth="0.8"
149+
android:strokeColor="#33FFFFFF" />
150+
<path
151+
android:fillColor="#00000000"
152+
android:pathData="M49,19L49,89"
153+
android:strokeWidth="0.8"
154+
android:strokeColor="#33FFFFFF" />
155+
<path
156+
android:fillColor="#00000000"
157+
android:pathData="M59,19L59,89"
158+
android:strokeWidth="0.8"
159+
android:strokeColor="#33FFFFFF" />
160+
<path
161+
android:fillColor="#00000000"
162+
android:pathData="M69,19L69,89"
163+
android:strokeWidth="0.8"
164+
android:strokeColor="#33FFFFFF" />
165+
<path
166+
android:fillColor="#00000000"
167+
android:pathData="M79,19L79,89"
168+
android:strokeWidth="0.8"
169+
android:strokeColor="#33FFFFFF" />
170+
</vector>

0 commit comments

Comments
 (0)