mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Fix Variant bug.
This commit is contained in:
parent
f60ab09594
commit
49041faa98
11 changed files with 48 additions and 43 deletions
|
@ -30,11 +30,11 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
* for {internal, release}, return [internalRelease, internal, release]
|
||||
*/
|
||||
fun allDirectories(project: Project): List<String> {
|
||||
val result = arrayListOf<String>()
|
||||
result.add(toCamelcaseDir())
|
||||
if (productFlavor != null) result.add(productFlavor.name)
|
||||
if (buildType != null) result.add(buildType.name)
|
||||
return result
|
||||
return arrayListOf<String>().apply {
|
||||
add(toCamelcaseDir())
|
||||
add(productFlavor.name)
|
||||
add(buildType.name)
|
||||
}
|
||||
}
|
||||
|
||||
fun sourceDirectories(project: Project, context: KobaltContext, sourceSet: SourceSet) : List<File> {
|
||||
|
@ -187,9 +187,10 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
|
||||
override fun toString() = toTask("")
|
||||
|
||||
|
||||
companion object {
|
||||
val DEFAULT_PRODUCT_FLAVOR = ProductFlavorConfig(null, "")
|
||||
val DEFAULT_BUILD_TYPE = BuildTypeConfig(null, "")
|
||||
val DEFAULT_PRODUCT_FLAVOR = ProductFlavorConfig("")
|
||||
val DEFAULT_BUILD_TYPE = BuildTypeConfig("")
|
||||
|
||||
fun allVariants(project: Project): List<Variant> {
|
||||
val result = arrayListOf<Variant>()
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
class BuildTypeConfig(val name: String) : IBuildConfig, IDependencyHolder by DependencyHolder() {
|
||||
|
||||
class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig,
|
||||
IDependencyHolder by DependencyHolder(project) {
|
||||
var minifyEnabled = false
|
||||
var applicationIdSuffix: String? = null
|
||||
var proguardFile: String? = null
|
||||
|
@ -11,9 +9,3 @@ class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig,
|
|||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.buildType(name: String, init: BuildTypeConfig.() -> Unit) = BuildTypeConfig(this, name).apply {
|
||||
init()
|
||||
addBuildType(name, this)
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@ import java.util.*
|
|||
|
||||
/**
|
||||
* Various elements in a build file let you specify dependencies: projects, buildType and productFlavor.
|
||||
* They all implement this interface and delegate to an instance of the concrete class below.
|
||||
* They all implement this interface and delegate to an instance of the `DependencyHolder` concrete class.
|
||||
*/
|
||||
interface IDependencyHolder {
|
||||
var project: Project
|
||||
|
||||
val compileDependencies : ArrayList<IClasspathDependency>
|
||||
val compileProvidedDependencies : ArrayList<IClasspathDependency>
|
||||
val compileRuntimeDependencies : ArrayList<IClasspathDependency>
|
||||
|
@ -20,7 +22,8 @@ interface IDependencyHolder {
|
|||
fun dependencies(init: Dependencies.() -> Unit) : Dependencies
|
||||
}
|
||||
|
||||
open class DependencyHolder(val project: Project?) : IDependencyHolder {
|
||||
open class DependencyHolder : IDependencyHolder {
|
||||
override lateinit var project: Project
|
||||
override val compileDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val compileProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val compileRuntimeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
|
@ -29,7 +32,7 @@ open class DependencyHolder(val project: Project?) : IDependencyHolder {
|
|||
override var dependencies : Dependencies? = null
|
||||
|
||||
override fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
|
||||
dependencies = Dependencies(project!!, compileDependencies, compileProvidedDependencies,
|
||||
dependencies = Dependencies(project, compileDependencies, compileProvidedDependencies,
|
||||
compileRuntimeDependencies, excludedDependencies)
|
||||
dependencies!!.init()
|
||||
return dependencies!!
|
||||
|
|
|
@ -7,7 +7,7 @@ interface IDependencyManager {
|
|||
/**
|
||||
* Parse the id and return the correct IClasspathDependency
|
||||
*/
|
||||
fun create(id: String, project: Project? = null): IClasspathDependency
|
||||
fun create(id: String, projectDirectory: String? = null): IClasspathDependency
|
||||
|
||||
/**
|
||||
* Create an IClasspathDependency from a Maven id.
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.beust.kobalt.misc.KobaltExecutors
|
|||
import java.io.File
|
||||
|
||||
class KobaltContext(val args: Args) {
|
||||
var variant: Variant = Variant()
|
||||
lateinit var variant: Variant
|
||||
val profiles = arrayListOf<String>()
|
||||
|
||||
init {
|
||||
|
|
|
@ -1,17 +1,9 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
|
||||
class ProductFlavorConfig(val project: Project?, val name: String) : IBuildConfig,
|
||||
IDependencyHolder by DependencyHolder(project) {
|
||||
class ProductFlavorConfig(val name: String) : IBuildConfig,
|
||||
IDependencyHolder by DependencyHolder() {
|
||||
var applicationId: String? = null
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) = ProductFlavorConfig(this, name).apply {
|
||||
init()
|
||||
addProductFlavor(name, this)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,11 @@ open class Project(
|
|||
@Directive open var url: String? = null,
|
||||
@Directive open var licenses: List<License> = arrayListOf<License>(),
|
||||
@Directive open var packageName: String? = group)
|
||||
: IBuildConfig, IDependencyHolder by DependencyHolder(null) {
|
||||
: IBuildConfig, IDependencyHolder by DependencyHolder() {
|
||||
|
||||
init {
|
||||
this.project = this
|
||||
}
|
||||
|
||||
class ProjectExtra(project: Project) {
|
||||
val dependsOn = arrayListOf<Project>()
|
||||
|
@ -142,7 +146,7 @@ class Dependencies(val project: Project,
|
|||
*/
|
||||
private fun addToDependencies(project: Project, dependencies: ArrayList<IClasspathDependency>,
|
||||
dep: Array<out String>): List<Future<File>>
|
||||
= with(dep.map { DependencyManager.create(it, project)}) {
|
||||
= with(dep.map { DependencyManager.create(it, project.directory)}) {
|
||||
dependencies.addAll(this)
|
||||
this.map { FutureTask { it.jarFile.get() } }
|
||||
}
|
||||
|
@ -201,3 +205,16 @@ fun Project.defaultConfig(init: BuildConfig.() -> Unit) = let { project ->
|
|||
project.defaultConfig = this
|
||||
}
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.buildType(name: String, init: BuildTypeConfig.() -> Unit) = BuildTypeConfig(name).apply {
|
||||
init()
|
||||
addBuildType(name, this)
|
||||
}
|
||||
|
||||
|
||||
@Directive
|
||||
fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) = ProductFlavorConfig(name).apply {
|
||||
init()
|
||||
addProductFlavor(name, this)
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ class IncrementalManager @Inject constructor(val args: Args, @Assisted val fileN
|
|||
* on the content of that IncrementalTaskInfo
|
||||
*/
|
||||
fun toIncrementalTaskClosure(shortTaskName: String, method: (Project) -> IncrementalTaskInfo,
|
||||
variant: Variant = Variant()): (Project) -> TaskResult {
|
||||
variant: Variant): (Project) -> TaskResult {
|
||||
return { project: Project ->
|
||||
Kobalt.context?.variant = variant
|
||||
val iti = method(project)
|
||||
|
|
|
@ -320,7 +320,7 @@ class TaskManager @Inject constructor(val args: Args,
|
|||
ta.runBefore, ta.runAfter, ta.alwaysRunAfter,
|
||||
incrementalManagerFactory.create().toIncrementalTaskClosure(ta.name, { project ->
|
||||
method.invoke(plugin, project) as IncrementalTaskInfo
|
||||
}))
|
||||
}, Variant()))
|
||||
|
||||
/** Tasks annotated with @Task or @IncrementalTask */
|
||||
val annotationTasks = arrayListOf<PluginTask>()
|
||||
|
|
|
@ -18,22 +18,22 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
|
|||
: IDependencyManager {
|
||||
|
||||
companion object {
|
||||
fun create(id: String, project: Project? = null) =
|
||||
Kobalt.INJECTOR.getInstance(DependencyManager::class.java).create(id, project)
|
||||
fun create(id: String, projectDirectory: String? = null) =
|
||||
Kobalt.INJECTOR.getInstance(DependencyManager::class.java).create(id, projectDirectory)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the id and return the correct IClasspathDependency
|
||||
*/
|
||||
override fun create(id: String, project: Project?) : IClasspathDependency {
|
||||
override fun create(id: String, projectDirectory: String?) : IClasspathDependency {
|
||||
if (id.startsWith(FileDependency.PREFIX_FILE)) {
|
||||
val path = if (project?.directory != null) {
|
||||
val path = if (projectDirectory != null) {
|
||||
val idPath = id.substring(FileDependency.PREFIX_FILE.length)
|
||||
if (! File(idPath).isAbsolute) {
|
||||
// If the project directory is relative, we might not be in the correct directory to locate
|
||||
// that file, so we'll use the absolute directory deduced from the build file path. Pick
|
||||
// the first one that produces an actual file
|
||||
val result = listOf(File(project!!.directory), Kobalt.context?.internalContext?.absoluteDir).map {
|
||||
val result = listOf(File(projectDirectory), Kobalt.context?.internalContext?.absoluteDir).map {
|
||||
File(it, idPath)
|
||||
}.first {
|
||||
it.exists()
|
||||
|
|
|
@ -17,12 +17,12 @@ public class CheckVersions @Inject constructor(val depManager: DependencyManager
|
|||
val executor = executors.newExecutor("CheckVersions", 5)
|
||||
|
||||
val newVersions = hashSetOf<String>()
|
||||
projects.forEach {
|
||||
listOf(it.compileDependencies, it.testDependencies).forEach { cds ->
|
||||
projects.forEach { project ->
|
||||
listOf(project.compileDependencies, project.testDependencies).forEach { cds ->
|
||||
cds.forEach { compileDependency ->
|
||||
if (MavenId.isMavenId(compileDependency.id)) {
|
||||
try {
|
||||
val dep = depManager.create(compileDependency.shortId)
|
||||
val dep = depManager.create(compileDependency.shortId, project.directory)
|
||||
val other = compileDependency as AetherDependency
|
||||
if (dep.id != compileDependency.id
|
||||
&& Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue