mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 07:57:12 -07:00
BuildConfig not being generated. (#464).
This commit is contained in:
parent
294799ee5d
commit
3d2e5b069d
5 changed files with 55 additions and 48 deletions
|
@ -126,61 +126,62 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
|
||||
var generatedSourceDirectory: File? = null
|
||||
|
||||
// private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
|
||||
// val buildTypeName = variant?.buildType?.name
|
||||
// return project.buildTypes[buildTypeName]?.buildConfig
|
||||
// }
|
||||
//
|
||||
// private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
|
||||
// val buildTypeName = variant?.productFlavor?.name
|
||||
// return project.productFlavors[buildTypeName]?.buildConfig
|
||||
// }
|
||||
private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
|
||||
val buildTypeName = variant?.buildType?.name
|
||||
return project.buildTypes[buildTypeName]?.buildConfig
|
||||
}
|
||||
|
||||
private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
|
||||
val buildTypeName = variant?.productFlavor?.name
|
||||
return project.productFlavors[buildTypeName]?.buildConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of the BuildConfigs found on the productFlavor{}, buildType{} and project{} (in that order).
|
||||
*/
|
||||
// private fun findBuildConfigs(project: Project, variant: Variant?) : List<BuildConfig> {
|
||||
// val result = listOf(
|
||||
// findBuildTypeBuildConfig(project, variant),
|
||||
// findProductFlavorBuildConfig(project, variant),
|
||||
// project.buildConfig)
|
||||
// .filterNotNull()
|
||||
//
|
||||
// return result
|
||||
// }
|
||||
private fun findBuildConfigs(project: Project, variant: Variant?) : List<BuildConfig> {
|
||||
val result = listOf(
|
||||
findBuildTypeBuildConfig(project, variant),
|
||||
findProductFlavorBuildConfig(project, variant),
|
||||
project.buildConfig)
|
||||
.filterNotNull()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
|
||||
* product flavor or main project, and use them to generateAndSave any additional field (in that order to
|
||||
* respect the priorities). Return the generated file if it was generated, null otherwise.
|
||||
*/
|
||||
// fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
|
||||
// val buildConfigs = findBuildConfigs(project, this)
|
||||
//
|
||||
// if (buildConfigs.size > 0) {
|
||||
// val pkg = project.packageName ?: project.group
|
||||
// ?: throw KobaltException(
|
||||
// "packageName needs to be defined on the project in order to generateAndSave BuildConfig")
|
||||
//
|
||||
// val contributor = ActorUtils.selectAffinityActor(context.pluginInfo.buildConfigContributors, project)
|
||||
// if (contributor != null) {
|
||||
// val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs)
|
||||
// val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig"))
|
||||
// // Make sure the generatedSourceDirectory doesn't contain the project.directory since
|
||||
// // that directory will be added when trying to find recursively all the sources in it
|
||||
// generatedSourceDirectory = result.relativeTo(File(project.directory))
|
||||
// val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
|
||||
// val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix)
|
||||
// KFiles.saveFile(outputDir, code)
|
||||
// context.logger.log(project.name, 2, "Generated ${outputDir.path}")
|
||||
// return result
|
||||
// } else {
|
||||
// throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig")
|
||||
// }
|
||||
// } else {
|
||||
// return null
|
||||
// }
|
||||
// }
|
||||
fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
|
||||
val buildConfigs = findBuildConfigs(project, this)
|
||||
|
||||
if (buildConfigs.size > 0) {
|
||||
val pkg = project.packageName ?: project.group
|
||||
?: throw KobaltException(
|
||||
"packageName needs to be defined on the project in order to generateAndSave BuildConfig")
|
||||
|
||||
val contributor = ActorUtils.selectAffinityActor(project, context,
|
||||
context.pluginInfo.buildConfigContributors)
|
||||
if (contributor != null) {
|
||||
val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs)
|
||||
val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig"))
|
||||
// Make sure the generatedSourceDirectory doesn't contain the project.directory since
|
||||
// that directory will be added when trying to find recursively all the sources in it
|
||||
generatedSourceDirectory = result.relativeTo(File(project.directory))
|
||||
val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
|
||||
val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix)
|
||||
KFiles.saveFile(outputDir, code)
|
||||
context.logger.log(project.name, 2, "Generated ${outputDir.path}")
|
||||
return result
|
||||
} else {
|
||||
throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig")
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString() = toTask("")
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.beust.kobalt.Variant
|
|||
/**
|
||||
* Plug-ins that can generate a BuildConfig file.
|
||||
*/
|
||||
interface IBuildConfigContributor : ISimpleAffinity<Project> {
|
||||
interface IBuildConfigContributor : IProjectAffinity {
|
||||
fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
|
||||
buildConfigs: List<BuildConfig>) : String
|
||||
|
||||
|
|
|
@ -157,6 +157,10 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
if (compilerContributors.isEmpty()) {
|
||||
throw KobaltException("Couldn't find any compiler for project ${project.name}")
|
||||
} else {
|
||||
|
||||
// Generate BuildConfig if applicable
|
||||
context.variant.maybeGenerateBuildConfig(project, context)
|
||||
|
||||
val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted()
|
||||
|
||||
/**
|
||||
|
|
|
@ -239,7 +239,9 @@ class KotlinCompiler @Inject constructor(
|
|||
location: CompilerMessageLocation?) {
|
||||
if (severity.isError) {
|
||||
"Couldn't compile file: ${dump(location, message)}".let { fullMessage ->
|
||||
throw KobaltException(fullMessage)
|
||||
error(fullMessage)
|
||||
val ex = KobaltException(fullMessage)
|
||||
throw ex
|
||||
}
|
||||
} else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) {
|
||||
warn(dump(location, message))
|
||||
|
|
|
@ -105,7 +105,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val outputFile = jarGenerator.fullArchiveName(project, context, it.name)
|
||||
outputFiles.add(outputFile)
|
||||
allIncludedFiles.addAll(files)
|
||||
zipToFiles[it.name] = files
|
||||
zipToFiles[outputFile.name] = files
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue