-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ALL_JAVA_RESOURCE
- Loading branch information
Showing
13 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
polyfill/src/main/kotlin/me/xx2bab/polyfill/jar/JavaResourceMergePreHookConfigureAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package me.xx2bab.polyfill.jar | ||
|
||
import com.android.build.api.variant.ApplicationVariant | ||
import com.android.build.gradle.internal.scope.getRegularFiles | ||
import com.android.build.gradle.internal.tasks.MergeJavaResourceTask | ||
import com.android.build.gradle.internal.tasks.ProcessJavaResTask | ||
import me.xx2bab.polyfill.getCapitalizedName | ||
import me.xx2bab.polyfill.task.MultipleArtifactPincerTaskConfiguration | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.RegularFile | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.TaskProvider | ||
import org.gradle.kotlin.dsl.listProperty | ||
import org.gradle.kotlin.dsl.withType | ||
|
||
/** | ||
* To retrieve all java resources (except current module) | ||
* that will participate the merge process. | ||
*/ | ||
class JavaResourceMergePreHookConfigureAction( | ||
project: Project, | ||
private val appVariant: ApplicationVariant, | ||
headTaskProvider: TaskProvider<*>, | ||
lazyLastTaskProvider: () -> TaskProvider<*> | ||
) : MultipleArtifactPincerTaskConfiguration<RegularFile>(project, appVariant, headTaskProvider, lazyLastTaskProvider) { | ||
|
||
override val data: Provider<List<RegularFile>> = project.objects.listProperty<RegularFile>() // A placeholder | ||
|
||
override fun orchestrate() { | ||
project.afterEvaluate { | ||
val variantCapitalizedName = variant.getCapitalizedName() | ||
val mergeTask = project.tasks.withType<MergeJavaResourceTask>().first { | ||
it.name.contains(variantCapitalizedName) | ||
&& !it.name.contains("test", true) | ||
} | ||
|
||
|
||
// Setup Data | ||
// val subProjectsJavaResList = appVariant.getApplicationVariantImpl().variantDependencies | ||
// .getArtifactFileCollection( | ||
// AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH, | ||
// AndroidArtifacts.ArtifactScope.PROJECT, | ||
// AndroidArtifacts.ArtifactType.JAVA_RES | ||
// ) | ||
// .getRegularFiles(project.rootProject.layout.projectDirectory) | ||
val subProjectsJavaResList = mergeTask.subProjectJavaRes | ||
?.getRegularFiles(project.rootProject.layout.projectDirectory) | ||
?: project.objects.listProperty() | ||
val externalDepJavaResList = mergeTask.externalLibJavaRes | ||
?.getRegularFiles(project.rootProject.layout.projectDirectory) | ||
?: project.objects.listProperty() | ||
subProjectsJavaResList.zip(externalDepJavaResList) { a, b -> a + b } | ||
(data as ListProperty<RegularFile>).set(subProjectsJavaResList) | ||
|
||
|
||
// Setup dependencies | ||
// Left flank | ||
project.rootProject.subprojects { | ||
val subProject = this | ||
if (subProject !== project) { | ||
subProject.tasks.whenTaskAdded { | ||
val targetTask = this | ||
if (targetTask is ProcessJavaResTask | ||
&& targetTask.name.contains(variantCapitalizedName) | ||
&& !targetTask.name.contains("test", true) | ||
) { | ||
headTaskProvider.configure { | ||
dependsOn(targetTask) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Right flank | ||
mergeTask.dependsOn(lazyTailTaskProvider()) | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
} | ||
|
||
android { | ||
compileSdk = 31 | ||
defaultConfig { | ||
minSdk = 21 | ||
targetSdk = 31 | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
sourceSets["main"].java.srcDir("src/main/kotlin") | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(deps.kotlin.std) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="me.xx2bab.polyfill.sample.android"> | ||
|
||
</manifest> |
7 changes: 7 additions & 0 deletions
7
...oid-lib/src/main/java/me/xx2bab/polyfill/sample/android/ExportedAndroidLibraryRunnable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.xx2bab.polyfill.sample.android | ||
|
||
class ExportedAndroidLibraryRunnable: Runnable { | ||
override fun run() { | ||
println("ExportedAndroidLibraryAPI is running") | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters