Master in licard-dev #10

Merged
bogdan.terehov merged 323 commits from merge_master_in_licard_dev into licard-dev 2023-09-04 19:22:24 +03:00
2 changed files with 15 additions and 9 deletions
Showing only changes of commit 7b54155ae1 - Show all commits

View File

@ -1,8 +1,9 @@
package apigen
import com.android.build.gradle.AppExtension
import com.android.build.gradle.LibraryExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
class ApiGeneratorAndroidPlugin : ApiGeneratorPlugin() {
@ -18,7 +19,12 @@ class ApiGeneratorAndroidPlugin : ApiGeneratorPlugin() {
extension.recreateOutputDir = true
afterEvaluate {
extensions.getByType<LibraryExtension>().apply {
extensions.findByType<LibraryExtension>()?.apply {
sourceSets.getByName("main")
.java
.srcDir(outputDir)
}
extensions.findByType<AppExtension>()?.apply {
sourceSets.getByName("main")
.java
.srcDir(outputDir)

View File

@ -2,11 +2,11 @@ import groovy.json.JsonSlurper
import groovy.xml.MarkupBuilder
task stringGenerator {
generate(android.languageMap, android.rootPath ?: "app")
generate(android.languageMap, project)
println("Strings generated!")
}
private def generate(Map<String, String> sources, String rootPath) {
private def generate(Map<String, String> sources, Project project) {
if (sources == null || sources.isEmpty()) {
throw new IOException("languageMap can't be null or empty")
}
@ -31,7 +31,7 @@ private def generate(Map<String, String> sources, String rootPath) {
}
}
def stringsFile = getFile(key, key == defaultLang, rootPath)
def stringsFile = getFile(key, key == defaultLang, project)
stringsFile.write(sw.toString(), "UTF-8")
}
}
@ -69,15 +69,15 @@ private static Map<String, Object> getJsonsMap(Map sources) {
}
}
private static File getFile(String key, boolean defaultLang, String rootPath) {
private static File getFile(String key, boolean defaultLang, Project project) {
if (defaultLang) {
return new File("${rootPath}/src/main/res/values/strings.xml")
return project.file("src/main/res/values/strings.xml")
} else {
def directory = new File("${rootPath}/src/main/res/values-$key")
def directory = project.file("src/main/res/values-$key")
if (!directory.exists()) {
directory.mkdir()
}
return new File("${rootPath}/src/main/res/values-$key/strings.xml")
return project.file("src/main/res/values-$key/strings.xml")
}
}