Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into strings-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 authored Mar 25, 2019
2 parents 5f7310a + c75c1fe commit 8a05ef6
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 71 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,5 @@ task ktlint(type: JavaExec, group: "verification") {
args "components/**/*.kt" , "samples/**/*.kt", "!**/build", "buildSrc/**/*.kt"
}

apply plugin: GVNightlyVersionVerifierPlugin
apply plugin: GVVersionVerifierPlugin
apply plugin: GitHubPlugin
69 changes: 0 additions & 69 deletions buildSrc/src/main/java/GVNightlyVersionVerifierPlugin.kt

This file was deleted.

119 changes: 119 additions & 0 deletions buildSrc/src/main/java/GVVersionVerifierPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import GeckoVersions.beta_version
import GeckoVersions.nightly_version
import GeckoVersions.release_version
import groovy.util.Node
import groovy.util.NodeList
import groovy.util.XmlParser
import org.gradle.api.Plugin
import org.gradle.api.Project
import java.io.File
import java.lang.Exception

open class GVVersionVerifierPlugin : Plugin<Project> {

companion object {
private const val GV_VERSION_PATH_FILE = "buildSrc/src/main/java/Gecko.kt"
private const val MAVEN_MOZILLA_NIGHTLY_GV_URL =
"https://maven.mozilla.org/maven2/org/mozilla/geckoview/geckoview-nightly-armeabi-v7a/maven-metadata.xml"
private const val MAVEN_MOZILLA_BETA_GV_URL =
"https://maven.mozilla.org/maven2/org/mozilla/geckoview/geckoview-beta-armeabi-v7a/maven-metadata.xml"
private const val MAVEN_MOZILLA_STABLE_GV_URL =
"https://maven.mozilla.org/maven2/org/mozilla/geckoview/geckoview-armeabi-v7a/maven-metadata.xml"
}

override fun apply(project: Project) {

project.task("updateGVNightlyVersion") {

doLast {
val configuration = GVConfiguration(
actualVersionMajor = nightly_version.extractMajor(),
variableName = "nightly_version",
mavenURL = project.getNightlyMavenURL()
)
updateGVVersion(project, configuration)
}
}

project.task("updateGVBetaVersion") {

doLast {
val configuration = GVConfiguration(
actualVersionMajor = beta_version.extractMajor(),
variableName = "beta_version",
mavenURL = project.getBetaMavenURL()
)
updateGVVersion(project, configuration)
}
}

project.task("updateGVStableVersion") {

doLast {
val configuration = GVConfiguration(
actualVersionMajor = release_version.extractMajor(),
variableName = "release_version",
mavenURL = project.getStableMavenURL()
)
updateGVVersion(project, configuration)
}
}
}

@Suppress("TooGenericExceptionThrown")
private fun updateGVVersion(project: Project, config: GVConfiguration) {

val newVersion = getLastGeckoViewVersion(config)

if (newVersion.isNotEmpty()) {
val filePath = project.property("gvVersionFile", GV_VERSION_PATH_FILE)
updateConfigFileWithNewGVVersion(filePath, newVersion, config.variableName)
} else {
throw Exception("Unable to find a new version of GeckoViewNightly")
}
}

@Suppress("UNCHECKED_CAST")
private fun getLastGeckoViewVersion(config: GVConfiguration): String {
val versioning = (XmlParser().parse(config.mavenURL)["versioning"] as List<Node>)
val latest = versioning[0]["latest"] as List<Node>
val value = ((latest.first().value() as NodeList)[0]).toString()

val lastVersion = if (value.isNotEmpty()) value else ""

val lastVersionMajor = lastVersion.extractMajor()

return if (config.actualVersionMajor == lastVersionMajor) lastVersion else ""
}

private fun updateConfigFileWithNewGVVersion(path: String, newVersion: String, variableName: String) {
val file = File(path)
var fileContent = file.readText()
fileContent = fileContent.replace(
Regex("$variableName.*=.*"),
"$variableName = \"$newVersion\""
)
file.writeText(fileContent)
println("${file.name} file updated")
}

private class GVConfiguration(val actualVersionMajor: String, val variableName: String, val mavenURL: String)

private fun String.extractMajor() = this.split(".").first()

private fun Project.getNightlyMavenURL(): String {
return project.property("gvMavenNightlyVersionURL", MAVEN_MOZILLA_NIGHTLY_GV_URL)
}

private fun Project.getBetaMavenURL(): String {
return project.property("gvMavenBetaVersionURL", MAVEN_MOZILLA_BETA_GV_URL)
}

private fun Project.getStableMavenURL(): String {
return project.property("gvMavenStableVersionURL", MAVEN_MOZILLA_STABLE_GV_URL)
}
}
8 changes: 7 additions & 1 deletion components/service/glean/scripts/sdk_generator.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ ext.gleanGenerateMetricsAPI = {
variant ->

def sourceOutputDir = "$buildDir/telemetry/src/${variant.name}/kotlin"
def fullNamespace = "${variant.applicationId}.GleanMetrics"
// Get the name of the package as if it were to be used in the R or BuildConfig
// files. This is required since applications can define different application ids
// depending on the variant type: the generated API definitions don't need to be
// different due to that.
Task buildConfig = variant.generateBuildConfig
def originalPackageName = buildConfig.getBuildConfigPackageName()
def fullNamespace = "${originalPackageName}.GleanMetrics"
def generateKotlinAPI = task("generateMetricsSourceFor${variant.name.capitalize()}", type: Exec) {
description = "Generate the Kotlin code for the Metrics API"

Expand Down
3 changes: 3 additions & 0 deletions samples/glean/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ android {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
}
}
}

Expand Down

0 comments on commit 8a05ef6

Please sign in to comment.