From bd52227ac75d63f4b0c7853bc93e721bcce3faf7 Mon Sep 17 00:00:00 2001 From: Julien Guerinet Date: Mon, 3 Dec 2018 14:40:28 -0500 Subject: [PATCH 1/5] Add .name to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9a6f705..7a853ba 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ out/ build_file_checksums.ser *.iml misc.xml +.name ## Gradle .gradle From 5395aa76e2ff8ee7af8264efb771b5128573cc6a Mon Sep 17 00:00:00 2001 From: Julien Guerinet Date: Mon, 3 Dec 2018 14:43:46 -0500 Subject: [PATCH 2/5] Move duplication checking to the String section specifically --- src/main/java/Weave.kt | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/Weave.kt b/src/main/java/Weave.kt index 96c34ca..a6fe94f 100644 --- a/src/main/java/Weave.kt +++ b/src/main/java/Weave.kt @@ -386,18 +386,6 @@ open class Weave { if (keyChecker.matcher(string1.key).find()) { error("${getLog(string1)} contains some illegal characters.") } - - // Check if there are any duplicates - for (j in i + 1 until filteredStrings.size) { - val string2 = filteredStrings[j] - - // If the keys are the same and it's not a header, show a warning and remove - // the older one - if (string1.key == string2.key) { - warning("${getLog(string1)} and ${getLog(string2)} have the same key. The second one will be used") - toRemove.add(string1) - } - } } // Remove all duplicates @@ -412,6 +400,26 @@ open class Weave { */ open fun verifyStringStrands(config: StringsConfig, strands: List): List { val toRemove = mutableListOf() + + // Check if there are any duplicates + for (i in strands.indices) { + val strand1 = strands[i] + + for (j in i + 1 until strands.size) { + val strand2 = strands[j] + + // If the keys are the same and it's not a header, show a warning and remove the older one + if (strand1.key == strand2.key) { + warning("${getLog(strand1)} and ${getLog(strand2)} have the same key. The second one will be used") + toRemove.add(strand1) + } + } + } + + val verifiedStrands = strands.toMutableList() + verifiedStrands.removeAll(toRemove) + toRemove.clear() + strands .mapNotNull { it as? LanguageStrand } .forEach { @@ -426,7 +434,6 @@ open class Weave { } } - val verifiedStrands = strands.toMutableList() verifiedStrands.removeAll(toRemove) return verifiedStrands } From 5dde3cb53755e46c364509724985e61682cd1815 Mon Sep 17 00:00:00 2001 From: Julien Guerinet Date: Mon, 3 Dec 2018 14:44:42 -0500 Subject: [PATCH 3/5] Rename some variables --- src/main/java/Weave.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/Weave.kt b/src/main/java/Weave.kt index a6fe94f..a2ee547 100644 --- a/src/main/java/Weave.kt +++ b/src/main/java/Weave.kt @@ -370,21 +370,19 @@ open class Weave { val keyChecker = Pattern.compile("[^A-Za-z0-9_]") // Get rid of all of the headers - val filteredStrings = strands.filter { it is LanguageStrand || it is AnalyticsStrand } + val filteredStrands = strands.filter { it is LanguageStrand || it is AnalyticsStrand } val toRemove = mutableListOf() // Check if there are any errors with the keys - for (i in filteredStrings.indices) { - val string1 = filteredStrings[i] - + filteredStrands.forEach { // Check if there are any spaces in the keys - if (string1.key.contains(" ")) { - error("${getLog(string1)} contains a space in its key.") + if (it.key.contains(" ")) { + error("${getLog(it)} contains a space in its key.") } - if (keyChecker.matcher(string1.key).find()) { - error("${getLog(string1)} contains some illegal characters.") + if (keyChecker.matcher(it.key).find()) { + error("${getLog(it)} contains some illegal characters.") } } From 9b41dff1b091bf07526fc2eaccfa1bc6e1ff4342 Mon Sep 17 00:00:00 2001 From: Julien Guerinet Date: Mon, 3 Dec 2018 14:49:55 -0500 Subject: [PATCH 4/5] Add Analytics Strands verification --- src/main/java/Weave.kt | 47 +++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/Weave.kt b/src/main/java/Weave.kt index a2ee547..ea23d98 100644 --- a/src/main/java/Weave.kt +++ b/src/main/java/Weave.kt @@ -90,8 +90,9 @@ open class Weave { } else { verifyAnalyticsConfigInfo(analyticsConfig) val downloadedStrands = downloadAllAnalyticStrands(analyticsConfig) - val verifiedStrings = verifyKeys(downloadedStrands) - writeAnalyticStrands(analyticsConfig, verifiedStrings) + val verifiedIds = verifyKeys(downloadedStrands) + val verifiedStrands = verifyAnalyticsStrands(verifiedIds) + writeAnalyticStrands(analyticsConfig, verifiedStrands) println("Analytics parsing complete") } } catch (e: IOException) { @@ -397,14 +398,15 @@ open class Weave { * that don't have all translations */ open fun verifyStringStrands(config: StringsConfig, strands: List): List { + val stringStrands = strands.mapNotNull { it as? LanguageStrand } val toRemove = mutableListOf() // Check if there are any duplicates - for (i in strands.indices) { - val strand1 = strands[i] + for (i in stringStrands.indices) { + val strand1 = stringStrands[i] - for (j in i + 1 until strands.size) { - val strand2 = strands[j] + for (j in i + 1 until stringStrands.size) { + val strand2 = stringStrands[j] // If the keys are the same and it's not a header, show a warning and remove the older one if (strand1.key == strand2.key) { @@ -418,8 +420,7 @@ open class Weave { verifiedStrands.removeAll(toRemove) toRemove.clear() - strands - .mapNotNull { it as? LanguageStrand } + stringStrands .forEach { val lineNumber = it.lineNumber val sourceName = it.sourceName @@ -659,6 +660,36 @@ open class Weave { } } + /** + * Verifies the analytics [strands] by ensuring that there are no duplicates (same type and same key) + */ + open fun verifyAnalyticsStrands(strands: List): List { + val analyticsStrands = strands.mapNotNull { it as? AnalyticsStrand } + val toRemove = mutableListOf() + + // Check if there are any duplicates + for (i in analyticsStrands.indices) { + val strand1 = analyticsStrands[i] + + for (j in i + 1 until analyticsStrands.size) { + val strand2 = analyticsStrands[j] + + // If the keys are the same and the type is the same, show a warning and remove the older one + if (strand1.key == strand2.key && strand1.type == strand2.type) { + warning( + "${getLog(strand1)} and ${getLog(strand2)} have the same key and type. " + + "The second one will be used" + ) + toRemove.add(strand1) + } + } + } + + val verifiedStrands = strands.toMutableList() + verifiedStrands.removeAll(toRemove) + return verifiedStrands + } + /** * Writes the analytics Strings using the [config] data */ From 362b12f21d4859d5c3b1069628eb79c7b28dc5bd Mon Sep 17 00:00:00 2001 From: Julien Guerinet Date: Mon, 3 Dec 2018 14:51:46 -0500 Subject: [PATCH 5/5] v5.2.0 --- CHANGELOG.md | 4 ++++ gradle.properties | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8442b41..ddf2914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## Version 5.2.0 (2018-12-03) + +- Changed the duplicate verification for `AnalyticsStrand`s such that it needs to be the same key **and** the same type for it to be considered a duplicate + ## Version 5.1.0 (2018-11-21) - Made the Analytics parsing part of Weave much more flexible. Categories can now be anything, and are optional diff --git a/gradle.properties b/gradle.properties index a36b184..69d546f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ # # Project properties -weave_version=5.0.0 +weave_version=5.2.0 artifact_name=weave artifact_main_class=com.guerinet.weave.Weave group=com.guerinet