@@ -28,7 +28,6 @@ import java.io.FileOutputStream
28
28
import java.util.zip.ZipEntry
29
29
import java.util.zip.ZipFile
30
30
import java.util.zip.ZipOutputStream
31
- import org.gradle.api.Action
32
31
import org.gradle.api.GradleException
33
32
import org.gradle.api.Plugin
34
33
import org.gradle.api.Project
@@ -37,13 +36,11 @@ import org.gradle.api.logging.Logger
37
36
38
37
class VendorPlugin : Plugin <Project > {
39
38
override fun apply (project : Project ) {
40
- project.plugins.all(object : Action <Plugin <Any >> {
41
- override fun execute (plugin : Plugin <Any >) {
42
- when (plugin) {
43
- is LibraryPlugin -> configureAndroid(project)
44
- }
39
+ project.plugins.all {
40
+ when (this ) {
41
+ is LibraryPlugin -> configureAndroid(project)
45
42
}
46
- })
43
+ }
47
44
}
48
45
49
46
fun configureAndroid (project : Project ) {
@@ -63,8 +60,13 @@ class VendorPlugin : Plugin<Project> {
63
60
android.registerTransform(VendorTransform (
64
61
vendor,
65
62
JarJarTransformer (
66
- parentPackageProvider = {
67
- android.libraryVariants.find { it.name == " release" }!! .applicationId
63
+ parentPackageProvider = { variantName ->
64
+ val packageName = android.libraryVariants.find {
65
+ it.name == " release"
66
+ }!! .applicationId
67
+ if (variantName.endsWith(" AndroidTest" ))
68
+ " $packageName .$variantName "
69
+ else packageName
68
70
},
69
71
jarJarProvider = { jarJar.resolve() },
70
72
project = project,
@@ -78,13 +80,13 @@ interface JarTransformer {
78
80
}
79
81
80
82
class JarJarTransformer (
81
- private val parentPackageProvider : () -> String ,
83
+ private val parentPackageProvider : (String ) -> String ,
82
84
private val jarJarProvider : () -> Collection <File >,
83
85
private val project : Project ,
84
86
private val logger : Logger
85
87
) : JarTransformer {
86
88
override fun transform (variantName : String , input : File , output : File , ownPackageNames : Set <String >, externalPackageNames : Set <String >) {
87
- val parentPackage = parentPackageProvider()
89
+ val parentPackage = parentPackageProvider(variantName )
88
90
val rulesFile = File .createTempFile(" $parentPackage -$variantName " , " .jarjar" )
89
91
rulesFile.printWriter().use {
90
92
for (packageName in ownPackageNames) {
@@ -125,6 +127,7 @@ class VendorTransform(
125
127
}
126
128
127
129
override fun transform (transformInvocation : TransformInvocation ) {
130
+ transformInvocation.javaClass.typeParameters
128
131
if (configuration.resolve().isEmpty()) {
129
132
logger.info(" Nothing to vendor. " +
130
133
" If you don't need vendor functionality please disable 'firebase-vendor' plugin. " +
@@ -162,13 +165,7 @@ class VendorTransform(
162
165
private fun process (workDir : File , transformInvocation : TransformInvocation ): File {
163
166
transformInvocation.context.variantName
164
167
val unzippedDir = File (workDir, " unzipped" )
165
- val unzippedExcludedDir = File (workDir, " unzipped-excluded" )
166
168
unzippedDir.mkdirs()
167
- unzippedExcludedDir.mkdirs()
168
-
169
- val externalCodeDir = if (
170
- transformInvocation.context.variantName.toLowerCase().contains(" test" ))
171
- unzippedExcludedDir else unzippedDir
172
169
173
170
for (input in transformInvocation.inputs) {
174
171
for (directoryInput in input.directoryInputs) {
@@ -179,11 +176,11 @@ class VendorTransform(
179
176
val ownPackageNames = inferPackages(unzippedDir)
180
177
181
178
for (jar in configuration.resolve()) {
182
- unzipJar(jar, externalCodeDir )
179
+ unzipJar(jar, unzippedDir )
183
180
}
184
- val externalPackageNames = inferPackages(externalCodeDir ) subtract ownPackageNames
185
- val java = File (externalCodeDir , " java" )
186
- val javax = File (externalCodeDir , " javax" )
181
+ val externalPackageNames = inferPackages(unzippedDir ) subtract ownPackageNames
182
+ val java = File (unzippedDir , " java" )
183
+ val javax = File (unzippedDir , " javax" )
187
184
if (java.exists() || javax.exists()) {
188
185
// JarJar unconditionally skips any classes whose package name starts with "java" or "javax".
189
186
throw GradleException (" Vendoring java or javax packages is not supported. " +
0 commit comments