Skip to content

Commit

Permalink
Add main marker strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeziellago committed Aug 20, 2020
1 parent c962bbf commit fe96a31
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ FlowNav is a mobile library for Android that helps and provider a better way to

```gradle
// latest stable
flownav_version = '0.5.0'
flownav_version = '0.5.1'
```

## Start Now!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,28 @@ internal class FlowNavProcessingStep(
val mainInitializer = mainFlowNavInitializerElements.first()
val packageName = processingEnv.elementUtils.getPackageOf(mainInitializer).toString()
val classBuilder = FlowNavActionsBuilder(generatedNavClass).openFile(packageName)

val mainMarker = "${packageName}_${mainInitializer.simpleName}$APP_MODULE_MARKER"
val mainMarkerFile = File(targetParentPath, mainMarker)
val entryRegisters = File(targetParentPath).listFiles()

if(entryRegisters.isNullOrEmpty()) {
if (entryRegisters.isNullOrEmpty() ||
entryRegisters.any { it.name.contains(APP_MODULE_MARKER) && it.name != mainMarker }
) {
File(targetParentPath).delete()
processingEnv.messager.printMessage(
Diagnostic.Kind.ERROR,
"Invalid cache detected! Clean and rebuild your modules."
"Invalid cache detected! Clean modules and rebuild."
)
return
}

entryRegisters.forEach { register ->
classBuilder
.addAction(register.name, register.readText())
.also { register.delete() }
}
entryRegisters
.filter {
!it.name.contains(APP_MODULE_MARKER)
}.forEach { register ->
classBuilder.addAction(register.name, register.readText())
}
mainMarkerFile.writeText(System.nanoTime().toString())
}

private fun createEntryFlowNavKeys(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal const val FLOWNAV_MAIN_MODULE_PROPERTY = "flownav.main.module"
internal const val BUILD_TYPE_SOURCE = "build/generated/source"
internal const val PATH_SEPARATOR = "/"
internal const val APP_MODULE_SEPARATOR = ","
internal const val APP_MODULE_MARKER = "_MARKER"

internal fun ProcessingEnvironment.getKaptKotlinGeneratedDir(): String? {
return options[KAPT_KOTLIN_GENERATED_OPTION_NAME] ?: run {
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext.kotlin_version = '1.3.72'
ext.publish_version = '0.5.0'
ext.publish_version = '0.5.1'
repositories {
mavenCentral()
jcenter()
Expand Down

0 comments on commit fe96a31

Please sign in to comment.