1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Merge branch 'master' of github.com:cbeust/kobalt

This commit is contained in:
Cedric Beust 2017-12-09 09:00:09 -08:00
commit ae59e1d7ff
12 changed files with 81 additions and 57 deletions

View file

@ -1 +1 @@
kobalt.version=1.0.90 kobalt.version=1.0.92

View file

@ -67,7 +67,7 @@ open class Jvm constructor(
return toolsJar return toolsJar
} }
if (javaHome!!.name.equals("jre", true)) { if (javaHome!!.name.equals("jre", true)) {
javaHome = javaHome!!.parentFile _javaHome = javaHome!!.parentFile
toolsJar = File(javaHome, "lib/tools.jar") toolsJar = File(javaHome, "lib/tools.jar")
if (toolsJar.exists()) { if (toolsJar.exists()) {
return toolsJar return toolsJar
@ -78,7 +78,7 @@ open class Jvm constructor(
val version = SystemProperties.Companion.javaVersion val version = SystemProperties.Companion.javaVersion
if (javaHome!!.name.toRegex().matches("jre\\d+") if (javaHome!!.name.toRegex().matches("jre\\d+")
|| javaHome!!.name == "jre$version") { || javaHome!!.name == "jre$version") {
javaHome = File(javaHome!!.parentFile, "jdk$version") _javaHome = File(javaHome!!.parentFile, "jdk$version")
toolsJar = File(javaHome, "lib/tools.jar") toolsJar = File(javaHome, "lib/tools.jar")
if (toolsJar.exists()) { if (toolsJar.exists()) {
return toolsJar return toolsJar

View file

@ -126,61 +126,62 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
var generatedSourceDirectory: File? = null var generatedSourceDirectory: File? = null
// private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? { private fun findBuildTypeBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
// val buildTypeName = variant?.buildType?.name val buildTypeName = variant?.buildType?.name
// return project.buildTypes[buildTypeName]?.buildConfig return project.buildTypes[buildTypeName]?.buildConfig
// } }
//
// private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? { private fun findProductFlavorBuildConfig(project: Project, variant: Variant?) : BuildConfig? {
// val buildTypeName = variant?.productFlavor?.name val buildTypeName = variant?.productFlavor?.name
// return project.productFlavors[buildTypeName]?.buildConfig return project.productFlavors[buildTypeName]?.buildConfig
// } }
/** /**
* Return a list of the BuildConfigs found on the productFlavor{}, buildType{} and project{} (in that order). * 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> { private fun findBuildConfigs(project: Project, variant: Variant?) : List<BuildConfig> {
// val result = listOf( val result = listOf(
// findBuildTypeBuildConfig(project, variant), findBuildTypeBuildConfig(project, variant),
// findProductFlavorBuildConfig(project, variant), findProductFlavorBuildConfig(project, variant),
// project.buildConfig) project.buildConfig)
// .filterNotNull() .filterNotNull()
//
// return result return result
// } }
/** /**
* 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 generateAndSave 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? {
// val buildConfigs = findBuildConfigs(project, this) val buildConfigs = findBuildConfigs(project, this)
//
// 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 generateAndSave 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(project, context,
// if (contributor != null) { context.pluginInfo.buildConfigContributors)
// val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs) if (contributor != null) {
// val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig")) val code = contributor.generateBuildConfig(project, context, pkg, this, buildConfigs)
// // Make sure the generatedSourceDirectory doesn't contain the project.directory since val result = KFiles.makeDir(KFiles.generatedSourceDir(project, this, "buildConfig"))
// // that directory will be added when trying to find recursively all the sources in it // Make sure the generatedSourceDirectory doesn't contain the project.directory since
// generatedSourceDirectory = result.relativeTo(File(project.directory)) // that directory will be added when trying to find recursively all the sources in it
// val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar)) generatedSourceDirectory = result.relativeTo(File(project.directory))
// val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix) val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
// KFiles.saveFile(outputDir, code) val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix)
// context.logger.log(project.name, 2, "Generated ${outputDir.path}") KFiles.saveFile(outputDir, code)
// return result context.logger.log(project.name, 2, "Generated ${outputDir.path}")
// } else { return result
// throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig") } else {
// } throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig")
// } else { }
// return null } else {
// } return null
// } }
}
override fun toString() = toTask("") override fun toString() = toTask("")

View file

@ -5,7 +5,7 @@ import com.beust.kobalt.Variant
/** /**
* Plug-ins that can generate a BuildConfig file. * 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, fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
buildConfigs: List<BuildConfig>) : String buildConfigs: List<BuildConfig>) : String

View file

@ -18,7 +18,7 @@ class Archives {
const val JAR_NAME_WITH_MAIN_CLASS = "jarNameWithMainClass" const val JAR_NAME_WITH_MAIN_CLASS = "jarNameWithMainClass"
fun defaultArchiveName(project: Project) = project.name + fun defaultArchiveName(project: Project) = project.name +
if (project.version == null || project.version == "") "" else "-${project.version}" if (project.version.isNullOrBlank()) "" else "-${project.version}"
fun generateArchive(project: Project, fun generateArchive(project: Project,
context: KobaltContext, context: KobaltContext,

View file

@ -157,6 +157,10 @@ open class JvmCompilerPlugin @Inject constructor(
if (compilerContributors.isEmpty()) { if (compilerContributors.isEmpty()) {
throw KobaltException("Couldn't find any compiler for project ${project.name}") throw KobaltException("Couldn't find any compiler for project ${project.name}")
} else { } else {
// Generate BuildConfig if applicable
context.variant.maybeGenerateBuildConfig(project, context)
val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted() val allCompilers = compilerContributors.flatMap { it.compilersFor(project, context)}.sorted()
/** /**

View file

@ -19,6 +19,7 @@ class RunCommandInfo {
*/ */
var useErrorStreamAsErrorIndicator : Boolean = true var useErrorStreamAsErrorIndicator : Boolean = true
var useInputStreamAsErrorIndicator : Boolean = false var useInputStreamAsErrorIndicator : Boolean = false
var ignoreExitValue : Boolean = false
var errorCallback: Function1<List<String>, Unit> = NewRunCommand.DEFAULT_ERROR var errorCallback: Function1<List<String>, Unit> = NewRunCommand.DEFAULT_ERROR
var successCallback: Function1<List<String>, Unit> = NewRunCommand.DEFAULT_SUCCESS var successCallback: Function1<List<String>, Unit> = NewRunCommand.DEFAULT_SUCCESS
@ -89,10 +90,14 @@ open class NewRunCommand(val info: RunCommandInfo) {
// Check to see if the command succeeded // Check to see if the command succeeded
val isSuccess = val isSuccess =
if (info.containsErrors != null) ! info.containsErrors!!(error) if (info.containsErrors != null) ! info.containsErrors!!(error)
else isSuccess(returnCode, input, error) else isSuccess(if (info.ignoreExitValue) true else returnCode, input, error)
if (isSuccess) { if (isSuccess) {
info.successCallback(input) if (!info.useErrorStreamAsErrorIndicator) {
info.successCallback(error + input)
} else {
info.successCallback(input)
}
} else { } else {
info.errorCallback(error + input) info.errorCallback(error + input)
} }
@ -105,7 +110,7 @@ open class NewRunCommand(val info: RunCommandInfo) {
* have various ways to signal errors. * have various ways to signal errors.
*/ */
open protected fun isSuccess(isSuccess: Boolean, input: List<String>, error: List<String>) : Boolean { open protected fun isSuccess(isSuccess: Boolean, input: List<String>, error: List<String>) : Boolean {
var hasErrors = ! isSuccess var hasErrors: Boolean = ! isSuccess
if (info.useErrorStreamAsErrorIndicator && ! hasErrors) { if (info.useErrorStreamAsErrorIndicator && ! hasErrors) {
hasErrors = hasErrors || error.isNotEmpty() hasErrors = hasErrors || error.isNotEmpty()
} }

View file

@ -56,7 +56,7 @@ class Profiles(val context: KobaltContext) {
val variable = if (match.first) match.second else oldMatch.second val variable = if (match.first) match.second else oldMatch.second
if (oldMatch.first) { if (oldMatch.first) {
warn("Old profile syntax detected for \"$line\"," + warn("Old profile syntax detected for \"${line.trim()}\"," +
" please update to \"val $variable by profile()\"") " please update to \"val $variable by profile()\"")
} }

View file

@ -33,6 +33,15 @@ class ApplicationConfig {
@Directive @Directive
fun args(vararg argv: String) = argv.forEach { args.add(it) } fun args(vararg argv: String) = argv.forEach { args.add(it) }
val args = arrayListOf<String>() val args = arrayListOf<String>()
@Directive
var ignoreErrorStream: Boolean = false
@Directive
var ignoreInputStream: Boolean = true
@Directive
var ignoreExitValue: Boolean = false
} }
@Directive @Directive
@ -147,6 +156,9 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigsActor<Applic
kobaltLog(1, "ERROR") kobaltLog(1, "ERROR")
kobaltLog(1, output.joinToString("\n")) kobaltLog(1, output.joinToString("\n"))
} }
useErrorStreamAsErrorIndicator = !config.ignoreErrorStream
useInputStreamAsErrorIndicator = !config.ignoreInputStream
ignoreExitValue = config.ignoreExitValue
} }
return TaskResult(exitCode == 0) return TaskResult(exitCode == 0)
} }

View file

@ -239,7 +239,9 @@ class KotlinCompiler @Inject constructor(
location: CompilerMessageLocation?) { location: CompilerMessageLocation?) {
if (severity.isError) { if (severity.isError) {
"Couldn't compile file: ${dump(location, message)}".let { fullMessage -> "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) { } else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) {
warn(dump(location, message)) warn(dump(location, message))

View file

@ -105,7 +105,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
val outputFile = jarGenerator.fullArchiveName(project, context, it.name) val outputFile = jarGenerator.fullArchiveName(project, context, it.name)
outputFiles.add(outputFile) outputFiles.add(outputFile)
allIncludedFiles.addAll(files) allIncludedFiles.addAll(files)
zipToFiles[it.name] = files zipToFiles[outputFile.name] = files
} }
} }
} }

View file

@ -1 +1 @@
kobalt.version=1.0.90 kobalt.version=1.0.92