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