diff --git a/.gitignore b/.gitignore index 6a15e2a0..9ea4f9ff 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,6 @@ local.properties classes libs .kobalt/ -build/ +./build/ +out +.DS_Store diff --git a/.idea/modules.xml b/.idea/modules.xml index fced32d6..a41ffd7c 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -4,7 +4,8 @@ - + + \ No newline at end of file diff --git a/kobalt.iml b/kobalt.iml index 6f84cb59..2b0a7d1a 100644 --- a/kobalt.iml +++ b/kobalt.iml @@ -1,23 +1,18 @@ - - - - + + - - + + - - - - - - + + + \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index eca4cd55..bc7f53f2 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,14 +1,19 @@ -import com.beust.kobalt.* -import com.beust.kobalt.api.* +import com.beust.kobalt.TaskResult +import com.beust.kobalt.api.License +import com.beust.kobalt.api.Project +import com.beust.kobalt.api.Scm import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.homeDir import com.beust.kobalt.plugin.application.application -import com.beust.kobalt.plugin.java.* -import com.beust.kobalt.plugin.kotlin.* +import com.beust.kobalt.plugin.java.javaCompiler +import com.beust.kobalt.plugin.java.javaProject +import com.beust.kobalt.plugin.kotlin.kotlinCompiler +import com.beust.kobalt.plugin.kotlin.kotlinProject import com.beust.kobalt.plugin.packaging.assemble import com.beust.kobalt.plugin.publish.github import com.beust.kobalt.plugin.publish.jcenter -import com.beust.kobalt.plugin.retrolambda.* +import com.beust.kobalt.repos import com.beust.kobalt.test import java.io.File import java.nio.file.Files @@ -35,25 +40,18 @@ val wrapper = javaProject { } } -// retrolambda { -// } - - productFlavor("dev") { - } - - buildType("debug") { - } - application { mainClass = "com.beust.kobalt.wrapper.Main" } } -val kobalt = kotlinProject(wrapper) { - name = "kobalt" + +val kobaltPluginApi = kotlinProject { + name = "kobalt-plugin-api" group = "com.beust" artifactId = name version = readVersion() + directory = "modules/kobalt-plugin-api" description = "A build system in Kotlin" url = "http://beust.com/kobalt" licenses = arrayListOf(License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0")) @@ -66,30 +64,78 @@ val kobalt = kotlinProject(wrapper) { } dependencies { - compile("org.jetbrains.kotlin:kotlin-stdlib:1.0.0-beta-3595", - "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-3595", - "org.jetbrains.dokka:dokka-fatjar:0.9.3", - "org.jetbrains.kotlinx:kotlinx.dom:0.0.4", + compile("org.jetbrains.kotlinx:kotlinx.dom:0.0.4", - "com.android.tools.build:builder:2.0.0-alpha3", - - "com.beust:jcommander:1.48", "com.squareup.okhttp:okhttp:2.5.0", - "org.jsoup:jsoup:1.8.3", + "com.squareup.okio:okio:1.6.0", "com.google.inject:guice:4.0", "com.google.inject.extensions:guice-assistedinject:4.0", "javax.inject:javax.inject:1", "com.google.guava:guava:19.0-rc2", "org.apache.maven:maven-model:3.3.3", - "com.github.spullara.mustache.java:compiler:0.9.1", "io.reactivex:rxjava:1.0.16", "com.google.code.gson:gson:2.4", "com.squareup.retrofit:retrofit:1.9.0", - "com.squareup.okio:okio:1.6.0" - ) + "com.beust:jcommander:1.48" + ) } + assemble { + mavenJars { + fatJar = true + manifest { + attributes("Main-Class", "com.beust.kobalt.MainKt") + } + } + } + +// install { +// libDir = "lib-test" +// } + + test { + args("-log", "1", "src/test/resources/testng.xml") + } + + kotlinCompiler { + args("-nowarn") + } + + jcenter { + publish = true + } +} + +val kobaltApp = kotlinProject(kobaltPluginApi, wrapper) { + name = "kobalt" + group = "com.beust" + artifactId = name + version = readVersion() + + dependencies { + // Used by the plugins + compile("com.android.tools.build:builder:2.0.0-alpha3", + "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-3595", + "org.jetbrains.dokka:dokka-fatjar:0.9.3") + + // Used by the main app + compile("com.github.spullara.mustache.java:compiler:0.9.1", + "com.squareup.okhttp:okhttp:2.5.0", + "javax.inject:javax.inject:1", + "com.google.inject:guice:4.0", + "com.google.inject.extensions:guice-assistedinject:4.0", + "com.beust:jcommander:1.48", + "com.squareup.retrofit:retrofit:1.9.0", + "org.apache.maven:maven-model:3.3.3", + "org.codehaus.plexus:plexus-utils:3.0.22") + + } + + dependenciesTest { + compile("org.testng:testng:6.9.9") + } + assemble { mavenJars { fatJar = true @@ -106,33 +152,17 @@ val kobalt = kotlinProject(wrapper) { } } -// install { -// libDir = "lib-test" -// } - - test { - args("-log", "1", "src/test/resources/testng.xml") - } - kotlinCompiler { args("-nowarn") } -// dokka { -// outputFormat = "markdown" -// } -// -// dokka { -// outputFormat = "html" -// } + jcenter { + publish = true + } github { file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip") } - - jcenter { - publish = true - } } fun readVersion() : String { diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index c1f897a7..8d4365a0 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=0.341 \ No newline at end of file +kobalt.version=0.346 \ No newline at end of file diff --git a/modules/kobalt-plugin-api/kobalt-plugin-api.iml b/modules/kobalt-plugin-api/kobalt-plugin-api.iml new file mode 100644 index 00000000..5562e359 --- /dev/null +++ b/modules/kobalt-plugin-api/kobalt-plugin-api.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/Args.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt diff --git a/src/main/kotlin/com/beust/kobalt/AsciiArt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/AsciiArt.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/AsciiArt.kt diff --git a/src/main/kotlin/com/beust/kobalt/BasePluginTask.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BasePluginTask.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/BasePluginTask.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BasePluginTask.kt diff --git a/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/BuildScript.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt diff --git a/src/main/kotlin/com/beust/kobalt/Constants.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/Constants.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Constants.kt diff --git a/src/main/kotlin/com/beust/kobalt/FileSpec.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/FileSpec.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt diff --git a/src/main/kotlin/com/beust/kobalt/JavaInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JavaInfo.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/JavaInfo.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JavaInfo.kt diff --git a/src/main/kotlin/com/beust/kobalt/Jvm.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/Jvm.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt diff --git a/src/main/kotlin/com/beust/kobalt/KobaltException.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/KobaltException.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/KobaltException.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/KobaltException.kt diff --git a/src/main/kotlin/com/beust/kobalt/OperatingSystem.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/OperatingSystem.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/OperatingSystem.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/OperatingSystem.kt diff --git a/src/main/kotlin/com/beust/kobalt/Plugins.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/Plugins.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt diff --git a/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt similarity index 91% rename from src/main/kotlin/com/beust/kobalt/ResolveDependency.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index 588252b9..a5ef7abb 100644 --- a/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -1,6 +1,7 @@ package com.beust.kobalt import com.beust.kobalt.api.IClasspathDependency +import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.maven.MavenId import com.beust.kobalt.maven.RepoFinder import com.beust.kobalt.maven.SimpleDep @@ -13,7 +14,7 @@ import java.util.* /** * Display information about a Maven id. */ -class ResolveDependency @Inject constructor(val repoFinder: RepoFinder) { +class ResolveDependency @Inject constructor(val repoFinder: RepoFinder, val localRepo: LocalRepo) { val increment = 8 val leftFirst = "\u2558" val leftMiddle = "\u255f" @@ -35,7 +36,8 @@ class ResolveDependency @Inject constructor(val repoFinder: RepoFinder) { val simpleDep = SimpleDep(MavenId.create(id)) val url = repoResult.hostConfig.url + simpleDep.toJarFile(repoResult) - AsciiArt.logBox(listOf(id, url).map { " $it" }, {s -> println(s) }) + val localFile = localRepo.toFullPath(simpleDep.toJarFile(repoResult)) + AsciiArt.logBox(listOf(id, url, localFile).map { " $it" }, {s -> println(s) }) display(root.children) println("") diff --git a/src/main/kotlin/com/beust/kobalt/SystemProperties.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/SystemProperties.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/SystemProperties.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/SystemProperties.kt diff --git a/src/main/kotlin/com/beust/kobalt/TaskResult.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/TaskResult.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/TaskResult.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/TaskResult.kt diff --git a/src/main/kotlin/com/beust/kobalt/Template.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Template.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/Template.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Template.kt diff --git a/src/main/kotlin/com/beust/kobalt/TestDirective.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/TestDirective.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/TestDirective.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/TestDirective.kt diff --git a/src/main/kotlin/com/beust/kobalt/Variant.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/Variant.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/BasePlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/BasePlugin.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/BasePlugin.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/BasePlugin.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/CompilerActionInfo.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ConfigPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ConfigPlugin.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ConfigPlugin.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ConfigPlugin.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ConfigsPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ConfigsPlugin.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ConfigsPlugin.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ConfigsPlugin.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IAffinity.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IAffinity.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IAffinity.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IAffinity.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IBuildConfigFieldContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigFieldContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IBuildConfigFieldContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildConfigFieldContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IClasspathContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IClasspathContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathDependency.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IClasspathInterceptor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathInterceptor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IClasspathInterceptor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IClasspathInterceptor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ICompilerFlagContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerFlagContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ICompilerFlagContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerFlagContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ICompilerInterceptor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerInterceptor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ICompilerInterceptor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ICompilerInterceptor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IDocContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IFactory.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IFactory.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IFactory.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IFactory.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IInitContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IMavenIdInterceptor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IMavenIdInterceptor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IMavenIdInterceptor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IMavenIdInterceptor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IPlugin.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IPlugin.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IPlugin.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IPluginActor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IPluginActor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IPluginActor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IPluginActor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IProjectAffinity.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IProjectAffinity.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IProjectAffinity.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IProjectAffinity.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IProjectContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IProjectContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IProjectContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IProjectContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IRepoContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRepoContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IRepoContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRepoContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/IRunnerContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ISimpleAffinity.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ISimpleAffinity.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ISimpleAffinity.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ISimpleAffinity.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoryContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoryContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ISourceDirectoryContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoryContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ITaskContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITaskContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ITaskContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITaskContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ITestRunnerContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITestRunnerContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ITestRunnerContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITestRunnerContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ITestSourceDirectoryContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITestSourceDirectoryContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ITestSourceDirectoryContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ITestSourceDirectoryContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/JarFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/JarFinder.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/JarFinder.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/JarFinder.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/Kobalt.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/PluginProperties.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/PluginProperties.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/PluginProperties.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/PluginProperties.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/PluginTask.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/PluginTask.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/PluginTask.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/PluginTask.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/Project.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/ProjectProperties.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/Task.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Task.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/Task.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Task.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/TaskContributor.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/TaskContributor.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/TaskContributor.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/TaskContributor.kt diff --git a/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/annotation/Annotations.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ActorUtils.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/DocUrl.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DocUrl.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/DocUrl.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DocUrl.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt similarity index 88% rename from src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index f6b44b14..e7b4756b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -3,10 +3,7 @@ package com.beust.kobalt.internal import com.beust.kobalt.JavaInfo import com.beust.kobalt.SystemProperties import com.beust.kobalt.TaskResult -import com.beust.kobalt.api.IClasspathDependency -import com.beust.kobalt.api.ITestRunnerContributor -import com.beust.kobalt.api.KobaltContext -import com.beust.kobalt.api.Project +import com.beust.kobalt.api.* import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.log import java.io.File @@ -14,15 +11,19 @@ import java.net.URLClassLoader /** * Base class for testing frameworks that are invoked from a main class with arguments. Test runners can - * subclass this class and override mainClass and args. + * subclass this class and override mainClass, args and the name of the dependency that should trigger this runner. */ abstract class GenericTestRunner : ITestRunnerContributor { + abstract val dependencyName : String abstract val mainClass: String abstract fun args(project: Project, classpath: List) : List override fun run(project: Project, context: KobaltContext, classpath: List) = TaskResult(runTests(project, classpath)) + override fun affinity(project: Project, context: KobaltContext) = + if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY + else 0 protected fun findTestClasses(project: Project, classpath: List): List { val path = KFiles.joinDir(project.directory, project.buildDirectory, KFiles.TEST_CLASSES_DIR) diff --git a/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt similarity index 52% rename from src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt index 5d0cb604..64350134 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt @@ -1,19 +1,13 @@ package com.beust.kobalt.internal -import com.beust.kobalt.api.IAffinity import com.beust.kobalt.api.IClasspathDependency -import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project open public class JUnitRunner() : GenericTestRunner() { override val mainClass = "org.junit.runner.JUnitCore" - open val dependencyName = "junit" - - override fun affinity(project: Project, context: KobaltContext) = - if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY - else 0 + override val dependencyName = "junit" override fun args(project: Project, classpath: List) = findTestClasses(project, classpath) } diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompiler.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt similarity index 93% rename from src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index 56e88b17..0b4f9e89 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -78,14 +78,25 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { val mavenIdInterceptors = arrayListOf() companion object { - val PLUGIN_XML = "META-INF/kobalt-plugin.xml" // Plugins.PLUGIN_XML) + /** + * Where plug-ins define their plug-in actors. + */ + val PLUGIN_XML = "META-INF/kobalt-plugin.xml" + + /** + * Kobalt's core XML file needs to be different from kobalt-plugin.xml because classloaders + * can put a plug-in's jar file in front of Kobalt's, which means we'll read + * that one instead of the core one. + */ + val PLUGIN_CORE_XML = "META-INF/kobalt-core-plugin.xml" /** * Read Kobalt's own kobalt-plugin.xml. */ fun readKobaltPluginXml(): PluginInfo { // Note: use forward slash here since we're looking up this file in a .jar file - val url = Kobalt::class.java.classLoader.getResource(PLUGIN_XML) + val url = Kobalt::class.java.classLoader.getResource(PLUGIN_CORE_XML) + log(2, "URL for core kobalt-plugin.xml: $url") if (url != null) { return readPluginXml(url.openConnection().inputStream) } else { @@ -100,6 +111,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { val jaxbContext = JAXBContext.newInstance(KobaltPluginXml::class.java) val kotlinPlugin: KobaltPluginXml = jaxbContext.createUnmarshaller().unmarshal(ins) as KobaltPluginXml + log(2, "Parsed plugin XML file, found: " + kotlinPlugin.name) return PluginInfo(kotlinPlugin, classLoader) } diff --git a/src/main/kotlin/com/beust/kobalt/internal/PluginLoader.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/PluginLoader.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/PluginLoader.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/PluginLoader.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ProjectInfo.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/SpekRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SpekRunner.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/SpekRunner.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/SpekRunner.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt similarity index 76% rename from src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 5254420a..fb2e0dba 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -1,8 +1,6 @@ package com.beust.kobalt.internal -import com.beust.kobalt.api.IAffinity import com.beust.kobalt.api.IClasspathDependency -import com.beust.kobalt.api.KobaltContext import com.beust.kobalt.api.Project import com.beust.kobalt.misc.KFiles import java.io.File @@ -11,9 +9,7 @@ public class TestNgRunner() : GenericTestRunner() { override val mainClass = "org.testng.TestNG" - override fun affinity(project: Project, context: KobaltContext) = - if (project.testDependencies.any { it.id.contains("testng")}) IAffinity.DEFAULT_POSITIVE_AFFINITY - else 0 + override val dependencyName = "org.testng" override fun args(project: Project, classpath: List) = arrayListOf().apply { if (project.testArgs.size > 0) { diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/PingCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/PingCommand.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/internal/remote/PingCommand.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/remote/PingCommand.kt diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/ArtifactFetcher.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/CompletedFuture.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/CompletedFuture.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/CompletedFuture.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/CompletedFuture.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt new file mode 100644 index 00000000..10f2e4a7 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt @@ -0,0 +1,60 @@ +package com.beust.kobalt.maven + +import com.beust.kobalt.KobaltException +import com.beust.kobalt.api.IClasspathDependency +import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.maven.dependency.FileDependency +import com.beust.kobalt.maven.dependency.MavenDependency +import com.beust.kobalt.misc.DependencyExecutor +import com.beust.kobalt.misc.KobaltExecutors +import com.google.inject.Key +import java.util.concurrent.ExecutorService +import javax.inject.Inject + +public class DepFactory @Inject constructor(val localRepo: LocalRepo, + val remoteRepo: RepoFinder, + val executors: KobaltExecutors, + val downloadManager: DownloadManager, + val pomFactory: Pom.IFactory) { + + companion object { + val defExecutor : ExecutorService by lazy { + Kobalt.INJECTOR.getInstance(Key.get(ExecutorService::class.java, DependencyExecutor::class.java)) + } + } + + /** + * Parse the id and return the correct IClasspathDependency + */ + public fun create(id: String, executor: ExecutorService = defExecutor, localFirst : Boolean = true) + : IClasspathDependency { + if (id.startsWith(FileDependency.PREFIX_FILE)) { + return FileDependency(id.substring(FileDependency.PREFIX_FILE.length)) + } else { + val mavenId = MavenId.create(id) + var tentativeVersion = mavenId.version + var packaging = mavenId.packaging + var repoResult: RepoFinder.RepoResult? + + val version = + if (tentativeVersion != null && ! MavenId.isRangedVersion(tentativeVersion)) tentativeVersion + else { + var localVersion: String? = tentativeVersion + if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging) + if (localFirst && localVersion != null) { + localVersion + } else { + repoResult = remoteRepo.findCorrectRepo(id) + if (!repoResult.found) { + throw KobaltException("Couldn't resolve $id") + } else { + repoResult.version?.version + } + } + } + + return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version), + executor, localRepo, remoteRepo, pomFactory, downloadManager) + } + } +} diff --git a/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/Gpg.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/Http.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/Http.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/Kurl.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Kurl.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/LocalDep.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalDep.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/LocalDep.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalDep.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/MavenId.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/Md5.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/Md5.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/Pom.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Pom.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/Pom.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Pom.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt similarity index 80% rename from src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt index c05ccf43..e9c99892 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/SimpleDep.kt @@ -11,20 +11,20 @@ open class SimpleDep(open val mavenId: MavenId) : UnversionedDep(mavenId.groupId val version: String get() = mavenId.version!! - private fun toFile(v: String, s: String, suffix: String) : String { + private fun toFile(v: String, snapshotVersion: String?, suffix: String) : String { val fv = if (v.contains("SNAPSHOT")) v.replace("SNAPSHOT", "") else v val result = Strings.join("/", arrayListOf(toDirectory(v, false) + - artifactId + "-" + fv + s + suffix)) + artifactId + "-" + fv + (snapshotVersion ?: "") + suffix)) return result } fun toPomFile(v: String) = toFile(v, "", ".pom") - fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion!!.version, ".pom") + fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion?.version, ".pom") fun toJarFile(v: String = version) = toFile(v, "", suffix) - fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion!!.version, suffix) + fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version!!.version, r.snapshotVersion?.version, suffix) fun toPomFileName() = "$artifactId-$version.pom" diff --git a/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/UnversionedDep.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/FileDependency.kt diff --git a/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/dependency/MavenDependency.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Benchmarks.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CountingFileRequestBody.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt new file mode 100644 index 00000000..93bb2077 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -0,0 +1,300 @@ +package com.beust.kobalt.misc + +import com.beust.kobalt.IFileSpec +import com.beust.kobalt.SystemProperties +import com.beust.kobalt.Variant +import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.api.Project +import com.beust.kobalt.homeDir +import com.beust.kobalt.internal.build.BuildFile +import java.io.File +import java.io.IOException +import java.nio.file.* +import kotlin.io.FileAlreadyExistsException +import kotlin.io.FileSystemException +import kotlin.io.NoSuchFileException + +class KFiles { + /** + * This actually returns a list of strings because in development mode, we are not pointing to a single + * jar file but to a set of /classes directories. + */ + val kobaltJar : List + get() { + val envJar = System.getenv("KOBALT_JAR") + if (envJar != null) { + debug("Using kobalt jar $envJar") + return listOf(File(envJar).absolutePath) + } else { + val jar = joinDir(distributionsDir, Kobalt.version, "kobalt/wrapper/kobalt-" + Kobalt.version + ".jar") + val jarFile = File(jar) + if (jarFile.exists()) { + return listOf(jarFile.absolutePath) + } else { + // Will only happen when building kobalt itself: the jar file might not be in the dist/ directory + // yet since we're currently building it. Instead, use the classes directly + val result = listOf("kobalt", "kobalt-plugin-api", "kobalt-wrapper").map { + File(homeDir(KFiles.joinDir("kotlin", "kobalt", "out", "production", it))).absolutePath + } + debug("Couldn't find ${jarFile.absolutePath}, using\n " + result.joinToString(" ")) + return result + } + } + } + + init { + File(KOBALT_DOT_DIR).mkdirs() + } + + companion object { + private const val KOBALT_DOT_DIR : String = ".kobalt" + const val KOBALT_DIR : String = "kobalt" + const val KOBALT_BUILD_DIR = "kobaltBuild" + + // Directories under ~/.kobalt + val localRepo = homeDir(KOBALT_DOT_DIR, "repository") + + /** Where all the .zip files are extracted */ + val distributionsDir = homeDir(KOBALT_DOT_DIR, "wrapper", "dist") + + // Directories under ./.kobalt + val SCRIPT_BUILD_DIR : String = "build" + val CLASSES_DIR : String = "classes" + + /** Where build file and support source files go, under KOBALT_DIR */ + private val SRC = "src" + + val TEST_CLASSES_DIR : String = "test-classes" + + private fun generatedDir(project: Project, variant: Variant) + = KFiles.joinDir(project.directory, project.buildDirectory, "generated", variant.toIntermediateDir()) + + fun generatedSourceDir(project: Project, variant: Variant, name: String) = + KFiles.joinDir(project.directory, project.buildDirectory, "generated", "source", name, + variant.toIntermediateDir()) + + fun buildDir(project: Project) = KFiles.makeDir(project.directory, project.buildDirectory) + + /** + * Join the paths elements with the file separator. + */ + fun joinDir(paths: List): String = paths.joinToString(File.separator) + + /** + * Join the paths elements with the file separator. + */ + fun joinDir(vararg ts: String): String = ts.toArrayList().joinToString(File.separator) + + /** + * The paths elements are expected to be a directory. Make that directory and join the + * elements with the file separator. + */ + fun joinAndMakeDir(paths: List) = joinDir(paths).apply { File(this).mkdirs() } + + /** + * The paths elements are expected to be a directory. Make that directory and join the + * elements with the file separator. + */ + fun joinAndMakeDir(vararg ts: String) = joinAndMakeDir(ts.toList()) + + /** + * The paths elements are expected to be a file. Make that parent directory of that file and join the + * elements with the file separator. + */ + fun joinFileAndMakeDir(vararg ts: String) = joinDir(joinAndMakeDir(ts.slice(0..ts.size - 2)), ts[ts.size - 1]) + + fun makeDir(dir: String, s: String? = null) = + (if (s != null) File(dir, s) else File(dir)).apply { mkdirs() } + + fun findRecursively(rootDir: File) : List = + findRecursively(rootDir, arrayListOf(), { s -> true }) + + fun findRecursively(rootDir: File, directories: List, + function: Function1): List { + var result = arrayListOf() + + val allDirs = arrayListOf() + if (directories.isEmpty()) { + allDirs.add(rootDir) + } else { + allDirs.addAll(directories.map { File(rootDir, it.path) }) + } + + val seen = hashSetOf() + allDirs.forEach { dir -> + if (! dir.exists()) { + log(2, "Couldn't find directory $dir") + } else { + val files = findRecursively(dir, function) + files.map { Paths.get(it) }.forEach { + val rel = Paths.get(dir.path).relativize(it) + if (! seen.contains(rel)) { + result.add(File(dir, rel.toFile().path).path) + seen.add(rel) + } else { + log(2, "Skipped file already seen in previous flavor: $rel") + } + } + } + } + // Return files relative to rootDir + val r = result.map { it.substring(rootDir.path.length + 1)} + return r + } + + fun findRecursively(directory: File, function: Function1): List { + var result = arrayListOf() + directory.listFiles().forEach { + if (it.isFile && function(it.path)) { + result.add(it.path) + } else if (it.isDirectory) { + result.addAll(findRecursively(it, function)) + } + } + return result + } + + fun copyRecursively(from: File, to: File, replaceExisting: Boolean = true, deleteFirst: Boolean = false, + onError: (File, IOException) -> OnErrorAction = { file, exception -> throw exception }) { + // Need to wait until copyRecursively supports an overwrite: Boolean = false parameter + // Until then, wipe everything first + if (deleteFirst) to.deleteRecursively() +// to.mkdirs() + hackCopyRecursively(from, to, replaceExisting, onError) + } + + /** Private exception class, used to terminate recursive copying */ + private class TerminateException(file: File) : FileSystemException(file) {} + + /** + * Copy/pasted from kotlin/io/Utils.kt to add support for overwriting. + */ + private fun hackCopyRecursively(from: File, dst: File, + replaceExisting: Boolean, + onError: (File, IOException) -> OnErrorAction = + { file, exception -> throw exception } + ): Boolean { + if (!from.exists()) { + return onError(from, NoSuchFileException(file = from, reason = "The source file doesn't exist")) != + OnErrorAction.TERMINATE + } + try { + // We cannot break for loop from inside a lambda, so we have to use an exception here + for (src in from.walkTopDown().fail { f, e -> if (onError(f, e) == OnErrorAction.TERMINATE) throw TerminateException(f) }) { + if (!src.exists()) { + if (onError(src, NoSuchFileException(file = src, reason = "The source file doesn't exist")) == + OnErrorAction.TERMINATE) + return false + } else { + val relPath = src.relativeTo(from) + val dstFile = File(dst, relPath) + if (dstFile.exists() && !replaceExisting && !(src.isDirectory() && dstFile.isDirectory())) { + if (onError(dstFile, FileAlreadyExistsException(file = src, + other = dstFile, + reason = "The destination file already exists")) == OnErrorAction.TERMINATE) + return false + } else if (src.isDirectory()) { + dstFile.mkdirs() + } else { + if (src.copyTo(dstFile, true) != src.length()) { + if (onError(src, IOException("src.length() != dst.length()")) == OnErrorAction.TERMINATE) + return false + } + } + } + } + return true + } catch (e: TerminateException) { + return false + } + } + + fun findDotDir(startDir: File) : File { + var result = startDir + while (result != null && ! File(result, KOBALT_DOT_DIR).exists()) { + result = result.parentFile + } + if (result == null) { + throw IllegalArgumentException("Couldn't locate $KOBALT_DOT_DIR in $startDir") + } + return File(result, KOBALT_DOT_DIR) + } + + /** + * The build location for build scripts is .kobalt/build + */ + fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String { + val result = joinDir(findDotDir(buildFile.directory).absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile) + log(2, "Script jar file: $result") + return result + } + + fun saveFile(file: File, text: String) { + file.absoluteFile.parentFile.mkdirs() + file.writeText(text) + log(2, "Wrote $file") + } + + private fun isWindows() = System.getProperty("os.name").contains("Windows"); + + fun copy(from: Path?, to: Path?, option: StandardCopyOption = StandardCopyOption.REPLACE_EXISTING) { + if (isWindows() && to!!.toFile().exists()) { + log(2, "Windows detected, not overwriting ${to}") + } else { + try { + log(2, "Copy from $from to ${to!!}") + Files.copy(from, to, option) + } catch(ex: IOException) { + // Windows is anal about this + log(1, "Couldn't copy $from to $to: ${ex.message}") + } + } + } + + fun createTempFile(suffix : String = "", deleteOnExit: Boolean = false) : File = + File.createTempFile("kobalt", suffix, File(SystemProperties.tmpDir)).let { + if (deleteOnExit) it.deleteOnExit() + return it + } + + fun src(filePath: String): String = KFiles.joinDir(KOBALT_DIR, SRC, filePath) + + fun makeDir(project: Project, suffix: String) : File { + return File(project.directory, project.buildDirectory + File.separator + suffix).apply { mkdirs() } + } + + fun makeOutputDir(project: Project) : File = makeDir(project, KFiles.CLASSES_DIR) + + fun makeOutputTestDir(project: Project) : File = makeDir(project, KFiles.TEST_CLASSES_DIR) + + fun isExcluded(file: File, excludes: List) = isExcluded(file.path, excludes) + + fun isExcluded(file: String, excludes: List) : Boolean { + if (excludes.isEmpty()) { + return false + } else { + val ex = arrayListOf() + excludes.forEach { + ex.add(FileSystems.getDefault().getPathMatcher("glob:${it.spec}")) + } + ex.forEach { + if (it.matches(Paths.get(file))) { + log(3, "Excluding $file") + return true + } + } + } + return false + } + + } + + fun findRecursively(directory: File, function: Function1): List { + return KFiles.findRecursively(directory, function) + } + + fun findRecursively(rootDir: File, directories: List, + function: Function1): List { + return KFiles.findRecursively(rootDir, directories, function) + } +} diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/LocalProperties.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/MainModule.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/Node.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Node.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/Node.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Node.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/Strings.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Strings.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/Strings.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Strings.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/ToString.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/ToString.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/ToString.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/ToString.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/Topological.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Topological.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/Topological.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Topological.kt diff --git a/src/main/kotlin/com/beust/kobalt/misc/Versions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt similarity index 100% rename from src/main/kotlin/com/beust/kobalt/misc/Versions.kt rename to modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Versions.kt diff --git a/modules/wrapper/kobalt-wrapper.iml b/modules/wrapper/kobalt-wrapper.iml new file mode 100644 index 00000000..0963114c --- /dev/null +++ b/modules/wrapper/kobalt-wrapper.iml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/modules/wrapper/modules_wrapper.iml b/modules/wrapper/modules_wrapper.iml new file mode 100644 index 00000000..2b976c0b --- /dev/null +++ b/modules/wrapper/modules_wrapper.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index 44ff5c02..fceeb162 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -116,10 +116,15 @@ private class Main @Inject constructor( val latestVersionString = latestVersionFuture.get(1, TimeUnit.SECONDS) val latestVersion = Versions.toLongVersion(latestVersionString) val current = Versions.toLongVersion(Kobalt.version) + val distFile = File(KFiles.joinDir(KFiles.distributionsDir, latestVersionString)) if (latestVersion > current) { - listOf("", "New Kobalt version available: $latestVersionString", - "To update, run ./kobaltw --update", "").forEach { - log(1, "**** $it") + if (distFile.exists()) { + log(1, "**** Version $latestVersionString is installed") + } else { + listOf("", "New Kobalt version available: $latestVersionString", + "To update, run ./kobaltw --update", "").forEach { + log(1, "**** $it") + } } } } catch(ex: TimeoutException) { diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt index b766b336..72dfe779 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt @@ -3,7 +3,9 @@ package com.beust.kobalt.app.remote import com.beust.kobalt.Args import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Project +import com.beust.kobalt.api.ProjectDescription import com.beust.kobalt.app.BuildFileCompiler +import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.internal.remote.CommandData @@ -51,15 +53,20 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors, val pluginDependencies = pluginUrls.map { File(it.toURI()) }.map { FileDependency(it.absolutePath) } projects.forEach { project -> - val allDependencies = - pluginDependencies.map { toDependencyData(it, "compile")} + - allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } + - allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "provided") } + - allDeps(project.compileRuntimeDependencies).map { toDependencyData(it, "runtime") } + - allDeps(project.testDependencies).map { toDependencyData(it, "testCompile") } + - allDeps(project.testProvidedDependencies).map { toDependencyData(it, "testProvided") } + val compileDependencies = pluginDependencies.map { toDependencyData(it, "compile")} + + allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } + val testDependencies = allDeps(project.testDependencies).map { toDependencyData(it, "testCompile") } - projectDatas.add(ProjectData(project.name, allDependencies)) + @Suppress("UNCHECKED_CAST") + val pd = (project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) + as List) + val dependentProjects = pd.filter { it.project.name == project.name }.flatMap { + it.dependsOn.map { it + .name + }} + projectDatas.add(ProjectData(project.name, project.directory, dependentProjects, + compileDependencies, testDependencies, + project.sourceDirectories, project.sourceDirectoriesTest)) } log(1, "Returning BuildScriptInfo") val result = toCommandData(Gson().toJson(GetDependenciesData(projectDatas))) @@ -73,7 +80,10 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors, class DependencyData(val id: String, val scope: String, val path: String) - class ProjectData( val name: String, val dependencies: List) + class ProjectData(val name: String, val directory: String, + val dependentProjects: List, + val compileDependencies: List, + val testDependencies: List, val sourceDirs: Set, val testDirs: Set) class GetDependenciesData(val projects: List) } \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 433c312c..1ea60c24 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -25,9 +25,9 @@ public class KobaltClient @Inject constructor() : Runnable { try { val socket = Socket("localhost", portNumber) outgoing = PrintWriter(socket.outputStream, true) - val testBuildfile = Paths.get(SystemProperties.homeDir, "java", "testng", "Build.kt") + val testBuildfile = Paths.get(SystemProperties.homeDir, "java/testng/kobalt/src/Build.kt") .toFile().absolutePath - val c : String = "{ \"name\":\"GetDependencies\", \"buildFile\": \"$testBuildfile\"}" + val c : String = "{ \"name\":\"getDependencies\", \"buildFile\": \"$testBuildfile\"}" outgoing!!.println(c) val ins = BufferedReader(InputStreamReader(socket.inputStream)) var line = ins.readLine() diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt index d65a26d1..48a76ac6 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt @@ -10,7 +10,6 @@ import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.misc.* import com.beust.kobalt.plugin.java.JavaCompiler -import com.beust.kobalt.misc.JarUtils import com.google.common.collect.HashMultimap import com.google.inject.Inject import com.google.inject.Singleton @@ -455,7 +454,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, override fun intercept(mavenId: MavenId) : MavenId = if (isAar(mavenId)) { val version = mavenId.version ?: "" - MavenId.createNoInterceptors("${mavenId.groupId}:${mavenId.artifactId}:aar:$version") + MavenId.createNoInterceptors("${mavenId.groupId}:${mavenId.artifactId}:$version@aar") } else { mavenId } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 467d8cb5..de965ccc 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.ExitCode import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import java.io.File +import java.util.* import javax.inject.Inject import javax.inject.Singleton import kotlin.properties.Delegates @@ -71,7 +72,8 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, * There are plenty of ways in which this method can break but this will be immediately * apparent if it happens. */ - private fun invokeCompiler(cp: List, allArgs: Array): Boolean { + private fun invokeCompiler(cp: List, args: Array): Boolean { + val allArgs = listOf("-module-name", "module" + Random().nextInt()) + args log(2, "Calling kotlinc " + allArgs.joinToString(" ")) val result : Boolean = if (true) { @@ -82,11 +84,11 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo, }.get(0) val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") val compilerInstance = kCompiler.newInstance() - val exitCode = compilerMain.invoke(null, compilerInstance, allArgs) + val exitCode = compilerMain.invoke(null, compilerInstance, allArgs.toTypedArray()) val nameMethod = exitCode.javaClass.getMethod("name") "OK" == nameMethod.invoke(exitCode).toString() } else { - val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs) + val exitCode = CLICompiler.doMainNoExit(K2JVMCompiler(), allArgs.toTypedArray()) exitCode == ExitCode.OK } return result diff --git a/src/main/resources/META-INF/kobalt-plugin.xml b/src/main/resources/META-INF/kobalt-core-plugin.xml similarity index 100% rename from src/main/resources/META-INF/kobalt-plugin.xml rename to src/main/resources/META-INF/kobalt-core-plugin.xml diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index af27f93c..7a171d3b 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=0.341 +kobalt.version=0.346 diff --git a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt index 4748815c..c6bc996f 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt @@ -27,7 +27,7 @@ public class DownloadTest @Inject constructor( } private fun deleteDir(): Boolean { - val dir = File(localRepo.toFullPath("$groupId")) + val dir = File(localRepo.toFullPath(groupId)) val result = dir.deleteRecursively() return result } @@ -45,7 +45,7 @@ public class DownloadTest @Inject constructor( Assert.assertTrue(file.exists()) } } else { - warn("Couldn't delete directory, not running test \"shouldDownloadNoVersion\"") + warn("Couldn't delete directory, not running test \"shouldDownloadWithVersion\"") } } @@ -65,7 +65,7 @@ public class DownloadTest @Inject constructor( val future = dep.jarFile val file = future.get() Assert.assertFalse(future is CompletedFuture) - Assert.assertEquals(file.name, jarFile) + Assert.assertNotNull(file) Assert.assertTrue(file.exists()) } else { warn("Couldn't delete directory, not running test \"shouldDownloadNoVersion\"") @@ -75,10 +75,9 @@ public class DownloadTest @Inject constructor( @Test public fun shouldDownloadRangedVersion() { File(localRepo.toFullPath("javax/servlet/servlet-api")).deleteRecursively() - testRange("[2.5,)", "3.0-alpha-1") - } + val range = "[2.5,)" + val expected = "3.0-alpha-1" - private fun testRange(range: String, expected: String) { val dep = depFactory.create("javax.servlet:servlet-api:${range}", executor) val future = dep.jarFile val file = future.get() @@ -103,8 +102,8 @@ public class DownloadTest @Inject constructor( val dep = depFactory.create(idNoVersion, executor, localFirst = false) val future = dep.jarFile val file = future.get() - Assert.assertEquals(file.name, jarFile) - Assert.assertTrue(file.exists()) + Assert.assertNotNull(file) + Assert.assertTrue(file.exists(), "Should find ${file}") } } diff --git a/tmp/Build.kt b/tmp/Build.kt new file mode 100644 index 00000000..bc7f53f2 --- /dev/null +++ b/tmp/Build.kt @@ -0,0 +1,190 @@ + +import com.beust.kobalt.TaskResult +import com.beust.kobalt.api.License +import com.beust.kobalt.api.Project +import com.beust.kobalt.api.Scm +import com.beust.kobalt.api.annotation.Task +import com.beust.kobalt.homeDir +import com.beust.kobalt.plugin.application.application +import com.beust.kobalt.plugin.java.javaCompiler +import com.beust.kobalt.plugin.java.javaProject +import com.beust.kobalt.plugin.kotlin.kotlinCompiler +import com.beust.kobalt.plugin.kotlin.kotlinProject +import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.publish.github +import com.beust.kobalt.plugin.publish.jcenter +import com.beust.kobalt.repos +import com.beust.kobalt.test +import java.io.File +import java.nio.file.Files +import java.nio.file.Paths +import java.nio.file.StandardCopyOption + +val r = repos("http://dl.bintray.com/kotlin/kotlinx.dom") + +val wrapper = javaProject { + name = "kobalt-wrapper" + version = readVersion() + directory = "modules/wrapper" + + javaCompiler { + args("-source", "1.7", "-target", "1.7") + } + + assemble { + jar { + name = projectName + ".jar" + manifest { + attributes("Main-Class", "com.beust.kobalt.wrapper.Main") + } + } + } + + application { + mainClass = "com.beust.kobalt.wrapper.Main" + } +} + + +val kobaltPluginApi = kotlinProject { + name = "kobalt-plugin-api" + group = "com.beust" + artifactId = name + version = readVersion() + directory = "modules/kobalt-plugin-api" + description = "A build system in Kotlin" + url = "http://beust.com/kobalt" + licenses = arrayListOf(License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0")) + scm = Scm(url = "http://github.com/cbeust/kobalt", + connection = "https://github.com/cbeust/kobalt.git", + developerConnection = "git@github.com:cbeust/kobalt.git") + + dependenciesTest { + compile("org.testng:testng:6.9.9") + } + + dependencies { + compile("org.jetbrains.kotlinx:kotlinx.dom:0.0.4", + + "com.squareup.okhttp:okhttp:2.5.0", + "com.squareup.okio:okio:1.6.0", + "com.google.inject:guice:4.0", + "com.google.inject.extensions:guice-assistedinject:4.0", + "javax.inject:javax.inject:1", + "com.google.guava:guava:19.0-rc2", + "org.apache.maven:maven-model:3.3.3", + "io.reactivex:rxjava:1.0.16", + "com.google.code.gson:gson:2.4", + "com.squareup.retrofit:retrofit:1.9.0", + "com.beust:jcommander:1.48" + ) + } + + + assemble { + mavenJars { + fatJar = true + manifest { + attributes("Main-Class", "com.beust.kobalt.MainKt") + } + } + } + +// install { +// libDir = "lib-test" +// } + + test { + args("-log", "1", "src/test/resources/testng.xml") + } + + kotlinCompiler { + args("-nowarn") + } + + jcenter { + publish = true + } +} + +val kobaltApp = kotlinProject(kobaltPluginApi, wrapper) { + name = "kobalt" + group = "com.beust" + artifactId = name + version = readVersion() + + dependencies { + // Used by the plugins + compile("com.android.tools.build:builder:2.0.0-alpha3", + "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-3595", + "org.jetbrains.dokka:dokka-fatjar:0.9.3") + + // Used by the main app + compile("com.github.spullara.mustache.java:compiler:0.9.1", + "com.squareup.okhttp:okhttp:2.5.0", + "javax.inject:javax.inject:1", + "com.google.inject:guice:4.0", + "com.google.inject.extensions:guice-assistedinject:4.0", + "com.beust:jcommander:1.48", + "com.squareup.retrofit:retrofit:1.9.0", + "org.apache.maven:maven-model:3.3.3", + "org.codehaus.plexus:plexus-utils:3.0.22") + + } + + dependenciesTest { + compile("org.testng:testng:6.9.9") + } + + assemble { + mavenJars { + fatJar = true + manifest { + attributes("Main-Class", "com.beust.kobalt.MainKt") + } + } + zip { + include("kobaltw") + include(from("$buildDirectory/libs"), to("kobalt/wrapper"), + "$projectName-$version.jar") + include(from("modules/wrapper/$buildDirectory/libs"), to("kobalt/wrapper"), + "$projectName-wrapper.jar") + } + } + + kotlinCompiler { + args("-nowarn") + } + + jcenter { + publish = true + } + + github { + file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip") + } +} + +fun readVersion() : String { + val p = java.util.Properties() + var localFile = java.io.File("src/main/resources/kobalt.properties") + if (! localFile.exists()) { + localFile = File(homeDir("kotlin", "kobalt", "src/main/resources/kobalt.properties")) + } + p.load(java.io.FileReader(localFile)) + return p.getProperty("kobalt.version") +} + +@Task(name = "copyVersionForWrapper", runBefore = arrayOf("assemble"), runAfter = arrayOf("compile"), description = "") +fun taskCopyVersionForWrapper(project: Project) : TaskResult { + if (project.name == "kobalt-wrapper") { + val toString = "modules/wrapper/kobaltBuild/classes" + File(toString).mkdirs() + val from = Paths.get("src/main/resources/kobalt.properties") + val to = Paths.get("$toString/kobalt.properties") + Files.copy(from, + to, + StandardCopyOption.REPLACE_EXISTING) + } + return TaskResult() +} diff --git a/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt b/tmp/DepFactory.kt similarity index 77% rename from src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt rename to tmp/DepFactory.kt index c218f9ae..48ac619f 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt +++ b/tmp/DepFactory.kt @@ -12,7 +12,7 @@ import java.util.concurrent.ExecutorService import javax.inject.Inject public class DepFactory @Inject constructor(val localRepo: LocalRepo, - val repoFinder: RepoFinder, + val remoteRepo: RepoFinder, val executors: KobaltExecutors, val downloadManager: DownloadManager, val pomFactory: Pom.IFactory) { @@ -26,8 +26,8 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo, /** * Parse the id and return the correct IClasspathDependency */ - public fun create(id: String, executor: ExecutorService = defExecutor, - localFirst : Boolean = true) : IClasspathDependency { + public fun create(id: String, executor: ExecutorService = defExecutor, localFirst : Boolean = true) + : IClasspathDependency { if (id.startsWith(FileDependency.PREFIX_FILE)) { return FileDependency(id.substring(FileDependency.PREFIX_FILE.length)) } else { @@ -36,11 +36,13 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo, var packaging = mavenId.packaging var repoResult: RepoFinder.RepoResult? - if (mavenId.version != null) { - var localVersion: String? = mavenId.version + if (version == null || MavenId.isRangedVersion(version)) { + var localVersion: String? = version if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging) - if (! localFirst || localVersion == null) { - repoResult = repoFinder.findCorrectRepo(id) + if (localFirst && localVersion != null) { + version = localVersion + } else { + repoResult = remoteRepo.findCorrectRepo(id) if (!repoResult.found) { throw KobaltException("Couldn't resolve $id") } else { @@ -49,8 +51,8 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo, } } - return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version!!), - executor, localRepo, repoFinder, pomFactory, downloadManager) + return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version), + executor, localRepo, remoteRepo, pomFactory, downloadManager) } } } diff --git a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/tmp/KFiles.kt similarity index 97% rename from src/main/kotlin/com/beust/kobalt/misc/KFiles.kt rename to tmp/KFiles.kt index 419487bd..c27949c7 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/tmp/KFiles.kt @@ -34,8 +34,10 @@ class KFiles { // Will only happen when building kobalt itself: the jar file might not be in the dist/ directory // yet since we're currently building it. Instead, use the classes directly debug("Couldn't find ${jarFile.absolutePath}, using build/classes/main") - return listOf(File(homeDir("kotlin", "kobalt", "build", "classes", "main")).absolutePath, - File(homeDir("kotlin", "kobalt", "classes", "production", "kobalt-plugin-api")).absolutePath) + val result = listOf("kobalt", "kobalt-plugin-api", "kobalt-wrapper").map { + File(homeDir(KFiles.joinDir("kotlin", "kobalt", "out", "production", it))).absolutePath + } + return result } } } diff --git a/tmp/create-new-world b/tmp/create-new-world new file mode 100755 index 00000000..4952c197 --- /dev/null +++ b/tmp/create-new-world @@ -0,0 +1,24 @@ +rm -rf modules/kobalt-plugin-api + +mkdir -p modules/kobalt-plugin-api/src + +mkdir -p modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt +for i in api internal kotlin maven misc +do + mv src/main/kotlin/com/beust/kobalt/$i modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt +done +mv src/main/kotlin/com/beust/kobalt/*kt modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt + +for i in Main.kt +do + mv modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/$i src/main/kotlin/com/beust/kobalt +done + +#mv modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/app src/main/kotlin/com/beust/kobalt + + +cp /Users/beust/t/kobalt-plugin-api.iml modules/kobalt-plugin-api + +cp tmp/Build.kt kobalt/src + +# return File(homeDir("kotlin", "kobalt", "classes", "production", "kobalt-plugin-api")).absolutePath diff --git a/tmp/kobalt-plugin-api.iml b/tmp/kobalt-plugin-api.iml new file mode 100644 index 00000000..271abfef --- /dev/null +++ b/tmp/kobalt-plugin-api.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/tmp/kobalt__Compile_.xml b/tmp/kobalt__Compile_.xml new file mode 100644 index 00000000..bf42a5b9 --- /dev/null +++ b/tmp/kobalt__Compile_.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tmp/org_testng_testng_6_9_10.xml b/tmp/org_testng_testng_6_9_10.xml new file mode 100644 index 00000000..14beb49b --- /dev/null +++ b/tmp/org_testng_testng_6_9_10.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file