diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 368ef2b6..db448912 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -25,30 +25,41 @@ open class Project( val projectInfo: IProjectInfo) : IBuildConfig { class ProjectExtra(project: Project) { - val suffixesFound = hashSetOf() - - init { + val suffixesFound : Set by lazy { + val sf = hashSetOf() Kobalt.context?.let { project.sourceDirectories.forEach { source -> val sourceDir = File(KFiles.joinDir(project.directory, source)) KFiles.findRecursively(sourceDir, { file -> val ind = file.lastIndexOf(".") if (ind >= 0) { - suffixesFound.add(file.substring(ind + 1)) + sf.add(file.substring(ind + 1)) } false }) } - println("Suffixes: " + suffixesFound) } + sf + } + + val dependsOn = arrayListOf() + + var isDirty = false + + /** + * @return true if any of the projects we depend on is dirty. + */ + fun dependsOnDirtyProjects(project: Project) = project.projectExtra.dependsOn.any { it.projectExtra.isDirty } + + init { } } /** - * Initialized as soon as all the projects are parsed. This field caches a bunch of things we don't - * want to recalculate all the time, such as the list of suffixes found in this project. + * This field caches a bunch of things we don't want to recalculate all the time, such as the list of suffixes + * found in this project. */ - lateinit var projectExtra : ProjectExtra + val projectExtra = ProjectExtra(this) val testConfigs = arrayListOf(TestConfig(this)) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseJvmPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseJvmPlugin.kt index 6a61596d..d9d80c27 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseJvmPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseJvmPlugin.kt @@ -15,7 +15,7 @@ abstract class BaseJvmPlugin: ConfigPlugin(), IProjectContributor, ICompil private val allProjects = arrayListOf() fun addDependentProjects(project: Project, dependents: List) { - project.projectInfo.dependsOn.addAll(dependents) + project.projectExtra.dependsOn.addAll(dependents) with(ProjectDescription(project, dependents)) { allProjects.add(this) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt index a6df859a..3968e5d6 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt @@ -82,7 +82,7 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI var upToDate = false var taskOutputChecksum : String? = null inputChecksumFor(taskName)?.let { inputChecksum -> - val dependsOnDirtyProjects = project.projectInfo.dependsOnDirtyProjects(project) + val dependsOnDirtyProjects = project.projectExtra.dependsOnDirtyProjects(project) if (inputChecksum == iit.inputChecksum && ! dependsOnDirtyProjects) { outputChecksumFor(taskName)?.let { outputChecksum -> taskOutputChecksum = iit.outputChecksum() @@ -99,7 +99,7 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI logIncremental(2, "Incremental task $taskName input is out of date, running it" + " old: $inputChecksum new: ${iit.inputChecksum}") } - project.projectInfo.isDirty = true + project.projectExtra.isDirty = true } } if (! upToDate) { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt index 795883c5..e16e8421 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt @@ -5,7 +5,6 @@ import com.beust.kobalt.api.BuildConfig import com.beust.kobalt.api.BuildConfigField import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project -import java.util.* /** * Data that is useful for projects to have but should not be specified in the DSL. @@ -18,17 +17,6 @@ interface IProjectInfo { fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant, buildConfigs: List) : String - /** - * The list of projects that this project depends on - */ - val dependsOn: ArrayList - - var isDirty: Boolean - - /** - * @return true if any of the projects we depend on is dirty. - */ - fun dependsOnDirtyProjects(project: Project) = project.projectInfo.dependsOn.any { it.projectInfo.isDirty } } abstract class BaseProjectInfo : IProjectInfo { @@ -42,8 +30,4 @@ abstract class BaseProjectInfo : IProjectInfo { }.map { generate(it) } - - override val dependsOn = arrayListOf() - - override var isDirty = false } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index 784d3e6b..2d25e1ba 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -59,7 +59,7 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana AsciiArt.logBox("Building ${project.name}") // Does the current project depend on any failed projects? - val fp = project.projectInfo.dependsOn.filter { + val fp = project.projectExtra.dependsOn.filter { failedProjects.contains(it.name) }.map { it.name diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index f516c036..a2ce54be 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -117,7 +117,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor */ fun dependencies(project: Project, context: KobaltContext) : List { val result = arrayListOf() - val projects = listOf(ProjectDescription(project, project.projectInfo.dependsOn)) + val projects = listOf(ProjectDescription(project, project.projectExtra.dependsOn)) result.add(FileDependency(KFiles.makeOutputDir(project).absolutePath)) result.add(FileDependency(KFiles.makeOutputTestDir(project).absolutePath)) with(project) { @@ -134,7 +134,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor */ fun testDependencies(project: Project, context: KobaltContext) : List { val result = arrayListOf() - val projects = listOf(ProjectDescription(project, project.projectInfo.dependsOn)) + val projects = listOf(ProjectDescription(project, project.projectExtra.dependsOn)) result.add(FileDependency(KFiles.makeOutputDir(project).absolutePath)) result.add(FileDependency(KFiles.makeOutputTestDir(project).absolutePath)) with(project) { diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index d76a3247..6c59fe37 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -55,9 +55,6 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b // Find all the projects in the build file, possibly compiling them // val allProjects = findProjects(context) - allProjects.forEach { - it.projectExtra = Project.ProjectExtra(it) - } plugins.applyPlugins(context, allProjects) return allProjects diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt index ec1c7c09..90730d21 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/WarGenerator.kt @@ -31,7 +31,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager) // The transitive closure of libraries goes into WEB-INF/libs. // Copy them all in kobaltBuild/war/WEB-INF/libs and create one IncludedFile out of that directory // - val dependentProjects = listOf(ProjectDescription(project, project.projectInfo.dependsOn)) + val dependentProjects = listOf(ProjectDescription(project, project.projectExtra.dependsOn)) val allDependencies = dependencyManager.calculateDependencies(project, context, dependentProjects, project.compileDependencies)