Skip to content

Commit 3d2e5b0

Browse files
committed
BuildConfig not being generated. (#464).
1 parent 294799e commit 3d2e5b0

File tree

5 files changed

+55
-48
lines changed

5 files changed

+55
-48
lines changed

modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt

+46-45
Original file line numberDiff line numberDiff line change
@@ -126,61 +126,62 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
126126

127127
var generatedSourceDirectory: File? = null
128128

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+
}
138138

139139
/**
140140
* Return a list of the BuildConfigs found on the productFlavor{}, buildType{} and project{} (in that order).
141141
*/
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+
}
151151

152152
/**
153153
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
154154
* product flavor or main project, and use them to generateAndSave any additional field (in that order to
155155
* respect the priorities). Return the generated file if it was generated, null otherwise.
156156
*/
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+
}
184185

185186
override fun toString() = toTask("")
186187

modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigContributor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.beust.kobalt.Variant
55
/**
66
* Plug-ins that can generate a BuildConfig file.
77
*/
8-
interface IBuildConfigContributor : ISimpleAffinity<Project> {
8+
interface IBuildConfigContributor : IProjectAffinity {
99
fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
1010
buildConfigs: List<BuildConfig>) : String
1111

modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ open class JvmCompilerPlugin @Inject constructor(
157157
if (compilerContributors.isEmpty()) {
158158
throw KobaltException("Couldn't find any compiler for project ${project.name}")
159159
} else {
160+
161+
// Generate BuildConfig if applicable
162+
context.variant.maybeGenerateBuildConfig(project, context)
163+
160164
val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted()
161165

162166
/**

src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ class KotlinCompiler @Inject constructor(
239239
location: CompilerMessageLocation?) {
240240
if (severity.isError) {
241241
"Couldn't compile file: ${dump(location, message)}".let { fullMessage ->
242-
throw KobaltException(fullMessage)
242+
error(fullMessage)
243+
val ex = KobaltException(fullMessage)
244+
throw ex
243245
}
244246
} else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) {
245247
warn(dump(location, message))

src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
105105
val outputFile = jarGenerator.fullArchiveName(project, context, it.name)
106106
outputFiles.add(outputFile)
107107
allIncludedFiles.addAll(files)
108-
zipToFiles[it.name] = files
108+
zipToFiles[outputFile.name] = files
109109
}
110110
}
111111
}

0 commit comments

Comments
 (0)