Incremental KAPT: add test for isolating AP with classpath origin
Add a regression test for KT-34340 that allows APs to have classpath types as origins.
This commit is contained in:
committed by
Mikhael Bogdanov
parent
05e47da458
commit
0522583602
-1
@@ -27,7 +27,6 @@ class KaptIncrementalWithAggregatingApt : KaptIncrementalIT() {
|
|||||||
override fun defaultBuildOptions(): BuildOptions =
|
override fun defaultBuildOptions(): BuildOptions =
|
||||||
super.defaultBuildOptions().copy(
|
super.defaultBuildOptions().copy(
|
||||||
incremental = true,
|
incremental = true,
|
||||||
debug=false,
|
|
||||||
kaptOptions = KaptOptions(
|
kaptOptions = KaptOptions(
|
||||||
verbose = true,
|
verbose = true,
|
||||||
useWorkers = true,
|
useWorkers = true,
|
||||||
|
|||||||
+33
-7
@@ -7,13 +7,11 @@ package org.jetbrains.kotlin.gradle
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.incapt.IncrementalProcessor
|
import org.jetbrains.kotlin.gradle.incapt.IncrementalProcessor
|
||||||
import org.jetbrains.kotlin.gradle.incapt.IncrementalProcessorReferencingClasspath
|
import org.jetbrains.kotlin.gradle.incapt.IncrementalProcessorReferencingClasspath
|
||||||
|
import org.jetbrains.kotlin.gradle.util.AGPVersion
|
||||||
import org.jetbrains.kotlin.gradle.util.modify
|
import org.jetbrains.kotlin.gradle.util.modify
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assume
|
import org.junit.Assume
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.objectweb.asm.ClassWriter
|
|
||||||
import org.objectweb.asm.Opcodes
|
|
||||||
import org.objectweb.asm.Type
|
|
||||||
import test.kt33617.MyClass
|
import test.kt33617.MyClass
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
@@ -229,7 +227,7 @@ class KaptIncrementalWithIsolatingApt : KaptIncrementalIT() {
|
|||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
project.build("clean", "kaptKotlin") {
|
project.build("clean", "build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,13 +247,41 @@ class KaptIncrementalWithIsolatingApt : KaptIncrementalIT() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Regression test for KT-34340. */
|
||||||
|
@Test
|
||||||
|
fun testIsolatingWithOriginsInClasspath() {
|
||||||
|
val project = Project("kaptIncrementalWithParceler", GradleVersionRequired.None).apply {
|
||||||
|
setupWorkingDir()
|
||||||
|
}
|
||||||
|
val options = defaultBuildOptions().copy(androidGradlePluginVersion = AGPVersion.v3_4_1)
|
||||||
|
project.build("clean", ":mylibrary:assembleDebug", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
|
||||||
|
project.projectFile("BaseClassParcel.java").modify { current ->
|
||||||
|
current.replace("protected FieldClassParcel", "private FieldClassParcel")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.build(":mylibrary:assembleDebug", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
assertEquals(
|
||||||
|
setOf(
|
||||||
|
fileInWorkingDir("mylibrary/src/main/java/com/example/lib/ExampleParcel.java").canonicalPath,
|
||||||
|
fileInWorkingDir("baseLibrary/src/main/java/com/example/lib2/basemodule/BaseClassParcel.java").canonicalPath,
|
||||||
|
),
|
||||||
|
getProcessedSources(output)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val patternApt = "Processing java sources with annotation processors:"
|
private const val patternApt = "Processing java sources with annotation processors:"
|
||||||
fun getProcessedSources(output: String): Set<String> {
|
fun getProcessedSources(output: String): Set<String> {
|
||||||
val logging = output.lines().single { it.contains(patternApt) }
|
return output.lines().filter { it.contains(patternApt) }.flatMapTo(HashSet()) { logging ->
|
||||||
val indexOf = logging.indexOf(patternApt) + patternApt.length
|
val indexOf = logging.indexOf(patternApt) + patternApt.length
|
||||||
return logging.drop(indexOf).split(",").map { it.trim() }.filter { !it.isEmpty() }.toSet()
|
logging.drop(indexOf).split(",").map { it.trim() }.filter { !it.isEmpty() }.toSet()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BaseGradleIT.Project.setupIncrementalAptProject(
|
fun BaseGradleIT.Project.setupIncrementalAptProject(
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.android.library'
|
||||||
|
id 'kotlin-android'
|
||||||
|
id 'kotlin-kapt'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 16
|
||||||
|
targetSdkVersion 30
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles "consumer-rules.pro"
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
kapt 'org.parceler:parceler:1.1.12'
|
||||||
|
implementation 'org.parceler:parceler-api:1.1.12'
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.mylibrary2">
|
||||||
|
|
||||||
|
</manifest>
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package com.example.lib2.basemodule;
|
||||||
|
|
||||||
|
import org.parceler.Parcel;
|
||||||
|
|
||||||
|
@Parcel
|
||||||
|
public class BaseClassParcel {
|
||||||
|
protected FieldClassParcel testField;
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package com.example.lib2.basemodule;
|
||||||
|
|
||||||
|
import org.parceler.Parcel;
|
||||||
|
|
||||||
|
@Parcel
|
||||||
|
public class FieldClassParcel {
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
maven { url 'https://maven.google.com' }
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "com.android.tools.build:gradle:$android_tools_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
maven { url 'https://maven.google.com' }
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.android.library'
|
||||||
|
id 'kotlin-android'
|
||||||
|
id 'kotlin-kapt'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 16
|
||||||
|
targetSdkVersion 30
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles "consumer-rules.pro"
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
kapt 'org.parceler:parceler:1.1.12'
|
||||||
|
implementation 'org.parceler:parceler-api:1.1.12'
|
||||||
|
implementation project(":baseLibrary")
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.mylibrary">
|
||||||
|
|
||||||
|
</manifest>
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
// Sample project obtained from https://youtrack.jetbrains.com/issue/KT-34340,
|
||||||
|
// originally obtained from https://github.com/johncarl81/parceler.
|
||||||
|
package com.example.lib;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.lib2.basemodule.BaseClassParcel;
|
||||||
|
|
||||||
|
import org.parceler.Parcel;
|
||||||
|
import org.parceler.ParcelFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intentionally in a different package to make sure we don't accidentally match it with org.parceler Proguard matchers.
|
||||||
|
*/
|
||||||
|
@Parcel
|
||||||
|
public class ExampleParcel extends BaseClassParcel {
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
@ParcelFactory
|
||||||
|
public static ExampleParcel create(String message) {
|
||||||
|
return new ExampleParcel(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExampleParcel(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage(){
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
rootProject.name = "PrarclerIncapKapt"
|
||||||
|
include ':mylibrary'
|
||||||
|
include ':baseLibrary'
|
||||||
Reference in New Issue
Block a user