Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into fat-jar-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
borisf committed Dec 21, 2017
2 parents 18e8428 + e04ed31 commit ff71d57
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AndroidStudioPoet(private val modulesWriter: SourceModuleWriter, private v
Injector.configPojoToBuildTypeConfigsConverter).run()
}

@Language("JSON") const val SAMPLE_CONFIG = """
@Language("JSON") val SAMPLE_CONFIG = """
{
"projectName": "genny",
"root": "./modules/",
Expand Down Expand Up @@ -73,7 +73,7 @@ class AndroidStudioPoet(private val modulesWriter: SourceModuleWriter, private v
],
"buildTypes": 6
}
"""
""".trimIndent()
}

fun run() {
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/com/google/androidstudiopoet/BuildGradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

package com.google.androidstudiopoet

import com.google.androidstudiopoet.utils.joinLines

annotation class Fancy

@Fancy
object BuildGradle {

fun print(dependencies: String, useKotlin: Boolean) = "" +
fun print(dependencies: String, useKotlin: Boolean, extraLines: List<String>? = null) = "" +
"apply plugin: 'java-library'\n" +
(if (useKotlin)
"apply plugin: 'kotlin'\n"
Expand Down Expand Up @@ -51,7 +53,7 @@ object BuildGradle {
"repositories {\n" +
" mavenCentral()\n" +
"}\n" +
if (useKotlin)
(if (useKotlin)
"compileKotlin {\n" +
" kotlinOptions {\n" +
" jvmTarget = \"1.8\"\n" +
Expand All @@ -63,5 +65,6 @@ object BuildGradle {
" }\n" +
"}\n"
else
""
"" ) +
extraLines.joinLines()
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object ModuleBlueprintFactory {
}
val result = ModuleBlueprint(getModuleNameByIndex(moduleConfig.index), projectRoot, moduleConfig.useKotlin, moduleDependencies,
moduleConfig.javaPackageCount, moduleConfig.javaClassCount, moduleConfig.javaMethodsPerClass,
moduleConfig.kotlinPackageCount, moduleConfig.kotlinClassCount, moduleConfig.kotlinMethodsPerClass)
moduleConfig.kotlinPackageCount, moduleConfig.kotlinClassCount, moduleConfig.kotlinMethodsPerClass, moduleConfig.extraLines)
synchronized(moduleDependencyLock[moduleConfig.index]) {
if (moduleDependencyCache[moduleConfig.index] == null) {
moduleDependencyCache[moduleConfig.index] = ModuleDependency(result.name, result.methodToCallFromOutside)
Expand Down Expand Up @@ -69,7 +69,7 @@ object ModuleBlueprintFactory {
*/
val tempModuleBlueprint = ModuleBlueprint(getModuleNameByIndex(index), projectRoot, useKotlin, listOf(),
javaPackageCount, javaClassCount, javaMethodsPerClass, kotlinPackageCount,kotlinClassCount,
kotlinMethodsPerClass)
kotlinMethodsPerClass, null)
return ModuleDependency(tempModuleBlueprint.name, tempModuleBlueprint.methodToCallFromOutside)

}
Expand Down Expand Up @@ -102,7 +102,8 @@ object ModuleBlueprintFactory {
moduleDependencies, androidModuleConfig.productFlavorConfigs, androidModuleConfig.buildTypes,
androidModuleConfig.javaPackageCount, androidModuleConfig.javaClassCount,
androidModuleConfig.javaMethodsPerClass, androidModuleConfig.kotlinPackageCount,
androidModuleConfig.kotlinClassCount, androidModuleConfig.kotlinMethodsPerClass)
androidModuleConfig.kotlinClassCount, androidModuleConfig.kotlinMethodsPerClass,
androidModuleConfig.extraLines)
}

private fun getModuleNameByIndex(index: Int) = "module$index"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class BuildGradleGenerator {
fun create(moduleBlueprint: ModuleBlueprint): String {
return BuildGradle.print(moduleBlueprint.dependencies
.map { it -> "compile project(':${it.name}')\n" }
.fold(), moduleBlueprint.useKotlin)
.fold(), moduleBlueprint.useKotlin, moduleBlueprint.extraLines)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.google.androidstudiopoet.models.AndroidModuleBlueprint
import com.google.androidstudiopoet.models.Flavor
import com.google.androidstudiopoet.utils.fold
import com.google.androidstudiopoet.utils.isNullOrEmpty
import com.google.androidstudiopoet.utils.joinLines
import com.google.androidstudiopoet.utils.joinPath
import com.google.androidstudiopoet.writers.FileWriter

Expand Down Expand Up @@ -87,6 +88,7 @@ dependencies {
${align(moduleDependencies.trimEnd()," ")}
}
${blueprint.extraLines.joinLines()}
""".trim()

fileWriter.writeToFile(gradleText, moduleRoot.joinPath("build.gradle"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ class AndroidModuleConfig(index: Int, config: ConfigPOJO, val productFlavorConfi
val hasLaunchActivity = index == 0
val resourcesConfig = ResourcesConfig(activityCount + 2,
activityCount + 5, activityCount)
override val extraLines = config.extraAndroidBuildFileLines
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ open class ModuleConfig(val index: Int, config: ConfigPOJO) {

val dependencies = config.resolvedDependencies[index]?.map { it.to } ?: listOf()


open val extraLines = config.extraBuildFileLines
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ data class AndroidModuleBlueprint(val index: Int,
private val productFlavorConfigs: List<FlavorConfig>?,
private val buildTypeConfigs: List<BuildTypeConfig>?,
private val javaPackageCount: Int, private val javaClassCount: Int, private val javaMethodsPerClass: Int,
private val kotlinPackageCount: Int, private val kotlinClassCount: Int, private val kotlinMethodsPerClass: Int
private val kotlinPackageCount: Int, private val kotlinClassCount: Int, private val kotlinMethodsPerClass: Int,
val extraLines: List<String>?
) : Blueprint {

val name = "androidAppModule" + index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class ConfigPOJO {

val topologies: List<Map<String, String>>? = null

val extraBuildFileLines : List<String>? = null

val extraAndroidBuildFileLines : List<String>? = null

override fun toString(): String = toJson()

private fun toJson(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ data class ModuleBlueprint(val name: String,
val useKotlin: Boolean,
val dependencies: List<ModuleDependency>,
private val javaPackageCount: Int, private val javaClassCount: Int, private val javaMethodsPerClass: Int,
private val kotlinPackageCount: Int, private val kotlinClassCount: Int, private val kotlinMethodsPerClass: Int) {
private val kotlinPackageCount: Int, private val kotlinClassCount: Int, private val kotlinMethodsPerClass: Int,
val extraLines: List<String>?) {

val moduleRoot = root.joinPath(name)
val packagesBlueprint = PackagesBlueprint(javaPackageCount, javaClassCount, javaMethodsPerClass, kotlinPackageCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@

package com.google.androidstudiopoet.utils

fun <T> Collection<T>?.isNullOrEmpty() = this == null || this.isEmpty()
fun <T> Collection<T>?.isNullOrEmpty() = this == null || this.isEmpty()

fun <T> Collection<T>?.joinLines(separator: CharSequence = "\n") : String {
if (this == null) {
return ""
}
return this.joinToString(separator = separator)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AndroidModuleBlueprintTest {
private val dependency: ModuleDependency = mock()
private val originalAndroidModuleBlueprint = AndroidModuleBlueprint(1, 1, resourcesConfig,
"root", true, false, listOf(dependency), null,null,
1, 1, 1, 1, 1, 1)
1, 1, 1, 1, 1, 1, null)

@Test
fun `blueprint create proper activity names`() {
Expand Down

0 comments on commit ff71d57

Please sign in to comment.