-
Notifications
You must be signed in to change notification settings - Fork 9
Never add meta-data to sdk-mock and visualize meta-data in JSON format on CI #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
107 changes: 107 additions & 0 deletions
107
plugins/library/src/main/java/com/deploygate/plugins/BaseSdkPlugin.kt
This file contains hidden or 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,107 @@ | ||
| package com.deploygate.plugins | ||
|
|
||
| import com.android.build.api.dsl.LibraryDefaultConfig | ||
| import com.android.build.api.dsl.LibraryExtension | ||
| import com.deploygate.plugins.dsl.SdkExtension | ||
| import com.deploygate.plugins.ext.libraryExtension | ||
| import org.gradle.api.GradleException | ||
| import org.gradle.api.JavaVersion | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.kotlin.dsl.apply | ||
| import org.gradle.kotlin.dsl.dependencies | ||
|
|
||
| abstract class BaseSdkPlugin : Plugin<Project> { | ||
| companion object { | ||
| /** | ||
| * sdk/java/com/deploygate/sdk/HostAppTest.java needs to be changed for a new release | ||
| */ | ||
| const val ARTIFACT_VERSION = "4.7.1" | ||
|
|
||
| val JAVA_VERSION = JavaVersion.VERSION_1_7 | ||
| } | ||
|
|
||
| protected val artifactVersion: String | ||
| get() = ARTIFACT_VERSION | ||
|
|
||
| override fun apply(target: Project) { | ||
| target.version = ARTIFACT_VERSION | ||
|
|
||
| target.extensions.add("sdk", createSdkExtension()) | ||
|
|
||
| target.apply(plugin = "com.android.library") | ||
| target.apply<MavenPublishPlugin>() | ||
|
|
||
| target.libraryExtension.configureLibraryExtension() | ||
|
|
||
| target.tasks.register("verifyReleaseVersion") { | ||
| doLast { | ||
| if (target.version != System.getenv("RELEASE_VERSION")) { | ||
| throw GradleException("${target.version} does not equal to ${System.getenv("RELEASE_VERSION")}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| target.dependencies { | ||
| add("testImplementation", "androidx.test:runner:1.5.2") | ||
| add("testImplementation", "androidx.test.ext:junit:1.1.5") | ||
| add("testImplementation", "org.robolectric:robolectric:4.10.3") | ||
| add("testImplementation", "androidx.test:rules:1.5.0") | ||
| add("testImplementation", "com.google.truth:truth:1.0") | ||
| } | ||
| } | ||
|
|
||
| private fun LibraryExtension.configureLibraryExtension() { | ||
| compileSdk = 33 | ||
|
|
||
| defaultConfig { | ||
| minSdk = 14 | ||
| // TODO remove this property and set the default sdk version for robolectric test instead | ||
| @Suppress("DEPRECATION") | ||
| targetSdk = 33 | ||
|
|
||
| configureLibraryDefaultConfig() | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| isMinifyEnabled = false | ||
| } | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility(JAVA_VERSION) | ||
| targetCompatibility(JAVA_VERSION) | ||
| } | ||
|
|
||
| testOptions { | ||
| unitTests { | ||
| isIncludeAndroidResources = true | ||
|
|
||
| all { | ||
| it.jvmArgs( | ||
| "-Xmx1g", | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| buildFeatures { | ||
| buildConfig = true | ||
| } | ||
|
|
||
| lint { | ||
| abortOnError = false | ||
| } | ||
|
|
||
| publishing { | ||
| singleVariant("release") { | ||
| withJavadocJar() | ||
| withSourcesJar() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| abstract fun createSdkExtension(): SdkExtension | ||
| abstract fun LibraryDefaultConfig.configureLibraryDefaultConfig() | ||
| } |
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
plugins/library/src/main/java/com/deploygate/plugins/SdkMockPlugin.kt
This file contains hidden or 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,19 @@ | ||
| package com.deploygate.plugins | ||
|
|
||
| import com.android.build.api.dsl.LibraryDefaultConfig | ||
| import com.deploygate.plugins.dsl.SdkExtension | ||
| import com.deploygate.plugins.internal.SdkExtensionImpl | ||
|
|
||
| class SdkMockPlugin : BaseSdkPlugin() { | ||
| override fun createSdkExtension(): SdkExtension { | ||
| return SdkExtensionImpl( | ||
| displayName = "DeployGate SDK Mock", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inlined. |
||
| artifactId = "sdk-mock", | ||
| description = "Mocked dummy DeployGate SDK for Android to reduce footprint of your release version app without code modification", | ||
| ) | ||
| } | ||
|
|
||
| override fun LibraryDefaultConfig.configureLibraryDefaultConfig() { | ||
| // Do not add meta-data and so on for sdk-mock | ||
| } | ||
| } | ||
163 changes: 56 additions & 107 deletions
163
plugins/library/src/main/java/com/deploygate/plugins/SdkPlugin.kt
This file contains hidden or 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,131 +1,80 @@ | ||
| package com.deploygate.plugins | ||
|
|
||
| import com.android.build.api.dsl.LibraryExtension | ||
| import com.android.build.api.dsl.LibraryDefaultConfig | ||
| import com.deploygate.plugins.dsl.SdkExtension | ||
| import com.deploygate.plugins.ext.libraryExtension | ||
| import org.gradle.api.GradleException | ||
| import org.gradle.api.JavaVersion | ||
| import org.gradle.api.Plugin | ||
| import com.deploygate.plugins.internal.SdkExtensionImpl | ||
| import com.deploygate.plugins.tasks.GenerateMetaDataJsonTask | ||
| import org.gradle.api.Project | ||
| import org.gradle.kotlin.dsl.apply | ||
| import org.gradle.kotlin.dsl.create | ||
| import org.gradle.kotlin.dsl.dependencies | ||
| import org.gradle.kotlin.dsl.register | ||
| import java.io.File | ||
|
|
||
| class SdkPlugin : Plugin<Project> { | ||
| class SdkPlugin : BaseSdkPlugin() { | ||
| companion object { | ||
| /** | ||
| * sdk/java/com/deploygate/sdk/HostAppTest.java needs to be changed for a new release | ||
| */ | ||
| private const val ARTIFACT_VERSION = "4.7.1" | ||
|
|
||
| val JAVA_VERSION = JavaVersion.VERSION_1_7 | ||
| } | ||
|
|
||
| override fun apply(target: Project) { | ||
| target.version = ARTIFACT_VERSION | ||
|
|
||
| target.extensions.create<SdkExtension>("sdk") | ||
|
|
||
| target.apply(plugin = "com.android.library") | ||
| target.apply<MavenPublishPlugin>() | ||
|
|
||
| target.libraryExtension.configureLibraryExtension( | ||
| artifactVersion = target.version as String, | ||
| // A map of <name => isSupporting> | ||
| // The order of elements are important! | ||
| private val SUPPORTED_FEATURES = arrayOf( | ||
| "UPDATE_MESSAGE_OF_BUILD" to true, | ||
| "SERIALIZED_EXCEPTION" to true, | ||
| "LOGCAT_BUNDLE" to true, | ||
| "STREAMED_LOGCAT" to true, | ||
| "DEVICE_CAPTURE" to true, | ||
| ) | ||
|
|
||
| target.tasks.register("verifyReleaseVersion") { | ||
| doLast { | ||
| if (target.version != System.getenv("RELEASE_VERSION")) { | ||
| throw GradleException("${target.version} does not equal to ${System.getenv("RELEASE_VERSION")}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| target.dependencies { | ||
| add("testImplementation", "androidx.test:runner:1.5.2") | ||
| add("testImplementation", "androidx.test.ext:junit:1.1.5") | ||
| add("testImplementation", "org.robolectric:robolectric:4.10.3") | ||
| add("testImplementation", "androidx.test:rules:1.5.0") | ||
| add("testImplementation", "com.google.truth:truth:1.0") | ||
| } | ||
|
|
||
| } | ||
|
|
||
| fun LibraryExtension.configureLibraryExtension( | ||
| artifactVersion: String, | ||
| ) { | ||
| compileSdk = 33 | ||
|
|
||
| defaultConfig { | ||
| minSdk = 14 | ||
| targetSdk = 33 | ||
|
|
||
| // A map of <name => isSupporting> | ||
| val features = linkedMapOf( | ||
| "UPDATE_MESSAGE_OF_BUILD" to true, | ||
| "SERIALIZED_EXCEPTION" to true, | ||
| "LOGCAT_BUNDLE" to true, | ||
| "STREAMED_LOGCAT" to true, | ||
| "DEVICE_CAPTURE" to true, | ||
| ) | ||
|
|
||
| var flags = 0 | ||
|
|
||
| features.entries.forEachIndexed { i, e -> | ||
| val (feature, isSupporting) = e | ||
|
|
||
| buildConfigField("int", feature, "1 << $i") | ||
| private val FEATURE_FLAGS: LinkedHashMap<String, Int> = | ||
| SUPPORTED_FEATURES.mapIndexed { idx, (feature, _) -> | ||
| feature to 1.shl(idx) | ||
| }.toMap(LinkedHashMap()) | ||
|
|
||
| private val ACTIVE_FEATURE_FLAGS = | ||
| SUPPORTED_FEATURES.fold(0) { acc, (feature, isSupporting) -> | ||
| if (isSupporting) { | ||
| flags = flags or 1.shl(i) | ||
| acc or FEATURE_FLAGS.getOrElse(feature) { error("$feature is not found in FEATURE_FLAGS") } | ||
| } else { | ||
| acc | ||
| } | ||
| } | ||
|
|
||
| addManifestPlaceholders( | ||
| mapOf( | ||
| "featureFlags" to flags, | ||
| "sdkVersion" to "4", | ||
| "sdkArtifactVersion" to artifactVersion, | ||
| ) | ||
| ) | ||
| } | ||
| private const val KEY_PREFIX = "com.deploygate.sdk." | ||
|
|
||
| buildTypes { | ||
| release { | ||
| isMinifyEnabled = false | ||
| } | ||
| } | ||
| private val META_DATA_ENTRIES = | ||
| mapOf( | ||
| "deploygate_sdk_feature_flags_name" to "${KEY_PREFIX}feature_flags", | ||
| "deploygate_sdk_feature_flags_value" to "$ACTIVE_FEATURE_FLAGS", | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility(JAVA_VERSION) | ||
| targetCompatibility(JAVA_VERSION) | ||
| } | ||
| "deploygate_sdk_version_name" to "${KEY_PREFIX}version", | ||
| "deploygate_sdk_version_value" to "4", | ||
|
|
||
| testOptions { | ||
| unitTests { | ||
| isIncludeAndroidResources = true | ||
| "deploygate_sdk_artifact_version_name" to "${KEY_PREFIX}artifact_version", | ||
| "deploygate_sdk_artifact_version_value" to ARTIFACT_VERSION, | ||
| ) | ||
| } | ||
|
|
||
| all { | ||
| it.jvmArgs( | ||
| "-Xmx1g", | ||
| ) | ||
| } | ||
| } | ||
| override fun apply(target: Project) { | ||
| super.apply(target) | ||
|
|
||
| target.tasks.register<GenerateMetaDataJsonTask>("generateMetaDataJson") { | ||
| getArtifactVersion().set(ARTIFACT_VERSION) | ||
| getFeatureFlags().set(FEATURE_FLAGS) | ||
| getActiveFeatureFlags().set(ACTIVE_FEATURE_FLAGS) | ||
| getMetaData().set(META_DATA_ENTRIES) | ||
| outputFile = | ||
| File(target.buildDir, "generated-sdk-metadata/sdk-meta-data-$ARTIFACT_VERSION.json") | ||
| } | ||
| } | ||
|
|
||
| buildFeatures { | ||
| buildConfig = true | ||
| } | ||
| override fun createSdkExtension(): SdkExtension { | ||
| return SdkExtensionImpl( | ||
| displayName = "DeployGate SDK", | ||
| artifactId = "sdk", | ||
| description = "DeployGate SDK for Android", | ||
| ) | ||
| } | ||
|
|
||
| lint { | ||
| abortOnError = false | ||
| override fun LibraryDefaultConfig.configureLibraryDefaultConfig() { | ||
| FEATURE_FLAGS.forEach { (feature, flag) -> | ||
| buildConfigField("int", feature, "$flag") | ||
| } | ||
|
|
||
| publishing { | ||
| singleVariant("release") { | ||
| withJavadocJar() | ||
| withSourcesJar() | ||
| } | ||
| } | ||
| addManifestPlaceholders(META_DATA_ENTRIES) | ||
| } | ||
| } |
8 changes: 3 additions & 5 deletions
8
plugins/library/src/main/java/com/deploygate/plugins/dsl/SdkExtension.kt
This file contains hidden or 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,9 +1,7 @@ | ||
| package com.deploygate.plugins.dsl | ||
|
|
||
| import org.gradle.api.provider.Property | ||
|
|
||
| interface SdkExtension { | ||
| val artifactId: Property<String> | ||
| val displayName: Property<String> | ||
| val description: Property<String> | ||
| val artifactId: String | ||
| val displayName: String | ||
| val description: String | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This restriction was meaningless.