-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
116 additions
and
39 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
20 changes: 20 additions & 0 deletions
20
airin-gradle-android/src/main/kotlin/io/morfly/airin/AndroidMetadata.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,20 @@ | ||
package io.morfly.airin | ||
|
||
import java.io.Serializable | ||
|
||
data class AndroidMetadata( | ||
val applicationId: String?, | ||
val packageName: String?, | ||
val composeEnabled: Boolean | ||
): Serializable { | ||
|
||
companion object { | ||
const val ID = "androidMetadata" | ||
} | ||
} | ||
|
||
var GradleProject.androidMetadata: AndroidMetadata? | ||
get() = properties[AndroidMetadata.ID] as? AndroidMetadata | ||
set(value) { | ||
properties[AndroidMetadata.ID] = value | ||
} |
51 changes: 51 additions & 0 deletions
51
airin-gradle-android/src/main/kotlin/io/morfly/airin/AndroidProjectDecorator.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,51 @@ | ||
package io.morfly.airin | ||
|
||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.android.build.api.dsl.CommonExtension | ||
import com.android.build.gradle.BaseExtension | ||
import groovy.xml.XmlSlurper | ||
import groovy.xml.slurpersupport.NodeChild | ||
import org.gradle.api.Project | ||
import java.io.File | ||
|
||
private val xmlParser = XmlSlurper() | ||
|
||
open class AndroidProjectDecorator : GradleProjectDecorator { | ||
|
||
override fun GradleProject.decorate(target: Project) { | ||
with(target.plugins) { | ||
if (!hasPlugin("com.android.application") && !hasPlugin("com.android.library")) { | ||
return | ||
} | ||
} | ||
|
||
androidMetadata = AndroidMetadata( | ||
applicationId = target.applicationId, | ||
packageName = target.namespace ?: target.manifestPackageName, | ||
composeEnabled = target.composeEnabled | ||
) | ||
} | ||
} | ||
|
||
val Project.namespace: String? | ||
get() = extensions.findByType(CommonExtension::class.java)?.namespace | ||
|
||
val Project.composeEnabled: Boolean | ||
get() = extensions.findByType(CommonExtension::class.java)?.buildFeatures?.compose ?: false | ||
|
||
val Project.applicationId: String? | ||
get() = extensions.findByType(ApplicationExtension::class.java)?.defaultConfig?.applicationId | ||
|
||
val Project.androidManifestFile: File? | ||
get() = extensions.findByType(BaseExtension::class.java) | ||
?.sourceSets | ||
?.map { it.manifest.srcFile } | ||
?.firstOrNull(File::exists) | ||
|
||
val Project.manifestPackageName: String? | ||
get() = androidManifestFile | ||
?.let(xmlParser::parse) | ||
?.list() | ||
?.filterIsInstance<NodeChild>() | ||
?.firstOrNull { it.name() == "manifest" } | ||
?.attributes()?.get("package")?.toString() |
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
13 changes: 3 additions & 10 deletions
13
airin-gradle-android/src/main/kotlin/io/morfly/airin/plugin/AirinAndroidGradlePlugin.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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
package io.morfly.airin.plugin | ||
|
||
import com.android.build.api.dsl.ApplicationExtension | ||
import org.gradle.api.Project | ||
import com.android.build.api.dsl.CommonExtension | ||
import io.morfly.airin.AndroidProjectDecorator | ||
|
||
class AirinAndroidGradlePlugin : AirinGradlePlugin() { | ||
|
||
override val defaultDecoratorClass = AndroidProjectDecorator::class.java | ||
|
||
companion object { | ||
const val ID = "io.morfly.airin.android" | ||
} | ||
} | ||
|
||
val Project.isComposeEnabled: Boolean | ||
get() = extensions.findByType(CommonExtension::class.java)?.buildFeatures?.compose ?: false | ||
|
||
val Project.applicationId: String? | ||
get() = extensions.findByType(ApplicationExtension::class.java)?.defaultConfig?.applicationId | ||
|
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
8 changes: 8 additions & 0 deletions
8
airin-gradle-plugin/src/main/kotlin/io/morfly/airin/GradleProjectDecorator.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,8 @@ | ||
package io.morfly.airin | ||
|
||
import org.gradle.api.Project | ||
|
||
interface GradleProjectDecorator { | ||
|
||
fun GradleProject.decorate(target: Project) | ||
} |
13 changes: 0 additions & 13 deletions
13
airin-gradle-plugin/src/main/kotlin/io/morfly/airin/PackageDescriptorFactory.kt
This file was deleted.
Oops, something went wrong.
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