mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
IBuildConfigContributor.
Step toward removing javaProject/kotlinProject.
This commit is contained in:
parent
08f5fcd04b
commit
691e59f0cb
10 changed files with 63 additions and 27 deletions
|
@ -139,18 +139,23 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
?: throw KobaltException(
|
||||
"packageName needs to be defined on the project in order to generate BuildConfig")
|
||||
|
||||
val code = project.projectInfo.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 = File(result.relativeTo(File(project.directory)))
|
||||
val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
|
||||
val compilers = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||
val outputDir = File(outputGeneratedSourceDirectory,
|
||||
"BuildConfig" + compilers[0].sourceSuffixes[0])
|
||||
KFiles.saveFile(outputDir, code)
|
||||
log(2, "Generated ${outputDir.path}")
|
||||
return result
|
||||
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 = File(result.relativeTo(File(project.directory)))
|
||||
val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
|
||||
val compilers = ActorUtils.selectAffinityActors(project, context, context.pluginInfo.compilerContributors)
|
||||
val outputDir = File(outputGeneratedSourceDirectory,
|
||||
"BuildConfig" + compilers[0].sourceSuffixes[0])
|
||||
KFiles.saveFile(outputDir, code)
|
||||
log(2, "Generated ${outputDir.path}")
|
||||
return result
|
||||
} else {
|
||||
throw KobaltException("Couldn't find a contributor to generate BuildConfig")
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.Variant
|
||||
|
||||
/**
|
||||
* Plug-ins that can generate a BuildConfig file.
|
||||
*/
|
||||
interface IBuildConfigContributor : ISimpleAffinity<Project> {
|
||||
fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
|
||||
buildConfigs: List<BuildConfig>) : String
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.beust.kobalt.api
|
|||
|
||||
import com.beust.kobalt.TestConfig
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.internal.IProjectInfo
|
||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import java.io.File
|
||||
|
@ -21,8 +20,7 @@ open class Project(
|
|||
@Directive open var scm : Scm? = null,
|
||||
@Directive open var url: String? = null,
|
||||
@Directive open var licenses: List<License> = arrayListOf<License>(),
|
||||
@Directive open var packageName: String? = group,
|
||||
val projectInfo: IProjectInfo) : IBuildConfig {
|
||||
@Directive open var packageName: String? = group) : IBuildConfig {
|
||||
|
||||
class ProjectExtra(project: Project) {
|
||||
val suffixesFound : Set<String> by lazy {
|
||||
|
|
|
@ -75,6 +75,8 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
val buildConfigFieldContributors = arrayListOf<IBuildConfigFieldContributor>()
|
||||
val taskContributors = arrayListOf<ITaskContributor>()
|
||||
|
||||
// Not documented yet
|
||||
val buildConfigContributors = arrayListOf<IBuildConfigContributor>()
|
||||
val mavenIdInterceptors = arrayListOf<IMavenIdInterceptor>()
|
||||
|
||||
companion object {
|
||||
|
@ -158,6 +160,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
// Not documented yet
|
||||
if (this is IMavenIdInterceptor) mavenIdInterceptors.add(this)
|
||||
if (this is ITestSourceDirectoryContributor) testSourceDirContributors.add(this)
|
||||
if (this is IBuildConfigContributor) buildConfigContributors.add(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,6 +190,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) {
|
|||
taskContributors.addAll(pluginInfo.taskContributors)
|
||||
testSourceDirContributors.addAll(pluginInfo.testSourceDirContributors)
|
||||
mavenIdInterceptors.addAll(pluginInfo.mavenIdInterceptors)
|
||||
buildConfigContributors.addAll(pluginInfo.buildConfigContributors)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue