File tree Expand file tree Collapse file tree 4 files changed +22
-5
lines changed
plugin/src/main/kotlin/dev/vyp/stringcare/plugin Expand file tree Collapse file tree 4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -269,23 +269,37 @@ fun defaultConfig(): StringCareConfiguration =
269269 )
270270 }
271271
272+ /* *
273+ * Copies a backup from [tempRoot] back under [projectPath].
274+ *
275+ * Backups are stored as `tempRoot/<module>/…` while [projectPath] is already the Gradle module directory,
276+ * so the path segment after [tempRoot] must be `<module>/src/…` and resolves to `projectPath/src/…`,
277+ * not `projectPath/<module>/src/…`.
278+ */
272279fun File.restore (
273280 projectPath : String ,
274281 tempRoot : String ,
282+ module : String ,
275283): File {
276284 val baseDir = File (tempRoot).canonicalFile
277285 val backupFile = this .canonicalFile
278286 val prefix = baseDir.absolutePath.let { if (it.endsWith(File .separator)) it else it + File .separator }
279287 require(backupFile.absolutePath.startsWith(prefix)) {
280288 " Backup ${backupFile.absolutePath} is not under temp root ${baseDir.absolutePath} "
281289 }
282- val relative = backupFile.absolutePath.substring(prefix.length)
290+ var relative = backupFile.absolutePath.substring(prefix.length)
291+ val modulePrefix = module + File .separator
292+ require(relative.startsWith(modulePrefix)) {
293+ " Backup relative path $relative does not start with module directory $modulePrefix "
294+ }
295+ relative = relative.substring(modulePrefix.length)
283296 val restore = File (projectPath, relative).normalize()
284297 withFileLock(restore) {
285298 if (restore.exists()) {
286299 restore.delete()
287300 }
288- File (restore.absolutePath).writeText(backupFile.getContent())
301+ restore.parentFile?.mkdirs()
302+ backupFile.copyTo(restore, overwrite = true )
289303 }
290304 return restore
291305}
Original file line number Diff line number Diff line change @@ -67,4 +67,4 @@ internal fun restoreBackedUpFiles(
6767 .walkTopDown()
6868 .toList()
6969 .filter { file -> ! file.isDirectory }
70- .map { file -> file.restore(projectPath, tempRoot) }
70+ .map { file -> file.restore(projectPath, tempRoot, module ) }
Original file line number Diff line number Diff line change @@ -107,6 +107,10 @@ fun Project.registerVariantObfuscationTasks(
107107 t.skip.set(provider { extension.skip })
108108 }
109109
110+ tasks.named(" stringcareBeforeMergeAssets$variantCapitalized " ).configure {
111+ it.mustRunAfter(tasks.named(" stringcareBeforeMergeResources$variantCapitalized " ))
112+ }
113+
110114 val mergeRes =
111115 " ${AndroidTaskNames .MERGE }${variantCapitalized}${AndroidTaskNames .RESOURCES } "
112116 val beforeRes = " stringcareBeforeMergeResources$variantCapitalized "
Original file line number Diff line number Diff line change @@ -44,13 +44,12 @@ abstract class RestoreStringsTask : DefaultTask() {
4444 }
4545
4646 @TaskAction
47- /* * Restores backed up XML files and resets temp folder state . */
47+ /* * Restores backed up XML files from the shared temp root (cleared later by [RestoreAssetsTask]) . */
4848 fun run () {
4949 if (skip.get()) return
5050 PrintUtils .print (moduleName.get(), restoreStringRes)
5151 val service = stringCareService.get()
5252 val tempRoot = service.getOrCreateTempFolder()
5353 restoreFilesUseCase.restoreResources(projectPath.get(), moduleName.get(), tempRoot)
54- service.resetTempFolder()
5554 }
5655}
You can’t perform that action at this time.
0 commit comments