fixed android api gen and string generator for old projects
This commit is contained in:
parent
0f53df4bb4
commit
7b54155ae1
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue