mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Refactor PomGenerator.
This commit is contained in:
parent
095a3918f1
commit
5df0d01a21
8 changed files with 29 additions and 20 deletions
|
@ -125,7 +125,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Generate the manifest
|
// Generate the manifest
|
||||||
// If manifest attributes were specified in the build file, use those to generate the manifest. Otherwise,
|
// If manifest attributes were specified in the build file, use those to generateAndSave the manifest. Otherwise,
|
||||||
// try to find a META-INF/MANIFEST.MF and use that one if we find any. Otherwise, use the default manifest.
|
// try to find a META-INF/MANIFEST.MF and use that one if we find any. Otherwise, use the default manifest.
|
||||||
//
|
//
|
||||||
val manifest =
|
val manifest =
|
||||||
|
|
|
@ -154,7 +154,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate BuildConfig.java if requested. Also look up if any BuildConfig is defined on the current build type,
|
* 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 generate any additional field (in that order to
|
* 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.
|
* respect the priorities). Return the generated file if it was generated, null otherwise.
|
||||||
*/
|
*/
|
||||||
fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
|
fun maybeGenerateBuildConfig(project: Project, context: KobaltContext) : File? {
|
||||||
|
@ -163,7 +163,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
if (buildConfigs.size > 0) {
|
if (buildConfigs.size > 0) {
|
||||||
val pkg = project.packageName ?: project.group
|
val pkg = project.packageName ?: project.group
|
||||||
?: throw KobaltException(
|
?: throw KobaltException(
|
||||||
"packageName needs to be defined on the project in order to generate BuildConfig")
|
"packageName needs to be defined on the project in order to generateAndSave BuildConfig")
|
||||||
|
|
||||||
val contributor = ActorUtils.selectAffinityActor(context.pluginInfo.buildConfigContributors, project)
|
val contributor = ActorUtils.selectAffinityActor(context.pluginInfo.buildConfigContributors, project)
|
||||||
if (contributor != null) {
|
if (contributor != null) {
|
||||||
|
@ -178,7 +178,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
log(2, "Generated ${outputDir.path}")
|
log(2, "Generated ${outputDir.path}")
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
throw KobaltException("Couldn't find a contributor to generate BuildConfig")
|
throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -46,7 +46,7 @@ open class Project(
|
||||||
|
|
||||||
val testConfigs = arrayListOf<TestConfig>()
|
val testConfigs = arrayListOf<TestConfig>()
|
||||||
|
|
||||||
// If one is specified by default, we only generate a BuildConfig, find a way to fix that
|
// If one is specified by default, we only generateAndSave a BuildConfig, find a way to fix that
|
||||||
override var buildConfig : BuildConfig? = null // BuildConfig()
|
override var buildConfig : BuildConfig? = null // BuildConfig()
|
||||||
|
|
||||||
val projectProperties = ProjectProperties()
|
val projectProperties = ProjectProperties()
|
||||||
|
|
|
@ -12,7 +12,7 @@ import com.beust.kobalt.api.Project
|
||||||
interface IBuildConfig {
|
interface IBuildConfig {
|
||||||
/**
|
/**
|
||||||
* If at least one build config was found either on the project or the variant, this function
|
* If at least one build config was found either on the project or the variant, this function
|
||||||
* will be used to generate the BuildConfig file with the correct language.
|
* will be used to generateAndSave the BuildConfig file with the correct language.
|
||||||
*/
|
*/
|
||||||
fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
|
fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
|
||||||
buildConfigs: List<BuildConfig>) : String
|
buildConfigs: List<BuildConfig>) : String
|
||||||
|
|
|
@ -18,7 +18,25 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) {
|
||||||
fun create(project: Project) : PomGenerator
|
fun create(project: Project) : PomGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generate() {
|
/**
|
||||||
|
* Generate the POM file and save it.
|
||||||
|
*/
|
||||||
|
fun generateAndSave() {
|
||||||
|
val buildDir = KFiles.makeDir(project.directory, project.buildDirectory)
|
||||||
|
val outputDir = KFiles.makeDir(buildDir.path, "libs")
|
||||||
|
val NO_CLASSIFIER = null
|
||||||
|
val mavenId = MavenId.create(project.group!!, project.artifactId!!, project.packaging, NO_CLASSIFIER,
|
||||||
|
project.version!!)
|
||||||
|
val pomFile = SimpleDep(mavenId).toPomFileName()
|
||||||
|
val outputFile = File(outputDir, pomFile)
|
||||||
|
outputFile.writeText(generate(), Charset.defaultCharset())
|
||||||
|
log(1, " Created $outputFile")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the text content of the POM file.
|
||||||
|
*/
|
||||||
|
fun generate() : String {
|
||||||
requireNotNull(project.version, { "version mandatory on project ${project.name}" })
|
requireNotNull(project.version, { "version mandatory on project ${project.name}" })
|
||||||
requireNotNull(project.group, { "group mandatory on project ${project.name}" })
|
requireNotNull(project.group, { "group mandatory on project ${project.name}" })
|
||||||
requireNotNull(project.artifactId, { "artifactId mandatory on project ${project.name}" })
|
requireNotNull(project.artifactId, { "artifactId mandatory on project ${project.name}" })
|
||||||
|
@ -60,15 +78,6 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) {
|
||||||
|
|
||||||
val s = StringWriter()
|
val s = StringWriter()
|
||||||
MavenXpp3Writer().write(s, pom)
|
MavenXpp3Writer().write(s, pom)
|
||||||
|
return s.toString()
|
||||||
val buildDir = KFiles.makeDir(project.directory, project.buildDirectory)
|
|
||||||
val outputDir = KFiles.makeDir(buildDir.path, "libs")
|
|
||||||
val NO_CLASSIFIER = null
|
|
||||||
val mavenId = MavenId.create(project.group!!, project.artifactId!!, project.packaging, NO_CLASSIFIER,
|
|
||||||
project.version!!)
|
|
||||||
val pomFile = SimpleDep(mavenId).toPomFileName()
|
|
||||||
val outputFile = File(outputDir, pomFile)
|
|
||||||
outputFile.writeText(s.toString(), Charset.defaultCharset())
|
|
||||||
log(1, " Created $outputFile")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
packageConfig.wars.forEach { warGenerator.generateWar(packageConfig.project, context, it) }
|
packageConfig.wars.forEach { warGenerator.generateWar(packageConfig.project, context, it) }
|
||||||
packageConfig.zips.forEach { zipGenerator.generateZip(packageConfig.project, context, it) }
|
packageConfig.zips.forEach { zipGenerator.generateZip(packageConfig.project, context, it) }
|
||||||
if (packageConfig.generatePom) {
|
if (packageConfig.generatePom) {
|
||||||
pomFactory.create(project).generate()
|
pomFactory.create(project).generateAndSave()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TaskResult()
|
TaskResult()
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
||||||
@Suppress("UNUSED_FUNCTION_LITERAL")
|
@Suppress("UNUSED_FUNCTION_LITERAL")
|
||||||
@Task(name = TASK_GENERATE_POM, description = "Generate the .pom file", dependsOn = arrayOf("assemble"))
|
@Task(name = TASK_GENERATE_POM, description = "Generate the .pom file", dependsOn = arrayOf("assemble"))
|
||||||
fun taskGeneratePom(project: Project): TaskResult {
|
fun taskGeneratePom(project: Project): TaskResult {
|
||||||
factory.create(project).generate()
|
factory.create(project).generateAndSave()
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class VariantTest : KobaltTest() {
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test(dataProvider = "projectVariants", description =
|
@Test(dataProvider = "projectVariants", description =
|
||||||
"Make sure we generate the correct dynamic tasks based on the product flavor and build types.")
|
"Make sure we generateAndSave the correct dynamic tasks based on the product flavor and build types.")
|
||||||
fun taskNamesShouldWork(expected: Set<String>, project: Project) {
|
fun taskNamesShouldWork(expected: Set<String>, project: Project) {
|
||||||
val variantNames = HashSet(Variant.allVariants(project).map { it.toTask("compile") })
|
val variantNames = HashSet(Variant.allVariants(project).map { it.toTask("compile") })
|
||||||
Assert.assertEquals(variantNames, expected)
|
Assert.assertEquals(variantNames, expected)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue