-
Notifications
You must be signed in to change notification settings - Fork 1
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
7 changed files
with
88 additions
and
103 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
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
45 changes: 45 additions & 0 deletions
45
components/src/main/java/lt/markmerkk/migration/ConfigMigration1.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,45 @@ | ||
package lt.markmerkk.migration | ||
|
||
import org.apache.commons.io.FileUtils | ||
import org.slf4j.Logger | ||
import java.io.File | ||
|
||
/** | ||
* Migration that would move configuration by the app flavor. | ||
* This is needed, as both flavors normally "inherit" its configuration and its changes | ||
* thus resulting in incorrect application when both applications are launched. | ||
* | ||
* For instance, when both apps are launched and are using different jiras at the same time | ||
*/ | ||
class ConfigMigration1( | ||
private val versionCode: Int, | ||
private val configDirLegacy: File, | ||
private val configDirFull: File, | ||
private val l: Logger | ||
) : ConfigPathMigrator.ConfigMigration { | ||
|
||
override fun isMigrationNeeded(): Boolean { | ||
val configCountInFull = ConfigUtils.listConfigs(configDirFull) | ||
.count() | ||
// Only one version would trigger migration + full path should be empty | ||
l.info("Checking if configs need migration1: [configCountInFull <= 1($configCountInFull)] " + | ||
"/ [versionCode <= 67($versionCode)]") | ||
return configCountInFull <= 1 && versionCode <= 67 | ||
} | ||
|
||
override fun doMigration() { | ||
l.info("Triggering migration1...") | ||
ConfigUtils.listConfigs(configDirLegacy) | ||
.filter { it != configDirFull } | ||
.filterNot { it.isDirectory && it.name == "logs" } // ignore log directory | ||
.forEach { | ||
try { | ||
FileUtils.copyToDirectory(it, configDirFull) | ||
} catch (e: Exception) { | ||
l.warn("Error doing migration1", e) | ||
} | ||
} | ||
l.info("Migration complete!") | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
components/src/main/java/lt/markmerkk/migration/ConfigPathMigrationFactory.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,15 @@ | ||
package lt.markmerkk.migration | ||
|
||
import java.io.File | ||
|
||
object ConfigPathMigrationFactory { | ||
fun create( | ||
versionCode: Int, | ||
configDirLegacy: File, | ||
configDirFull: File | ||
): List<ConfigPathMigrator.ConfigMigration> { | ||
return listOf( | ||
ConfigMigration1(versionCode, configDirLegacy, configDirFull, ConfigPathMigrator.l) | ||
) | ||
} | ||
} |
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: 13 additions & 0 deletions
13
components/src/main/java/lt/markmerkk/migration/ConfigUtils.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,13 @@ | ||
package lt.markmerkk.migration | ||
|
||
import java.io.File | ||
|
||
object ConfigUtils { | ||
fun listConfigs(configDir: File): List<File> { | ||
return if (configDir.exists() && configDir.isDirectory) { | ||
configDir.listFiles()?.asList() ?: emptyList() | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
} |
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,2 +1,2 @@ | ||
version_name=1.8.1 | ||
version_code=66 | ||
version_name=1.8.2 | ||
version_code=67 |