Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	gradle.properties
  • Loading branch information
jguerinet committed Dec 3, 2018
2 parents afd0e0b + 362b12f commit b38de30
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ out/
build_file_checksums.ser
*.iml
misc.xml
.name

## Gradle
.gradle
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.3 (2018-11-21)

- Fixed header parsing so that you can use the Id column for other values
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

# Project properties
weave_version=5.1.3
weave_version=5.2.0
artifact_name=weave
artifact_main_class=com.guerinet.weave.Weave
group=com.guerinet
Expand Down
86 changes: 61 additions & 25 deletions src/main/java/Weave.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -374,33 +375,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<BaseStrand>()

// 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 (keyChecker.matcher(string1.key).find()) {
error("${getLog(string1)} contains some illegal characters.")
if (it.key.contains(" ")) {
error("${getLog(it)} contains a space in its key.")
}

// 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)
}
if (keyChecker.matcher(it.key).find()) {
error("${getLog(it)} contains some illegal characters.")
}
}

Expand All @@ -415,9 +402,29 @@ open class Weave {
* that don't have all translations
*/
open fun verifyStringStrands(config: StringsConfig, strands: List<BaseStrand>): List<BaseStrand> {
val stringStrands = strands.mapNotNull { it as? LanguageStrand }
val toRemove = mutableListOf<BaseStrand>()
strands
.mapNotNull { it as? LanguageStrand }

// Check if there are any duplicates
for (i in stringStrands.indices) {
val strand1 = stringStrands[i]

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) {
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()

stringStrands
.forEach {
val lineNumber = it.lineNumber
val sourceName = it.sourceName
Expand All @@ -430,7 +437,6 @@ open class Weave {
}
}

val verifiedStrands = strands.toMutableList()
verifiedStrands.removeAll(toRemove)
return verifiedStrands
}
Expand Down Expand Up @@ -658,6 +664,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<BaseStrand>): List<BaseStrand> {
val analyticsStrands = strands.mapNotNull { it as? AnalyticsStrand }
val toRemove = mutableListOf<BaseStrand>()

// 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
*/
Expand Down

0 comments on commit b38de30

Please sign in to comment.