@@ -126,61 +126,62 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
126
126
127
127
var generatedSourceDirectory: File ? = null
128
128
129
- // private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
130
- // val buildTypeName = variant?.buildType?.name
131
- // return project.buildTypes[buildTypeName]?.buildConfig
132
- // }
133
- //
134
- // private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
135
- // val buildTypeName = variant?.productFlavor?.name
136
- // return project.productFlavors[buildTypeName]?.buildConfig
137
- // }
129
+ private fun findBuildTypeBuildConfig (project : Project , variant : Variant ? ) : BuildConfig ? {
130
+ val buildTypeName = variant?.buildType?.name
131
+ return project.buildTypes[buildTypeName]?.buildConfig
132
+ }
133
+
134
+ private fun findProductFlavorBuildConfig (project : Project , variant : Variant ? ) : BuildConfig ? {
135
+ val buildTypeName = variant?.productFlavor?.name
136
+ return project.productFlavors[buildTypeName]?.buildConfig
137
+ }
138
138
139
139
/* *
140
140
* Return a list of the BuildConfigs found on the productFlavor{}, buildType{} and project{} (in that order).
141
141
*/
142
- // private fun findBuildConfigs(project: Project, variant: Variant?) : List<BuildConfig> {
143
- // val result = listOf(
144
- // findBuildTypeBuildConfig(project, variant),
145
- // findProductFlavorBuildConfig(project, variant),
146
- // project.buildConfig)
147
- // .filterNotNull()
148
- //
149
- // return result
150
- // }
142
+ private fun findBuildConfigs (project : Project , variant : Variant ? ) : List <BuildConfig > {
143
+ val result = listOf (
144
+ findBuildTypeBuildConfig(project, variant),
145
+ findProductFlavorBuildConfig(project, variant),
146
+ project.buildConfig)
147
+ .filterNotNull()
148
+
149
+ return result
150
+ }
151
151
152
152
/* *
153
153
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
154
154
* product flavor or main project, and use them to generateAndSave any additional field (in that order to
155
155
* respect the priorities). Return the generated file if it was generated, null otherwise.
156
156
*/
157
- // fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
158
- // val buildConfigs = findBuildConfigs(project, this)
159
- //
160
- // if (buildConfigs.size > 0) {
161
- // val pkg = project.packageName ?: project.group
162
- // ?: throw KobaltException(
163
- // "packageName needs to be defined on the project in order to generateAndSave BuildConfig")
164
- //
165
- // val contributor = ActorUtils.selectAffinityActor(context.pluginInfo.buildConfigContributors, project)
166
- // if (contributor != null) {
167
- // val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs)
168
- // val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig"))
169
- // // Make sure the generatedSourceDirectory doesn't contain the project.directory since
170
- // // that directory will be added when trying to find recursively all the sources in it
171
- // generatedSourceDirectory = result.relativeTo(File(project.directory))
172
- // val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
173
- // val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix)
174
- // KFiles.saveFile(outputDir, code)
175
- // context.logger.log(project.name, 2, "Generated ${outputDir.path}")
176
- // return result
177
- // } else {
178
- // throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig")
179
- // }
180
- // } else {
181
- // return null
182
- // }
183
- // }
157
+ fun maybeGenerateBuildConfig (project : Project , context : KobaltContext ) : File ? {
158
+ val buildConfigs = findBuildConfigs(project, this )
159
+
160
+ if (buildConfigs.size > 0 ) {
161
+ val pkg = project.packageName ? : project.group
162
+ ? : throw KobaltException (
163
+ " packageName needs to be defined on the project in order to generateAndSave BuildConfig" )
164
+
165
+ val contributor = ActorUtils .selectAffinityActor(project, context,
166
+ context.pluginInfo.buildConfigContributors)
167
+ if (contributor != null ) {
168
+ val code = contributor.generateBuildConfig(project, context, pkg, this , buildConfigs)
169
+ val result = KFiles .makeDir(KFiles .generatedSourceDir(project, this , " buildConfig" ))
170
+ // Make sure the generatedSourceDirectory doesn't contain the project.directory since
171
+ // that directory will be added when trying to find recursively all the sources in it
172
+ generatedSourceDirectory = result.relativeTo(File (project.directory))
173
+ val outputGeneratedSourceDirectory = File (result, pkg.replace(' .' , File .separatorChar))
174
+ val outputDir = File (outputGeneratedSourceDirectory, " BuildConfig." + contributor.buildConfigSuffix)
175
+ KFiles .saveFile(outputDir, code)
176
+ context.logger.log(project.name, 2 , " Generated ${outputDir.path} " )
177
+ return result
178
+ } else {
179
+ throw KobaltException (" Couldn't find a contributor to generateAndSave BuildConfig" )
180
+ }
181
+ } else {
182
+ return null
183
+ }
184
+ }
184
185
185
186
override fun toString () = toTask(" " )
186
187
0 commit comments